Skip to content

Commit 4f89658

Browse files
authored
---
yaml --- r: 20095 b: refs/heads/autosynth-os-login c: f0efbe9 h: refs/heads/master i: 20093: ba02bb3 20091: 685db46 20087: c349cec 20079: 8406570 20063: 4f12583 20031: 15cc324 19967: b8a8707
1 parent 231b58a commit 4f89658

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
@@ -135,7 +135,7 @@ refs/heads/autosynth-firestore: d1a44f9acc302750e37b008ecb9c1aa535cc94df
135135
refs/heads/autosynth-iot: f03bdd338a9056ca3b7ea6d9ca901649ba9aab78
136136
refs/heads/autosynth-kms: 2828edfe3d2c53dd6e71912eae8a53c87bf40c87
137137
refs/heads/autosynth-language: c3d990dd34d81e7e935041e7147fb9dd27f8a557
138-
refs/heads/autosynth-os-login: ea0df60854388b161e8e38ab632c7b7791d60a27
138+
refs/heads/autosynth-os-login: f0efbe9d6cd2a5f4663865d5cb18e6c994a583c2
139139
refs/heads/autosynth-redis: 0cdb2e47359d51b73763bcea8af3de62aa99119b
140140
refs/heads/autosynth-scheduler: d97f8743ba965c7d5e492c8dc1f51d023104e260
141141
refs/heads/autosynth-spanner: 9bff86d057df31e04c76d72865e8e073ac5794fb
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+
}
Lines changed: 87 additions & 0 deletions
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)