Search in sources :

Example 1 with CloudCredentialStatus

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);
}
Also used : AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView) AmazonEC2Client(com.amazonaws.services.ec2.AmazonEC2Client) AmazonClientException(com.amazonaws.AmazonClientException) DescribeRegionsRequest(com.amazonaws.services.ec2.model.DescribeRegionsRequest) CloudCredentialStatus(com.sequenceiq.cloudbreak.cloud.model.CloudCredentialStatus)

Example 2 with CloudCredentialStatus

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);
    }
}
Also used : AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView) ExtendedCloudCredential(com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) AmazonClientException(com.amazonaws.AmazonClientException) CloudCredentialStatus(com.sequenceiq.cloudbreak.cloud.model.CloudCredentialStatus)

Example 3 with CloudCredentialStatus

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);
}
Also used : AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) CloudCredentialStatus(com.sequenceiq.cloudbreak.cloud.model.CloudCredentialStatus)

Example 4 with CloudCredentialStatus

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());
}
Also used : AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) CloudCredentialStatus(com.sequenceiq.cloudbreak.cloud.model.CloudCredentialStatus) Test(org.junit.Test)

Example 5 with CloudCredentialStatus

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());
}
Also used : CloudCredentialStatus(com.sequenceiq.cloudbreak.cloud.model.CloudCredentialStatus) Test(org.junit.Test)

Aggregations

CloudCredentialStatus (com.sequenceiq.cloudbreak.cloud.model.CloudCredentialStatus)16 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)9 Test (org.junit.Test)7 CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)3 AmazonClientException (com.amazonaws.AmazonClientException)2 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView)2 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)2 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)2 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)2 CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)2 ExtendedCloudCredential (com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential)2 Event (reactor.bus.Event)2 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)1 DescribeRegionsRequest (com.amazonaws.services.ec2.model.DescribeRegionsRequest)1 TokenResponseException (com.google.api.client.auth.oauth2.TokenResponseException)1 AzureClient (com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient)1 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)1 CredentialVerificationException (com.sequenceiq.cloudbreak.cloud.event.credential.CredentialVerificationException)1 CredentialVerificationRequest (com.sequenceiq.cloudbreak.cloud.event.credential.CredentialVerificationRequest)1 CredentialVerificationResult (com.sequenceiq.cloudbreak.cloud.event.credential.CredentialVerificationResult)1