use of com.google.cloud.kms.v1.KeyRingName in project java-storage by googleapis.
the class ITStorageTest method ensureKmsKeyExistsForTests.
private static String ensureKmsKeyExistsForTests(KeyManagementServiceBlockingStub kmsStub, String projectId, String location, String keyRingName, String keyName) throws StatusRuntimeException {
String kmsKeyResourcePath = CryptoKeyName.of(projectId, location, keyRingName, keyName).toString();
try {
// Attempt to Get CryptoKey
requestParamsHeader.put(requestParamsKey, "name=" + kmsKeyResourcePath);
GetCryptoKeyRequest getCryptoKeyRequest = GetCryptoKeyRequest.newBuilder().setName(kmsKeyResourcePath).build();
KeyManagementServiceGrpc.KeyManagementServiceBlockingStub stubForGetCryptoKey = MetadataUtils.attachHeaders(kmsStub, requestParamsHeader);
stubForGetCryptoKey.getCryptoKey(getCryptoKeyRequest);
} catch (StatusRuntimeException ex) {
if (ex.getStatus().getCode() == Status.Code.NOT_FOUND) {
String kmsKeyRingResourcePath = KeyRingName.of(projectId, location, keyRingName).toString();
CryptoKey cryptoKey = CryptoKey.newBuilder().setPurpose(CryptoKey.CryptoKeyPurpose.ENCRYPT_DECRYPT).build();
CreateCryptoKeyRequest createCryptoKeyRequest = CreateCryptoKeyRequest.newBuilder().setCryptoKeyId(keyName).setParent(kmsKeyRingResourcePath).setCryptoKey(cryptoKey).build();
requestParamsHeader.put(requestParamsKey, "parent=" + kmsKeyRingResourcePath);
KeyManagementServiceGrpc.KeyManagementServiceBlockingStub stubForCreateCryptoKey = MetadataUtils.attachHeaders(kmsStub, requestParamsHeader);
stubForCreateCryptoKey.createCryptoKey(createCryptoKeyRequest);
} else {
throw ex;
}
}
return kmsKeyResourcePath;
}
use of com.google.cloud.kms.v1.KeyRingName in project gapic-generator-java by googleapis.
the class KeyManagementServiceClientTest method listImportJobsTest.
@Test
public void listImportJobsTest() throws Exception {
ImportJob responsesElement = ImportJob.newBuilder().build();
ListImportJobsResponse expectedResponse = ListImportJobsResponse.newBuilder().setNextPageToken("").addAllImportJobs(Arrays.asList(responsesElement)).build();
mockKeyManagementService.addResponse(expectedResponse);
KeyRingName parent = KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]");
ListImportJobsPagedResponse pagedListResponse = client.listImportJobs(parent);
List<ImportJob> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getImportJobsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockKeyManagementService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListImportJobsRequest actualRequest = ((ListImportJobsRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.kms.v1.KeyRingName in project gapic-generator-java by googleapis.
the class KeyManagementServiceClientTest method listCryptoKeysTest.
@Test
public void listCryptoKeysTest() throws Exception {
CryptoKey responsesElement = CryptoKey.newBuilder().build();
ListCryptoKeysResponse expectedResponse = ListCryptoKeysResponse.newBuilder().setNextPageToken("").addAllCryptoKeys(Arrays.asList(responsesElement)).build();
mockKeyManagementService.addResponse(expectedResponse);
KeyRingName parent = KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]");
ListCryptoKeysPagedResponse pagedListResponse = client.listCryptoKeys(parent);
List<CryptoKey> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getCryptoKeysList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockKeyManagementService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListCryptoKeysRequest actualRequest = ((ListCryptoKeysRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.kms.v1.KeyRingName in project gapic-generator-java by googleapis.
the class SyncCreateImportJobKeyringnameStringImportjob method syncCreateImportJobKeyringnameStringImportjob.
public static void syncCreateImportJobKeyringnameStringImportjob() throws Exception {
// It may require modifications to work in your environment.
try (KeyManagementServiceClient keyManagementServiceClient = KeyManagementServiceClient.create()) {
KeyRingName parent = KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]");
String importJobId = "importJobId1449444627";
ImportJob importJob = ImportJob.newBuilder().build();
ImportJob response = keyManagementServiceClient.createImportJob(parent, importJobId, importJob);
}
}
use of com.google.cloud.kms.v1.KeyRingName in project gapic-generator-java by googleapis.
the class SyncCreateCryptoKeyKeyringnameStringCryptokey method syncCreateCryptoKeyKeyringnameStringCryptokey.
public static void syncCreateCryptoKeyKeyringnameStringCryptokey() throws Exception {
// It may require modifications to work in your environment.
try (KeyManagementServiceClient keyManagementServiceClient = KeyManagementServiceClient.create()) {
KeyRingName parent = KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]");
String cryptoKeyId = "cryptoKeyId-1643185255";
CryptoKey cryptoKey = CryptoKey.newBuilder().build();
CryptoKey response = keyManagementServiceClient.createCryptoKey(parent, cryptoKeyId, cryptoKey);
}
}
Aggregations