String username = getConnectionCredentials().getIdentity();
String password = getConnectionCredentials().getCredential();
if (!StringUtils.hasText(username) || !StringUtils.hasText(password)) {
throw new InvalidCredentialsException("You must supply an identity/username for cloud connections.");
}
try {
computeServiceContext = ContextBuilder.newBuilder("aws-ec2")
.credentials(username, password)
.modules(ImmutableSet.<Module>of(
new SshjSshClientModule(),
new SLF4JLoggingModule()))
.overrides(overrides)
.buildView(ComputeServiceContext.class);
// since the compute service context doesn't try to auth against AWS until it
// needs to, make a call to listNodes() to force the auth.
computeServiceContext.getComputeService().listNodes();
} catch (AuthorizationException ae) {
throw new InvalidCredentialsException(ae);
}
}
return computeServiceContext;
}