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));
}
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();
}
}
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);
}
}
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);
}
}
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;
}
Aggregations