Skip to content

Commit a9e0124

Browse files
authored
---
yaml --- r: 20715 b: refs/heads/autosynth-iamcredentials c: f0efbe9 h: refs/heads/master i: 20713: 66d901f 20711: 7276f09
1 parent 4365814 commit a9e0124

5 files changed

Lines changed: 169 additions & 1 deletion

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ refs/heads/pubsub-ordering-keys: 858d4e986a0ba48e08f00d42f51cbdecb175f5d6
162162
refs/tags/v0.75.0: c3673089ae09a897c1b4cf7dfe167fe4f8ab32fb
163163
refs/tags/v0.76.0: 395b016826d3ddf9cb8b34919636df15a4dbd032
164164
refs/tags/v0.77.0: 28a85a77883ccf5d48f297fd0ef3b3dca6ce01f0
165-
refs/heads/autosynth-iamcredentials: ea0df60854388b161e8e38ab632c7b7791d60a27
165+
refs/heads/autosynth-iamcredentials: f0efbe9d6cd2a5f4663865d5cb18e6c994a583c2
166166
refs/heads/release-google-cloud-java-v0.78.0: fae5e980779cf0173a152636b278015b9f60ee55
167167
refs/heads/release-google-cloud-java-v0.81.0: 0352cd0dd11f4fd1fbd1ff16e7a96beaccc7b475
168168
refs/heads/release-google-cloud-java-v0.81.1-SNAPSHOT: 5a74ccb1f12506a3b67b65521881298fde20bd6f
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
# Configure the docker image for kokoro-trampoline.
4+
env_vars: {
5+
key: "TRAMPOLINE_IMAGE"
6+
value: "gcr.io/cloud-devrel-kokoro-resources/java8"
7+
}
8+
9+
env_vars: {
10+
key: "INTEGRATION_TEST_ARGS"
11+
value: "google-cloud-clients/google-cloud-kms"
12+
}
13+
14+
env_vars: {
15+
key: "JOB_TYPE"
16+
value: "integration"
17+
}
18+
19+
env_vars: {
20+
key: "GCLOUD_PROJECT"
21+
value: "gcloud-devel"
22+
}
23+
24+
env_vars: {
25+
key: "GOOGLE_APPLICATION_CREDENTIALS"
26+
value: "keystore/73713_java_it_service_account"
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
# Configure the docker image for kokoro-trampoline.
4+
env_vars: {
5+
key: "TRAMPOLINE_IMAGE"
6+
value: "gcr.io/cloud-devrel-kokoro-resources/java8"
7+
}
8+
9+
env_vars: {
10+
key: "INTEGRATION_TEST_ARGS"
11+
value: "google-cloud-clients/google-cloud-kms"
12+
}
13+
14+
env_vars: {
15+
key: "JOB_TYPE"
16+
value: "integration"
17+
}
18+
19+
env_vars: {
20+
key: "GCLOUD_PROJECT"
21+
value: "gcloud-devel"
22+
}
23+
24+
env_vars: {
25+
key: "GOOGLE_APPLICATION_CREDENTIALS"
26+
value: "keystore/73713_java_it_service_account"
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
# Configure the docker image for kokoro-trampoline.
4+
env_vars: {
5+
key: "TRAMPOLINE_IMAGE"
6+
value: "gcr.io/cloud-devrel-kokoro-resources/java8"
7+
}
8+
9+
env_vars: {
10+
key: "INTEGRATION_TEST_ARGS"
11+
value: "google-cloud-clients/google-cloud-kms"
12+
}
13+
14+
env_vars: {
15+
key: "JOB_TYPE"
16+
value: "integration"
17+
}
18+
19+
env_vars: {
20+
key: "GCLOUD_PROJECT"
21+
value: "gcloud-devel"
22+
}
23+
24+
env_vars: {
25+
key: "GOOGLE_APPLICATION_CREDENTIALS"
26+
value: "keystore/73713_java_it_service_account"
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Copyright 2019 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.cloud.kms.it;
18+
19+
import com.google.auth.oauth2.GoogleCredentials;
20+
import com.google.cloud.ServiceOptions;
21+
import com.google.cloud.kms.v1.*;
22+
import io.grpc.*;
23+
import io.grpc.auth.MoreCallCredentials;
24+
import io.grpc.stub.MetadataUtils;
25+
import java.io.IOException;
26+
import org.junit.Assert;
27+
import org.junit.Before;
28+
import org.junit.Test;
29+
30+
public class ITKmsTest {
31+
private static final String KMS_KEY_RING_LOCATION = "us";
32+
private static final String KMS_KEY_RING_NAME = "gcs_test_kms_key_ring";
33+
private static Metadata requestParamsHeader = new Metadata();
34+
private static Metadata.Key<String> requestParamsKey =
35+
Metadata.Key.of("x-goog-request-params", Metadata.ASCII_STRING_MARSHALLER);
36+
private static KeyManagementServiceGrpc.KeyManagementServiceBlockingStub kmsStub;
37+
38+
@Before
39+
public void setUp() throws IOException {
40+
GoogleCredentials credentials = GoogleCredentials.getApplicationDefault();
41+
ManagedChannel kmsChannel =
42+
ManagedChannelBuilder.forTarget("cloudkms.googleapis.com:443").build();
43+
kmsStub =
44+
KeyManagementServiceGrpc.newBlockingStub(kmsChannel)
45+
.withCallCredentials(MoreCallCredentials.from(credentials));
46+
}
47+
48+
@Test
49+
public void ensureKmsKeyRingExists() {
50+
String projectId = ServiceOptions.getDefaultProjectId();
51+
KeyRing keyRing = getKeyRing(kmsStub, projectId);
52+
Assert.assertNotNull(keyRing);
53+
}
54+
55+
private static KeyRing getKeyRing(
56+
KeyManagementServiceGrpc.KeyManagementServiceBlockingStub kmsStub, String projectId)
57+
throws StatusRuntimeException {
58+
String kmsKeyRingResourcePath =
59+
KeyRingName.of(projectId, ITKmsTest.KMS_KEY_RING_LOCATION, ITKmsTest.KMS_KEY_RING_NAME)
60+
.toString();
61+
try {
62+
GetKeyRingRequest getKeyRingRequest =
63+
GetKeyRingRequest.newBuilder().setName(kmsKeyRingResourcePath).build();
64+
requestParamsHeader.put(requestParamsKey, "name=" + kmsKeyRingResourcePath);
65+
KeyManagementServiceGrpc.KeyManagementServiceBlockingStub stubForGetKeyRing =
66+
MetadataUtils.attachHeaders(kmsStub, requestParamsHeader);
67+
return stubForGetKeyRing.getKeyRing(getKeyRingRequest);
68+
} catch (StatusRuntimeException ex) {
69+
if (ex.getStatus().getCode() == Status.Code.NOT_FOUND) {
70+
String keyRingParent =
71+
LocationName.of(projectId, ITKmsTest.KMS_KEY_RING_LOCATION).toString();
72+
CreateKeyRingRequest createKeyRingRequest =
73+
CreateKeyRingRequest.newBuilder()
74+
.setParent(keyRingParent)
75+
.setKeyRingId(ITKmsTest.KMS_KEY_RING_NAME)
76+
.build();
77+
requestParamsHeader.put(requestParamsKey, "parent=" + keyRingParent);
78+
KeyManagementServiceGrpc.KeyManagementServiceBlockingStub stubForCreateKeyRing =
79+
MetadataUtils.attachHeaders(kmsStub, requestParamsHeader);
80+
return stubForCreateKeyRing.createKeyRing(createKeyRingRequest);
81+
} else {
82+
Assert.fail("Error creating or looking up key");
83+
}
84+
}
85+
return null;
86+
}
87+
}

0 commit comments

Comments
 (0)