From 3b62ca3eb8d9953274d18f1b5954483a948c19f1 Mon Sep 17 00:00:00 2001 From: arithmetic1728 Date: Tue, 20 Jul 2021 23:09:11 -0700 Subject: [PATCH] feat: add self signed jwt --- google-cloud-kms/pom.xml | 11 ++++-- .../KeyManagementServiceStubSettings.java | 2 +- .../com/google/cloud/kms/v1/sampleTest.java | 38 +++++++++++++++++++ 3 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 google-cloud-kms/src/test/java/com/google/cloud/kms/v1/sampleTest.java diff --git a/google-cloud-kms/pom.xml b/google-cloud-kms/pom.xml index dc747378..3f27e3a4 100644 --- a/google-cloud-kms/pom.xml +++ b/google-cloud-kms/pom.xml @@ -17,6 +17,11 @@ google-cloud-kms + + com.google.auth + google-auth-library-oauth2-http + 0.27.0 + io.grpc grpc-api @@ -53,10 +58,12 @@ com.google.api gax + 1.67.1-SNAPSHOT com.google.api gax-grpc + 1.67.1-SNAPSHOT org.threeten @@ -74,10 +81,6 @@ com.google.api.grpc proto-google-iam-v1 - - com.google.auth - google-auth-library-oauth2-http - diff --git a/google-cloud-kms/src/main/java/com/google/cloud/kms/v1/stub/KeyManagementServiceStubSettings.java b/google-cloud-kms/src/main/java/com/google/cloud/kms/v1/stub/KeyManagementServiceStubSettings.java index 2e60f128..8b41572b 100644 --- a/google-cloud-kms/src/main/java/com/google/cloud/kms/v1/stub/KeyManagementServiceStubSettings.java +++ b/google-cloud-kms/src/main/java/com/google/cloud/kms/v1/stub/KeyManagementServiceStubSettings.java @@ -358,7 +358,7 @@ public static List getDefaultServiceScopes() { /** Returns a builder for the default credentials for this service. */ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder() { - return GoogleCredentialsProvider.newBuilder().setScopesToApply(DEFAULT_SERVICE_SCOPES); + return GoogleCredentialsProvider.newBuilder().setScopesToApply(DEFAULT_SERVICE_SCOPES).setUseJwtAccessWithScope(true); } /** Returns a builder for the default ChannelProvider for this service. */ diff --git a/google-cloud-kms/src/test/java/com/google/cloud/kms/v1/sampleTest.java b/google-cloud-kms/src/test/java/com/google/cloud/kms/v1/sampleTest.java new file mode 100644 index 00000000..4a988116 --- /dev/null +++ b/google-cloud-kms/src/test/java/com/google/cloud/kms/v1/sampleTest.java @@ -0,0 +1,38 @@ +/* + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.kms.v1; + +import static com.google.cloud.kms.v1.KeyManagementServiceClient.ListKeyRingsPagedResponse; + +import com.google.common.collect.Lists; + +import java.util.List; +import org.junit.Test; + +public class sampleTest { + + @Test + public void myTest() throws Exception { + KeyManagementServiceSettings settings = KeyManagementServiceSettings.newBuilder().setEndpoint("cloudkms.mtls.googleapis.com:443").build(); + KeyManagementServiceClient client = KeyManagementServiceClient.create(settings); + String project = "projects/sijunliu-nondca-test/locations/global"; + + ListKeyRingsPagedResponse resp = client.listKeyRings(project); + List resources = Lists.newArrayList(resp.iterateAll()); + System.out.println(resources); + } +} \ No newline at end of file