Search in sources :

Example 6 with CustomerEncryptionKey

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());
}
Also used : CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Disk(com.google.api.services.compute.model.Disk) CustomerEncryptionKey(com.google.api.services.compute.model.CustomerEncryptionKey) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) Test(org.junit.jupiter.api.Test)

Example 7 with CustomerEncryptionKey

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);
}
Also used : ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CustomerEncryptionKey(com.google.api.services.compute.model.CustomerEncryptionKey) Test(org.junit.Test)

Example 8 with 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());
    });
}
Also used : InstanceGroup(com.google.api.services.compute.model.InstanceGroup) Group(com.sequenceiq.cloudbreak.cloud.model.Group) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) Instance(com.google.api.services.compute.model.Instance) AttachedDisk(com.google.api.services.compute.model.AttachedDisk) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) CustomerEncryptionKey(com.google.api.services.compute.model.CustomerEncryptionKey) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)

Example 9 with CustomerEncryptionKey

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);
}
Also used : ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CustomerEncryptionKey(com.google.api.services.compute.model.CustomerEncryptionKey) Test(org.junit.Test)

Example 10 with 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));
}
Also used : Disk(com.google.api.services.compute.model.Disk) 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)

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