Search in sources :

Example 1 with CloudEncryptionKey

use of com.sequenceiq.cloudbreak.cloud.model.CloudEncryptionKey in project cloudbreak by hortonworks.

the class PlatformResourceClientService method getEncryptionKeys.

public CloudEncryptionKeys getEncryptionKeys(String envCrn, String region) {
    LOGGER.info("Fetch encryption keys by environment crn: {} and region: {}", envCrn, region);
    PlatformEncryptionKeysResponse encryptionKeys = environmentPlatformResourceEndpoint.getEncryptionKeys(envCrn, region, null, null);
    Set<CloudEncryptionKey> keys = encryptionKeys.getEncryptionKeyConfigs().stream().map(response -> new CloudEncryptionKey(response.getName(), response.getId(), response.getDescription(), response.getDisplayName(), response.getProperties())).collect(Collectors.toSet());
    return new CloudEncryptionKeys(keys);
}
Also used : PlatformEncryptionKeysResponse(com.sequenceiq.environment.api.v1.platformresource.model.PlatformEncryptionKeysResponse) CloudEncryptionKey(com.sequenceiq.cloudbreak.cloud.model.CloudEncryptionKey) Inject(javax.inject.Inject) Logger(org.slf4j.Logger) Service(org.springframework.stereotype.Service) LoggerFactory(org.slf4j.LoggerFactory) CloudEncryptionKeys(com.sequenceiq.cloudbreak.cloud.model.CloudEncryptionKeys) Set(java.util.Set) EnvironmentPlatformResourceEndpoint(com.sequenceiq.environment.api.v1.platformresource.EnvironmentPlatformResourceEndpoint) PlatformEncryptionKeysResponse(com.sequenceiq.environment.api.v1.platformresource.model.PlatformEncryptionKeysResponse) CloudEncryptionKey(com.sequenceiq.cloudbreak.cloud.model.CloudEncryptionKey) Collectors(java.util.stream.Collectors) CloudEncryptionKeys(com.sequenceiq.cloudbreak.cloud.model.CloudEncryptionKeys)

Example 2 with CloudEncryptionKey

use of com.sequenceiq.cloudbreak.cloud.model.CloudEncryptionKey in project cloudbreak by hortonworks.

the class CloudEncryptionKeysToPlatformEncryptionKeysV1ResponseConverter method convert.

public PlatformEncryptionKeysResponse convert(CloudEncryptionKeys source) {
    PlatformEncryptionKeysResponse platformEncryptionKeysResponse = new PlatformEncryptionKeysResponse();
    Set<EncryptionKeyConfigResponse> result = new HashSet<>();
    for (CloudEncryptionKey entry : source.getCloudEncryptionKeys()) {
        EncryptionKeyConfigResponse actual = new EncryptionKeyConfigResponse(entry.getName(), entry.getId(), entry.getDescription(), entry.getDisplayName(), entry.getProperties());
        result.add(actual);
    }
    platformEncryptionKeysResponse.setEncryptionKeyConfigs(result);
    return platformEncryptionKeysResponse;
}
Also used : PlatformEncryptionKeysResponse(com.sequenceiq.environment.api.v1.platformresource.model.PlatformEncryptionKeysResponse) CloudEncryptionKey(com.sequenceiq.cloudbreak.cloud.model.CloudEncryptionKey) EncryptionKeyConfigResponse(com.sequenceiq.environment.api.v1.platformresource.model.EncryptionKeyConfigResponse) HashSet(java.util.HashSet)

Example 3 with CloudEncryptionKey

use of com.sequenceiq.cloudbreak.cloud.model.CloudEncryptionKey in project cloudbreak by hortonworks.

the class EncryptionKeyArnValidatorTest method testWithValidEncryptionKeyWithAwsListKeysCall.

@Test
void testWithValidEncryptionKeyWithAwsListKeysCall() {
    String validKey = "arn:aws:kms:us-east-1:012345678910:key/1234abcd-12ab-34cd-56ef-1234567890ab";
    EnvironmentDto environmentDto = createEnvironmentDto(validKey);
    EnvironmentValidationDto environmentValidationDto = EnvironmentValidationDto.builder().withEnvironmentDto(environmentDto).build();
    when(credentialToCloudCredentialConverter.convert(credential)).thenReturn(cloudCredential);
    CloudEncryptionKey testInput = new CloudEncryptionKey();
    testInput.setName("arn:aws:kms:us-east-1:012345678910:key/1234abcd-12ab-34cd-56ef-1234567890ab");
    CloudEncryptionKeys cloudEncryptionKeys = new CloudEncryptionKeys(Set.of(testInput));
    when(retryService.testWith2SecDelayMax15Times(any(Supplier.class))).thenReturn(cloudEncryptionKeys);
    ValidationResult validationResult = underTest.validate(environmentValidationDto);
    assertFalse(validationResult.hasError());
}
Also used : CloudEncryptionKey(com.sequenceiq.cloudbreak.cloud.model.CloudEncryptionKey) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) Supplier(java.util.function.Supplier) EnvironmentValidationDto(com.sequenceiq.environment.environment.dto.EnvironmentValidationDto) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) CloudEncryptionKeys(com.sequenceiq.cloudbreak.cloud.model.CloudEncryptionKeys) Test(org.junit.jupiter.api.Test)

Example 4 with CloudEncryptionKey

use of com.sequenceiq.cloudbreak.cloud.model.CloudEncryptionKey in project cloudbreak by hortonworks.

the class EncryptionKeyArnValidatorTest method testWithInvalidEncryptionKeyWithAwsListKeysCall.

@Test
void testWithInvalidEncryptionKeyWithAwsListKeysCall() {
    String invalidKey = "arn:aws:kms:us-east-1:012345678910:key/1234abcd-12ab-34cd-56ef-1234567890ab";
    EnvironmentDto environmentDto = createEnvironmentDto(invalidKey);
    EnvironmentValidationDto environmentValidationDto = EnvironmentValidationDto.builder().withEnvironmentDto(environmentDto).build();
    when(credentialToCloudCredentialConverter.convert(credential)).thenReturn(cloudCredential);
    CloudEncryptionKey testInput = new CloudEncryptionKey();
    testInput.setName("arn:aws:kms:eu-west-2:123456789012:key/1a2b3c4d-5e6f-7g8h-9i0j-1k2l3m4n5o6p");
    CloudEncryptionKeys cloudEncryptionKeys = new CloudEncryptionKeys(Set.of(testInput));
    when(retryService.testWith2SecDelayMax15Times(any(Supplier.class))).thenReturn(cloudEncryptionKeys);
    ValidationResult validationResult = underTest.validate(environmentValidationDto);
    assertTrue(validationResult.hasError());
    assertEquals(String.format("The provided encryption key does not exist in the given region's encryption key list for this credential."), validationResult.getFormattedErrors());
}
Also used : CloudEncryptionKey(com.sequenceiq.cloudbreak.cloud.model.CloudEncryptionKey) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) Supplier(java.util.function.Supplier) EnvironmentValidationDto(com.sequenceiq.environment.environment.dto.EnvironmentValidationDto) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) CloudEncryptionKeys(com.sequenceiq.cloudbreak.cloud.model.CloudEncryptionKeys) Test(org.junit.jupiter.api.Test)

Example 5 with CloudEncryptionKey

use of com.sequenceiq.cloudbreak.cloud.model.CloudEncryptionKey in project cloudbreak by hortonworks.

the class StackAwsEncryptionValidatorTest method createPlatformEncryptionKeysResponseWithNameValue.

private CloudEncryptionKeys createPlatformEncryptionKeysResponseWithNameValue() {
    CloudEncryptionKey testInput = new CloudEncryptionKey();
    testInput.setName(TEST_ENCRYPTION_KEY);
    return new CloudEncryptionKeys(Set.of(testInput));
}
Also used : CloudEncryptionKey(com.sequenceiq.cloudbreak.cloud.model.CloudEncryptionKey) CloudEncryptionKeys(com.sequenceiq.cloudbreak.cloud.model.CloudEncryptionKeys)

Aggregations

CloudEncryptionKey (com.sequenceiq.cloudbreak.cloud.model.CloudEncryptionKey)7 CloudEncryptionKeys (com.sequenceiq.cloudbreak.cloud.model.CloudEncryptionKeys)6 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)2 PlatformEncryptionKeysResponse (com.sequenceiq.environment.api.v1.platformresource.model.PlatformEncryptionKeysResponse)2 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)2 EnvironmentValidationDto (com.sequenceiq.environment.environment.dto.EnvironmentValidationDto)2 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 Supplier (java.util.function.Supplier)2 Test (org.junit.jupiter.api.Test)2 AmazonServiceException (com.amazonaws.AmazonServiceException)1 SdkClientException (com.amazonaws.SdkClientException)1 AmazonEC2Exception (com.amazonaws.services.ec2.model.AmazonEC2Exception)1 AliasListEntry (com.amazonaws.services.kms.model.AliasListEntry)1 DescribeKeyRequest (com.amazonaws.services.kms.model.DescribeKeyRequest)1 DescribeKeyResult (com.amazonaws.services.kms.model.DescribeKeyResult)1 ListAliasesRequest (com.amazonaws.services.kms.model.ListAliasesRequest)1 ListAliasesResult (com.amazonaws.services.kms.model.ListAliasesResult)1 ListKeysRequest (com.amazonaws.services.kms.model.ListKeysRequest)1 ListKeysResult (com.amazonaws.services.kms.model.ListKeysResult)1