Search in sources :

Example 1 with CloudEncryptionKeys

use of com.sequenceiq.cloudbreak.cloud.model.CloudEncryptionKeys 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 CloudEncryptionKeys

use of com.sequenceiq.cloudbreak.cloud.model.CloudEncryptionKeys 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 3 with CloudEncryptionKeys

use of com.sequenceiq.cloudbreak.cloud.model.CloudEncryptionKeys 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 4 with CloudEncryptionKeys

use of com.sequenceiq.cloudbreak.cloud.model.CloudEncryptionKeys 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)

Example 5 with CloudEncryptionKeys

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

the class CredentialPlatformResourceController method getEncryptionKeys.

@Override
@CustomPermissionCheck
public PlatformEncryptionKeysResponse getEncryptionKeys(String credentialName, String credentialCrn, String region, String platformVariant, String availabilityZone) {
    customCheckUtil.run(() -> permissionCheckByCredential(credentialName, credentialCrn));
    String accountId = getAccountId();
    PlatformResourceRequest request = platformParameterService.getPlatformResourceRequest(accountId, credentialName, credentialCrn, region, platformVariant, availabilityZone);
    LOGGER.info("Get /platform_resources/encryption_keys, request: {}", request);
    CloudEncryptionKeys encryptionKeys = platformParameterService.getEncryptionKeys(request);
    PlatformEncryptionKeysResponse response = cloudEncryptionKeysToPlatformEncryptionKeysV1ResponseConverter.convert(encryptionKeys);
    LOGGER.info("Resp /platform_resources/encryption_keys, request: {}, ipPools: {}, response: {}", request, encryptionKeys, response);
    return response;
}
Also used : PlatformEncryptionKeysResponse(com.sequenceiq.environment.api.v1.platformresource.model.PlatformEncryptionKeysResponse) PlatformResourceRequest(com.sequenceiq.environment.platformresource.PlatformResourceRequest) CloudEncryptionKeys(com.sequenceiq.cloudbreak.cloud.model.CloudEncryptionKeys) CustomPermissionCheck(com.sequenceiq.authorization.annotation.CustomPermissionCheck)

Aggregations

CloudEncryptionKeys (com.sequenceiq.cloudbreak.cloud.model.CloudEncryptionKeys)11 CloudEncryptionKey (com.sequenceiq.cloudbreak.cloud.model.CloudEncryptionKey)6 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)3 PlatformEncryptionKeysResponse (com.sequenceiq.environment.api.v1.platformresource.model.PlatformEncryptionKeysResponse)3 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)3 Test (org.junit.jupiter.api.Test)3 AliasListEntry (com.amazonaws.services.kms.model.AliasListEntry)2 DescribeKeyRequest (com.amazonaws.services.kms.model.DescribeKeyRequest)2 DescribeKeyResult (com.amazonaws.services.kms.model.DescribeKeyResult)2 ListAliasesRequest (com.amazonaws.services.kms.model.ListAliasesRequest)2 ListAliasesResult (com.amazonaws.services.kms.model.ListAliasesResult)2 ListKeysRequest (com.amazonaws.services.kms.model.ListKeysRequest)2 ListKeysResult (com.amazonaws.services.kms.model.ListKeysResult)2 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView)2 CloudPlatformVariant (com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant)2 EnvironmentValidationDto (com.sequenceiq.environment.environment.dto.EnvironmentValidationDto)2 PlatformResourceRequest (com.sequenceiq.environment.platformresource.PlatformResourceRequest)2 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 Supplier (java.util.function.Supplier)2