Search in sources :

Example 6 with AwsEnvironmentParameters

use of com.sequenceiq.environment.api.v1.environment.model.request.aws.AwsEnvironmentParameters in project cloudbreak by hortonworks.

the class EnvironmentValidatorServiceTest method testValidateAwsEnvironmentRequestNoDynamoTable.

@Test
void testValidateAwsEnvironmentRequestNoDynamoTable() {
    when(credentialService.getCloudPlatformByCredential(anyString(), anyString(), any())).thenReturn("AWS");
    EnvironmentRequest request = new EnvironmentRequest();
    request.setCredentialName("aws-credential");
    AwsEnvironmentParameters aws = new AwsEnvironmentParameters();
    aws.setS3guard(new S3GuardRequestParameters());
    request.setAws(aws);
    ValidationResult result = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.validateAwsEnvironmentRequest(request));
    assertTrue(result.hasError());
    assertEquals("S3Guard Dynamo DB table name is not found in environment request.", result.getErrors().get(0));
}
Also used : S3GuardRequestParameters(com.sequenceiq.environment.api.v1.environment.model.request.aws.S3GuardRequestParameters) AwsEnvironmentParameters(com.sequenceiq.environment.api.v1.environment.model.request.aws.AwsEnvironmentParameters) EnvironmentRequest(com.sequenceiq.environment.api.v1.environment.model.request.EnvironmentRequest) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with AwsEnvironmentParameters

use of com.sequenceiq.environment.api.v1.environment.model.request.aws.AwsEnvironmentParameters in project cloudbreak by hortonworks.

the class EnvironmentValidatorServiceTest method testValidateAwsEnvironmentRequestValid.

@Test
void testValidateAwsEnvironmentRequestValid() {
    when(credentialService.getCloudPlatformByCredential(anyString(), anyString(), any())).thenReturn("AWS");
    EnvironmentRequest request = new EnvironmentRequest();
    request.setCredentialName("aws-credential");
    AwsEnvironmentParameters aws = new AwsEnvironmentParameters();
    S3GuardRequestParameters s3GuardRequestParameters = new S3GuardRequestParameters();
    s3GuardRequestParameters.setDynamoDbTableName("table");
    aws.setS3guard(s3GuardRequestParameters);
    request.setAws(aws);
    ValidationResult result = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.validateAwsEnvironmentRequest(request));
    assertFalse(result.hasError());
}
Also used : S3GuardRequestParameters(com.sequenceiq.environment.api.v1.environment.model.request.aws.S3GuardRequestParameters) AwsEnvironmentParameters(com.sequenceiq.environment.api.v1.environment.model.request.aws.AwsEnvironmentParameters) EnvironmentRequest(com.sequenceiq.environment.api.v1.environment.model.request.EnvironmentRequest) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 8 with AwsEnvironmentParameters

use of com.sequenceiq.environment.api.v1.environment.model.request.aws.AwsEnvironmentParameters in project cloudbreak by hortonworks.

the class EnvironmentValidatorServiceTest method testValidateAwsEnvironmentNoS3GuardParams.

@Test
void testValidateAwsEnvironmentNoS3GuardParams() {
    when(credentialService.getCloudPlatformByCredential(anyString(), anyString(), any())).thenReturn("AWS");
    EnvironmentRequest request = new EnvironmentRequest();
    request.setCredentialName("aws-credential");
    request.setAws(new AwsEnvironmentParameters());
    ValidationResult result = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.validateAwsEnvironmentRequest(request));
    assertTrue(result.hasError());
    assertEquals("S3Guard Dynamo DB table name is not found in environment request.", result.getErrors().get(0));
}
Also used : AwsEnvironmentParameters(com.sequenceiq.environment.api.v1.environment.model.request.aws.AwsEnvironmentParameters) EnvironmentRequest(com.sequenceiq.environment.api.v1.environment.model.request.EnvironmentRequest) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 9 with AwsEnvironmentParameters

use of com.sequenceiq.environment.api.v1.environment.model.request.aws.AwsEnvironmentParameters in project cloudbreak by hortonworks.

the class InstanceTemplateParameterConverterTest method createDetailedEnvironmentResponseForAwsEncryption.

private DetailedEnvironmentResponse createDetailedEnvironmentResponseForAwsEncryption(boolean withAws, boolean withResourceEncryption, String environmentEncryptionKey) {
    DetailedEnvironmentResponse environment = new DetailedEnvironmentResponse();
    if (withAws) {
        AwsEnvironmentParameters parameters = new AwsEnvironmentParameters();
        environment.setAws(parameters);
        if (withResourceEncryption && ENVIRONMENT_ENCRYPTION_KEY != null) {
            AwsDiskEncryptionParameters encryption = new AwsDiskEncryptionParameters();
            parameters.setAwsDiskEncryptionParameters(encryption);
            encryption.setEncryptionKeyArn(environmentEncryptionKey);
        }
    }
    return environment;
}
Also used : AwsDiskEncryptionParameters(com.sequenceiq.environment.api.v1.environment.model.request.aws.AwsDiskEncryptionParameters) AwsEnvironmentParameters(com.sequenceiq.environment.api.v1.environment.model.request.aws.AwsEnvironmentParameters) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)

Example 10 with AwsEnvironmentParameters

use of com.sequenceiq.environment.api.v1.environment.model.request.aws.AwsEnvironmentParameters in project cloudbreak by hortonworks.

the class EnvironmentValidatorService method validateAwsEnvironmentRequest.

public ValidationResult validateAwsEnvironmentRequest(EnvironmentRequest environmentRequest) {
    ValidationResultBuilder resultBuilder = new ValidationResultBuilder();
    String accountId = ThreadBasedUserCrnProvider.getAccountId();
    String cloudPlatform = credentialService.getCloudPlatformByCredential(environmentRequest.getCredentialName(), accountId, ENVIRONMENT);
    resultBuilder.ifError(() -> !AWS.name().equalsIgnoreCase(cloudPlatform), "Environment request is not for cloud platform AWS.");
    resultBuilder.ifError(() -> StringUtils.isBlank(Optional.ofNullable(environmentRequest.getAws()).map(AwsEnvironmentParameters::getS3guard).map(S3GuardRequestParameters::getDynamoDbTableName).orElse(null)), "S3Guard Dynamo DB table name is not found in environment request.");
    return resultBuilder.build();
}
Also used : AwsEnvironmentParameters(com.sequenceiq.environment.api.v1.environment.model.request.aws.AwsEnvironmentParameters) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder)

Aggregations

AwsEnvironmentParameters (com.sequenceiq.environment.api.v1.environment.model.request.aws.AwsEnvironmentParameters)10 S3GuardRequestParameters (com.sequenceiq.environment.api.v1.environment.model.request.aws.S3GuardRequestParameters)5 Test (org.junit.jupiter.api.Test)4 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)3 EnvironmentRequest (com.sequenceiq.environment.api.v1.environment.model.request.EnvironmentRequest)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 AwsEncryptionV4Parameters (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.template.AwsEncryptionV4Parameters)2 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 FileSystemV4Endpoint (com.sequenceiq.cloudbreak.api.endpoint.v4.filesystems.FileSystemV4Endpoint)1 FileSystemParameterV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.filesystems.responses.FileSystemParameterV4Response)1 FileSystemParameterV4Responses (com.sequenceiq.cloudbreak.api.endpoint.v4.filesystems.responses.FileSystemParameterV4Responses)1 AwsInstanceTemplateV4Parameters (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.template.AwsInstanceTemplateV4Parameters)1 ClusterV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.ClusterV4Request)1 ThreadBasedUserCrnProvider (com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider)1 RegionAwareInternalCrnGenerator (com.sequenceiq.cloudbreak.auth.crn.RegionAwareInternalCrnGenerator)1 RegionAwareInternalCrnGeneratorFactory (com.sequenceiq.cloudbreak.auth.crn.RegionAwareInternalCrnGeneratorFactory)1 ValidationResultBuilder (com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder)1 CloudStorageRequest (com.sequenceiq.common.api.cloudstorage.CloudStorageRequest)1 StorageLocationBase (com.sequenceiq.common.api.cloudstorage.StorageLocationBase)1