use of com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView in project cloudbreak by hortonworks.
the class AwsPublicKeyConnector method unregister.
@Override
public void unregister(PublicKeyUnregisterRequest request) {
LOGGER.debug("Deleting public key {} in {} region on AWS", request.getPublicKeyId(), request.getRegion());
AwsCredentialView awsCredential = new AwsCredentialView(request.getCredential());
try {
AmazonEc2Client client = awsClient.createEc2Client(awsCredential, request.getRegion());
DeleteKeyPairRequest deleteKeyPairRequest = new DeleteKeyPairRequest(request.getPublicKeyId());
client.deleteKeyPair(deleteKeyPairRequest);
} catch (Exception e) {
String errorMessage = String.format("Failed to delete public key [%s: '%s', region: '%s'], detailed message: %s", getType(awsCredential), getAwsId(awsCredential), request.getRegion(), e.getMessage());
LOGGER.error(errorMessage, e);
}
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView in project cloudbreak by hortonworks.
the class AwsEfsResourceBuilder method getAmazonEfsClient.
private AmazonEfsClient getAmazonEfsClient(AuthenticatedContext auth) {
AwsCredentialView credentialView = new AwsCredentialView(auth.getCloudCredential());
String regionName = auth.getCloudContext().getLocation().getRegion().value();
return awsClient.createElasticFileSystemClient(credentialView, regionName);
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView in project cloudbreak by hortonworks.
the class AwsClient method createAuthenticatedContext.
public AuthenticatedContext createAuthenticatedContext(CloudContext cloudContext, CloudCredential cloudCredential) {
AuthenticatedContext authenticatedContext = new AuthenticatedContext(cloudContext, cloudCredential);
try {
AuthenticatedContextView authenticatedContextView = new AuthenticatedContextView(authenticatedContext);
String region = authenticatedContextView.getRegion();
AwsCredentialView awsCredentialView = authenticatedContextView.getAwsCredentialView();
AmazonEc2Client amazonEC2Client = null;
if (region != null) {
amazonEC2Client = createEc2Client(awsCredentialView, region);
AmazonElasticLoadBalancingClient loadBalancingClient = createElasticLoadBalancingClient(awsCredentialView, region);
authenticatedContext.putParameter(AmazonElasticLoadBalancingClient.class, loadBalancingClient);
} else {
amazonEC2Client = createEc2Client(awsCredentialView);
}
authenticatedContext.putParameter(AmazonEc2Client.class, amazonEC2Client);
} catch (AmazonServiceException e) {
throw new CredentialVerificationException(e.getErrorMessage(), e);
}
return authenticatedContext;
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView in project cloudbreak by hortonworks.
the class AwsCredentialConnector method verifyIamRoleIsAssumable.
private CloudCredentialStatus verifyIamRoleIsAssumable(CloudCredential cloudCredential, CredentialVerificationContext credentialVerificationContext) {
AwsCredentialView awsCredential = credentialViewProvider.createAwsCredentialView(cloudCredential);
CloudCredentialStatus credentialStatus = new CloudCredentialStatus(cloudCredential, CredentialStatus.VERIFIED);
try {
credentialClient.retrieveSessionCredentials(awsCredential);
checkRoleIsAssumableWithoutExternalId(credentialVerificationContext, awsCredential);
credentialStatus = verifyCredentialsPermission(cloudCredential, awsCredential, credentialStatus);
credentialStatus = determineDefaultRegion(cloudCredential, credentialStatus);
} catch (AmazonClientException ae) {
String errorMessage = getErrorMessageForAwsClientException(awsCredential, ae);
LOGGER.warn(errorMessage, ae);
credentialStatus = new CloudCredentialStatus(cloudCredential, CredentialStatus.FAILED, ae, errorMessage);
} catch (AwsConfusedDeputyException confusedDeputyEx) {
credentialStatus = new CloudCredentialStatus(cloudCredential, CredentialStatus.FAILED, confusedDeputyEx, confusedDeputyEx.getMessage());
} catch (RuntimeException e) {
String errorMessage = String.format("Unable to verify credential: check if the role '%s' exists and it's created with the correct external ID. " + "Cause: '%s'", awsCredential.getRoleArn(), e.getMessage());
LOGGER.warn(errorMessage, e);
credentialStatus = new CloudCredentialStatus(cloudCredential, CredentialStatus.FAILED, e, errorMessage);
}
return credentialStatus;
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView in project cloudbreak by hortonworks.
the class AwsAvailabilityZoneProvider method describeAvailabilityZones.
@Cacheable(cacheNames = "cloudResourceAzCache", key = "{ #cloudCredential?.id, #awsRegion.regionName }")
public List<AvailabilityZone> describeAvailabilityZones(CloudCredential cloudCredential, DescribeAvailabilityZonesRequest describeAvailabilityZonesRequest, com.amazonaws.services.ec2.model.Region awsRegion) {
AmazonEc2Client ec2Client = awsClient.createEc2Client(new AwsCredentialView(cloudCredential), awsRegion.getRegionName());
DescribeAvailabilityZonesResult describeAvailabilityZonesResult = ec2Client.describeAvailabilityZones(describeAvailabilityZonesRequest);
return describeAvailabilityZonesResult.getAvailabilityZones();
}
Aggregations