use of com.sequenceiq.cloudbreak.cloud.model.CloudCredentialStatus in project cloudbreak by hortonworks.
the class AwsCredentialConnector method verifyAccessKeySecretKeyIsAssumable.
private CloudCredentialStatus verifyAccessKeySecretKeyIsAssumable(CloudCredential cloudCredential) {
AwsCredentialView awsCredential = new AwsCredentialView(cloudCredential);
try {
AmazonEC2Client access = awsClient.createAccess(cloudCredential);
DescribeRegionsRequest describeRegionsRequest = new DescribeRegionsRequest();
access.describeRegions(describeRegionsRequest);
} catch (AmazonClientException ae) {
String errorMessage = "Unable to verify AWS credentials: please make sure the access key and secret key is correct";
LOGGER.error(errorMessage, ae);
return new CloudCredentialStatus(cloudCredential, CredentialStatus.FAILED, ae, errorMessage);
} catch (RuntimeException e) {
String errorMessage = String.format("Could not verify keys '%s': check if the keys exists and if it's created with the correct external ID", awsCredential.getAccessKey());
LOGGER.error(errorMessage, e);
return new CloudCredentialStatus(cloudCredential, CredentialStatus.FAILED, e, errorMessage);
}
return new CloudCredentialStatus(cloudCredential, CredentialStatus.CREATED);
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudCredentialStatus in project cloudbreak by hortonworks.
the class AwsCredentialConnector method verify.
@Override
public CloudCredentialStatus verify(AuthenticatedContext authenticatedContext) {
CloudCredential credential = authenticatedContext.getCloudCredential();
LOGGER.info("Create credential: {}", credential);
AwsCredentialView awsCredential = new AwsCredentialView(credential);
String roleArn = awsCredential.getRoleArn();
String accessKey = awsCredential.getAccessKey();
String secretKey = awsCredential.getSecretKey();
String smartSenseId = smartSenseIdGenerator.getSmartSenseId(awsCredential);
if (isNoneEmpty(smartSenseId)) {
credential.putParameter(SMART_SENSE_ID, smartSenseId);
}
if (isNoneEmpty(roleArn) && isNoneEmpty(accessKey) && isNoneEmpty(secretKey)) {
String message = "Please only provide the 'role arn' or the 'access' and 'secret key'";
return new CloudCredentialStatus(credential, CredentialStatus.FAILED, new Exception(message), message);
}
if (isNoneEmpty(roleArn)) {
return verifyIamRoleIsAssumable(credential);
}
if (isEmpty(accessKey) || isEmpty(secretKey)) {
String message = "Please provide both the 'access' and 'secret key'";
return new CloudCredentialStatus(credential, CredentialStatus.FAILED, new Exception(message), message);
} else {
return verifyAccessKeySecretKeyIsAssumable(credential);
}
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudCredentialStatus in project cloudbreak by hortonworks.
the class AzureCredentialConnector method verify.
@Override
public CloudCredentialStatus verify(AuthenticatedContext authenticatedContext) {
try {
AzureClient client = authenticatedContext.getParameter(AzureClient.class);
client.getStorageAccounts().list();
} catch (RuntimeException e) {
LOGGER.error(e.getMessage(), e);
return new CloudCredentialStatus(authenticatedContext.getCloudCredential(), CredentialStatus.FAILED, e, e.getMessage());
}
return new CloudCredentialStatus(authenticatedContext.getCloudCredential(), CredentialStatus.VERIFIED);
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudCredentialStatus in project cloudbreak by hortonworks.
the class GcpCredentialConnectorTest method testForFailedStatusBecauseMissingPrjId.
/**
* Testing the GcpContext checking mechanism. If the inner created
* GcpContext does not contains a valid project id then a FAILED
* status should come back.
*/
@Test
public void testForFailedStatusBecauseMissingPrjId() {
final AuthenticatedContext authContext = createAuthContext();
when(contextBuilder.contextInit(authContext.getCloudContext(), authContext, null, null, false)).thenReturn(context);
when(context.getProjectId()).thenReturn(null);
when(context.getServiceAccountId()).thenReturn("some service id");
final CloudCredentialStatus status = underTest.verify(authContext);
Assert.assertNotNull("The returned CloudCredentialStatus instance is null!", status);
Assert.assertEquals("Invalid credential status has specified!", CredentialStatus.FAILED, status.getStatus());
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudCredentialStatus in project cloudbreak by hortonworks.
the class GcpCredentialConnectorTest method testCreatePositive.
/**
* Test that if the create function has called with a proper
* AuthenticationContext, then the returning CredentialStatus
* should be CREATED.
*/
@Test
public void testCreatePositive() {
final CloudCredentialStatus status = underTest.create(createAuthContext());
Assert.assertNotNull("The returned CloudCredentialStatus instance is null!", status);
Assert.assertEquals("Invalid credential status has specified!", CredentialStatus.CREATED, status.getStatus());
}
Aggregations