use of com.google.api.services.compute.model.CustomerEncryptionKey in project cloudbreak by hortonworks.
the class GcpDiskResourceBuilderTest method testBuildWithDiskEncryption.
@Test
void testBuildWithDiskEncryption() throws Exception {
CustomerEncryptionKey encryptionKey = new CustomerEncryptionKey();
encryptionKey.setRawKey("rawKey==");
ArgumentCaptor<Disk> diskCaptor = ArgumentCaptor.forClass(Disk.class);
doAnswer(invocation -> {
Disk disk = invocation.getArgument(1);
disk.setDiskEncryptionKey(encryptionKey);
return invocation;
}).when(customGcpDiskEncryptionService).addEncryptionKeyToDisk(any(InstanceTemplate.class), diskCaptor.capture());
List<CloudResource> build = underTest.build(context, cloudInstance, privateId, auth, group, buildableResource, cloudStack);
assertNotNull(build);
assertEquals(1, build.size());
CloudResource resource = build.iterator().next();
assertEquals(ResourceType.GCP_DISK, resource.getType());
assertEquals(CommonStatus.REQUESTED, resource.getStatus());
assertEquals("disk", resource.getName());
assertNotNull(diskCaptor.getValue());
assertEquals(encryptionKey, diskCaptor.getValue().getDiskEncryptionKey());
}
use of com.google.api.services.compute.model.CustomerEncryptionKey in project cloudbreak by hortonworks.
the class GcpInstanceResourceBuilderTest method testStartWithRsaEncryptedKey.
@Test
public void testStartWithRsaEncryptedKey() throws Exception {
CustomerEncryptionKey customerEncryptionKey = new CustomerEncryptionKey();
customerEncryptionKey.setRawKey("HelloWorld==");
Map<String, Object> params = Map.of(InstanceTemplate.VOLUME_ENCRYPTION_KEY_TYPE, EncryptionType.CUSTOM.name(), "keyEncryptionMethod", "RSA", InstanceTemplate.VOLUME_ENCRYPTION_KEY_ID, "Hello World");
doTestCustomEncryption(params, customerEncryptionKey);
}
use of com.google.api.services.compute.model.CustomerEncryptionKey in project cloudbreak by hortonworks.
the class GcpInstanceResourceBuilderTest method doTestDiskEncryption.
private void doTestDiskEncryption(String encryptionKey, ImmutableMap<String, Object> templateParams) throws Exception {
Group group = newGroupWithParams(templateParams);
CloudResource requestedDisk = CloudResource.builder().type(ResourceType.GCP_DISK).status(CommonStatus.REQUESTED).name("dasdisk").build();
List<CloudResource> buildableResources = List.of(requestedDisk);
context.addComputeResources(0L, buildableResources);
when(compute.instances()).thenReturn(instances);
ArgumentCaptor<Instance> instanceArgumentCaptor = ArgumentCaptor.forClass(Instance.class);
when(instances.insert(anyString(), anyString(), instanceArgumentCaptor.capture())).thenReturn(insert);
when(insert.execute()).thenReturn(operation);
CustomerEncryptionKey customerEncryptionKey = new CustomerEncryptionKey();
customerEncryptionKey.setRawKey("encodedKey==");
doAnswer(invocation -> {
AttachedDisk argument = invocation.getArgument(1);
argument.setDiskEncryptionKey(customerEncryptionKey);
return invocation;
}).when(customGcpDiskEncryptionService).addEncryptionKeyToDisk(any(InstanceTemplate.class), any(AttachedDisk.class));
builder.build(context, group.getInstances().get(0), privateId, authenticatedContext, group, buildableResources, cloudStack);
verify(customGcpDiskEncryptionService, times(1)).addEncryptionKeyToDisk(any(InstanceTemplate.class), any(AttachedDisk.class));
instanceArgumentCaptor.getValue().getDisks().forEach(attachedDisk -> {
assertNotNull(attachedDisk.getDiskEncryptionKey());
assertEquals(customerEncryptionKey, attachedDisk.getDiskEncryptionKey());
});
}
use of com.google.api.services.compute.model.CustomerEncryptionKey in project cloudbreak by hortonworks.
the class GcpInstanceResourceBuilderTest method testStartWithRawEncryptedKey.
@Test
public void testStartWithRawEncryptedKey() throws Exception {
CustomerEncryptionKey customerEncryptionKey = new CustomerEncryptionKey();
customerEncryptionKey.setRawKey("HelloWorld==");
Map<String, Object> params = Map.of(InstanceTemplate.VOLUME_ENCRYPTION_KEY_TYPE, EncryptionType.CUSTOM.name(), "keyEncryptionMethod", "RAW", InstanceTemplate.VOLUME_ENCRYPTION_KEY_ID, "Hello World");
doTestCustomEncryption(params, customerEncryptionKey);
}
use of com.google.api.services.compute.model.CustomerEncryptionKey in project cloudbreak by hortonworks.
the class CustomGcpDiskEncryptionServiceTest method testAddEncryptionKeyToDiskWhenHasCustomEncryptionRequestedShouldCreateNewEncryption.
@Test
public void testAddEncryptionKeyToDiskWhenHasCustomEncryptionRequestedShouldCreateNewEncryption() {
CustomerEncryptionKey customerEncryptionKey = new CustomerEncryptionKey();
Disk disk = disk();
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));
}
Aggregations