Skip to content

Commit

Permalink
feat: Add the FakeKeyManagementServiceClient class for the testing.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 577329411
Change-Id: I826e80d546fe0069c7c10094e621e789ec7992eb
  • Loading branch information
ise-crypto authored and copybara-github committed Oct 27, 2023
1 parent 0173811 commit 3a03db5
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 4 deletions.
1 change: 1 addition & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ gen_maven_jar_rules(
"com.google.crypto.tink.integration.gcpkms",
],
deps = [
"//src/main/java/com/google/crypto/tink/integration/gcpkms:fake_key_management_service_client",
"//src/main/java/com/google/crypto/tink/integration/gcpkms:gcp_kms_aead",
"//src/main/java/com/google/crypto/tink/integration/gcpkms:gcp_kms_client",
],
Expand Down
4 changes: 2 additions & 2 deletions examples/WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
workspace(name = "tink_java_awskms_examples")
workspace(name = "tink_java_gcpkms_examples")

local_repository(
name = "tink_java_gcpkms",
Expand All @@ -23,7 +23,7 @@ maven_install(
artifacts = TINK_MAVEN_ARTIFACTS +
TINK_JAVA_GCPKMS_MAVEN_ARTIFACTS + [
"args4j:args4j:2.33",
"com.google.cloud:google-cloud-storage:2.17.2",
"com.google.cloud:google-cloud-storage:2.28.0",
],
repositories = [
"https://maven.google.com",
Expand Down
8 changes: 7 additions & 1 deletion maven/tink-java-gcpkms.pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@
<java.version>1.8</java.version>
<google-api-client.version>2.2.0</google-api-client.version>
<google-api-services-cloudkms.version>v1-rev20221107-2.0.0</google-api-services-cloudkms.version>
<google-auth-library-oauth2-http.version>1.5.3</google-auth-library-oauth2-http.version>
<google-cloud-google-cloud-kms.version>2.31.0</google-cloud-google-cloud-kms.version>
<google-auth-library-oauth2-http.version>1.20.0</google-auth-library-oauth2-http.version>
<auto-service-annotations.version>1.1.1</auto-service-annotations.version>
<jsr305.version>3.0.2</jsr305.version>
<error_prone_annotations.version>2.22.0</error_prone_annotations.version>
Expand All @@ -107,6 +108,11 @@
<artifactId>google-api-services-cloudkms</artifactId>
<version>${google-api-services-cloudkms.version}</version>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-kms</artifactId>
<version>${google-cloud-google-cloud-kms.version}</version>
</dependency>
<dependency>
<groupId>com.google.auth</groupId>
<artifactId>google-auth-library-oauth2-http</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,9 @@ java_library(
"@maven//:com_google_http_client_google_http_client_gson",
],
)

java_library(
name = "fake_key_management_service_client",
srcs = ["FakeKeyManagementServiceClient.java"],
deps = ["@maven//:com_google_cloud_google_cloud_kms"],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2023 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
//
// http://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.crypto.tink.integration.gcpkms;

import com.google.cloud.kms.v1.KeyManagementServiceClient;
import com.google.cloud.kms.v1.stub.GrpcKeyManagementServiceStub;
import com.google.cloud.kms.v1.stub.KeyManagementServiceStubSettings;
import java.security.GeneralSecurityException;

/** A partial, fake implementation of {@link com.google.cloud.kms.v1.KeyManagementServiceClient}. */
final class FakeKeyManagementServiceClient {
public FakeKeyManagementServiceClient() {}

public static KeyManagementServiceClient createKeyManagementServiceClient()
throws GeneralSecurityException {
try {
KeyManagementServiceStubSettings.Builder kmsSettingsBuilder =
KeyManagementServiceStubSettings.newBuilder();
KeyManagementServiceStubSettings kmsSettings = kmsSettingsBuilder.build();
GrpcKeyManagementServiceStub grpcKmsStub = GrpcKeyManagementServiceStub.create(kmsSettings);
return KeyManagementServiceClient.create(grpcKmsStub);
} catch (Exception e) {
throw new GeneralSecurityException("creation of FakeKeyManagementServiceClient failed", e);
}
}
}
3 changes: 2 additions & 1 deletion tink_java_gcpkms_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ TINK_JAVA_GCPKMS_MAVEN_TOOLS_ARTIFACTS = [
TINK_JAVA_GCPKMS_MAVEN_ARTIFACTS = [
"com.google.api-client:google-api-client:2.2.0",
"com.google.apis:google-api-services-cloudkms:v1-rev20221107-2.0.0",
"com.google.auth:google-auth-library-oauth2-http:1.5.3",
"com.google.auth:google-auth-library-oauth2-http:1.20.0",
"com.google.auto.service:auto-service-annotations:1.1.1",
"com.google.auto.service:auto-service:1.1.1",
"com.google.auto:auto-common:1.2.2",
"com.google.cloud:google-cloud-kms:2.31.0",
"com.google.code.findbugs:jsr305:3.0.2",
"com.google.errorprone:error_prone_annotations:2.22.0",
"com.google.http-client:google-http-client-gson:1.43.3",
Expand Down

0 comments on commit 3a03db5

Please sign in to comment.