Search in sources :

Example 11 with CustomerEncryptionKey

use of com.google.api.services.compute.model.CustomerEncryptionKey in project cloudbreak by hortonworks.

the class CustomGcpDiskEncryptionServiceTest method testAddEncryptionKeyToAttachedDiskWhenHasCustomEncryptionRequestedShouldCreateNewEncryption.

@Test
public void testAddEncryptionKeyToAttachedDiskWhenHasCustomEncryptionRequestedShouldCreateNewEncryption() {
    CustomerEncryptionKey customerEncryptionKey = new CustomerEncryptionKey();
    AttachedDisk disk = attachedDisk();
    when(customGcpDiskEncryptionCreatorService.createCustomerEncryptionKey(any(InstanceTemplate.class))).thenReturn(customerEncryptionKey);
    underTest.addEncryptionKeyToDisk(instanceTemplate(EncryptionType.CUSTOM), disk);
    Assert.assertTrue(disk.getDiskEncryptionKey().equals(customerEncryptionKey));
    verify(customGcpDiskEncryptionCreatorService, times(1)).createCustomerEncryptionKey(any(InstanceTemplate.class));
}
Also used : AttachedDisk(com.google.api.services.compute.model.AttachedDisk) CustomerEncryptionKey(com.google.api.services.compute.model.CustomerEncryptionKey) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) Test(org.junit.jupiter.api.Test)

Example 12 with CustomerEncryptionKey

use of com.google.api.services.compute.model.CustomerEncryptionKey in project cloudbreak by hortonworks.

the class GcpInstanceResourceBuilder method executeStartOperation.

private Operation executeStartOperation(String projectId, String availabilityZone, Compute compute, String instanceId, InstanceTemplate template, List<AttachedDisk> disks) throws IOException {
    if (customGcpDiskEncryptionService.hasCustomEncryptionRequested(template)) {
        CustomerEncryptionKey customerEncryptionKey = customGcpDiskEncryptionCreatorService.createCustomerEncryptionKey(template);
        List<CustomerEncryptionKeyProtectedDisk> protectedDisks = disks.stream().map(AttachedDisk::getSource).map(toCustomerEncryptionKeyProtectedDisk(customerEncryptionKey)).collect(Collectors.toList());
        InstancesStartWithEncryptionKeyRequest request = new InstancesStartWithEncryptionKeyRequest();
        request.setDisks(protectedDisks);
        return compute.instances().startWithEncryptionKey(projectId, availabilityZone, instanceId, request).setPrettyPrint(true).execute();
    } else {
        return compute.instances().start(projectId, availabilityZone, instanceId).setPrettyPrint(true).execute();
    }
}
Also used : AttachedDisk(com.google.api.services.compute.model.AttachedDisk) InstancesStartWithEncryptionKeyRequest(com.google.api.services.compute.model.InstancesStartWithEncryptionKeyRequest) CustomerEncryptionKeyProtectedDisk(com.google.api.services.compute.model.CustomerEncryptionKeyProtectedDisk) CustomerEncryptionKey(com.google.api.services.compute.model.CustomerEncryptionKey)

Example 13 with CustomerEncryptionKey

use of com.google.api.services.compute.model.CustomerEncryptionKey in project cloudbreak by hortonworks.

the class CustomGcpDiskEncryptionService method addEncryptionKeyToDisk.

public void addEncryptionKeyToDisk(InstanceTemplate template, AttachedDisk disk) {
    if (hasCustomEncryptionRequested(template)) {
        CustomerEncryptionKey customerEncryptionKey = customGcpDiskEncryptionCreatorService.createCustomerEncryptionKey(template);
        disk.setDiskEncryptionKey(customerEncryptionKey);
    }
}
Also used : CustomerEncryptionKey(com.google.api.services.compute.model.CustomerEncryptionKey)

Example 14 with CustomerEncryptionKey

use of com.google.api.services.compute.model.CustomerEncryptionKey in project cloudbreak by hortonworks.

the class CustomGcpDiskEncryptionService method addEncryptionKeyToDisk.

public void addEncryptionKeyToDisk(InstanceTemplate template, Disk disk) {
    if (hasCustomEncryptionRequested(template)) {
        CustomerEncryptionKey customerEncryptionKey = customGcpDiskEncryptionCreatorService.createCustomerEncryptionKey(template);
        disk.setDiskEncryptionKey(customerEncryptionKey);
    }
}
Also used : CustomerEncryptionKey(com.google.api.services.compute.model.CustomerEncryptionKey)

Example 15 with CustomerEncryptionKey

use of com.google.api.services.compute.model.CustomerEncryptionKey in project cloudbreak by hortonworks.

the class GcpClientActions method listVolumeEncryptionKey.

public List<String> listVolumeEncryptionKey(List<String> instanceIds) {
    List<String> encryptionKeys = new ArrayList<>();
    Compute compute = buildCompute();
    for (String instanceId : instanceIds) {
        try {
            Instance instance = compute.instances().get(getProjectId(), gcpProperties.getAvailabilityZone(), instanceId).execute();
            Optional<String> encryptionKey = instance.getDisks().stream().findFirst().map(AttachedDisk::getDiskEncryptionKey).map(CustomerEncryptionKey::getKmsKeyName);
            if (encryptionKey.isPresent()) {
                encryptionKeys.add(encryptionKey.get());
            }
        } catch (Exception e) {
            LOGGER.warn(String.format("Failed to get the details of the instance from Gcp with instance id: '%s'", instanceId), e);
        }
    }
    return encryptionKeys;
}
Also used : Instance(com.google.api.services.compute.model.Instance) Compute(com.google.api.services.compute.Compute) ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) IOException(java.io.IOException) CustomerEncryptionKey(com.google.api.services.compute.model.CustomerEncryptionKey)

Aggregations

CustomerEncryptionKey (com.google.api.services.compute.model.CustomerEncryptionKey)15 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)5 AttachedDisk (com.google.api.services.compute.model.AttachedDisk)4 Test (org.junit.jupiter.api.Test)4 Disk (com.google.api.services.compute.model.Disk)3 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)3 Test (org.junit.Test)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 Instance (com.google.api.services.compute.model.Instance)2 GoogleJsonResponseException (com.google.api.client.googleapis.json.GoogleJsonResponseException)1 Compute (com.google.api.services.compute.Compute)1 CustomerEncryptionKeyProtectedDisk (com.google.api.services.compute.model.CustomerEncryptionKeyProtectedDisk)1 InstanceGroup (com.google.api.services.compute.model.InstanceGroup)1 InstancesStartWithEncryptionKeyRequest (com.google.api.services.compute.model.InstancesStartWithEncryptionKeyRequest)1 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)1 Group (com.sequenceiq.cloudbreak.cloud.model.Group)1 TestFailException (com.sequenceiq.it.cloudbreak.exception.TestFailException)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 PublicKey (java.security.PublicKey)1