Search in sources :

Example 1 with CustomerEncryptionKey

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

the class GcpAttachedDiskResourceBuilderTest 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.CREATED, 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 2 with CustomerEncryptionKey

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

the class GcpInstanceResourceBuilderTest method testStartWithEmptyMethodRsaEncryptedKey.

@Test
public void testStartWithEmptyMethodRsaEncryptedKey() throws Exception {
    CustomerEncryptionKey customerEncryptionKey = new CustomerEncryptionKey();
    customerEncryptionKey.setRawKey("HelloWorld==");
    Map<String, Object> params = Map.of(InstanceTemplate.VOLUME_ENCRYPTION_KEY_TYPE, EncryptionType.CUSTOM.name(), 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 3 with CustomerEncryptionKey

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

the class CustomGcpDiskEncryptionCreatorService method rawKey.

private CustomerEncryptionKey rawKey(String encryptionKey) {
    CustomerEncryptionKey customerEncryptionKey = new CustomerEncryptionKey();
    customerEncryptionKey.setRawKey(encode(getEncryptionKeyBytes(encryptionKey)));
    return customerEncryptionKey;
}
Also used : CustomerEncryptionKey(com.google.api.services.compute.model.CustomerEncryptionKey)

Example 4 with CustomerEncryptionKey

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

the class CustomGcpDiskEncryptionCreatorService method rsaEncryptedKey.

private CustomerEncryptionKey rsaEncryptedKey(String encryptionKey) {
    String pemPublicKey = getGooglePublicKey();
    PublicKey publicKey = readPublicKeyFromCertificate(pemPublicKey.getBytes(StandardCharsets.UTF_8));
    byte[] rsaWrapped = encrypt(publicKey, getEncryptionKeyBytes(encryptionKey));
    CustomerEncryptionKey customerEncryptionKey = new CustomerEncryptionKey();
    customerEncryptionKey.setSha256(encode(rsaWrapped));
    return customerEncryptionKey;
}
Also used : PublicKey(java.security.PublicKey) CustomerEncryptionKey(com.google.api.services.compute.model.CustomerEncryptionKey)

Example 5 with CustomerEncryptionKey

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

the class CustomGcpDiskEncryptionCreatorService method kmsKey.

private CustomerEncryptionKey kmsKey(String kmsKeyPath) {
    CustomerEncryptionKey customerEncryptionKey = new CustomerEncryptionKey();
    customerEncryptionKey.setKmsKeyName(kmsKeyPath);
    return customerEncryptionKey;
}
Also used : 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