Search in sources :

Example 11 with CredentialPrerequisitesResponse

use of com.sequenceiq.cloudbreak.cloud.response.CredentialPrerequisitesResponse in project cloudbreak by hortonworks.

the class AzureCredentialConnectorTest method testGetPrerequisitesOnlyAzureIsImplemented.

@Test
public void testGetPrerequisitesOnlyAzureIsImplemented() {
    String expected = "someAppCreationCommandValue";
    when(appCreationCommand.generateEnvironmentCredentialCommand(anyString())).thenReturn(expected);
    CredentialPrerequisitesResponse result = underTest.getPrerequisites(TEST_CLOUD_CONTEXT, "2", "3", DEPLOYMENT_ADDRESS, CredentialType.ENVIRONMENT);
    assertNull(result.getAws());
    assertNull(result.getGcp());
    assertNotNull(result.getAzure());
}
Also used : CredentialPrerequisitesResponse(com.sequenceiq.cloudbreak.cloud.response.CredentialPrerequisitesResponse) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 12 with CredentialPrerequisitesResponse

use of com.sequenceiq.cloudbreak.cloud.response.CredentialPrerequisitesResponse in project cloudbreak by hortonworks.

the class GcpCredentialConnector method getPrerequisites.

@Override
public CredentialPrerequisitesResponse getPrerequisites(CloudContext cloudContext, String externalId, String auditExternalId, String deploymentAddress, CredentialType type) {
    String prerequisitesCreationCommand = gcpPlatformParameters.getPrerequisitesCreationCommand(type);
    GcpCredentialPrerequisites gcpPrereqs = new GcpCredentialPrerequisites(Base64.encodeBase64String(prerequisitesCreationCommand.getBytes()));
    return new CredentialPrerequisitesResponse(cloudContext.getPlatform().value(), gcpPrereqs);
}
Also used : GcpCredentialPrerequisites(com.sequenceiq.cloudbreak.cloud.response.GcpCredentialPrerequisites) CredentialPrerequisitesResponse(com.sequenceiq.cloudbreak.cloud.response.CredentialPrerequisitesResponse)

Example 13 with CredentialPrerequisitesResponse

use of com.sequenceiq.cloudbreak.cloud.response.CredentialPrerequisitesResponse in project cloudbreak by hortonworks.

the class CredentialPrerequisitesHandler method accept.

@Override
public void accept(Event<CredentialPrerequisitesRequest> credentialPrerequisitesRequestEvent) {
    LOGGER.debug("Received event: {}", credentialPrerequisitesRequestEvent);
    CredentialPrerequisitesRequest request = credentialPrerequisitesRequestEvent.getData();
    CloudContext cloudContext = request.getCloudContext();
    try {
        LOGGER.info("Gathering credential prerequisites for platform: '{}'", cloudContext.getPlatform());
        CloudConnector<?> connector = cloudPlatformConnectors.getDefault(cloudContext.getPlatform());
        CredentialPrerequisitesResponse result = connector.credentials().getPrerequisites(cloudContext, request.getExternalId(), request.getAuditExternalId(), request.getDeploymentAddress(), request.getType());
        CredentialPrerequisitesResult credentialPrerequisitesResult = new CredentialPrerequisitesResult(request.getResourceId(), result);
        request.getResult().onNext(credentialPrerequisitesResult);
        LOGGER.debug("Credential prerequisites have been collected successfully for platform: '{}'!", cloudContext.getPlatform().value());
    } catch (RuntimeException e) {
        request.getResult().onNext(new CredentialPrerequisitesResult(e.getMessage(), e, request.getResourceId()));
    }
}
Also used : CredentialPrerequisitesRequest(com.sequenceiq.cloudbreak.cloud.event.credential.CredentialPrerequisitesRequest) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CredentialPrerequisitesResponse(com.sequenceiq.cloudbreak.cloud.response.CredentialPrerequisitesResponse) CredentialPrerequisitesResult(com.sequenceiq.cloudbreak.cloud.event.credential.CredentialPrerequisitesResult)

Example 14 with CredentialPrerequisitesResponse

use of com.sequenceiq.cloudbreak.cloud.response.CredentialPrerequisitesResponse in project cloudbreak by hortonworks.

the class AzureCredentialConnector method getPrerequisites.

@Override
public CredentialPrerequisitesResponse getPrerequisites(CloudContext cloudContext, String externalId, String auditExternalId, String deploymentAddress, CredentialType type) {
    String credentialCreationCommand = appCreationCommand.generateEnvironmentCredentialCommand(deploymentAddress);
    String auditCredentialCreationCommand = appCreationCommand.generateAuditCredentialCommand(deploymentAddress);
    String encodedCommand;
    String roleDefJson;
    switch(type) {
        case ENVIRONMENT:
            roleDefJson = azurePlatformParameters.getRoleDefJson();
            encodedCommand = Base64.encodeBase64String(credentialCreationCommand.getBytes());
            break;
        case AUDIT:
            roleDefJson = azurePlatformParameters.getAuditRoleDefJson();
            encodedCommand = Base64.encodeBase64String(auditCredentialCreationCommand.getBytes());
            break;
        default:
            encodedCommand = null;
            roleDefJson = null;
            break;
    }
    AzureCredentialPrerequisites azurePrerequisites = new AzureCredentialPrerequisites(encodedCommand, roleDefJson);
    return new CredentialPrerequisitesResponse(cloudContext.getPlatform().value(), azurePrerequisites);
}
Also used : AzureCredentialPrerequisites(com.sequenceiq.cloudbreak.cloud.response.AzureCredentialPrerequisites) CredentialPrerequisitesResponse(com.sequenceiq.cloudbreak.cloud.response.CredentialPrerequisitesResponse)

Example 15 with CredentialPrerequisitesResponse

use of com.sequenceiq.cloudbreak.cloud.response.CredentialPrerequisitesResponse in project cloudbreak by hortonworks.

the class CredentialPrerequisiteService method getPrerequisites.

public CredentialPrerequisitesResponse getPrerequisites(String cloudPlatform, String deploymentAddress, CredentialType type) {
    CredentialPrerequisitesResponse result = getCloudbreakPrerequisites(cloudPlatform, deploymentAddress, type);
    if (isPolicyFetchFromExperiencesAllowed()) {
        if (AWS.name().equalsIgnoreCase(cloudPlatform)) {
            try {
                Map<String, String> policies = getExperiencePrerequisites(cloudPlatform);
                if (result.getAws().getPolicies() != null) {
                    policies.putAll(result.getAws().getPolicies());
                }
                fillPoliciesWithDefaultIfMissing(result.getAws().getPolicyJson(), policies);
                result.getAws().setPolicies(policies);
            } catch (Exception e) {
                LOGGER.warn("Something has happened during the granular policy fetch from the experiences!", e);
            }
        } else {
            LOGGER.info("Fetching is enabled but the requested prerequisites from the experiences are addressed for a currently not supported " + "cloud platform: " + cloudPlatform);
        }
    } else {
        LOGGER.info("Fetching fine graded policies from the experiences has disabled by the entitlement: " + CDP_AWS_RESTRICTED_POLICY.name());
    }
    return result;
}
Also used : CredentialPrerequisitesResponse(com.sequenceiq.cloudbreak.cloud.response.CredentialPrerequisitesResponse) BadRequestException(javax.ws.rs.BadRequestException) CredentialOperationException(com.sequenceiq.environment.credential.exception.CredentialOperationException) IOException(java.io.IOException) OperationException(com.sequenceiq.cloudbreak.service.OperationException)

Aggregations

CredentialPrerequisitesResponse (com.sequenceiq.cloudbreak.cloud.response.CredentialPrerequisitesResponse)15 Test (org.junit.jupiter.api.Test)6 GcpCredentialPrerequisites (com.sequenceiq.cloudbreak.cloud.response.GcpCredentialPrerequisites)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 AwsCredentialPrerequisites (com.sequenceiq.cloudbreak.cloud.response.AwsCredentialPrerequisites)2 AzureCredentialPrerequisites (com.sequenceiq.cloudbreak.cloud.response.AzureCredentialPrerequisites)2 OperationException (com.sequenceiq.cloudbreak.service.OperationException)2 CredentialOperationException (com.sequenceiq.environment.credential.exception.CredentialOperationException)2 IOException (java.io.IOException)2 BadRequestException (javax.ws.rs.BadRequestException)2 Test (org.junit.Test)2 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)1 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)1 CredentialPrerequisitesRequest (com.sequenceiq.cloudbreak.cloud.event.credential.CredentialPrerequisitesRequest)1 CredentialPrerequisitesResult (com.sequenceiq.cloudbreak.cloud.event.credential.CredentialPrerequisitesResult)1