diff --git a/README.md b/README.md index 50b86332..f144e547 100644 --- a/README.md +++ b/README.md @@ -57,13 +57,13 @@ implementation 'com.google.cloud:google-cloud-kms' If you are using Gradle without BOM, add this to your dependencies ```Groovy -implementation 'com.google.cloud:google-cloud-kms:2.5.2' +implementation 'com.google.cloud:google-cloud-kms:2.5.3' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-kms" % "2.5.2" +libraryDependencies += "com.google.cloud" % "google-cloud-kms" % "2.5.3" ``` ## Authentication diff --git a/google-cloud-kms/pom.xml b/google-cloud-kms/pom.xml index a409998a..eab85522 100644 --- a/google-cloud-kms/pom.xml +++ b/google-cloud-kms/pom.xml @@ -58,6 +58,10 @@ com.google.api gax-grpc + + com.google.api + gax-httpjson + org.threeten threetenbp @@ -102,12 +106,24 @@ test + + com.google.api + gax + testlib + test + com.google.api gax-grpc testlib test + + com.google.api + gax-httpjson + testlib + test + diff --git a/google-cloud-kms/src/main/java/com/google/cloud/kms/v1/EkmServiceClient.java b/google-cloud-kms/src/main/java/com/google/cloud/kms/v1/EkmServiceClient.java index a65cd65d..29eb6840 100644 --- a/google-cloud-kms/src/main/java/com/google/cloud/kms/v1/EkmServiceClient.java +++ b/google-cloud-kms/src/main/java/com/google/cloud/kms/v1/EkmServiceClient.java @@ -109,6 +109,20 @@ * EkmServiceClient ekmServiceClient = EkmServiceClient.create(ekmServiceSettings); * } * + *

To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over + * the wire: + * + *

{@code
+ * // This snippet has been automatically generated for illustrative purposes only.
+ * // It may require modifications to work in your environment.
+ * EkmServiceSettings ekmServiceSettings =
+ *     EkmServiceSettings.newBuilder()
+ *         .setTransportChannelProvider(
+ *             EkmServiceSettings.defaultHttpJsonTransportProviderBuilder().build())
+ *         .build();
+ * EkmServiceClient ekmServiceClient = EkmServiceClient.create(ekmServiceSettings);
+ * }
+ * *

Please refer to the GitHub repository's samples for more quickstart code snippets. */ @Generated("by gapic-generator-java") diff --git a/google-cloud-kms/src/main/java/com/google/cloud/kms/v1/EkmServiceSettings.java b/google-cloud-kms/src/main/java/com/google/cloud/kms/v1/EkmServiceSettings.java index 68ceab57..35fcb467 100644 --- a/google-cloud-kms/src/main/java/com/google/cloud/kms/v1/EkmServiceSettings.java +++ b/google-cloud-kms/src/main/java/com/google/cloud/kms/v1/EkmServiceSettings.java @@ -23,6 +23,7 @@ import com.google.api.gax.core.GoogleCredentialsProvider; import com.google.api.gax.core.InstantiatingExecutorProvider; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; import com.google.api.gax.rpc.ApiClientHeaderProvider; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.ClientSettings; @@ -139,11 +140,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde return EkmServiceStubSettings.defaultCredentialsProviderBuilder(); } - /** Returns a builder for the default ChannelProvider for this service. */ + /** Returns a builder for the default gRPC ChannelProvider for this service. */ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { return EkmServiceStubSettings.defaultGrpcTransportProviderBuilder(); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return EkmServiceStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return EkmServiceStubSettings.defaultTransportChannelProvider(); } @@ -153,11 +161,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil return EkmServiceStubSettings.defaultApiClientHeaderProviderBuilder(); } - /** Returns a new builder for this class. */ + /** Returns a new gRPC builder for this class. */ public static Builder newBuilder() { return Builder.createDefault(); } + /** Returns a new REST builder for this class. */ + @BetaApi + public static Builder newHttpJsonBuilder() { + return Builder.createHttpJsonDefault(); + } + /** Returns a new builder for this class. */ public static Builder newBuilder(ClientContext clientContext) { return new Builder(clientContext); @@ -195,6 +209,11 @@ private static Builder createDefault() { return new Builder(EkmServiceStubSettings.newBuilder()); } + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(EkmServiceStubSettings.newHttpJsonBuilder()); + } + public EkmServiceStubSettings.Builder getStubSettingsBuilder() { return ((EkmServiceStubSettings.Builder) getStubSettings()); } diff --git a/google-cloud-kms/src/main/java/com/google/cloud/kms/v1/KeyManagementServiceClient.java b/google-cloud-kms/src/main/java/com/google/cloud/kms/v1/KeyManagementServiceClient.java index f6b33437..42ee4c12 100644 --- a/google-cloud-kms/src/main/java/com/google/cloud/kms/v1/KeyManagementServiceClient.java +++ b/google-cloud-kms/src/main/java/com/google/cloud/kms/v1/KeyManagementServiceClient.java @@ -121,6 +121,21 @@ * KeyManagementServiceClient.create(keyManagementServiceSettings); * } * + *

To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over + * the wire: + * + *

{@code
+ * // This snippet has been automatically generated for illustrative purposes only.
+ * // It may require modifications to work in your environment.
+ * KeyManagementServiceSettings keyManagementServiceSettings =
+ *     KeyManagementServiceSettings.newBuilder()
+ *         .setTransportChannelProvider(
+ *             KeyManagementServiceSettings.defaultHttpJsonTransportProviderBuilder().build())
+ *         .build();
+ * KeyManagementServiceClient keyManagementServiceClient =
+ *     KeyManagementServiceClient.create(keyManagementServiceSettings);
+ * }
+ * *

Please refer to the GitHub repository's samples for more quickstart code snippets. */ @Generated("by gapic-generator-java") diff --git a/google-cloud-kms/src/main/java/com/google/cloud/kms/v1/KeyManagementServiceSettings.java b/google-cloud-kms/src/main/java/com/google/cloud/kms/v1/KeyManagementServiceSettings.java index 1cf8e55d..ef7bafd6 100644 --- a/google-cloud-kms/src/main/java/com/google/cloud/kms/v1/KeyManagementServiceSettings.java +++ b/google-cloud-kms/src/main/java/com/google/cloud/kms/v1/KeyManagementServiceSettings.java @@ -26,6 +26,7 @@ import com.google.api.gax.core.GoogleCredentialsProvider; import com.google.api.gax.core.InstantiatingExecutorProvider; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; import com.google.api.gax.rpc.ApiClientHeaderProvider; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.ClientSettings; @@ -270,11 +271,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde return KeyManagementServiceStubSettings.defaultCredentialsProviderBuilder(); } - /** Returns a builder for the default ChannelProvider for this service. */ + /** Returns a builder for the default gRPC ChannelProvider for this service. */ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { return KeyManagementServiceStubSettings.defaultGrpcTransportProviderBuilder(); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return KeyManagementServiceStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return KeyManagementServiceStubSettings.defaultTransportChannelProvider(); } @@ -284,11 +292,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil return KeyManagementServiceStubSettings.defaultApiClientHeaderProviderBuilder(); } - /** Returns a new builder for this class. */ + /** Returns a new gRPC builder for this class. */ public static Builder newBuilder() { return Builder.createDefault(); } + /** Returns a new REST builder for this class. */ + @BetaApi + public static Builder newHttpJsonBuilder() { + return Builder.createHttpJsonDefault(); + } + /** Returns a new builder for this class. */ public static Builder newBuilder(ClientContext clientContext) { return new Builder(clientContext); @@ -327,6 +341,11 @@ private static Builder createDefault() { return new Builder(KeyManagementServiceStubSettings.newBuilder()); } + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(KeyManagementServiceStubSettings.newHttpJsonBuilder()); + } + public KeyManagementServiceStubSettings.Builder getStubSettingsBuilder() { return ((KeyManagementServiceStubSettings.Builder) getStubSettings()); } diff --git a/google-cloud-kms/src/main/java/com/google/cloud/kms/v1/stub/EkmServiceStubSettings.java b/google-cloud-kms/src/main/java/com/google/cloud/kms/v1/stub/EkmServiceStubSettings.java index 04b4131d..fe7f6434 100644 --- a/google-cloud-kms/src/main/java/com/google/cloud/kms/v1/stub/EkmServiceStubSettings.java +++ b/google-cloud-kms/src/main/java/com/google/cloud/kms/v1/stub/EkmServiceStubSettings.java @@ -27,6 +27,9 @@ import com.google.api.gax.grpc.GaxGrpcProperties; import com.google.api.gax.grpc.GrpcTransportChannel; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.HttpJsonTransportChannel; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; import com.google.api.gax.retrying.RetrySettings; import com.google.api.gax.rpc.ApiCallContext; import com.google.api.gax.rpc.ApiClientHeaderProvider; @@ -222,6 +225,11 @@ public EkmServiceStub createStub() throws IOException { .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcEkmServiceStub.create(this); } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonEkmServiceStub.create(this); + } throw new UnsupportedOperationException( String.format( "Transport not supported: %s", getTransportChannelProvider().getTransportName())); @@ -254,18 +262,25 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde .setUseJwtAccessWithScope(true); } - /** Returns a builder for the default ChannelProvider for this service. */ + /** Returns a builder for the default gRPC ChannelProvider for this service. */ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { return InstantiatingGrpcChannelProvider.newBuilder() .setMaxInboundMessageSize(Integer.MAX_VALUE); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return InstantiatingHttpJsonChannelProvider.newBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return defaultGrpcTransportProviderBuilder().build(); } @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") - public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + public static ApiClientHeaderProvider.Builder defaultGrpcApiClientHeaderProviderBuilder() { return ApiClientHeaderProvider.newBuilder() .setGeneratedLibToken( "gapic", GaxProperties.getLibraryVersion(EkmServiceStubSettings.class)) @@ -273,11 +288,30 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion()); } - /** Returns a new builder for this class. */ + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultHttpJsonApiClientHeaderProviderBuilder() { + return ApiClientHeaderProvider.newBuilder() + .setGeneratedLibToken( + "gapic", GaxProperties.getLibraryVersion(EkmServiceStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return EkmServiceStubSettings.defaultGrpcApiClientHeaderProviderBuilder(); + } + + /** Returns a new gRPC builder for this class. */ public static Builder newBuilder() { return Builder.createDefault(); } + /** Returns a new REST builder for this class. */ + public static Builder newHttpJsonBuilder() { + return Builder.createHttpJsonDefault(); + } + /** Returns a new builder for this class. */ public static Builder newBuilder(ClientContext clientContext) { return new Builder(clientContext); @@ -411,6 +445,19 @@ private static Builder createDefault() { return initDefaults(builder); } + private static Builder createHttpJsonDefault() { + Builder builder = new Builder(((ClientContext) null)); + + builder.setTransportChannelProvider(defaultHttpJsonTransportProviderBuilder().build()); + builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); + builder.setInternalHeaderProvider(defaultHttpJsonApiClientHeaderProviderBuilder().build()); + builder.setEndpoint(getDefaultEndpoint()); + builder.setMtlsEndpoint(getDefaultMtlsEndpoint()); + builder.setSwitchToMtlsEndpointAllowed(true); + + return initDefaults(builder); + } + private static Builder initDefaults(Builder builder) { builder .listEkmConnectionsSettings() diff --git a/google-cloud-kms/src/main/java/com/google/cloud/kms/v1/stub/HttpJsonEkmServiceCallableFactory.java b/google-cloud-kms/src/main/java/com/google/cloud/kms/v1/stub/HttpJsonEkmServiceCallableFactory.java new file mode 100644 index 00000000..056c8636 --- /dev/null +++ b/google-cloud-kms/src/main/java/com/google/cloud/kms/v1/stub/HttpJsonEkmServiceCallableFactory.java @@ -0,0 +1,105 @@ +/* + * Copyright 2022 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.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonCallableFactory; +import com.google.api.gax.httpjson.HttpJsonOperationSnapshotCallable; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.httpjson.longrunning.stub.OperationsStub; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST callable factory implementation for the EkmService service API. + * + *

This class is for advanced usage. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonEkmServiceCallableFactory + implements HttpJsonStubCallableFactory { + + @Override + public UnaryCallable createUnaryCallable( + HttpJsonCallSettings httpJsonCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createUnaryCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + HttpJsonCallSettings httpJsonCallSettings, + PagedCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createPagedCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + HttpJsonCallSettings httpJsonCallSettings, + BatchingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createBatchingCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + @Override + public + OperationCallable createOperationCallable( + HttpJsonCallSettings httpJsonCallSettings, + OperationCallSettings callSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + UnaryCallable innerCallable = + HttpJsonCallableFactory.createBaseUnaryCallable( + httpJsonCallSettings, callSettings.getInitialCallSettings(), clientContext); + HttpJsonOperationSnapshotCallable initialCallable = + new HttpJsonOperationSnapshotCallable( + innerCallable, + httpJsonCallSettings.getMethodDescriptor().getOperationSnapshotFactory()); + return HttpJsonCallableFactory.createOperationCallable( + callSettings, clientContext, operationsStub.longRunningClient(), initialCallable); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + HttpJsonCallSettings httpJsonCallSettings, + ServerStreamingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createServerStreamingCallable( + httpJsonCallSettings, callSettings, clientContext); + } +} diff --git a/google-cloud-kms/src/main/java/com/google/cloud/kms/v1/stub/HttpJsonEkmServiceStub.java b/google-cloud-kms/src/main/java/com/google/cloud/kms/v1/stub/HttpJsonEkmServiceStub.java new file mode 100644 index 00000000..8c09067e --- /dev/null +++ b/google-cloud-kms/src/main/java/com/google/cloud/kms/v1/stub/HttpJsonEkmServiceStub.java @@ -0,0 +1,553 @@ +/* + * Copyright 2022 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.stub; + +import static com.google.cloud.kms.v1.EkmServiceClient.ListEkmConnectionsPagedResponse; + +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.core.BackgroundResourceAggregation; +import com.google.api.gax.httpjson.ApiMethodDescriptor; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.httpjson.ProtoMessageRequestFormatter; +import com.google.api.gax.httpjson.ProtoMessageResponseParser; +import com.google.api.gax.httpjson.ProtoRestSerializer; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.cloud.kms.v1.CreateEkmConnectionRequest; +import com.google.cloud.kms.v1.EkmConnection; +import com.google.cloud.kms.v1.GetEkmConnectionRequest; +import com.google.cloud.kms.v1.ListEkmConnectionsRequest; +import com.google.cloud.kms.v1.ListEkmConnectionsResponse; +import com.google.cloud.kms.v1.UpdateEkmConnectionRequest; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; +import com.google.protobuf.TypeRegistry; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST stub implementation for the EkmService service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonEkmServiceStub extends EkmServiceStub { + private static final TypeRegistry typeRegistry = TypeRegistry.newBuilder().build(); + + private static final ApiMethodDescriptor + listEkmConnectionsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.kms.v1.EkmService/ListEkmConnections") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=projects/*/locations/*}/ekmConnections", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "filter", request.getFilter()); + serializer.putQueryParam(fields, "orderBy", request.getOrderBy()); + serializer.putQueryParam(fields, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListEkmConnectionsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + getEkmConnectionMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.kms.v1.EkmService/GetEkmConnection") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/ekmConnections/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(EkmConnection.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + createEkmConnectionMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.kms.v1.EkmService/CreateEkmConnection") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=projects/*/locations/*}/ekmConnections", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam( + fields, "ekmConnectionId", request.getEkmConnectionId()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("ekmConnection", request.getEkmConnection())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(EkmConnection.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + updateEkmConnectionMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.kms.v1.EkmService/UpdateEkmConnection") + .setHttpMethod("PATCH") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{ekmConnection.name=projects/*/locations/*/ekmConnections/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam( + fields, "ekmConnection.name", request.getEkmConnection().getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "updateMask", request.getUpdateMask()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("ekmConnection", request.getEkmConnection())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(EkmConnection.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + setIamPolicyMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.iam.v1.IAMPolicy/SetIamPolicy") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{resource=projects/*/locations/*/keyRings/*}:setIamPolicy", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "resource", request.getResource()); + return fields; + }) + .setAdditionalPaths( + "/v1/{resource=projects/*/locations/*/keyRings/*/cryptoKeys/*}:setIamPolicy", + "/v1/{resource=projects/*/locations/*/keyRings/*/importJobs/*}:setIamPolicy", + "/v1/{resource=projects/*/locations/*/ekmConnections/*}:setIamPolicy") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearResource().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Policy.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + getIamPolicyMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.iam.v1.IAMPolicy/GetIamPolicy") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{resource=projects/*/locations/*/keyRings/*}:getIamPolicy", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "resource", request.getResource()); + return fields; + }) + .setAdditionalPaths( + "/v1/{resource=projects/*/locations/*/keyRings/*/cryptoKeys/*}:getIamPolicy", + "/v1/{resource=projects/*/locations/*/keyRings/*/importJobs/*}:getIamPolicy", + "/v1/{resource=projects/*/locations/*/ekmConnections/*}:getIamPolicy") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Policy.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + testIamPermissionsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.iam.v1.IAMPolicy/TestIamPermissions") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{resource=projects/*/locations/*/keyRings/*}:testIamPermissions", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "resource", request.getResource()); + return fields; + }) + .setAdditionalPaths( + "/v1/{resource=projects/*/locations/*/keyRings/*/cryptoKeys/*}:testIamPermissions", + "/v1/{resource=projects/*/locations/*/keyRings/*/importJobs/*}:testIamPermissions", + "/v1/{resource=projects/*/locations/*/ekmConnections/*}:testIamPermissions") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearResource().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(TestIamPermissionsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private final UnaryCallable + listEkmConnectionsCallable; + private final UnaryCallable + listEkmConnectionsPagedCallable; + private final UnaryCallable getEkmConnectionCallable; + private final UnaryCallable + createEkmConnectionCallable; + private final UnaryCallable + updateEkmConnectionCallable; + private final UnaryCallable setIamPolicyCallable; + private final UnaryCallable getIamPolicyCallable; + private final UnaryCallable + testIamPermissionsCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonEkmServiceStub create(EkmServiceStubSettings settings) + throws IOException { + return new HttpJsonEkmServiceStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonEkmServiceStub create(ClientContext clientContext) + throws IOException { + return new HttpJsonEkmServiceStub( + EkmServiceStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonEkmServiceStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonEkmServiceStub( + EkmServiceStubSettings.newHttpJsonBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of HttpJsonEkmServiceStub, using the given settings. This is protected + * so that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected HttpJsonEkmServiceStub(EkmServiceStubSettings settings, ClientContext clientContext) + throws IOException { + this(settings, clientContext, new HttpJsonEkmServiceCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonEkmServiceStub, using the given settings. This is protected + * so that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected HttpJsonEkmServiceStub( + EkmServiceStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + + HttpJsonCallSettings + listEkmConnectionsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listEkmConnectionsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getEkmConnectionTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getEkmConnectionMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + createEkmConnectionTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(createEkmConnectionMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + updateEkmConnectionTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(updateEkmConnectionMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings setIamPolicyTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(setIamPolicyMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getIamPolicyTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getIamPolicyMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + testIamPermissionsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(testIamPermissionsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + + this.listEkmConnectionsCallable = + callableFactory.createUnaryCallable( + listEkmConnectionsTransportSettings, + settings.listEkmConnectionsSettings(), + clientContext); + this.listEkmConnectionsPagedCallable = + callableFactory.createPagedCallable( + listEkmConnectionsTransportSettings, + settings.listEkmConnectionsSettings(), + clientContext); + this.getEkmConnectionCallable = + callableFactory.createUnaryCallable( + getEkmConnectionTransportSettings, settings.getEkmConnectionSettings(), clientContext); + this.createEkmConnectionCallable = + callableFactory.createUnaryCallable( + createEkmConnectionTransportSettings, + settings.createEkmConnectionSettings(), + clientContext); + this.updateEkmConnectionCallable = + callableFactory.createUnaryCallable( + updateEkmConnectionTransportSettings, + settings.updateEkmConnectionSettings(), + clientContext); + this.setIamPolicyCallable = + callableFactory.createUnaryCallable( + setIamPolicyTransportSettings, settings.setIamPolicySettings(), clientContext); + this.getIamPolicyCallable = + callableFactory.createUnaryCallable( + getIamPolicyTransportSettings, settings.getIamPolicySettings(), clientContext); + this.testIamPermissionsCallable = + callableFactory.createUnaryCallable( + testIamPermissionsTransportSettings, + settings.testIamPermissionsSettings(), + clientContext); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(listEkmConnectionsMethodDescriptor); + methodDescriptors.add(getEkmConnectionMethodDescriptor); + methodDescriptors.add(createEkmConnectionMethodDescriptor); + methodDescriptors.add(updateEkmConnectionMethodDescriptor); + methodDescriptors.add(setIamPolicyMethodDescriptor); + methodDescriptors.add(getIamPolicyMethodDescriptor); + methodDescriptors.add(testIamPermissionsMethodDescriptor); + return methodDescriptors; + } + + @Override + public UnaryCallable + listEkmConnectionsCallable() { + return listEkmConnectionsCallable; + } + + @Override + public UnaryCallable + listEkmConnectionsPagedCallable() { + return listEkmConnectionsPagedCallable; + } + + @Override + public UnaryCallable getEkmConnectionCallable() { + return getEkmConnectionCallable; + } + + @Override + public UnaryCallable createEkmConnectionCallable() { + return createEkmConnectionCallable; + } + + @Override + public UnaryCallable updateEkmConnectionCallable() { + return updateEkmConnectionCallable; + } + + @Override + public UnaryCallable setIamPolicyCallable() { + return setIamPolicyCallable; + } + + @Override + public UnaryCallable getIamPolicyCallable() { + return getIamPolicyCallable; + } + + @Override + public UnaryCallable + testIamPermissionsCallable() { + return testIamPermissionsCallable; + } + + @Override + public final void close() { + try { + backgroundResources.close(); + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + throw new IllegalStateException("Failed to close resource", e); + } + } + + @Override + public void shutdown() { + backgroundResources.shutdown(); + } + + @Override + public boolean isShutdown() { + return backgroundResources.isShutdown(); + } + + @Override + public boolean isTerminated() { + return backgroundResources.isTerminated(); + } + + @Override + public void shutdownNow() { + backgroundResources.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return backgroundResources.awaitTermination(duration, unit); + } +} diff --git a/google-cloud-kms/src/main/java/com/google/cloud/kms/v1/stub/HttpJsonKeyManagementServiceCallableFactory.java b/google-cloud-kms/src/main/java/com/google/cloud/kms/v1/stub/HttpJsonKeyManagementServiceCallableFactory.java new file mode 100644 index 00000000..79b5e535 --- /dev/null +++ b/google-cloud-kms/src/main/java/com/google/cloud/kms/v1/stub/HttpJsonKeyManagementServiceCallableFactory.java @@ -0,0 +1,105 @@ +/* + * Copyright 2022 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.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonCallableFactory; +import com.google.api.gax.httpjson.HttpJsonOperationSnapshotCallable; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.httpjson.longrunning.stub.OperationsStub; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST callable factory implementation for the KeyManagementService service API. + * + *

This class is for advanced usage. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonKeyManagementServiceCallableFactory + implements HttpJsonStubCallableFactory { + + @Override + public UnaryCallable createUnaryCallable( + HttpJsonCallSettings httpJsonCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createUnaryCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + HttpJsonCallSettings httpJsonCallSettings, + PagedCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createPagedCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + HttpJsonCallSettings httpJsonCallSettings, + BatchingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createBatchingCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + @Override + public + OperationCallable createOperationCallable( + HttpJsonCallSettings httpJsonCallSettings, + OperationCallSettings callSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + UnaryCallable innerCallable = + HttpJsonCallableFactory.createBaseUnaryCallable( + httpJsonCallSettings, callSettings.getInitialCallSettings(), clientContext); + HttpJsonOperationSnapshotCallable initialCallable = + new HttpJsonOperationSnapshotCallable( + innerCallable, + httpJsonCallSettings.getMethodDescriptor().getOperationSnapshotFactory()); + return HttpJsonCallableFactory.createOperationCallable( + callSettings, clientContext, operationsStub.longRunningClient(), initialCallable); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + HttpJsonCallSettings httpJsonCallSettings, + ServerStreamingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createServerStreamingCallable( + httpJsonCallSettings, callSettings, clientContext); + } +} diff --git a/google-cloud-kms/src/main/java/com/google/cloud/kms/v1/stub/HttpJsonKeyManagementServiceStub.java b/google-cloud-kms/src/main/java/com/google/cloud/kms/v1/stub/HttpJsonKeyManagementServiceStub.java new file mode 100644 index 00000000..edf57a62 --- /dev/null +++ b/google-cloud-kms/src/main/java/com/google/cloud/kms/v1/stub/HttpJsonKeyManagementServiceStub.java @@ -0,0 +1,1795 @@ +/* + * Copyright 2022 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.stub; + +import static com.google.cloud.kms.v1.KeyManagementServiceClient.ListCryptoKeyVersionsPagedResponse; +import static com.google.cloud.kms.v1.KeyManagementServiceClient.ListCryptoKeysPagedResponse; +import static com.google.cloud.kms.v1.KeyManagementServiceClient.ListImportJobsPagedResponse; +import static com.google.cloud.kms.v1.KeyManagementServiceClient.ListKeyRingsPagedResponse; + +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.core.BackgroundResourceAggregation; +import com.google.api.gax.httpjson.ApiMethodDescriptor; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.httpjson.ProtoMessageRequestFormatter; +import com.google.api.gax.httpjson.ProtoMessageResponseParser; +import com.google.api.gax.httpjson.ProtoRestSerializer; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.cloud.kms.v1.AsymmetricDecryptRequest; +import com.google.cloud.kms.v1.AsymmetricDecryptResponse; +import com.google.cloud.kms.v1.AsymmetricSignRequest; +import com.google.cloud.kms.v1.AsymmetricSignResponse; +import com.google.cloud.kms.v1.CreateCryptoKeyRequest; +import com.google.cloud.kms.v1.CreateCryptoKeyVersionRequest; +import com.google.cloud.kms.v1.CreateImportJobRequest; +import com.google.cloud.kms.v1.CreateKeyRingRequest; +import com.google.cloud.kms.v1.CryptoKey; +import com.google.cloud.kms.v1.CryptoKeyVersion; +import com.google.cloud.kms.v1.DecryptRequest; +import com.google.cloud.kms.v1.DecryptResponse; +import com.google.cloud.kms.v1.DestroyCryptoKeyVersionRequest; +import com.google.cloud.kms.v1.EncryptRequest; +import com.google.cloud.kms.v1.EncryptResponse; +import com.google.cloud.kms.v1.GenerateRandomBytesRequest; +import com.google.cloud.kms.v1.GenerateRandomBytesResponse; +import com.google.cloud.kms.v1.GetCryptoKeyRequest; +import com.google.cloud.kms.v1.GetCryptoKeyVersionRequest; +import com.google.cloud.kms.v1.GetImportJobRequest; +import com.google.cloud.kms.v1.GetKeyRingRequest; +import com.google.cloud.kms.v1.GetPublicKeyRequest; +import com.google.cloud.kms.v1.ImportCryptoKeyVersionRequest; +import com.google.cloud.kms.v1.ImportJob; +import com.google.cloud.kms.v1.KeyRing; +import com.google.cloud.kms.v1.ListCryptoKeyVersionsRequest; +import com.google.cloud.kms.v1.ListCryptoKeyVersionsResponse; +import com.google.cloud.kms.v1.ListCryptoKeysRequest; +import com.google.cloud.kms.v1.ListCryptoKeysResponse; +import com.google.cloud.kms.v1.ListImportJobsRequest; +import com.google.cloud.kms.v1.ListImportJobsResponse; +import com.google.cloud.kms.v1.ListKeyRingsRequest; +import com.google.cloud.kms.v1.ListKeyRingsResponse; +import com.google.cloud.kms.v1.MacSignRequest; +import com.google.cloud.kms.v1.MacSignResponse; +import com.google.cloud.kms.v1.MacVerifyRequest; +import com.google.cloud.kms.v1.MacVerifyResponse; +import com.google.cloud.kms.v1.PublicKey; +import com.google.cloud.kms.v1.RestoreCryptoKeyVersionRequest; +import com.google.cloud.kms.v1.UpdateCryptoKeyPrimaryVersionRequest; +import com.google.cloud.kms.v1.UpdateCryptoKeyRequest; +import com.google.cloud.kms.v1.UpdateCryptoKeyVersionRequest; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; +import com.google.protobuf.TypeRegistry; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST stub implementation for the KeyManagementService service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonKeyManagementServiceStub extends KeyManagementServiceStub { + private static final TypeRegistry typeRegistry = TypeRegistry.newBuilder().build(); + + private static final ApiMethodDescriptor + listKeyRingsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.kms.v1.KeyManagementService/ListKeyRings") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=projects/*/locations/*}/keyRings", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "filter", request.getFilter()); + serializer.putQueryParam(fields, "orderBy", request.getOrderBy()); + serializer.putQueryParam(fields, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListKeyRingsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + listCryptoKeysMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.kms.v1.KeyManagementService/ListCryptoKeys") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=projects/*/locations/*/keyRings/*}/cryptoKeys", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "filter", request.getFilter()); + serializer.putQueryParam(fields, "orderBy", request.getOrderBy()); + serializer.putQueryParam(fields, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + serializer.putQueryParam( + fields, "versionView", request.getVersionView()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListCryptoKeysResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor< + ListCryptoKeyVersionsRequest, ListCryptoKeyVersionsResponse> + listCryptoKeyVersionsMethodDescriptor = + ApiMethodDescriptor + .newBuilder() + .setFullMethodName("google.cloud.kms.v1.KeyManagementService/ListCryptoKeyVersions") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=projects/*/locations/*/keyRings/*/cryptoKeys/*}/cryptoKeyVersions", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "filter", request.getFilter()); + serializer.putQueryParam(fields, "orderBy", request.getOrderBy()); + serializer.putQueryParam(fields, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + serializer.putQueryParam(fields, "view", request.getView()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListCryptoKeyVersionsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + listImportJobsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.kms.v1.KeyManagementService/ListImportJobs") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=projects/*/locations/*/keyRings/*}/importJobs", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "filter", request.getFilter()); + serializer.putQueryParam(fields, "orderBy", request.getOrderBy()); + serializer.putQueryParam(fields, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListImportJobsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor getKeyRingMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.kms.v1.KeyManagementService/GetKeyRing") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/keyRings/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(KeyRing.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + getCryptoKeyMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.kms.v1.KeyManagementService/GetCryptoKey") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/keyRings/*/cryptoKeys/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(CryptoKey.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + getCryptoKeyVersionMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.kms.v1.KeyManagementService/GetCryptoKeyVersion") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/keyRings/*/cryptoKeys/*/cryptoKeyVersions/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(CryptoKeyVersion.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + getPublicKeyMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.kms.v1.KeyManagementService/GetPublicKey") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/keyRings/*/cryptoKeys/*/cryptoKeyVersions/*}/publicKey", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(PublicKey.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + getImportJobMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.kms.v1.KeyManagementService/GetImportJob") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/keyRings/*/importJobs/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ImportJob.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + createKeyRingMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.kms.v1.KeyManagementService/CreateKeyRing") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=projects/*/locations/*}/keyRings", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "keyRingId", request.getKeyRingId()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create().toBody("keyRing", request.getKeyRing())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(KeyRing.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + createCryptoKeyMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.kms.v1.KeyManagementService/CreateCryptoKey") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=projects/*/locations/*/keyRings/*}/cryptoKeys", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam( + fields, "cryptoKeyId", request.getCryptoKeyId()); + serializer.putQueryParam( + fields, + "skipInitialVersionCreation", + request.getSkipInitialVersionCreation()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("cryptoKey", request.getCryptoKey())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(CryptoKey.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + createCryptoKeyVersionMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.kms.v1.KeyManagementService/CreateCryptoKeyVersion") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=projects/*/locations/*/keyRings/*/cryptoKeys/*}/cryptoKeyVersions", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("cryptoKeyVersion", request.getCryptoKeyVersion())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(CryptoKeyVersion.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + importCryptoKeyVersionMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.kms.v1.KeyManagementService/ImportCryptoKeyVersion") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=projects/*/locations/*/keyRings/*/cryptoKeys/*}/cryptoKeyVersions:import", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearParent().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(CryptoKeyVersion.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + createImportJobMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.kms.v1.KeyManagementService/CreateImportJob") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=projects/*/locations/*/keyRings/*}/importJobs", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam( + fields, "importJobId", request.getImportJobId()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("importJob", request.getImportJob())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ImportJob.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + updateCryptoKeyMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.kms.v1.KeyManagementService/UpdateCryptoKey") + .setHttpMethod("PATCH") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{cryptoKey.name=projects/*/locations/*/keyRings/*/cryptoKeys/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam( + fields, "cryptoKey.name", request.getCryptoKey().getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "updateMask", request.getUpdateMask()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("cryptoKey", request.getCryptoKey())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(CryptoKey.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + updateCryptoKeyVersionMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.kms.v1.KeyManagementService/UpdateCryptoKeyVersion") + .setHttpMethod("PATCH") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{cryptoKeyVersion.name=projects/*/locations/*/keyRings/*/cryptoKeys/*/cryptoKeyVersions/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam( + fields, + "cryptoKeyVersion.name", + request.getCryptoKeyVersion().getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "updateMask", request.getUpdateMask()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("cryptoKeyVersion", request.getCryptoKeyVersion())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(CryptoKeyVersion.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + updateCryptoKeyPrimaryVersionMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.kms.v1.KeyManagementService/UpdateCryptoKeyPrimaryVersion") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/keyRings/*/cryptoKeys/*}:updatePrimaryVersion", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearName().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(CryptoKey.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + destroyCryptoKeyVersionMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.kms.v1.KeyManagementService/DestroyCryptoKeyVersion") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/keyRings/*/cryptoKeys/*/cryptoKeyVersions/*}:destroy", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearName().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(CryptoKeyVersion.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + restoreCryptoKeyVersionMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.kms.v1.KeyManagementService/RestoreCryptoKeyVersion") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/keyRings/*/cryptoKeys/*/cryptoKeyVersions/*}:restore", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearName().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(CryptoKeyVersion.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + encryptMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.kms.v1.KeyManagementService/Encrypt") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/keyRings/*/cryptoKeys/**}:encrypt", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearName().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(EncryptResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + decryptMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.kms.v1.KeyManagementService/Decrypt") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/keyRings/*/cryptoKeys/*}:decrypt", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearName().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(DecryptResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + asymmetricSignMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.kms.v1.KeyManagementService/AsymmetricSign") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/keyRings/*/cryptoKeys/*/cryptoKeyVersions/*}:asymmetricSign", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearName().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(AsymmetricSignResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + asymmetricDecryptMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.kms.v1.KeyManagementService/AsymmetricDecrypt") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/keyRings/*/cryptoKeys/*/cryptoKeyVersions/*}:asymmetricDecrypt", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearName().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(AsymmetricDecryptResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + macSignMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.kms.v1.KeyManagementService/MacSign") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/keyRings/*/cryptoKeys/*/cryptoKeyVersions/*}:macSign", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearName().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(MacSignResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + macVerifyMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.kms.v1.KeyManagementService/MacVerify") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/keyRings/*/cryptoKeys/*/cryptoKeyVersions/*}:macVerify", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearName().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(MacVerifyResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + generateRandomBytesMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.kms.v1.KeyManagementService/GenerateRandomBytes") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{location=projects/*/locations/*}:generateRandomBytes", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "location", request.getLocation()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearLocation().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(GenerateRandomBytesResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + setIamPolicyMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.iam.v1.IAMPolicy/SetIamPolicy") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{resource=projects/*/locations/*/keyRings/*}:setIamPolicy", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "resource", request.getResource()); + return fields; + }) + .setAdditionalPaths( + "/v1/{resource=projects/*/locations/*/keyRings/*/cryptoKeys/*}:setIamPolicy", + "/v1/{resource=projects/*/locations/*/keyRings/*/importJobs/*}:setIamPolicy", + "/v1/{resource=projects/*/locations/*/ekmConnections/*}:setIamPolicy") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearResource().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Policy.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + getIamPolicyMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.iam.v1.IAMPolicy/GetIamPolicy") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{resource=projects/*/locations/*/keyRings/*}:getIamPolicy", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "resource", request.getResource()); + return fields; + }) + .setAdditionalPaths( + "/v1/{resource=projects/*/locations/*/keyRings/*/cryptoKeys/*}:getIamPolicy", + "/v1/{resource=projects/*/locations/*/keyRings/*/importJobs/*}:getIamPolicy", + "/v1/{resource=projects/*/locations/*/ekmConnections/*}:getIamPolicy") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Policy.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + testIamPermissionsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.iam.v1.IAMPolicy/TestIamPermissions") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{resource=projects/*/locations/*/keyRings/*}:testIamPermissions", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "resource", request.getResource()); + return fields; + }) + .setAdditionalPaths( + "/v1/{resource=projects/*/locations/*/keyRings/*/cryptoKeys/*}:testIamPermissions", + "/v1/{resource=projects/*/locations/*/keyRings/*/importJobs/*}:testIamPermissions", + "/v1/{resource=projects/*/locations/*/ekmConnections/*}:testIamPermissions") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearResource().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(TestIamPermissionsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private final UnaryCallable listKeyRingsCallable; + private final UnaryCallable + listKeyRingsPagedCallable; + private final UnaryCallable listCryptoKeysCallable; + private final UnaryCallable + listCryptoKeysPagedCallable; + private final UnaryCallable + listCryptoKeyVersionsCallable; + private final UnaryCallable + listCryptoKeyVersionsPagedCallable; + private final UnaryCallable listImportJobsCallable; + private final UnaryCallable + listImportJobsPagedCallable; + private final UnaryCallable getKeyRingCallable; + private final UnaryCallable getCryptoKeyCallable; + private final UnaryCallable + getCryptoKeyVersionCallable; + private final UnaryCallable getPublicKeyCallable; + private final UnaryCallable getImportJobCallable; + private final UnaryCallable createKeyRingCallable; + private final UnaryCallable createCryptoKeyCallable; + private final UnaryCallable + createCryptoKeyVersionCallable; + private final UnaryCallable + importCryptoKeyVersionCallable; + private final UnaryCallable createImportJobCallable; + private final UnaryCallable updateCryptoKeyCallable; + private final UnaryCallable + updateCryptoKeyVersionCallable; + private final UnaryCallable + updateCryptoKeyPrimaryVersionCallable; + private final UnaryCallable + destroyCryptoKeyVersionCallable; + private final UnaryCallable + restoreCryptoKeyVersionCallable; + private final UnaryCallable encryptCallable; + private final UnaryCallable decryptCallable; + private final UnaryCallable asymmetricSignCallable; + private final UnaryCallable + asymmetricDecryptCallable; + private final UnaryCallable macSignCallable; + private final UnaryCallable macVerifyCallable; + private final UnaryCallable + generateRandomBytesCallable; + private final UnaryCallable setIamPolicyCallable; + private final UnaryCallable getIamPolicyCallable; + private final UnaryCallable + testIamPermissionsCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonKeyManagementServiceStub create( + KeyManagementServiceStubSettings settings) throws IOException { + return new HttpJsonKeyManagementServiceStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonKeyManagementServiceStub create(ClientContext clientContext) + throws IOException { + return new HttpJsonKeyManagementServiceStub( + KeyManagementServiceStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonKeyManagementServiceStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonKeyManagementServiceStub( + KeyManagementServiceStubSettings.newHttpJsonBuilder().build(), + clientContext, + callableFactory); + } + + /** + * Constructs an instance of HttpJsonKeyManagementServiceStub, using the given settings. This is + * protected so that it is easy to make a subclass, but otherwise, the static factory methods + * should be preferred. + */ + protected HttpJsonKeyManagementServiceStub( + KeyManagementServiceStubSettings settings, ClientContext clientContext) throws IOException { + this(settings, clientContext, new HttpJsonKeyManagementServiceCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonKeyManagementServiceStub, using the given settings. This is + * protected so that it is easy to make a subclass, but otherwise, the static factory methods + * should be preferred. + */ + protected HttpJsonKeyManagementServiceStub( + KeyManagementServiceStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + + HttpJsonCallSettings listKeyRingsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listKeyRingsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + listCryptoKeysTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listCryptoKeysMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + listCryptoKeyVersionsTransportSettings = + HttpJsonCallSettings + .newBuilder() + .setMethodDescriptor(listCryptoKeyVersionsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + listImportJobsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listImportJobsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getKeyRingTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getKeyRingMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getCryptoKeyTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getCryptoKeyMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + getCryptoKeyVersionTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getCryptoKeyVersionMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getPublicKeyTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getPublicKeyMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getImportJobTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getImportJobMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings createKeyRingTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(createKeyRingMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings createCryptoKeyTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(createCryptoKeyMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + createCryptoKeyVersionTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(createCryptoKeyVersionMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + importCryptoKeyVersionTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(importCryptoKeyVersionMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings createImportJobTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(createImportJobMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings updateCryptoKeyTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(updateCryptoKeyMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + updateCryptoKeyVersionTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(updateCryptoKeyVersionMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + updateCryptoKeyPrimaryVersionTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(updateCryptoKeyPrimaryVersionMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + destroyCryptoKeyVersionTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(destroyCryptoKeyVersionMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + restoreCryptoKeyVersionTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(restoreCryptoKeyVersionMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings encryptTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(encryptMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings decryptTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(decryptMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + asymmetricSignTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(asymmetricSignMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + asymmetricDecryptTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(asymmetricDecryptMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings macSignTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(macSignMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings macVerifyTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(macVerifyMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + generateRandomBytesTransportSettings = + HttpJsonCallSettings + .newBuilder() + .setMethodDescriptor(generateRandomBytesMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings setIamPolicyTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(setIamPolicyMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getIamPolicyTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getIamPolicyMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + testIamPermissionsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(testIamPermissionsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + + this.listKeyRingsCallable = + callableFactory.createUnaryCallable( + listKeyRingsTransportSettings, settings.listKeyRingsSettings(), clientContext); + this.listKeyRingsPagedCallable = + callableFactory.createPagedCallable( + listKeyRingsTransportSettings, settings.listKeyRingsSettings(), clientContext); + this.listCryptoKeysCallable = + callableFactory.createUnaryCallable( + listCryptoKeysTransportSettings, settings.listCryptoKeysSettings(), clientContext); + this.listCryptoKeysPagedCallable = + callableFactory.createPagedCallable( + listCryptoKeysTransportSettings, settings.listCryptoKeysSettings(), clientContext); + this.listCryptoKeyVersionsCallable = + callableFactory.createUnaryCallable( + listCryptoKeyVersionsTransportSettings, + settings.listCryptoKeyVersionsSettings(), + clientContext); + this.listCryptoKeyVersionsPagedCallable = + callableFactory.createPagedCallable( + listCryptoKeyVersionsTransportSettings, + settings.listCryptoKeyVersionsSettings(), + clientContext); + this.listImportJobsCallable = + callableFactory.createUnaryCallable( + listImportJobsTransportSettings, settings.listImportJobsSettings(), clientContext); + this.listImportJobsPagedCallable = + callableFactory.createPagedCallable( + listImportJobsTransportSettings, settings.listImportJobsSettings(), clientContext); + this.getKeyRingCallable = + callableFactory.createUnaryCallable( + getKeyRingTransportSettings, settings.getKeyRingSettings(), clientContext); + this.getCryptoKeyCallable = + callableFactory.createUnaryCallable( + getCryptoKeyTransportSettings, settings.getCryptoKeySettings(), clientContext); + this.getCryptoKeyVersionCallable = + callableFactory.createUnaryCallable( + getCryptoKeyVersionTransportSettings, + settings.getCryptoKeyVersionSettings(), + clientContext); + this.getPublicKeyCallable = + callableFactory.createUnaryCallable( + getPublicKeyTransportSettings, settings.getPublicKeySettings(), clientContext); + this.getImportJobCallable = + callableFactory.createUnaryCallable( + getImportJobTransportSettings, settings.getImportJobSettings(), clientContext); + this.createKeyRingCallable = + callableFactory.createUnaryCallable( + createKeyRingTransportSettings, settings.createKeyRingSettings(), clientContext); + this.createCryptoKeyCallable = + callableFactory.createUnaryCallable( + createCryptoKeyTransportSettings, settings.createCryptoKeySettings(), clientContext); + this.createCryptoKeyVersionCallable = + callableFactory.createUnaryCallable( + createCryptoKeyVersionTransportSettings, + settings.createCryptoKeyVersionSettings(), + clientContext); + this.importCryptoKeyVersionCallable = + callableFactory.createUnaryCallable( + importCryptoKeyVersionTransportSettings, + settings.importCryptoKeyVersionSettings(), + clientContext); + this.createImportJobCallable = + callableFactory.createUnaryCallable( + createImportJobTransportSettings, settings.createImportJobSettings(), clientContext); + this.updateCryptoKeyCallable = + callableFactory.createUnaryCallable( + updateCryptoKeyTransportSettings, settings.updateCryptoKeySettings(), clientContext); + this.updateCryptoKeyVersionCallable = + callableFactory.createUnaryCallable( + updateCryptoKeyVersionTransportSettings, + settings.updateCryptoKeyVersionSettings(), + clientContext); + this.updateCryptoKeyPrimaryVersionCallable = + callableFactory.createUnaryCallable( + updateCryptoKeyPrimaryVersionTransportSettings, + settings.updateCryptoKeyPrimaryVersionSettings(), + clientContext); + this.destroyCryptoKeyVersionCallable = + callableFactory.createUnaryCallable( + destroyCryptoKeyVersionTransportSettings, + settings.destroyCryptoKeyVersionSettings(), + clientContext); + this.restoreCryptoKeyVersionCallable = + callableFactory.createUnaryCallable( + restoreCryptoKeyVersionTransportSettings, + settings.restoreCryptoKeyVersionSettings(), + clientContext); + this.encryptCallable = + callableFactory.createUnaryCallable( + encryptTransportSettings, settings.encryptSettings(), clientContext); + this.decryptCallable = + callableFactory.createUnaryCallable( + decryptTransportSettings, settings.decryptSettings(), clientContext); + this.asymmetricSignCallable = + callableFactory.createUnaryCallable( + asymmetricSignTransportSettings, settings.asymmetricSignSettings(), clientContext); + this.asymmetricDecryptCallable = + callableFactory.createUnaryCallable( + asymmetricDecryptTransportSettings, + settings.asymmetricDecryptSettings(), + clientContext); + this.macSignCallable = + callableFactory.createUnaryCallable( + macSignTransportSettings, settings.macSignSettings(), clientContext); + this.macVerifyCallable = + callableFactory.createUnaryCallable( + macVerifyTransportSettings, settings.macVerifySettings(), clientContext); + this.generateRandomBytesCallable = + callableFactory.createUnaryCallable( + generateRandomBytesTransportSettings, + settings.generateRandomBytesSettings(), + clientContext); + this.setIamPolicyCallable = + callableFactory.createUnaryCallable( + setIamPolicyTransportSettings, settings.setIamPolicySettings(), clientContext); + this.getIamPolicyCallable = + callableFactory.createUnaryCallable( + getIamPolicyTransportSettings, settings.getIamPolicySettings(), clientContext); + this.testIamPermissionsCallable = + callableFactory.createUnaryCallable( + testIamPermissionsTransportSettings, + settings.testIamPermissionsSettings(), + clientContext); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(listKeyRingsMethodDescriptor); + methodDescriptors.add(listCryptoKeysMethodDescriptor); + methodDescriptors.add(listCryptoKeyVersionsMethodDescriptor); + methodDescriptors.add(listImportJobsMethodDescriptor); + methodDescriptors.add(getKeyRingMethodDescriptor); + methodDescriptors.add(getCryptoKeyMethodDescriptor); + methodDescriptors.add(getCryptoKeyVersionMethodDescriptor); + methodDescriptors.add(getPublicKeyMethodDescriptor); + methodDescriptors.add(getImportJobMethodDescriptor); + methodDescriptors.add(createKeyRingMethodDescriptor); + methodDescriptors.add(createCryptoKeyMethodDescriptor); + methodDescriptors.add(createCryptoKeyVersionMethodDescriptor); + methodDescriptors.add(importCryptoKeyVersionMethodDescriptor); + methodDescriptors.add(createImportJobMethodDescriptor); + methodDescriptors.add(updateCryptoKeyMethodDescriptor); + methodDescriptors.add(updateCryptoKeyVersionMethodDescriptor); + methodDescriptors.add(updateCryptoKeyPrimaryVersionMethodDescriptor); + methodDescriptors.add(destroyCryptoKeyVersionMethodDescriptor); + methodDescriptors.add(restoreCryptoKeyVersionMethodDescriptor); + methodDescriptors.add(encryptMethodDescriptor); + methodDescriptors.add(decryptMethodDescriptor); + methodDescriptors.add(asymmetricSignMethodDescriptor); + methodDescriptors.add(asymmetricDecryptMethodDescriptor); + methodDescriptors.add(macSignMethodDescriptor); + methodDescriptors.add(macVerifyMethodDescriptor); + methodDescriptors.add(generateRandomBytesMethodDescriptor); + methodDescriptors.add(setIamPolicyMethodDescriptor); + methodDescriptors.add(getIamPolicyMethodDescriptor); + methodDescriptors.add(testIamPermissionsMethodDescriptor); + return methodDescriptors; + } + + @Override + public UnaryCallable listKeyRingsCallable() { + return listKeyRingsCallable; + } + + @Override + public UnaryCallable listKeyRingsPagedCallable() { + return listKeyRingsPagedCallable; + } + + @Override + public UnaryCallable listCryptoKeysCallable() { + return listCryptoKeysCallable; + } + + @Override + public UnaryCallable + listCryptoKeysPagedCallable() { + return listCryptoKeysPagedCallable; + } + + @Override + public UnaryCallable + listCryptoKeyVersionsCallable() { + return listCryptoKeyVersionsCallable; + } + + @Override + public UnaryCallable + listCryptoKeyVersionsPagedCallable() { + return listCryptoKeyVersionsPagedCallable; + } + + @Override + public UnaryCallable listImportJobsCallable() { + return listImportJobsCallable; + } + + @Override + public UnaryCallable + listImportJobsPagedCallable() { + return listImportJobsPagedCallable; + } + + @Override + public UnaryCallable getKeyRingCallable() { + return getKeyRingCallable; + } + + @Override + public UnaryCallable getCryptoKeyCallable() { + return getCryptoKeyCallable; + } + + @Override + public UnaryCallable getCryptoKeyVersionCallable() { + return getCryptoKeyVersionCallable; + } + + @Override + public UnaryCallable getPublicKeyCallable() { + return getPublicKeyCallable; + } + + @Override + public UnaryCallable getImportJobCallable() { + return getImportJobCallable; + } + + @Override + public UnaryCallable createKeyRingCallable() { + return createKeyRingCallable; + } + + @Override + public UnaryCallable createCryptoKeyCallable() { + return createCryptoKeyCallable; + } + + @Override + public UnaryCallable + createCryptoKeyVersionCallable() { + return createCryptoKeyVersionCallable; + } + + @Override + public UnaryCallable + importCryptoKeyVersionCallable() { + return importCryptoKeyVersionCallable; + } + + @Override + public UnaryCallable createImportJobCallable() { + return createImportJobCallable; + } + + @Override + public UnaryCallable updateCryptoKeyCallable() { + return updateCryptoKeyCallable; + } + + @Override + public UnaryCallable + updateCryptoKeyVersionCallable() { + return updateCryptoKeyVersionCallable; + } + + @Override + public UnaryCallable + updateCryptoKeyPrimaryVersionCallable() { + return updateCryptoKeyPrimaryVersionCallable; + } + + @Override + public UnaryCallable + destroyCryptoKeyVersionCallable() { + return destroyCryptoKeyVersionCallable; + } + + @Override + public UnaryCallable + restoreCryptoKeyVersionCallable() { + return restoreCryptoKeyVersionCallable; + } + + @Override + public UnaryCallable encryptCallable() { + return encryptCallable; + } + + @Override + public UnaryCallable decryptCallable() { + return decryptCallable; + } + + @Override + public UnaryCallable asymmetricSignCallable() { + return asymmetricSignCallable; + } + + @Override + public UnaryCallable + asymmetricDecryptCallable() { + return asymmetricDecryptCallable; + } + + @Override + public UnaryCallable macSignCallable() { + return macSignCallable; + } + + @Override + public UnaryCallable macVerifyCallable() { + return macVerifyCallable; + } + + @Override + public UnaryCallable + generateRandomBytesCallable() { + return generateRandomBytesCallable; + } + + @Override + public UnaryCallable setIamPolicyCallable() { + return setIamPolicyCallable; + } + + @Override + public UnaryCallable getIamPolicyCallable() { + return getIamPolicyCallable; + } + + @Override + public UnaryCallable + testIamPermissionsCallable() { + return testIamPermissionsCallable; + } + + @Override + public final void close() { + try { + backgroundResources.close(); + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + throw new IllegalStateException("Failed to close resource", e); + } + } + + @Override + public void shutdown() { + backgroundResources.shutdown(); + } + + @Override + public boolean isShutdown() { + return backgroundResources.isShutdown(); + } + + @Override + public boolean isTerminated() { + return backgroundResources.isTerminated(); + } + + @Override + public void shutdownNow() { + backgroundResources.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return backgroundResources.awaitTermination(duration, unit); + } +} 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 fa545533..7ef20869 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 @@ -30,6 +30,9 @@ import com.google.api.gax.grpc.GaxGrpcProperties; import com.google.api.gax.grpc.GrpcTransportChannel; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.HttpJsonTransportChannel; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; import com.google.api.gax.retrying.RetrySettings; import com.google.api.gax.rpc.ApiCallContext; import com.google.api.gax.rpc.ApiClientHeaderProvider; @@ -591,6 +594,11 @@ public KeyManagementServiceStub createStub() throws IOException { .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcKeyManagementServiceStub.create(this); } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonKeyManagementServiceStub.create(this); + } throw new UnsupportedOperationException( String.format( "Transport not supported: %s", getTransportChannelProvider().getTransportName())); @@ -623,18 +631,25 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde .setUseJwtAccessWithScope(true); } - /** Returns a builder for the default ChannelProvider for this service. */ + /** Returns a builder for the default gRPC ChannelProvider for this service. */ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { return InstantiatingGrpcChannelProvider.newBuilder() .setMaxInboundMessageSize(Integer.MAX_VALUE); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return InstantiatingHttpJsonChannelProvider.newBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return defaultGrpcTransportProviderBuilder().build(); } @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") - public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + public static ApiClientHeaderProvider.Builder defaultGrpcApiClientHeaderProviderBuilder() { return ApiClientHeaderProvider.newBuilder() .setGeneratedLibToken( "gapic", GaxProperties.getLibraryVersion(KeyManagementServiceStubSettings.class)) @@ -642,11 +657,30 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion()); } - /** Returns a new builder for this class. */ + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultHttpJsonApiClientHeaderProviderBuilder() { + return ApiClientHeaderProvider.newBuilder() + .setGeneratedLibToken( + "gapic", GaxProperties.getLibraryVersion(KeyManagementServiceStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return KeyManagementServiceStubSettings.defaultGrpcApiClientHeaderProviderBuilder(); + } + + /** Returns a new gRPC builder for this class. */ public static Builder newBuilder() { return Builder.createDefault(); } + /** Returns a new REST builder for this class. */ + public static Builder newHttpJsonBuilder() { + return Builder.createHttpJsonDefault(); + } + /** Returns a new builder for this class. */ public static Builder newBuilder(ClientContext clientContext) { return new Builder(clientContext); @@ -944,6 +978,19 @@ private static Builder createDefault() { return initDefaults(builder); } + private static Builder createHttpJsonDefault() { + Builder builder = new Builder(((ClientContext) null)); + + builder.setTransportChannelProvider(defaultHttpJsonTransportProviderBuilder().build()); + builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); + builder.setInternalHeaderProvider(defaultHttpJsonApiClientHeaderProviderBuilder().build()); + builder.setEndpoint(getDefaultEndpoint()); + builder.setMtlsEndpoint(getDefaultMtlsEndpoint()); + builder.setSwitchToMtlsEndpointAllowed(true); + + return initDefaults(builder); + } + private static Builder initDefaults(Builder builder) { builder .listKeyRingsSettings() diff --git a/google-cloud-kms/src/test/java/com/google/cloud/kms/v1/EkmServiceClientHttpJsonTest.java b/google-cloud-kms/src/test/java/com/google/cloud/kms/v1/EkmServiceClientHttpJsonTest.java new file mode 100644 index 00000000..926d97e7 --- /dev/null +++ b/google-cloud-kms/src/test/java/com/google/cloud/kms/v1/EkmServiceClientHttpJsonTest.java @@ -0,0 +1,623 @@ +/* + * Copyright 2022 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.EkmServiceClient.ListEkmConnectionsPagedResponse; + +import com.google.api.gax.core.NoCredentialsProvider; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.testing.MockHttpService; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ApiException; +import com.google.api.gax.rpc.ApiExceptionFactory; +import com.google.api.gax.rpc.InvalidArgumentException; +import com.google.api.gax.rpc.StatusCode; +import com.google.api.gax.rpc.testing.FakeStatusCode; +import com.google.cloud.kms.v1.stub.HttpJsonEkmServiceStub; +import com.google.common.collect.Lists; +import com.google.iam.v1.AuditConfig; +import com.google.iam.v1.Binding; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.GetPolicyOptions; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; +import com.google.protobuf.ByteString; +import com.google.protobuf.FieldMask; +import com.google.protobuf.Timestamp; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import javax.annotation.Generated; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +@Generated("by gapic-generator-java") +public class EkmServiceClientHttpJsonTest { + private static MockHttpService mockService; + private static EkmServiceClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonEkmServiceStub.getMethodDescriptors(), EkmServiceSettings.getDefaultEndpoint()); + EkmServiceSettings settings = + EkmServiceSettings.newHttpJsonBuilder() + .setTransportChannelProvider( + EkmServiceSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = EkmServiceClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void listEkmConnectionsTest() throws Exception { + EkmConnection responsesElement = EkmConnection.newBuilder().build(); + ListEkmConnectionsResponse expectedResponse = + ListEkmConnectionsResponse.newBuilder() + .setNextPageToken("") + .addAllEkmConnections(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + + ListEkmConnectionsPagedResponse pagedListResponse = client.listEkmConnections(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getEkmConnectionsList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listEkmConnectionsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + client.listEkmConnections(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listEkmConnectionsTest2() throws Exception { + EkmConnection responsesElement = EkmConnection.newBuilder().build(); + ListEkmConnectionsResponse expectedResponse = + ListEkmConnectionsResponse.newBuilder() + .setNextPageToken("") + .addAllEkmConnections(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-5833/locations/location-5833"; + + ListEkmConnectionsPagedResponse pagedListResponse = client.listEkmConnections(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getEkmConnectionsList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listEkmConnectionsExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-5833/locations/location-5833"; + client.listEkmConnections(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getEkmConnectionTest() throws Exception { + EkmConnection expectedResponse = + EkmConnection.newBuilder() + .setName(EkmConnectionName.of("[PROJECT]", "[LOCATION]", "[EKM_CONNECTION]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .addAllServiceResolvers(new ArrayList()) + .setEtag("etag3123477") + .build(); + mockService.addResponse(expectedResponse); + + EkmConnectionName name = EkmConnectionName.of("[PROJECT]", "[LOCATION]", "[EKM_CONNECTION]"); + + EkmConnection actualResponse = client.getEkmConnection(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getEkmConnectionExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + EkmConnectionName name = EkmConnectionName.of("[PROJECT]", "[LOCATION]", "[EKM_CONNECTION]"); + client.getEkmConnection(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getEkmConnectionTest2() throws Exception { + EkmConnection expectedResponse = + EkmConnection.newBuilder() + .setName(EkmConnectionName.of("[PROJECT]", "[LOCATION]", "[EKM_CONNECTION]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .addAllServiceResolvers(new ArrayList()) + .setEtag("etag3123477") + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-5346/locations/location-5346/ekmConnections/ekmConnection-5346"; + + EkmConnection actualResponse = client.getEkmConnection(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getEkmConnectionExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-5346/locations/location-5346/ekmConnections/ekmConnection-5346"; + client.getEkmConnection(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createEkmConnectionTest() throws Exception { + EkmConnection expectedResponse = + EkmConnection.newBuilder() + .setName(EkmConnectionName.of("[PROJECT]", "[LOCATION]", "[EKM_CONNECTION]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .addAllServiceResolvers(new ArrayList()) + .setEtag("etag3123477") + .build(); + mockService.addResponse(expectedResponse); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + String ekmConnectionId = "ekmConnectionId-445017408"; + EkmConnection ekmConnection = EkmConnection.newBuilder().build(); + + EkmConnection actualResponse = + client.createEkmConnection(parent, ekmConnectionId, ekmConnection); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void createEkmConnectionExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + String ekmConnectionId = "ekmConnectionId-445017408"; + EkmConnection ekmConnection = EkmConnection.newBuilder().build(); + client.createEkmConnection(parent, ekmConnectionId, ekmConnection); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createEkmConnectionTest2() throws Exception { + EkmConnection expectedResponse = + EkmConnection.newBuilder() + .setName(EkmConnectionName.of("[PROJECT]", "[LOCATION]", "[EKM_CONNECTION]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .addAllServiceResolvers(new ArrayList()) + .setEtag("etag3123477") + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-5833/locations/location-5833"; + String ekmConnectionId = "ekmConnectionId-445017408"; + EkmConnection ekmConnection = EkmConnection.newBuilder().build(); + + EkmConnection actualResponse = + client.createEkmConnection(parent, ekmConnectionId, ekmConnection); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void createEkmConnectionExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-5833/locations/location-5833"; + String ekmConnectionId = "ekmConnectionId-445017408"; + EkmConnection ekmConnection = EkmConnection.newBuilder().build(); + client.createEkmConnection(parent, ekmConnectionId, ekmConnection); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void updateEkmConnectionTest() throws Exception { + EkmConnection expectedResponse = + EkmConnection.newBuilder() + .setName(EkmConnectionName.of("[PROJECT]", "[LOCATION]", "[EKM_CONNECTION]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .addAllServiceResolvers(new ArrayList()) + .setEtag("etag3123477") + .build(); + mockService.addResponse(expectedResponse); + + EkmConnection ekmConnection = + EkmConnection.newBuilder() + .setName(EkmConnectionName.of("[PROJECT]", "[LOCATION]", "[EKM_CONNECTION]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .addAllServiceResolvers(new ArrayList()) + .setEtag("etag3123477") + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + + EkmConnection actualResponse = client.updateEkmConnection(ekmConnection, updateMask); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void updateEkmConnectionExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + EkmConnection ekmConnection = + EkmConnection.newBuilder() + .setName( + EkmConnectionName.of("[PROJECT]", "[LOCATION]", "[EKM_CONNECTION]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .addAllServiceResolvers(new ArrayList()) + .setEtag("etag3123477") + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + client.updateEkmConnection(ekmConnection, updateMask); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void setIamPolicyTest() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setVersion(351608024) + .addAllBindings(new ArrayList()) + .addAllAuditConfigs(new ArrayList()) + .setEtag(ByteString.EMPTY) + .build(); + mockService.addResponse(expectedResponse); + + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + + Policy actualResponse = client.setIamPolicy(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void setIamPolicyExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + client.setIamPolicy(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getIamPolicyTest() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setVersion(351608024) + .addAllBindings(new ArrayList()) + .addAllAuditConfigs(new ArrayList()) + .setEtag(ByteString.EMPTY) + .build(); + mockService.addResponse(expectedResponse); + + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + + Policy actualResponse = client.getIamPolicy(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getIamPolicyExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + client.getIamPolicy(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void testIamPermissionsTest() throws Exception { + TestIamPermissionsResponse expectedResponse = + TestIamPermissionsResponse.newBuilder().addAllPermissions(new ArrayList()).build(); + mockService.addResponse(expectedResponse); + + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .addAllPermissions(new ArrayList()) + .build(); + + TestIamPermissionsResponse actualResponse = client.testIamPermissions(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void testIamPermissionsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .addAllPermissions(new ArrayList()) + .build(); + client.testIamPermissions(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } +} diff --git a/google-cloud-kms/src/test/java/com/google/cloud/kms/v1/KeyManagementServiceClientHttpJsonTest.java b/google-cloud-kms/src/test/java/com/google/cloud/kms/v1/KeyManagementServiceClientHttpJsonTest.java new file mode 100644 index 00000000..2357fb81 --- /dev/null +++ b/google-cloud-kms/src/test/java/com/google/cloud/kms/v1/KeyManagementServiceClientHttpJsonTest.java @@ -0,0 +1,3027 @@ +/* + * Copyright 2022 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.ListCryptoKeyVersionsPagedResponse; +import static com.google.cloud.kms.v1.KeyManagementServiceClient.ListCryptoKeysPagedResponse; +import static com.google.cloud.kms.v1.KeyManagementServiceClient.ListImportJobsPagedResponse; +import static com.google.cloud.kms.v1.KeyManagementServiceClient.ListKeyRingsPagedResponse; + +import com.google.api.gax.core.NoCredentialsProvider; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.testing.MockHttpService; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ApiException; +import com.google.api.gax.rpc.ApiExceptionFactory; +import com.google.api.gax.rpc.InvalidArgumentException; +import com.google.api.gax.rpc.StatusCode; +import com.google.api.gax.rpc.testing.FakeStatusCode; +import com.google.api.resourcenames.ResourceName; +import com.google.cloud.kms.v1.stub.HttpJsonKeyManagementServiceStub; +import com.google.common.collect.Lists; +import com.google.iam.v1.AuditConfig; +import com.google.iam.v1.Binding; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.GetPolicyOptions; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; +import com.google.protobuf.ByteString; +import com.google.protobuf.Duration; +import com.google.protobuf.FieldMask; +import com.google.protobuf.Int64Value; +import com.google.protobuf.Timestamp; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import javax.annotation.Generated; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +@Generated("by gapic-generator-java") +public class KeyManagementServiceClientHttpJsonTest { + private static MockHttpService mockService; + private static KeyManagementServiceClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonKeyManagementServiceStub.getMethodDescriptors(), + KeyManagementServiceSettings.getDefaultEndpoint()); + KeyManagementServiceSettings settings = + KeyManagementServiceSettings.newHttpJsonBuilder() + .setTransportChannelProvider( + KeyManagementServiceSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = KeyManagementServiceClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void listKeyRingsTest() throws Exception { + KeyRing responsesElement = KeyRing.newBuilder().build(); + ListKeyRingsResponse expectedResponse = + ListKeyRingsResponse.newBuilder() + .setNextPageToken("") + .addAllKeyRings(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + + ListKeyRingsPagedResponse pagedListResponse = client.listKeyRings(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getKeyRingsList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listKeyRingsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + client.listKeyRings(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listKeyRingsTest2() throws Exception { + KeyRing responsesElement = KeyRing.newBuilder().build(); + ListKeyRingsResponse expectedResponse = + ListKeyRingsResponse.newBuilder() + .setNextPageToken("") + .addAllKeyRings(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-5833/locations/location-5833"; + + ListKeyRingsPagedResponse pagedListResponse = client.listKeyRings(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getKeyRingsList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listKeyRingsExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-5833/locations/location-5833"; + client.listKeyRings(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listCryptoKeysTest() throws Exception { + CryptoKey responsesElement = CryptoKey.newBuilder().build(); + ListCryptoKeysResponse expectedResponse = + ListCryptoKeysResponse.newBuilder() + .setNextPageToken("") + .addAllCryptoKeys(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + KeyRingName parent = KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]"); + + ListCryptoKeysPagedResponse pagedListResponse = client.listCryptoKeys(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getCryptoKeysList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listCryptoKeysExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + KeyRingName parent = KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]"); + client.listCryptoKeys(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listCryptoKeysTest2() throws Exception { + CryptoKey responsesElement = CryptoKey.newBuilder().build(); + ListCryptoKeysResponse expectedResponse = + ListCryptoKeysResponse.newBuilder() + .setNextPageToken("") + .addAllCryptoKeys(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-7749/locations/location-7749/keyRings/keyRing-7749"; + + ListCryptoKeysPagedResponse pagedListResponse = client.listCryptoKeys(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getCryptoKeysList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listCryptoKeysExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-7749/locations/location-7749/keyRings/keyRing-7749"; + client.listCryptoKeys(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listCryptoKeyVersionsTest() throws Exception { + CryptoKeyVersion responsesElement = CryptoKeyVersion.newBuilder().build(); + ListCryptoKeyVersionsResponse expectedResponse = + ListCryptoKeyVersionsResponse.newBuilder() + .setNextPageToken("") + .addAllCryptoKeyVersions(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + CryptoKeyName parent = + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]"); + + ListCryptoKeyVersionsPagedResponse pagedListResponse = client.listCryptoKeyVersions(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getCryptoKeyVersionsList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listCryptoKeyVersionsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + CryptoKeyName parent = + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]"); + client.listCryptoKeyVersions(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listCryptoKeyVersionsTest2() throws Exception { + CryptoKeyVersion responsesElement = CryptoKeyVersion.newBuilder().build(); + ListCryptoKeyVersionsResponse expectedResponse = + ListCryptoKeyVersionsResponse.newBuilder() + .setNextPageToken("") + .addAllCryptoKeyVersions(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = + "projects/project-7206/locations/location-7206/keyRings/keyRing-7206/cryptoKeys/cryptoKey-7206"; + + ListCryptoKeyVersionsPagedResponse pagedListResponse = client.listCryptoKeyVersions(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getCryptoKeyVersionsList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listCryptoKeyVersionsExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = + "projects/project-7206/locations/location-7206/keyRings/keyRing-7206/cryptoKeys/cryptoKey-7206"; + client.listCryptoKeyVersions(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listImportJobsTest() throws Exception { + ImportJob responsesElement = ImportJob.newBuilder().build(); + ListImportJobsResponse expectedResponse = + ListImportJobsResponse.newBuilder() + .setNextPageToken("") + .addAllImportJobs(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + KeyRingName parent = KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]"); + + ListImportJobsPagedResponse pagedListResponse = client.listImportJobs(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getImportJobsList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listImportJobsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + KeyRingName parent = KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]"); + client.listImportJobs(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listImportJobsTest2() throws Exception { + ImportJob responsesElement = ImportJob.newBuilder().build(); + ListImportJobsResponse expectedResponse = + ListImportJobsResponse.newBuilder() + .setNextPageToken("") + .addAllImportJobs(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-7749/locations/location-7749/keyRings/keyRing-7749"; + + ListImportJobsPagedResponse pagedListResponse = client.listImportJobs(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getImportJobsList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listImportJobsExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-7749/locations/location-7749/keyRings/keyRing-7749"; + client.listImportJobs(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getKeyRingTest() throws Exception { + KeyRing expectedResponse = + KeyRing.newBuilder() + .setName(KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + KeyRingName name = KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]"); + + KeyRing actualResponse = client.getKeyRing(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getKeyRingExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + KeyRingName name = KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]"); + client.getKeyRing(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getKeyRingTest2() throws Exception { + KeyRing expectedResponse = + KeyRing.newBuilder() + .setName(KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-4820/locations/location-4820/keyRings/keyRing-4820"; + + KeyRing actualResponse = client.getKeyRing(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getKeyRingExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-4820/locations/location-4820/keyRings/keyRing-4820"; + client.getKeyRing(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getCryptoKeyTest() throws Exception { + CryptoKey expectedResponse = + CryptoKey.newBuilder() + .setName( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .setPrimary(CryptoKeyVersion.newBuilder().build()) + .setCreateTime(Timestamp.newBuilder().build()) + .setNextRotationTime(Timestamp.newBuilder().build()) + .setVersionTemplate(CryptoKeyVersionTemplate.newBuilder().build()) + .putAllLabels(new HashMap()) + .setImportOnly(true) + .setDestroyScheduledDuration(Duration.newBuilder().build()) + .setCryptoKeyBackend( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .build(); + mockService.addResponse(expectedResponse); + + CryptoKeyName name = CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]"); + + CryptoKey actualResponse = client.getCryptoKey(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getCryptoKeyExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + CryptoKeyName name = + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]"); + client.getCryptoKey(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getCryptoKeyTest2() throws Exception { + CryptoKey expectedResponse = + CryptoKey.newBuilder() + .setName( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .setPrimary(CryptoKeyVersion.newBuilder().build()) + .setCreateTime(Timestamp.newBuilder().build()) + .setNextRotationTime(Timestamp.newBuilder().build()) + .setVersionTemplate(CryptoKeyVersionTemplate.newBuilder().build()) + .putAllLabels(new HashMap()) + .setImportOnly(true) + .setDestroyScheduledDuration(Duration.newBuilder().build()) + .setCryptoKeyBackend( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .build(); + mockService.addResponse(expectedResponse); + + String name = + "projects/project-5355/locations/location-5355/keyRings/keyRing-5355/cryptoKeys/cryptoKey-5355"; + + CryptoKey actualResponse = client.getCryptoKey(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getCryptoKeyExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-5355/locations/location-5355/keyRings/keyRing-5355/cryptoKeys/cryptoKey-5355"; + client.getCryptoKey(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getCryptoKeyVersionTest() throws Exception { + CryptoKeyVersion expectedResponse = + CryptoKeyVersion.newBuilder() + .setName( + CryptoKeyVersionName.of( + "[PROJECT]", + "[LOCATION]", + "[KEY_RING]", + "[CRYPTO_KEY]", + "[CRYPTO_KEY_VERSION]") + .toString()) + .setProtectionLevel(ProtectionLevel.forNumber(0)) + .setAttestation(KeyOperationAttestation.newBuilder().build()) + .setCreateTime(Timestamp.newBuilder().build()) + .setGenerateTime(Timestamp.newBuilder().build()) + .setDestroyTime(Timestamp.newBuilder().build()) + .setDestroyEventTime(Timestamp.newBuilder().build()) + .setImportJob("importJob-208547368") + .setImportTime(Timestamp.newBuilder().build()) + .setImportFailureReason("importFailureReason985493705") + .setExternalProtectionLevelOptions(ExternalProtectionLevelOptions.newBuilder().build()) + .setReimportEligible(true) + .build(); + mockService.addResponse(expectedResponse); + + CryptoKeyVersionName name = + CryptoKeyVersionName.of( + "[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]", "[CRYPTO_KEY_VERSION]"); + + CryptoKeyVersion actualResponse = client.getCryptoKeyVersion(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getCryptoKeyVersionExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + CryptoKeyVersionName name = + CryptoKeyVersionName.of( + "[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]", "[CRYPTO_KEY_VERSION]"); + client.getCryptoKeyVersion(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getCryptoKeyVersionTest2() throws Exception { + CryptoKeyVersion expectedResponse = + CryptoKeyVersion.newBuilder() + .setName( + CryptoKeyVersionName.of( + "[PROJECT]", + "[LOCATION]", + "[KEY_RING]", + "[CRYPTO_KEY]", + "[CRYPTO_KEY_VERSION]") + .toString()) + .setProtectionLevel(ProtectionLevel.forNumber(0)) + .setAttestation(KeyOperationAttestation.newBuilder().build()) + .setCreateTime(Timestamp.newBuilder().build()) + .setGenerateTime(Timestamp.newBuilder().build()) + .setDestroyTime(Timestamp.newBuilder().build()) + .setDestroyEventTime(Timestamp.newBuilder().build()) + .setImportJob("importJob-208547368") + .setImportTime(Timestamp.newBuilder().build()) + .setImportFailureReason("importFailureReason985493705") + .setExternalProtectionLevelOptions(ExternalProtectionLevelOptions.newBuilder().build()) + .setReimportEligible(true) + .build(); + mockService.addResponse(expectedResponse); + + String name = + "projects/project-9504/locations/location-9504/keyRings/keyRing-9504/cryptoKeys/cryptoKey-9504/cryptoKeyVersions/cryptoKeyVersion-9504"; + + CryptoKeyVersion actualResponse = client.getCryptoKeyVersion(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getCryptoKeyVersionExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-9504/locations/location-9504/keyRings/keyRing-9504/cryptoKeys/cryptoKey-9504/cryptoKeyVersions/cryptoKeyVersion-9504"; + client.getCryptoKeyVersion(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getPublicKeyTest() throws Exception { + PublicKey expectedResponse = + PublicKey.newBuilder() + .setPem("pem110872") + .setPemCrc32C(Int64Value.newBuilder().build()) + .setName("name3373707") + .setProtectionLevel(ProtectionLevel.forNumber(0)) + .build(); + mockService.addResponse(expectedResponse); + + CryptoKeyVersionName name = + CryptoKeyVersionName.of( + "[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]", "[CRYPTO_KEY_VERSION]"); + + PublicKey actualResponse = client.getPublicKey(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getPublicKeyExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + CryptoKeyVersionName name = + CryptoKeyVersionName.of( + "[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]", "[CRYPTO_KEY_VERSION]"); + client.getPublicKey(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getPublicKeyTest2() throws Exception { + PublicKey expectedResponse = + PublicKey.newBuilder() + .setPem("pem110872") + .setPemCrc32C(Int64Value.newBuilder().build()) + .setName("name3373707") + .setProtectionLevel(ProtectionLevel.forNumber(0)) + .build(); + mockService.addResponse(expectedResponse); + + String name = + "projects/project-9504/locations/location-9504/keyRings/keyRing-9504/cryptoKeys/cryptoKey-9504/cryptoKeyVersions/cryptoKeyVersion-9504"; + + PublicKey actualResponse = client.getPublicKey(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getPublicKeyExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-9504/locations/location-9504/keyRings/keyRing-9504/cryptoKeys/cryptoKey-9504/cryptoKeyVersions/cryptoKeyVersion-9504"; + client.getPublicKey(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getImportJobTest() throws Exception { + ImportJob expectedResponse = + ImportJob.newBuilder() + .setName( + ImportJobName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[IMPORT_JOB]") + .toString()) + .setProtectionLevel(ProtectionLevel.forNumber(0)) + .setCreateTime(Timestamp.newBuilder().build()) + .setGenerateTime(Timestamp.newBuilder().build()) + .setExpireTime(Timestamp.newBuilder().build()) + .setExpireEventTime(Timestamp.newBuilder().build()) + .setPublicKey(ImportJob.WrappingPublicKey.newBuilder().build()) + .setAttestation(KeyOperationAttestation.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + ImportJobName name = ImportJobName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[IMPORT_JOB]"); + + ImportJob actualResponse = client.getImportJob(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getImportJobExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ImportJobName name = + ImportJobName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[IMPORT_JOB]"); + client.getImportJob(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getImportJobTest2() throws Exception { + ImportJob expectedResponse = + ImportJob.newBuilder() + .setName( + ImportJobName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[IMPORT_JOB]") + .toString()) + .setProtectionLevel(ProtectionLevel.forNumber(0)) + .setCreateTime(Timestamp.newBuilder().build()) + .setGenerateTime(Timestamp.newBuilder().build()) + .setExpireTime(Timestamp.newBuilder().build()) + .setExpireEventTime(Timestamp.newBuilder().build()) + .setPublicKey(ImportJob.WrappingPublicKey.newBuilder().build()) + .setAttestation(KeyOperationAttestation.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String name = + "projects/project-6111/locations/location-6111/keyRings/keyRing-6111/importJobs/importJob-6111"; + + ImportJob actualResponse = client.getImportJob(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getImportJobExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-6111/locations/location-6111/keyRings/keyRing-6111/importJobs/importJob-6111"; + client.getImportJob(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createKeyRingTest() throws Exception { + KeyRing expectedResponse = + KeyRing.newBuilder() + .setName(KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + String keyRingId = "keyRingId-2027180374"; + KeyRing keyRing = KeyRing.newBuilder().build(); + + KeyRing actualResponse = client.createKeyRing(parent, keyRingId, keyRing); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void createKeyRingExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + String keyRingId = "keyRingId-2027180374"; + KeyRing keyRing = KeyRing.newBuilder().build(); + client.createKeyRing(parent, keyRingId, keyRing); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createKeyRingTest2() throws Exception { + KeyRing expectedResponse = + KeyRing.newBuilder() + .setName(KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]").toString()) + .setCreateTime(Timestamp.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-5833/locations/location-5833"; + String keyRingId = "keyRingId-2027180374"; + KeyRing keyRing = KeyRing.newBuilder().build(); + + KeyRing actualResponse = client.createKeyRing(parent, keyRingId, keyRing); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void createKeyRingExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-5833/locations/location-5833"; + String keyRingId = "keyRingId-2027180374"; + KeyRing keyRing = KeyRing.newBuilder().build(); + client.createKeyRing(parent, keyRingId, keyRing); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createCryptoKeyTest() throws Exception { + CryptoKey expectedResponse = + CryptoKey.newBuilder() + .setName( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .setPrimary(CryptoKeyVersion.newBuilder().build()) + .setCreateTime(Timestamp.newBuilder().build()) + .setNextRotationTime(Timestamp.newBuilder().build()) + .setVersionTemplate(CryptoKeyVersionTemplate.newBuilder().build()) + .putAllLabels(new HashMap()) + .setImportOnly(true) + .setDestroyScheduledDuration(Duration.newBuilder().build()) + .setCryptoKeyBackend(KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]").toString()) + .build(); + mockService.addResponse(expectedResponse); + + KeyRingName parent = KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]"); + String cryptoKeyId = "cryptoKeyId-1643185255"; + CryptoKey cryptoKey = CryptoKey.newBuilder().build(); + + CryptoKey actualResponse = client.createCryptoKey(parent, cryptoKeyId, cryptoKey); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void createCryptoKeyExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + KeyRingName parent = KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]"); + String cryptoKeyId = "cryptoKeyId-1643185255"; + CryptoKey cryptoKey = CryptoKey.newBuilder().build(); + client.createCryptoKey(parent, cryptoKeyId, cryptoKey); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createCryptoKeyTest2() throws Exception { + CryptoKey expectedResponse = + CryptoKey.newBuilder() + .setName( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .setPrimary(CryptoKeyVersion.newBuilder().build()) + .setCreateTime(Timestamp.newBuilder().build()) + .setNextRotationTime(Timestamp.newBuilder().build()) + .setVersionTemplate(CryptoKeyVersionTemplate.newBuilder().build()) + .putAllLabels(new HashMap()) + .setImportOnly(true) + .setDestroyScheduledDuration(Duration.newBuilder().build()) + .setCryptoKeyBackend(KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]").toString()) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-7749/locations/location-7749/keyRings/keyRing-7749"; + String cryptoKeyId = "cryptoKeyId-1643185255"; + CryptoKey cryptoKey = CryptoKey.newBuilder().build(); + + CryptoKey actualResponse = client.createCryptoKey(parent, cryptoKeyId, cryptoKey); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void createCryptoKeyExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-7749/locations/location-7749/keyRings/keyRing-7749"; + String cryptoKeyId = "cryptoKeyId-1643185255"; + CryptoKey cryptoKey = CryptoKey.newBuilder().build(); + client.createCryptoKey(parent, cryptoKeyId, cryptoKey); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createCryptoKeyVersionTest() throws Exception { + CryptoKeyVersion expectedResponse = + CryptoKeyVersion.newBuilder() + .setName( + CryptoKeyVersionName.of( + "[PROJECT]", + "[LOCATION]", + "[KEY_RING]", + "[CRYPTO_KEY]", + "[CRYPTO_KEY_VERSION]") + .toString()) + .setProtectionLevel(ProtectionLevel.forNumber(0)) + .setAttestation(KeyOperationAttestation.newBuilder().build()) + .setCreateTime(Timestamp.newBuilder().build()) + .setGenerateTime(Timestamp.newBuilder().build()) + .setDestroyTime(Timestamp.newBuilder().build()) + .setDestroyEventTime(Timestamp.newBuilder().build()) + .setImportJob("importJob-208547368") + .setImportTime(Timestamp.newBuilder().build()) + .setImportFailureReason("importFailureReason985493705") + .setExternalProtectionLevelOptions(ExternalProtectionLevelOptions.newBuilder().build()) + .setReimportEligible(true) + .build(); + mockService.addResponse(expectedResponse); + + CryptoKeyName parent = + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]"); + CryptoKeyVersion cryptoKeyVersion = CryptoKeyVersion.newBuilder().build(); + + CryptoKeyVersion actualResponse = client.createCryptoKeyVersion(parent, cryptoKeyVersion); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void createCryptoKeyVersionExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + CryptoKeyName parent = + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]"); + CryptoKeyVersion cryptoKeyVersion = CryptoKeyVersion.newBuilder().build(); + client.createCryptoKeyVersion(parent, cryptoKeyVersion); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createCryptoKeyVersionTest2() throws Exception { + CryptoKeyVersion expectedResponse = + CryptoKeyVersion.newBuilder() + .setName( + CryptoKeyVersionName.of( + "[PROJECT]", + "[LOCATION]", + "[KEY_RING]", + "[CRYPTO_KEY]", + "[CRYPTO_KEY_VERSION]") + .toString()) + .setProtectionLevel(ProtectionLevel.forNumber(0)) + .setAttestation(KeyOperationAttestation.newBuilder().build()) + .setCreateTime(Timestamp.newBuilder().build()) + .setGenerateTime(Timestamp.newBuilder().build()) + .setDestroyTime(Timestamp.newBuilder().build()) + .setDestroyEventTime(Timestamp.newBuilder().build()) + .setImportJob("importJob-208547368") + .setImportTime(Timestamp.newBuilder().build()) + .setImportFailureReason("importFailureReason985493705") + .setExternalProtectionLevelOptions(ExternalProtectionLevelOptions.newBuilder().build()) + .setReimportEligible(true) + .build(); + mockService.addResponse(expectedResponse); + + String parent = + "projects/project-7206/locations/location-7206/keyRings/keyRing-7206/cryptoKeys/cryptoKey-7206"; + CryptoKeyVersion cryptoKeyVersion = CryptoKeyVersion.newBuilder().build(); + + CryptoKeyVersion actualResponse = client.createCryptoKeyVersion(parent, cryptoKeyVersion); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void createCryptoKeyVersionExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = + "projects/project-7206/locations/location-7206/keyRings/keyRing-7206/cryptoKeys/cryptoKey-7206"; + CryptoKeyVersion cryptoKeyVersion = CryptoKeyVersion.newBuilder().build(); + client.createCryptoKeyVersion(parent, cryptoKeyVersion); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void importCryptoKeyVersionTest() throws Exception { + CryptoKeyVersion expectedResponse = + CryptoKeyVersion.newBuilder() + .setName( + CryptoKeyVersionName.of( + "[PROJECT]", + "[LOCATION]", + "[KEY_RING]", + "[CRYPTO_KEY]", + "[CRYPTO_KEY_VERSION]") + .toString()) + .setProtectionLevel(ProtectionLevel.forNumber(0)) + .setAttestation(KeyOperationAttestation.newBuilder().build()) + .setCreateTime(Timestamp.newBuilder().build()) + .setGenerateTime(Timestamp.newBuilder().build()) + .setDestroyTime(Timestamp.newBuilder().build()) + .setDestroyEventTime(Timestamp.newBuilder().build()) + .setImportJob("importJob-208547368") + .setImportTime(Timestamp.newBuilder().build()) + .setImportFailureReason("importFailureReason985493705") + .setExternalProtectionLevelOptions(ExternalProtectionLevelOptions.newBuilder().build()) + .setReimportEligible(true) + .build(); + mockService.addResponse(expectedResponse); + + ImportCryptoKeyVersionRequest request = + ImportCryptoKeyVersionRequest.newBuilder() + .setParent( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .setCryptoKeyVersion( + CryptoKeyVersionName.of( + "[PROJECT]", + "[LOCATION]", + "[KEY_RING]", + "[CRYPTO_KEY]", + "[CRYPTO_KEY_VERSION]") + .toString()) + .setImportJob("importJob-208547368") + .build(); + + CryptoKeyVersion actualResponse = client.importCryptoKeyVersion(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void importCryptoKeyVersionExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ImportCryptoKeyVersionRequest request = + ImportCryptoKeyVersionRequest.newBuilder() + .setParent( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .setCryptoKeyVersion( + CryptoKeyVersionName.of( + "[PROJECT]", + "[LOCATION]", + "[KEY_RING]", + "[CRYPTO_KEY]", + "[CRYPTO_KEY_VERSION]") + .toString()) + .setImportJob("importJob-208547368") + .build(); + client.importCryptoKeyVersion(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createImportJobTest() throws Exception { + ImportJob expectedResponse = + ImportJob.newBuilder() + .setName( + ImportJobName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[IMPORT_JOB]") + .toString()) + .setProtectionLevel(ProtectionLevel.forNumber(0)) + .setCreateTime(Timestamp.newBuilder().build()) + .setGenerateTime(Timestamp.newBuilder().build()) + .setExpireTime(Timestamp.newBuilder().build()) + .setExpireEventTime(Timestamp.newBuilder().build()) + .setPublicKey(ImportJob.WrappingPublicKey.newBuilder().build()) + .setAttestation(KeyOperationAttestation.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + KeyRingName parent = KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]"); + String importJobId = "importJobId1449444627"; + ImportJob importJob = ImportJob.newBuilder().build(); + + ImportJob actualResponse = client.createImportJob(parent, importJobId, importJob); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void createImportJobExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + KeyRingName parent = KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]"); + String importJobId = "importJobId1449444627"; + ImportJob importJob = ImportJob.newBuilder().build(); + client.createImportJob(parent, importJobId, importJob); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createImportJobTest2() throws Exception { + ImportJob expectedResponse = + ImportJob.newBuilder() + .setName( + ImportJobName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[IMPORT_JOB]") + .toString()) + .setProtectionLevel(ProtectionLevel.forNumber(0)) + .setCreateTime(Timestamp.newBuilder().build()) + .setGenerateTime(Timestamp.newBuilder().build()) + .setExpireTime(Timestamp.newBuilder().build()) + .setExpireEventTime(Timestamp.newBuilder().build()) + .setPublicKey(ImportJob.WrappingPublicKey.newBuilder().build()) + .setAttestation(KeyOperationAttestation.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-7749/locations/location-7749/keyRings/keyRing-7749"; + String importJobId = "importJobId1449444627"; + ImportJob importJob = ImportJob.newBuilder().build(); + + ImportJob actualResponse = client.createImportJob(parent, importJobId, importJob); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void createImportJobExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-7749/locations/location-7749/keyRings/keyRing-7749"; + String importJobId = "importJobId1449444627"; + ImportJob importJob = ImportJob.newBuilder().build(); + client.createImportJob(parent, importJobId, importJob); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void updateCryptoKeyTest() throws Exception { + CryptoKey expectedResponse = + CryptoKey.newBuilder() + .setName( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .setPrimary(CryptoKeyVersion.newBuilder().build()) + .setCreateTime(Timestamp.newBuilder().build()) + .setNextRotationTime(Timestamp.newBuilder().build()) + .setVersionTemplate(CryptoKeyVersionTemplate.newBuilder().build()) + .putAllLabels(new HashMap()) + .setImportOnly(true) + .setDestroyScheduledDuration(Duration.newBuilder().build()) + .setCryptoKeyBackend( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .build(); + mockService.addResponse(expectedResponse); + + CryptoKey cryptoKey = + CryptoKey.newBuilder() + .setName( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .setPrimary(CryptoKeyVersion.newBuilder().build()) + .setCreateTime(Timestamp.newBuilder().build()) + .setNextRotationTime(Timestamp.newBuilder().build()) + .setVersionTemplate(CryptoKeyVersionTemplate.newBuilder().build()) + .putAllLabels(new HashMap()) + .setImportOnly(true) + .setDestroyScheduledDuration(Duration.newBuilder().build()) + .setCryptoKeyBackend( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + + CryptoKey actualResponse = client.updateCryptoKey(cryptoKey, updateMask); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void updateCryptoKeyExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + CryptoKey cryptoKey = + CryptoKey.newBuilder() + .setName( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .setPrimary(CryptoKeyVersion.newBuilder().build()) + .setCreateTime(Timestamp.newBuilder().build()) + .setNextRotationTime(Timestamp.newBuilder().build()) + .setVersionTemplate(CryptoKeyVersionTemplate.newBuilder().build()) + .putAllLabels(new HashMap()) + .setImportOnly(true) + .setDestroyScheduledDuration(Duration.newBuilder().build()) + .setCryptoKeyBackend( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + client.updateCryptoKey(cryptoKey, updateMask); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void updateCryptoKeyVersionTest() throws Exception { + CryptoKeyVersion expectedResponse = + CryptoKeyVersion.newBuilder() + .setName( + CryptoKeyVersionName.of( + "[PROJECT]", + "[LOCATION]", + "[KEY_RING]", + "[CRYPTO_KEY]", + "[CRYPTO_KEY_VERSION]") + .toString()) + .setProtectionLevel(ProtectionLevel.forNumber(0)) + .setAttestation(KeyOperationAttestation.newBuilder().build()) + .setCreateTime(Timestamp.newBuilder().build()) + .setGenerateTime(Timestamp.newBuilder().build()) + .setDestroyTime(Timestamp.newBuilder().build()) + .setDestroyEventTime(Timestamp.newBuilder().build()) + .setImportJob("importJob-208547368") + .setImportTime(Timestamp.newBuilder().build()) + .setImportFailureReason("importFailureReason985493705") + .setExternalProtectionLevelOptions(ExternalProtectionLevelOptions.newBuilder().build()) + .setReimportEligible(true) + .build(); + mockService.addResponse(expectedResponse); + + CryptoKeyVersion cryptoKeyVersion = + CryptoKeyVersion.newBuilder() + .setName( + CryptoKeyVersionName.of( + "[PROJECT]", + "[LOCATION]", + "[KEY_RING]", + "[CRYPTO_KEY]", + "[CRYPTO_KEY_VERSION]") + .toString()) + .setProtectionLevel(ProtectionLevel.forNumber(0)) + .setAttestation(KeyOperationAttestation.newBuilder().build()) + .setCreateTime(Timestamp.newBuilder().build()) + .setGenerateTime(Timestamp.newBuilder().build()) + .setDestroyTime(Timestamp.newBuilder().build()) + .setDestroyEventTime(Timestamp.newBuilder().build()) + .setImportJob("importJob-208547368") + .setImportTime(Timestamp.newBuilder().build()) + .setImportFailureReason("importFailureReason985493705") + .setExternalProtectionLevelOptions(ExternalProtectionLevelOptions.newBuilder().build()) + .setReimportEligible(true) + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + + CryptoKeyVersion actualResponse = client.updateCryptoKeyVersion(cryptoKeyVersion, updateMask); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void updateCryptoKeyVersionExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + CryptoKeyVersion cryptoKeyVersion = + CryptoKeyVersion.newBuilder() + .setName( + CryptoKeyVersionName.of( + "[PROJECT]", + "[LOCATION]", + "[KEY_RING]", + "[CRYPTO_KEY]", + "[CRYPTO_KEY_VERSION]") + .toString()) + .setProtectionLevel(ProtectionLevel.forNumber(0)) + .setAttestation(KeyOperationAttestation.newBuilder().build()) + .setCreateTime(Timestamp.newBuilder().build()) + .setGenerateTime(Timestamp.newBuilder().build()) + .setDestroyTime(Timestamp.newBuilder().build()) + .setDestroyEventTime(Timestamp.newBuilder().build()) + .setImportJob("importJob-208547368") + .setImportTime(Timestamp.newBuilder().build()) + .setImportFailureReason("importFailureReason985493705") + .setExternalProtectionLevelOptions( + ExternalProtectionLevelOptions.newBuilder().build()) + .setReimportEligible(true) + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + client.updateCryptoKeyVersion(cryptoKeyVersion, updateMask); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void updateCryptoKeyPrimaryVersionTest() throws Exception { + CryptoKey expectedResponse = + CryptoKey.newBuilder() + .setName( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .setPrimary(CryptoKeyVersion.newBuilder().build()) + .setCreateTime(Timestamp.newBuilder().build()) + .setNextRotationTime(Timestamp.newBuilder().build()) + .setVersionTemplate(CryptoKeyVersionTemplate.newBuilder().build()) + .putAllLabels(new HashMap()) + .setImportOnly(true) + .setDestroyScheduledDuration(Duration.newBuilder().build()) + .setCryptoKeyBackend( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .build(); + mockService.addResponse(expectedResponse); + + CryptoKeyName name = CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]"); + String cryptoKeyVersionId = "cryptoKeyVersionId987674581"; + + CryptoKey actualResponse = client.updateCryptoKeyPrimaryVersion(name, cryptoKeyVersionId); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void updateCryptoKeyPrimaryVersionExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + CryptoKeyName name = + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]"); + String cryptoKeyVersionId = "cryptoKeyVersionId987674581"; + client.updateCryptoKeyPrimaryVersion(name, cryptoKeyVersionId); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void updateCryptoKeyPrimaryVersionTest2() throws Exception { + CryptoKey expectedResponse = + CryptoKey.newBuilder() + .setName( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .setPrimary(CryptoKeyVersion.newBuilder().build()) + .setCreateTime(Timestamp.newBuilder().build()) + .setNextRotationTime(Timestamp.newBuilder().build()) + .setVersionTemplate(CryptoKeyVersionTemplate.newBuilder().build()) + .putAllLabels(new HashMap()) + .setImportOnly(true) + .setDestroyScheduledDuration(Duration.newBuilder().build()) + .setCryptoKeyBackend( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .build(); + mockService.addResponse(expectedResponse); + + String name = + "projects/project-5355/locations/location-5355/keyRings/keyRing-5355/cryptoKeys/cryptoKey-5355"; + String cryptoKeyVersionId = "cryptoKeyVersionId987674581"; + + CryptoKey actualResponse = client.updateCryptoKeyPrimaryVersion(name, cryptoKeyVersionId); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void updateCryptoKeyPrimaryVersionExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-5355/locations/location-5355/keyRings/keyRing-5355/cryptoKeys/cryptoKey-5355"; + String cryptoKeyVersionId = "cryptoKeyVersionId987674581"; + client.updateCryptoKeyPrimaryVersion(name, cryptoKeyVersionId); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void destroyCryptoKeyVersionTest() throws Exception { + CryptoKeyVersion expectedResponse = + CryptoKeyVersion.newBuilder() + .setName( + CryptoKeyVersionName.of( + "[PROJECT]", + "[LOCATION]", + "[KEY_RING]", + "[CRYPTO_KEY]", + "[CRYPTO_KEY_VERSION]") + .toString()) + .setProtectionLevel(ProtectionLevel.forNumber(0)) + .setAttestation(KeyOperationAttestation.newBuilder().build()) + .setCreateTime(Timestamp.newBuilder().build()) + .setGenerateTime(Timestamp.newBuilder().build()) + .setDestroyTime(Timestamp.newBuilder().build()) + .setDestroyEventTime(Timestamp.newBuilder().build()) + .setImportJob("importJob-208547368") + .setImportTime(Timestamp.newBuilder().build()) + .setImportFailureReason("importFailureReason985493705") + .setExternalProtectionLevelOptions(ExternalProtectionLevelOptions.newBuilder().build()) + .setReimportEligible(true) + .build(); + mockService.addResponse(expectedResponse); + + CryptoKeyVersionName name = + CryptoKeyVersionName.of( + "[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]", "[CRYPTO_KEY_VERSION]"); + + CryptoKeyVersion actualResponse = client.destroyCryptoKeyVersion(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void destroyCryptoKeyVersionExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + CryptoKeyVersionName name = + CryptoKeyVersionName.of( + "[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]", "[CRYPTO_KEY_VERSION]"); + client.destroyCryptoKeyVersion(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void destroyCryptoKeyVersionTest2() throws Exception { + CryptoKeyVersion expectedResponse = + CryptoKeyVersion.newBuilder() + .setName( + CryptoKeyVersionName.of( + "[PROJECT]", + "[LOCATION]", + "[KEY_RING]", + "[CRYPTO_KEY]", + "[CRYPTO_KEY_VERSION]") + .toString()) + .setProtectionLevel(ProtectionLevel.forNumber(0)) + .setAttestation(KeyOperationAttestation.newBuilder().build()) + .setCreateTime(Timestamp.newBuilder().build()) + .setGenerateTime(Timestamp.newBuilder().build()) + .setDestroyTime(Timestamp.newBuilder().build()) + .setDestroyEventTime(Timestamp.newBuilder().build()) + .setImportJob("importJob-208547368") + .setImportTime(Timestamp.newBuilder().build()) + .setImportFailureReason("importFailureReason985493705") + .setExternalProtectionLevelOptions(ExternalProtectionLevelOptions.newBuilder().build()) + .setReimportEligible(true) + .build(); + mockService.addResponse(expectedResponse); + + String name = + "projects/project-9504/locations/location-9504/keyRings/keyRing-9504/cryptoKeys/cryptoKey-9504/cryptoKeyVersions/cryptoKeyVersion-9504"; + + CryptoKeyVersion actualResponse = client.destroyCryptoKeyVersion(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void destroyCryptoKeyVersionExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-9504/locations/location-9504/keyRings/keyRing-9504/cryptoKeys/cryptoKey-9504/cryptoKeyVersions/cryptoKeyVersion-9504"; + client.destroyCryptoKeyVersion(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void restoreCryptoKeyVersionTest() throws Exception { + CryptoKeyVersion expectedResponse = + CryptoKeyVersion.newBuilder() + .setName( + CryptoKeyVersionName.of( + "[PROJECT]", + "[LOCATION]", + "[KEY_RING]", + "[CRYPTO_KEY]", + "[CRYPTO_KEY_VERSION]") + .toString()) + .setProtectionLevel(ProtectionLevel.forNumber(0)) + .setAttestation(KeyOperationAttestation.newBuilder().build()) + .setCreateTime(Timestamp.newBuilder().build()) + .setGenerateTime(Timestamp.newBuilder().build()) + .setDestroyTime(Timestamp.newBuilder().build()) + .setDestroyEventTime(Timestamp.newBuilder().build()) + .setImportJob("importJob-208547368") + .setImportTime(Timestamp.newBuilder().build()) + .setImportFailureReason("importFailureReason985493705") + .setExternalProtectionLevelOptions(ExternalProtectionLevelOptions.newBuilder().build()) + .setReimportEligible(true) + .build(); + mockService.addResponse(expectedResponse); + + CryptoKeyVersionName name = + CryptoKeyVersionName.of( + "[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]", "[CRYPTO_KEY_VERSION]"); + + CryptoKeyVersion actualResponse = client.restoreCryptoKeyVersion(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void restoreCryptoKeyVersionExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + CryptoKeyVersionName name = + CryptoKeyVersionName.of( + "[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]", "[CRYPTO_KEY_VERSION]"); + client.restoreCryptoKeyVersion(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void restoreCryptoKeyVersionTest2() throws Exception { + CryptoKeyVersion expectedResponse = + CryptoKeyVersion.newBuilder() + .setName( + CryptoKeyVersionName.of( + "[PROJECT]", + "[LOCATION]", + "[KEY_RING]", + "[CRYPTO_KEY]", + "[CRYPTO_KEY_VERSION]") + .toString()) + .setProtectionLevel(ProtectionLevel.forNumber(0)) + .setAttestation(KeyOperationAttestation.newBuilder().build()) + .setCreateTime(Timestamp.newBuilder().build()) + .setGenerateTime(Timestamp.newBuilder().build()) + .setDestroyTime(Timestamp.newBuilder().build()) + .setDestroyEventTime(Timestamp.newBuilder().build()) + .setImportJob("importJob-208547368") + .setImportTime(Timestamp.newBuilder().build()) + .setImportFailureReason("importFailureReason985493705") + .setExternalProtectionLevelOptions(ExternalProtectionLevelOptions.newBuilder().build()) + .setReimportEligible(true) + .build(); + mockService.addResponse(expectedResponse); + + String name = + "projects/project-9504/locations/location-9504/keyRings/keyRing-9504/cryptoKeys/cryptoKey-9504/cryptoKeyVersions/cryptoKeyVersion-9504"; + + CryptoKeyVersion actualResponse = client.restoreCryptoKeyVersion(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void restoreCryptoKeyVersionExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-9504/locations/location-9504/keyRings/keyRing-9504/cryptoKeys/cryptoKey-9504/cryptoKeyVersions/cryptoKeyVersion-9504"; + client.restoreCryptoKeyVersion(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void encryptTest() throws Exception { + EncryptResponse expectedResponse = + EncryptResponse.newBuilder() + .setName("name3373707") + .setCiphertext(ByteString.EMPTY) + .setCiphertextCrc32C(Int64Value.newBuilder().build()) + .setVerifiedPlaintextCrc32C(true) + .setVerifiedAdditionalAuthenticatedDataCrc32C(true) + .setProtectionLevel(ProtectionLevel.forNumber(0)) + .build(); + mockService.addResponse(expectedResponse); + + ResourceName name = CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]"); + ByteString plaintext = ByteString.EMPTY; + + EncryptResponse actualResponse = client.encrypt(name, plaintext); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void encryptExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ResourceName name = CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]"); + ByteString plaintext = ByteString.EMPTY; + client.encrypt(name, plaintext); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void encryptTest2() throws Exception { + EncryptResponse expectedResponse = + EncryptResponse.newBuilder() + .setName("name3373707") + .setCiphertext(ByteString.EMPTY) + .setCiphertextCrc32C(Int64Value.newBuilder().build()) + .setVerifiedPlaintextCrc32C(true) + .setVerifiedAdditionalAuthenticatedDataCrc32C(true) + .setProtectionLevel(ProtectionLevel.forNumber(0)) + .build(); + mockService.addResponse(expectedResponse); + + String name = + "projects/project-4975/locations/location-4975/keyRings/keyRing-4975/cryptoKeys/cryptoKey-4975"; + ByteString plaintext = ByteString.EMPTY; + + EncryptResponse actualResponse = client.encrypt(name, plaintext); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void encryptExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-4975/locations/location-4975/keyRings/keyRing-4975/cryptoKeys/cryptoKey-4975"; + ByteString plaintext = ByteString.EMPTY; + client.encrypt(name, plaintext); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void decryptTest() throws Exception { + DecryptResponse expectedResponse = + DecryptResponse.newBuilder() + .setPlaintext(ByteString.EMPTY) + .setPlaintextCrc32C(Int64Value.newBuilder().build()) + .setUsedPrimary(true) + .setProtectionLevel(ProtectionLevel.forNumber(0)) + .build(); + mockService.addResponse(expectedResponse); + + CryptoKeyName name = CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]"); + ByteString ciphertext = ByteString.EMPTY; + + DecryptResponse actualResponse = client.decrypt(name, ciphertext); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void decryptExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + CryptoKeyName name = + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]"); + ByteString ciphertext = ByteString.EMPTY; + client.decrypt(name, ciphertext); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void decryptTest2() throws Exception { + DecryptResponse expectedResponse = + DecryptResponse.newBuilder() + .setPlaintext(ByteString.EMPTY) + .setPlaintextCrc32C(Int64Value.newBuilder().build()) + .setUsedPrimary(true) + .setProtectionLevel(ProtectionLevel.forNumber(0)) + .build(); + mockService.addResponse(expectedResponse); + + String name = + "projects/project-5355/locations/location-5355/keyRings/keyRing-5355/cryptoKeys/cryptoKey-5355"; + ByteString ciphertext = ByteString.EMPTY; + + DecryptResponse actualResponse = client.decrypt(name, ciphertext); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void decryptExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-5355/locations/location-5355/keyRings/keyRing-5355/cryptoKeys/cryptoKey-5355"; + ByteString ciphertext = ByteString.EMPTY; + client.decrypt(name, ciphertext); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void asymmetricSignTest() throws Exception { + AsymmetricSignResponse expectedResponse = + AsymmetricSignResponse.newBuilder() + .setSignature(ByteString.EMPTY) + .setSignatureCrc32C(Int64Value.newBuilder().build()) + .setVerifiedDigestCrc32C(true) + .setName("name3373707") + .setVerifiedDataCrc32C(true) + .setProtectionLevel(ProtectionLevel.forNumber(0)) + .build(); + mockService.addResponse(expectedResponse); + + CryptoKeyVersionName name = + CryptoKeyVersionName.of( + "[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]", "[CRYPTO_KEY_VERSION]"); + Digest digest = Digest.newBuilder().build(); + + AsymmetricSignResponse actualResponse = client.asymmetricSign(name, digest); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void asymmetricSignExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + CryptoKeyVersionName name = + CryptoKeyVersionName.of( + "[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]", "[CRYPTO_KEY_VERSION]"); + Digest digest = Digest.newBuilder().build(); + client.asymmetricSign(name, digest); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void asymmetricSignTest2() throws Exception { + AsymmetricSignResponse expectedResponse = + AsymmetricSignResponse.newBuilder() + .setSignature(ByteString.EMPTY) + .setSignatureCrc32C(Int64Value.newBuilder().build()) + .setVerifiedDigestCrc32C(true) + .setName("name3373707") + .setVerifiedDataCrc32C(true) + .setProtectionLevel(ProtectionLevel.forNumber(0)) + .build(); + mockService.addResponse(expectedResponse); + + String name = + "projects/project-9504/locations/location-9504/keyRings/keyRing-9504/cryptoKeys/cryptoKey-9504/cryptoKeyVersions/cryptoKeyVersion-9504"; + Digest digest = Digest.newBuilder().build(); + + AsymmetricSignResponse actualResponse = client.asymmetricSign(name, digest); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void asymmetricSignExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-9504/locations/location-9504/keyRings/keyRing-9504/cryptoKeys/cryptoKey-9504/cryptoKeyVersions/cryptoKeyVersion-9504"; + Digest digest = Digest.newBuilder().build(); + client.asymmetricSign(name, digest); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void asymmetricDecryptTest() throws Exception { + AsymmetricDecryptResponse expectedResponse = + AsymmetricDecryptResponse.newBuilder() + .setPlaintext(ByteString.EMPTY) + .setPlaintextCrc32C(Int64Value.newBuilder().build()) + .setVerifiedCiphertextCrc32C(true) + .setProtectionLevel(ProtectionLevel.forNumber(0)) + .build(); + mockService.addResponse(expectedResponse); + + CryptoKeyVersionName name = + CryptoKeyVersionName.of( + "[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]", "[CRYPTO_KEY_VERSION]"); + ByteString ciphertext = ByteString.EMPTY; + + AsymmetricDecryptResponse actualResponse = client.asymmetricDecrypt(name, ciphertext); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void asymmetricDecryptExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + CryptoKeyVersionName name = + CryptoKeyVersionName.of( + "[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]", "[CRYPTO_KEY_VERSION]"); + ByteString ciphertext = ByteString.EMPTY; + client.asymmetricDecrypt(name, ciphertext); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void asymmetricDecryptTest2() throws Exception { + AsymmetricDecryptResponse expectedResponse = + AsymmetricDecryptResponse.newBuilder() + .setPlaintext(ByteString.EMPTY) + .setPlaintextCrc32C(Int64Value.newBuilder().build()) + .setVerifiedCiphertextCrc32C(true) + .setProtectionLevel(ProtectionLevel.forNumber(0)) + .build(); + mockService.addResponse(expectedResponse); + + String name = + "projects/project-9504/locations/location-9504/keyRings/keyRing-9504/cryptoKeys/cryptoKey-9504/cryptoKeyVersions/cryptoKeyVersion-9504"; + ByteString ciphertext = ByteString.EMPTY; + + AsymmetricDecryptResponse actualResponse = client.asymmetricDecrypt(name, ciphertext); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void asymmetricDecryptExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-9504/locations/location-9504/keyRings/keyRing-9504/cryptoKeys/cryptoKey-9504/cryptoKeyVersions/cryptoKeyVersion-9504"; + ByteString ciphertext = ByteString.EMPTY; + client.asymmetricDecrypt(name, ciphertext); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void macSignTest() throws Exception { + MacSignResponse expectedResponse = + MacSignResponse.newBuilder() + .setName("name3373707") + .setMac(ByteString.EMPTY) + .setMacCrc32C(Int64Value.newBuilder().build()) + .setVerifiedDataCrc32C(true) + .setProtectionLevel(ProtectionLevel.forNumber(0)) + .build(); + mockService.addResponse(expectedResponse); + + CryptoKeyVersionName name = + CryptoKeyVersionName.of( + "[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]", "[CRYPTO_KEY_VERSION]"); + ByteString data = ByteString.EMPTY; + + MacSignResponse actualResponse = client.macSign(name, data); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void macSignExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + CryptoKeyVersionName name = + CryptoKeyVersionName.of( + "[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]", "[CRYPTO_KEY_VERSION]"); + ByteString data = ByteString.EMPTY; + client.macSign(name, data); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void macSignTest2() throws Exception { + MacSignResponse expectedResponse = + MacSignResponse.newBuilder() + .setName("name3373707") + .setMac(ByteString.EMPTY) + .setMacCrc32C(Int64Value.newBuilder().build()) + .setVerifiedDataCrc32C(true) + .setProtectionLevel(ProtectionLevel.forNumber(0)) + .build(); + mockService.addResponse(expectedResponse); + + String name = + "projects/project-9504/locations/location-9504/keyRings/keyRing-9504/cryptoKeys/cryptoKey-9504/cryptoKeyVersions/cryptoKeyVersion-9504"; + ByteString data = ByteString.EMPTY; + + MacSignResponse actualResponse = client.macSign(name, data); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void macSignExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-9504/locations/location-9504/keyRings/keyRing-9504/cryptoKeys/cryptoKey-9504/cryptoKeyVersions/cryptoKeyVersion-9504"; + ByteString data = ByteString.EMPTY; + client.macSign(name, data); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void macVerifyTest() throws Exception { + MacVerifyResponse expectedResponse = + MacVerifyResponse.newBuilder() + .setName("name3373707") + .setSuccess(true) + .setVerifiedDataCrc32C(true) + .setVerifiedMacCrc32C(true) + .setVerifiedSuccessIntegrity(true) + .setProtectionLevel(ProtectionLevel.forNumber(0)) + .build(); + mockService.addResponse(expectedResponse); + + CryptoKeyVersionName name = + CryptoKeyVersionName.of( + "[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]", "[CRYPTO_KEY_VERSION]"); + ByteString data = ByteString.EMPTY; + ByteString mac = ByteString.EMPTY; + + MacVerifyResponse actualResponse = client.macVerify(name, data, mac); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void macVerifyExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + CryptoKeyVersionName name = + CryptoKeyVersionName.of( + "[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]", "[CRYPTO_KEY_VERSION]"); + ByteString data = ByteString.EMPTY; + ByteString mac = ByteString.EMPTY; + client.macVerify(name, data, mac); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void macVerifyTest2() throws Exception { + MacVerifyResponse expectedResponse = + MacVerifyResponse.newBuilder() + .setName("name3373707") + .setSuccess(true) + .setVerifiedDataCrc32C(true) + .setVerifiedMacCrc32C(true) + .setVerifiedSuccessIntegrity(true) + .setProtectionLevel(ProtectionLevel.forNumber(0)) + .build(); + mockService.addResponse(expectedResponse); + + String name = + "projects/project-9504/locations/location-9504/keyRings/keyRing-9504/cryptoKeys/cryptoKey-9504/cryptoKeyVersions/cryptoKeyVersion-9504"; + ByteString data = ByteString.EMPTY; + ByteString mac = ByteString.EMPTY; + + MacVerifyResponse actualResponse = client.macVerify(name, data, mac); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void macVerifyExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-9504/locations/location-9504/keyRings/keyRing-9504/cryptoKeys/cryptoKey-9504/cryptoKeyVersions/cryptoKeyVersion-9504"; + ByteString data = ByteString.EMPTY; + ByteString mac = ByteString.EMPTY; + client.macVerify(name, data, mac); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void generateRandomBytesTest() throws Exception { + GenerateRandomBytesResponse expectedResponse = + GenerateRandomBytesResponse.newBuilder() + .setData(ByteString.EMPTY) + .setDataCrc32C(Int64Value.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String location = "projects/project-7132/locations/location-7132"; + int lengthBytes = -745661998; + ProtectionLevel protectionLevel = ProtectionLevel.forNumber(0); + + GenerateRandomBytesResponse actualResponse = + client.generateRandomBytes(location, lengthBytes, protectionLevel); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void generateRandomBytesExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String location = "projects/project-7132/locations/location-7132"; + int lengthBytes = -745661998; + ProtectionLevel protectionLevel = ProtectionLevel.forNumber(0); + client.generateRandomBytes(location, lengthBytes, protectionLevel); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void setIamPolicyTest() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setVersion(351608024) + .addAllBindings(new ArrayList()) + .addAllAuditConfigs(new ArrayList()) + .setEtag(ByteString.EMPTY) + .build(); + mockService.addResponse(expectedResponse); + + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + + Policy actualResponse = client.setIamPolicy(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void setIamPolicyExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + client.setIamPolicy(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getIamPolicyTest() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setVersion(351608024) + .addAllBindings(new ArrayList()) + .addAllAuditConfigs(new ArrayList()) + .setEtag(ByteString.EMPTY) + .build(); + mockService.addResponse(expectedResponse); + + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + + Policy actualResponse = client.getIamPolicy(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getIamPolicyExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + client.getIamPolicy(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void testIamPermissionsTest() throws Exception { + TestIamPermissionsResponse expectedResponse = + TestIamPermissionsResponse.newBuilder().addAllPermissions(new ArrayList()).build(); + mockService.addResponse(expectedResponse); + + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .addAllPermissions(new ArrayList()) + .build(); + + TestIamPermissionsResponse actualResponse = client.testIamPermissions(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void testIamPermissionsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .addAllPermissions(new ArrayList()) + .build(); + client.testIamPermissions(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } +} diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/create/SyncCreateSetCredentialsProvider.java b/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/create/SyncCreateSetCredentialsProvider.java new file mode 100644 index 00000000..e0b3a970 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/create/SyncCreateSetCredentialsProvider.java @@ -0,0 +1,41 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_ekmserviceclient_create_setcredentialsprovider_sync] +import com.google.api.gax.core.FixedCredentialsProvider; +import com.google.cloud.kms.v1.EkmServiceClient; +import com.google.cloud.kms.v1.EkmServiceSettings; +import com.google.cloud.kms.v1.myCredentials; + +public class SyncCreateSetCredentialsProvider { + + public static void main(String[] args) throws Exception { + syncCreateSetCredentialsProvider(); + } + + public static void syncCreateSetCredentialsProvider() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + EkmServiceSettings ekmServiceSettings = + EkmServiceSettings.newBuilder() + .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) + .build(); + EkmServiceClient ekmServiceClient = EkmServiceClient.create(ekmServiceSettings); + } +} +// [END kms_v1_generated_ekmserviceclient_create_setcredentialsprovider_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/create/SyncCreateSetCredentialsProvider1.java b/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/create/SyncCreateSetCredentialsProvider1.java new file mode 100644 index 00000000..75d03b90 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/create/SyncCreateSetCredentialsProvider1.java @@ -0,0 +1,40 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_ekmserviceclient_create_setcredentialsprovider1_sync] +import com.google.cloud.kms.v1.EkmServiceClient; +import com.google.cloud.kms.v1.EkmServiceSettings; + +public class SyncCreateSetCredentialsProvider1 { + + public static void main(String[] args) throws Exception { + syncCreateSetCredentialsProvider1(); + } + + public static void syncCreateSetCredentialsProvider1() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + EkmServiceSettings ekmServiceSettings = + EkmServiceSettings.newBuilder() + .setTransportChannelProvider( + EkmServiceSettings.defaultHttpJsonTransportProviderBuilder().build()) + .build(); + EkmServiceClient ekmServiceClient = EkmServiceClient.create(ekmServiceSettings); + } +} +// [END kms_v1_generated_ekmserviceclient_create_setcredentialsprovider1_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/create/SyncCreateSetEndpoint.java b/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/create/SyncCreateSetEndpoint.java new file mode 100644 index 00000000..afcae3a2 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/create/SyncCreateSetEndpoint.java @@ -0,0 +1,38 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_ekmserviceclient_create_setendpoint_sync] +import com.google.cloud.kms.v1.EkmServiceClient; +import com.google.cloud.kms.v1.EkmServiceSettings; +import com.google.cloud.kms.v1.myEndpoint; + +public class SyncCreateSetEndpoint { + + public static void main(String[] args) throws Exception { + syncCreateSetEndpoint(); + } + + public static void syncCreateSetEndpoint() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + EkmServiceSettings ekmServiceSettings = + EkmServiceSettings.newBuilder().setEndpoint(myEndpoint).build(); + EkmServiceClient ekmServiceClient = EkmServiceClient.create(ekmServiceSettings); + } +} +// [END kms_v1_generated_ekmserviceclient_create_setendpoint_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/createekmconnection/AsyncCreateEkmConnection.java b/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/createekmconnection/AsyncCreateEkmConnection.java new file mode 100644 index 00000000..8cf75f58 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/createekmconnection/AsyncCreateEkmConnection.java @@ -0,0 +1,49 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_ekmserviceclient_createekmconnection_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.kms.v1.CreateEkmConnectionRequest; +import com.google.cloud.kms.v1.EkmConnection; +import com.google.cloud.kms.v1.EkmServiceClient; +import com.google.cloud.kms.v1.LocationName; + +public class AsyncCreateEkmConnection { + + public static void main(String[] args) throws Exception { + asyncCreateEkmConnection(); + } + + public static void asyncCreateEkmConnection() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (EkmServiceClient ekmServiceClient = EkmServiceClient.create()) { + CreateEkmConnectionRequest request = + CreateEkmConnectionRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setEkmConnectionId("ekmConnectionId-445017408") + .setEkmConnection(EkmConnection.newBuilder().build()) + .build(); + ApiFuture future = + ekmServiceClient.createEkmConnectionCallable().futureCall(request); + // Do something. + EkmConnection response = future.get(); + } + } +} +// [END kms_v1_generated_ekmserviceclient_createekmconnection_async] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/createekmconnection/SyncCreateEkmConnection.java b/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/createekmconnection/SyncCreateEkmConnection.java new file mode 100644 index 00000000..f31737fe --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/createekmconnection/SyncCreateEkmConnection.java @@ -0,0 +1,45 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_ekmserviceclient_createekmconnection_sync] +import com.google.cloud.kms.v1.CreateEkmConnectionRequest; +import com.google.cloud.kms.v1.EkmConnection; +import com.google.cloud.kms.v1.EkmServiceClient; +import com.google.cloud.kms.v1.LocationName; + +public class SyncCreateEkmConnection { + + public static void main(String[] args) throws Exception { + syncCreateEkmConnection(); + } + + public static void syncCreateEkmConnection() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (EkmServiceClient ekmServiceClient = EkmServiceClient.create()) { + CreateEkmConnectionRequest request = + CreateEkmConnectionRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setEkmConnectionId("ekmConnectionId-445017408") + .setEkmConnection(EkmConnection.newBuilder().build()) + .build(); + EkmConnection response = ekmServiceClient.createEkmConnection(request); + } + } +} +// [END kms_v1_generated_ekmserviceclient_createekmconnection_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/createekmconnection/SyncCreateEkmConnectionLocationnameStringEkmconnection.java b/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/createekmconnection/SyncCreateEkmConnectionLocationnameStringEkmconnection.java new file mode 100644 index 00000000..9cb41fd3 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/createekmconnection/SyncCreateEkmConnectionLocationnameStringEkmconnection.java @@ -0,0 +1,42 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_ekmserviceclient_createekmconnection_locationnamestringekmconnection_sync] +import com.google.cloud.kms.v1.EkmConnection; +import com.google.cloud.kms.v1.EkmServiceClient; +import com.google.cloud.kms.v1.LocationName; + +public class SyncCreateEkmConnectionLocationnameStringEkmconnection { + + public static void main(String[] args) throws Exception { + syncCreateEkmConnectionLocationnameStringEkmconnection(); + } + + public static void syncCreateEkmConnectionLocationnameStringEkmconnection() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (EkmServiceClient ekmServiceClient = EkmServiceClient.create()) { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + String ekmConnectionId = "ekmConnectionId-445017408"; + EkmConnection ekmConnection = EkmConnection.newBuilder().build(); + EkmConnection response = + ekmServiceClient.createEkmConnection(parent, ekmConnectionId, ekmConnection); + } + } +} +// [END kms_v1_generated_ekmserviceclient_createekmconnection_locationnamestringekmconnection_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/createekmconnection/SyncCreateEkmConnectionStringStringEkmconnection.java b/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/createekmconnection/SyncCreateEkmConnectionStringStringEkmconnection.java new file mode 100644 index 00000000..061a4c07 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/createekmconnection/SyncCreateEkmConnectionStringStringEkmconnection.java @@ -0,0 +1,42 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_ekmserviceclient_createekmconnection_stringstringekmconnection_sync] +import com.google.cloud.kms.v1.EkmConnection; +import com.google.cloud.kms.v1.EkmServiceClient; +import com.google.cloud.kms.v1.LocationName; + +public class SyncCreateEkmConnectionStringStringEkmconnection { + + public static void main(String[] args) throws Exception { + syncCreateEkmConnectionStringStringEkmconnection(); + } + + public static void syncCreateEkmConnectionStringStringEkmconnection() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (EkmServiceClient ekmServiceClient = EkmServiceClient.create()) { + String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString(); + String ekmConnectionId = "ekmConnectionId-445017408"; + EkmConnection ekmConnection = EkmConnection.newBuilder().build(); + EkmConnection response = + ekmServiceClient.createEkmConnection(parent, ekmConnectionId, ekmConnection); + } + } +} +// [END kms_v1_generated_ekmserviceclient_createekmconnection_stringstringekmconnection_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/getekmconnection/AsyncGetEkmConnection.java b/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/getekmconnection/AsyncGetEkmConnection.java new file mode 100644 index 00000000..d366a373 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/getekmconnection/AsyncGetEkmConnection.java @@ -0,0 +1,48 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_ekmserviceclient_getekmconnection_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.kms.v1.EkmConnection; +import com.google.cloud.kms.v1.EkmConnectionName; +import com.google.cloud.kms.v1.EkmServiceClient; +import com.google.cloud.kms.v1.GetEkmConnectionRequest; + +public class AsyncGetEkmConnection { + + public static void main(String[] args) throws Exception { + asyncGetEkmConnection(); + } + + public static void asyncGetEkmConnection() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (EkmServiceClient ekmServiceClient = EkmServiceClient.create()) { + GetEkmConnectionRequest request = + GetEkmConnectionRequest.newBuilder() + .setName( + EkmConnectionName.of("[PROJECT]", "[LOCATION]", "[EKM_CONNECTION]").toString()) + .build(); + ApiFuture future = + ekmServiceClient.getEkmConnectionCallable().futureCall(request); + // Do something. + EkmConnection response = future.get(); + } + } +} +// [END kms_v1_generated_ekmserviceclient_getekmconnection_async] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/getekmconnection/SyncGetEkmConnection.java b/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/getekmconnection/SyncGetEkmConnection.java new file mode 100644 index 00000000..9edf556b --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/getekmconnection/SyncGetEkmConnection.java @@ -0,0 +1,44 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_ekmserviceclient_getekmconnection_sync] +import com.google.cloud.kms.v1.EkmConnection; +import com.google.cloud.kms.v1.EkmConnectionName; +import com.google.cloud.kms.v1.EkmServiceClient; +import com.google.cloud.kms.v1.GetEkmConnectionRequest; + +public class SyncGetEkmConnection { + + public static void main(String[] args) throws Exception { + syncGetEkmConnection(); + } + + public static void syncGetEkmConnection() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (EkmServiceClient ekmServiceClient = EkmServiceClient.create()) { + GetEkmConnectionRequest request = + GetEkmConnectionRequest.newBuilder() + .setName( + EkmConnectionName.of("[PROJECT]", "[LOCATION]", "[EKM_CONNECTION]").toString()) + .build(); + EkmConnection response = ekmServiceClient.getEkmConnection(request); + } + } +} +// [END kms_v1_generated_ekmserviceclient_getekmconnection_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/getekmconnection/SyncGetEkmConnectionEkmconnectionname.java b/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/getekmconnection/SyncGetEkmConnectionEkmconnectionname.java new file mode 100644 index 00000000..d8d6d7dd --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/getekmconnection/SyncGetEkmConnectionEkmconnectionname.java @@ -0,0 +1,39 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_ekmserviceclient_getekmconnection_ekmconnectionname_sync] +import com.google.cloud.kms.v1.EkmConnection; +import com.google.cloud.kms.v1.EkmConnectionName; +import com.google.cloud.kms.v1.EkmServiceClient; + +public class SyncGetEkmConnectionEkmconnectionname { + + public static void main(String[] args) throws Exception { + syncGetEkmConnectionEkmconnectionname(); + } + + public static void syncGetEkmConnectionEkmconnectionname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (EkmServiceClient ekmServiceClient = EkmServiceClient.create()) { + EkmConnectionName name = EkmConnectionName.of("[PROJECT]", "[LOCATION]", "[EKM_CONNECTION]"); + EkmConnection response = ekmServiceClient.getEkmConnection(name); + } + } +} +// [END kms_v1_generated_ekmserviceclient_getekmconnection_ekmconnectionname_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/getekmconnection/SyncGetEkmConnectionString.java b/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/getekmconnection/SyncGetEkmConnectionString.java new file mode 100644 index 00000000..c8fcd02d --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/getekmconnection/SyncGetEkmConnectionString.java @@ -0,0 +1,39 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_ekmserviceclient_getekmconnection_string_sync] +import com.google.cloud.kms.v1.EkmConnection; +import com.google.cloud.kms.v1.EkmConnectionName; +import com.google.cloud.kms.v1.EkmServiceClient; + +public class SyncGetEkmConnectionString { + + public static void main(String[] args) throws Exception { + syncGetEkmConnectionString(); + } + + public static void syncGetEkmConnectionString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (EkmServiceClient ekmServiceClient = EkmServiceClient.create()) { + String name = EkmConnectionName.of("[PROJECT]", "[LOCATION]", "[EKM_CONNECTION]").toString(); + EkmConnection response = ekmServiceClient.getEkmConnection(name); + } + } +} +// [END kms_v1_generated_ekmserviceclient_getekmconnection_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/getiampolicy/AsyncGetIamPolicy.java b/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/getiampolicy/AsyncGetIamPolicy.java new file mode 100644 index 00000000..97ce4848 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/getiampolicy/AsyncGetIamPolicy.java @@ -0,0 +1,50 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_ekmserviceclient_getiampolicy_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.kms.v1.CryptoKeyName; +import com.google.cloud.kms.v1.EkmServiceClient; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.GetPolicyOptions; +import com.google.iam.v1.Policy; + +public class AsyncGetIamPolicy { + + public static void main(String[] args) throws Exception { + asyncGetIamPolicy(); + } + + public static void asyncGetIamPolicy() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (EkmServiceClient ekmServiceClient = EkmServiceClient.create()) { + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + ApiFuture future = ekmServiceClient.getIamPolicyCallable().futureCall(request); + // Do something. + Policy response = future.get(); + } + } +} +// [END kms_v1_generated_ekmserviceclient_getiampolicy_async] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/getiampolicy/SyncGetIamPolicy.java b/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/getiampolicy/SyncGetIamPolicy.java new file mode 100644 index 00000000..a943e0df --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/getiampolicy/SyncGetIamPolicy.java @@ -0,0 +1,47 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_ekmserviceclient_getiampolicy_sync] +import com.google.cloud.kms.v1.CryptoKeyName; +import com.google.cloud.kms.v1.EkmServiceClient; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.GetPolicyOptions; +import com.google.iam.v1.Policy; + +public class SyncGetIamPolicy { + + public static void main(String[] args) throws Exception { + syncGetIamPolicy(); + } + + public static void syncGetIamPolicy() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (EkmServiceClient ekmServiceClient = EkmServiceClient.create()) { + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + Policy response = ekmServiceClient.getIamPolicy(request); + } + } +} +// [END kms_v1_generated_ekmserviceclient_getiampolicy_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/listekmconnections/AsyncListEkmConnections.java b/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/listekmconnections/AsyncListEkmConnections.java new file mode 100644 index 00000000..b4a3e3fc --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/listekmconnections/AsyncListEkmConnections.java @@ -0,0 +1,53 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_ekmserviceclient_listekmconnections_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.kms.v1.EkmConnection; +import com.google.cloud.kms.v1.EkmServiceClient; +import com.google.cloud.kms.v1.ListEkmConnectionsRequest; +import com.google.cloud.kms.v1.LocationName; + +public class AsyncListEkmConnections { + + public static void main(String[] args) throws Exception { + asyncListEkmConnections(); + } + + public static void asyncListEkmConnections() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (EkmServiceClient ekmServiceClient = EkmServiceClient.create()) { + ListEkmConnectionsRequest request = + ListEkmConnectionsRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .setOrderBy("orderBy-1207110587") + .build(); + ApiFuture future = + ekmServiceClient.listEkmConnectionsPagedCallable().futureCall(request); + // Do something. + for (EkmConnection element : future.get().iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END kms_v1_generated_ekmserviceclient_listekmconnections_async] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/listekmconnections/AsyncListEkmConnectionsPaged.java b/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/listekmconnections/AsyncListEkmConnectionsPaged.java new file mode 100644 index 00000000..bfc0ade5 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/listekmconnections/AsyncListEkmConnectionsPaged.java @@ -0,0 +1,61 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_ekmserviceclient_listekmconnections_paged_async] +import com.google.cloud.kms.v1.EkmConnection; +import com.google.cloud.kms.v1.EkmServiceClient; +import com.google.cloud.kms.v1.ListEkmConnectionsRequest; +import com.google.cloud.kms.v1.ListEkmConnectionsResponse; +import com.google.cloud.kms.v1.LocationName; +import com.google.common.base.Strings; + +public class AsyncListEkmConnectionsPaged { + + public static void main(String[] args) throws Exception { + asyncListEkmConnectionsPaged(); + } + + public static void asyncListEkmConnectionsPaged() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (EkmServiceClient ekmServiceClient = EkmServiceClient.create()) { + ListEkmConnectionsRequest request = + ListEkmConnectionsRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .setOrderBy("orderBy-1207110587") + .build(); + while (true) { + ListEkmConnectionsResponse response = + ekmServiceClient.listEkmConnectionsCallable().call(request); + for (EkmConnection element : response.getEkmConnectionsList()) { + // doThingsWith(element); + } + String nextPageToken = response.getNextPageToken(); + if (!Strings.isNullOrEmpty(nextPageToken)) { + request = request.toBuilder().setPageToken(nextPageToken).build(); + } else { + break; + } + } + } + } +} +// [END kms_v1_generated_ekmserviceclient_listekmconnections_paged_async] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/listekmconnections/SyncListEkmConnections.java b/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/listekmconnections/SyncListEkmConnections.java new file mode 100644 index 00000000..f8853360 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/listekmconnections/SyncListEkmConnections.java @@ -0,0 +1,49 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_ekmserviceclient_listekmconnections_sync] +import com.google.cloud.kms.v1.EkmConnection; +import com.google.cloud.kms.v1.EkmServiceClient; +import com.google.cloud.kms.v1.ListEkmConnectionsRequest; +import com.google.cloud.kms.v1.LocationName; + +public class SyncListEkmConnections { + + public static void main(String[] args) throws Exception { + syncListEkmConnections(); + } + + public static void syncListEkmConnections() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (EkmServiceClient ekmServiceClient = EkmServiceClient.create()) { + ListEkmConnectionsRequest request = + ListEkmConnectionsRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .setOrderBy("orderBy-1207110587") + .build(); + for (EkmConnection element : ekmServiceClient.listEkmConnections(request).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END kms_v1_generated_ekmserviceclient_listekmconnections_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/listekmconnections/SyncListEkmConnectionsLocationname.java b/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/listekmconnections/SyncListEkmConnectionsLocationname.java new file mode 100644 index 00000000..cf3803c2 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/listekmconnections/SyncListEkmConnectionsLocationname.java @@ -0,0 +1,41 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_ekmserviceclient_listekmconnections_locationname_sync] +import com.google.cloud.kms.v1.EkmConnection; +import com.google.cloud.kms.v1.EkmServiceClient; +import com.google.cloud.kms.v1.LocationName; + +public class SyncListEkmConnectionsLocationname { + + public static void main(String[] args) throws Exception { + syncListEkmConnectionsLocationname(); + } + + public static void syncListEkmConnectionsLocationname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (EkmServiceClient ekmServiceClient = EkmServiceClient.create()) { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + for (EkmConnection element : ekmServiceClient.listEkmConnections(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END kms_v1_generated_ekmserviceclient_listekmconnections_locationname_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/listekmconnections/SyncListEkmConnectionsString.java b/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/listekmconnections/SyncListEkmConnectionsString.java new file mode 100644 index 00000000..7c8d520c --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/listekmconnections/SyncListEkmConnectionsString.java @@ -0,0 +1,41 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_ekmserviceclient_listekmconnections_string_sync] +import com.google.cloud.kms.v1.EkmConnection; +import com.google.cloud.kms.v1.EkmServiceClient; +import com.google.cloud.kms.v1.LocationName; + +public class SyncListEkmConnectionsString { + + public static void main(String[] args) throws Exception { + syncListEkmConnectionsString(); + } + + public static void syncListEkmConnectionsString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (EkmServiceClient ekmServiceClient = EkmServiceClient.create()) { + String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString(); + for (EkmConnection element : ekmServiceClient.listEkmConnections(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END kms_v1_generated_ekmserviceclient_listekmconnections_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/setiampolicy/AsyncSetIamPolicy.java b/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/setiampolicy/AsyncSetIamPolicy.java new file mode 100644 index 00000000..b689376a --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/setiampolicy/AsyncSetIamPolicy.java @@ -0,0 +1,51 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_ekmserviceclient_setiampolicy_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.kms.v1.CryptoKeyName; +import com.google.cloud.kms.v1.EkmServiceClient; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.protobuf.FieldMask; + +public class AsyncSetIamPolicy { + + public static void main(String[] args) throws Exception { + asyncSetIamPolicy(); + } + + public static void asyncSetIamPolicy() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (EkmServiceClient ekmServiceClient = EkmServiceClient.create()) { + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + ApiFuture future = ekmServiceClient.setIamPolicyCallable().futureCall(request); + // Do something. + Policy response = future.get(); + } + } +} +// [END kms_v1_generated_ekmserviceclient_setiampolicy_async] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/setiampolicy/SyncSetIamPolicy.java b/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/setiampolicy/SyncSetIamPolicy.java new file mode 100644 index 00000000..1be20070 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/setiampolicy/SyncSetIamPolicy.java @@ -0,0 +1,48 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_ekmserviceclient_setiampolicy_sync] +import com.google.cloud.kms.v1.CryptoKeyName; +import com.google.cloud.kms.v1.EkmServiceClient; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.protobuf.FieldMask; + +public class SyncSetIamPolicy { + + public static void main(String[] args) throws Exception { + syncSetIamPolicy(); + } + + public static void syncSetIamPolicy() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (EkmServiceClient ekmServiceClient = EkmServiceClient.create()) { + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + Policy response = ekmServiceClient.setIamPolicy(request); + } + } +} +// [END kms_v1_generated_ekmserviceclient_setiampolicy_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/testiampermissions/AsyncTestIamPermissions.java b/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/testiampermissions/AsyncTestIamPermissions.java new file mode 100644 index 00000000..13ce5904 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/testiampermissions/AsyncTestIamPermissions.java @@ -0,0 +1,51 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_ekmserviceclient_testiampermissions_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.kms.v1.CryptoKeyName; +import com.google.cloud.kms.v1.EkmServiceClient; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; +import java.util.ArrayList; + +public class AsyncTestIamPermissions { + + public static void main(String[] args) throws Exception { + asyncTestIamPermissions(); + } + + public static void asyncTestIamPermissions() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (EkmServiceClient ekmServiceClient = EkmServiceClient.create()) { + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .addAllPermissions(new ArrayList()) + .build(); + ApiFuture future = + ekmServiceClient.testIamPermissionsCallable().futureCall(request); + // Do something. + TestIamPermissionsResponse response = future.get(); + } + } +} +// [END kms_v1_generated_ekmserviceclient_testiampermissions_async] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/testiampermissions/SyncTestIamPermissions.java b/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/testiampermissions/SyncTestIamPermissions.java new file mode 100644 index 00000000..cea81922 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/testiampermissions/SyncTestIamPermissions.java @@ -0,0 +1,47 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_ekmserviceclient_testiampermissions_sync] +import com.google.cloud.kms.v1.CryptoKeyName; +import com.google.cloud.kms.v1.EkmServiceClient; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; +import java.util.ArrayList; + +public class SyncTestIamPermissions { + + public static void main(String[] args) throws Exception { + syncTestIamPermissions(); + } + + public static void syncTestIamPermissions() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (EkmServiceClient ekmServiceClient = EkmServiceClient.create()) { + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .addAllPermissions(new ArrayList()) + .build(); + TestIamPermissionsResponse response = ekmServiceClient.testIamPermissions(request); + } + } +} +// [END kms_v1_generated_ekmserviceclient_testiampermissions_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/updateekmconnection/AsyncUpdateEkmConnection.java b/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/updateekmconnection/AsyncUpdateEkmConnection.java new file mode 100644 index 00000000..5330fe72 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/updateekmconnection/AsyncUpdateEkmConnection.java @@ -0,0 +1,48 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_ekmserviceclient_updateekmconnection_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.kms.v1.EkmConnection; +import com.google.cloud.kms.v1.EkmServiceClient; +import com.google.cloud.kms.v1.UpdateEkmConnectionRequest; +import com.google.protobuf.FieldMask; + +public class AsyncUpdateEkmConnection { + + public static void main(String[] args) throws Exception { + asyncUpdateEkmConnection(); + } + + public static void asyncUpdateEkmConnection() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (EkmServiceClient ekmServiceClient = EkmServiceClient.create()) { + UpdateEkmConnectionRequest request = + UpdateEkmConnectionRequest.newBuilder() + .setEkmConnection(EkmConnection.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + ApiFuture future = + ekmServiceClient.updateEkmConnectionCallable().futureCall(request); + // Do something. + EkmConnection response = future.get(); + } + } +} +// [END kms_v1_generated_ekmserviceclient_updateekmconnection_async] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/updateekmconnection/SyncUpdateEkmConnection.java b/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/updateekmconnection/SyncUpdateEkmConnection.java new file mode 100644 index 00000000..eb877481 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/updateekmconnection/SyncUpdateEkmConnection.java @@ -0,0 +1,44 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_ekmserviceclient_updateekmconnection_sync] +import com.google.cloud.kms.v1.EkmConnection; +import com.google.cloud.kms.v1.EkmServiceClient; +import com.google.cloud.kms.v1.UpdateEkmConnectionRequest; +import com.google.protobuf.FieldMask; + +public class SyncUpdateEkmConnection { + + public static void main(String[] args) throws Exception { + syncUpdateEkmConnection(); + } + + public static void syncUpdateEkmConnection() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (EkmServiceClient ekmServiceClient = EkmServiceClient.create()) { + UpdateEkmConnectionRequest request = + UpdateEkmConnectionRequest.newBuilder() + .setEkmConnection(EkmConnection.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + EkmConnection response = ekmServiceClient.updateEkmConnection(request); + } + } +} +// [END kms_v1_generated_ekmserviceclient_updateekmconnection_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/updateekmconnection/SyncUpdateEkmConnectionEkmconnectionFieldmask.java b/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/updateekmconnection/SyncUpdateEkmConnectionEkmconnectionFieldmask.java new file mode 100644 index 00000000..7d8ef7ea --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/ekmserviceclient/updateekmconnection/SyncUpdateEkmConnectionEkmconnectionFieldmask.java @@ -0,0 +1,40 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_ekmserviceclient_updateekmconnection_ekmconnectionfieldmask_sync] +import com.google.cloud.kms.v1.EkmConnection; +import com.google.cloud.kms.v1.EkmServiceClient; +import com.google.protobuf.FieldMask; + +public class SyncUpdateEkmConnectionEkmconnectionFieldmask { + + public static void main(String[] args) throws Exception { + syncUpdateEkmConnectionEkmconnectionFieldmask(); + } + + public static void syncUpdateEkmConnectionEkmconnectionFieldmask() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (EkmServiceClient ekmServiceClient = EkmServiceClient.create()) { + EkmConnection ekmConnection = EkmConnection.newBuilder().build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + EkmConnection response = ekmServiceClient.updateEkmConnection(ekmConnection, updateMask); + } + } +} +// [END kms_v1_generated_ekmserviceclient_updateekmconnection_ekmconnectionfieldmask_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/ekmservicesettings/getekmconnection/SyncGetEkmConnection.java b/samples/snippets/generated/com/google/cloud/kms/v1/ekmservicesettings/getekmconnection/SyncGetEkmConnection.java new file mode 100644 index 00000000..48169069 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/ekmservicesettings/getekmconnection/SyncGetEkmConnection.java @@ -0,0 +1,45 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_ekmservicesettings_getekmconnection_sync] +import com.google.cloud.kms.v1.EkmServiceSettings; +import java.time.Duration; + +public class SyncGetEkmConnection { + + public static void main(String[] args) throws Exception { + syncGetEkmConnection(); + } + + public static void syncGetEkmConnection() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + EkmServiceSettings.Builder ekmServiceSettingsBuilder = EkmServiceSettings.newBuilder(); + ekmServiceSettingsBuilder + .getEkmConnectionSettings() + .setRetrySettings( + ekmServiceSettingsBuilder + .getEkmConnectionSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + EkmServiceSettings ekmServiceSettings = ekmServiceSettingsBuilder.build(); + } +} +// [END kms_v1_generated_ekmservicesettings_getekmconnection_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/asymmetricdecrypt/AsyncAsymmetricDecrypt.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/asymmetricdecrypt/AsyncAsymmetricDecrypt.java new file mode 100644 index 00000000..d2d323b4 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/asymmetricdecrypt/AsyncAsymmetricDecrypt.java @@ -0,0 +1,59 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_asymmetricdecrypt_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.kms.v1.AsymmetricDecryptRequest; +import com.google.cloud.kms.v1.AsymmetricDecryptResponse; +import com.google.cloud.kms.v1.CryptoKeyVersionName; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.protobuf.ByteString; +import com.google.protobuf.Int64Value; + +public class AsyncAsymmetricDecrypt { + + public static void main(String[] args) throws Exception { + asyncAsymmetricDecrypt(); + } + + public static void asyncAsymmetricDecrypt() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + AsymmetricDecryptRequest request = + AsymmetricDecryptRequest.newBuilder() + .setName( + CryptoKeyVersionName.of( + "[PROJECT]", + "[LOCATION]", + "[KEY_RING]", + "[CRYPTO_KEY]", + "[CRYPTO_KEY_VERSION]") + .toString()) + .setCiphertext(ByteString.EMPTY) + .setCiphertextCrc32C(Int64Value.newBuilder().build()) + .build(); + ApiFuture future = + keyManagementServiceClient.asymmetricDecryptCallable().futureCall(request); + // Do something. + AsymmetricDecryptResponse response = future.get(); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_asymmetricdecrypt_async] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/asymmetricdecrypt/SyncAsymmetricDecrypt.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/asymmetricdecrypt/SyncAsymmetricDecrypt.java new file mode 100644 index 00000000..efda2ce9 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/asymmetricdecrypt/SyncAsymmetricDecrypt.java @@ -0,0 +1,55 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_asymmetricdecrypt_sync] +import com.google.cloud.kms.v1.AsymmetricDecryptRequest; +import com.google.cloud.kms.v1.AsymmetricDecryptResponse; +import com.google.cloud.kms.v1.CryptoKeyVersionName; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.protobuf.ByteString; +import com.google.protobuf.Int64Value; + +public class SyncAsymmetricDecrypt { + + public static void main(String[] args) throws Exception { + syncAsymmetricDecrypt(); + } + + public static void syncAsymmetricDecrypt() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + AsymmetricDecryptRequest request = + AsymmetricDecryptRequest.newBuilder() + .setName( + CryptoKeyVersionName.of( + "[PROJECT]", + "[LOCATION]", + "[KEY_RING]", + "[CRYPTO_KEY]", + "[CRYPTO_KEY_VERSION]") + .toString()) + .setCiphertext(ByteString.EMPTY) + .setCiphertextCrc32C(Int64Value.newBuilder().build()) + .build(); + AsymmetricDecryptResponse response = keyManagementServiceClient.asymmetricDecrypt(request); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_asymmetricdecrypt_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/asymmetricdecrypt/SyncAsymmetricDecryptCryptokeyversionnameBytestring.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/asymmetricdecrypt/SyncAsymmetricDecryptCryptokeyversionnameBytestring.java new file mode 100644 index 00000000..57378973 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/asymmetricdecrypt/SyncAsymmetricDecryptCryptokeyversionnameBytestring.java @@ -0,0 +1,45 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_asymmetricdecrypt_cryptokeyversionnamebytestring_sync] +import com.google.cloud.kms.v1.AsymmetricDecryptResponse; +import com.google.cloud.kms.v1.CryptoKeyVersionName; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.protobuf.ByteString; + +public class SyncAsymmetricDecryptCryptokeyversionnameBytestring { + + public static void main(String[] args) throws Exception { + syncAsymmetricDecryptCryptokeyversionnameBytestring(); + } + + public static void syncAsymmetricDecryptCryptokeyversionnameBytestring() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + CryptoKeyVersionName name = + CryptoKeyVersionName.of( + "[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]", "[CRYPTO_KEY_VERSION]"); + ByteString ciphertext = ByteString.EMPTY; + AsymmetricDecryptResponse response = + keyManagementServiceClient.asymmetricDecrypt(name, ciphertext); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_asymmetricdecrypt_cryptokeyversionnamebytestring_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/asymmetricdecrypt/SyncAsymmetricDecryptStringBytestring.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/asymmetricdecrypt/SyncAsymmetricDecryptStringBytestring.java new file mode 100644 index 00000000..7aac61a8 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/asymmetricdecrypt/SyncAsymmetricDecryptStringBytestring.java @@ -0,0 +1,46 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_asymmetricdecrypt_stringbytestring_sync] +import com.google.cloud.kms.v1.AsymmetricDecryptResponse; +import com.google.cloud.kms.v1.CryptoKeyVersionName; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.protobuf.ByteString; + +public class SyncAsymmetricDecryptStringBytestring { + + public static void main(String[] args) throws Exception { + syncAsymmetricDecryptStringBytestring(); + } + + public static void syncAsymmetricDecryptStringBytestring() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + String name = + CryptoKeyVersionName.of( + "[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]", "[CRYPTO_KEY_VERSION]") + .toString(); + ByteString ciphertext = ByteString.EMPTY; + AsymmetricDecryptResponse response = + keyManagementServiceClient.asymmetricDecrypt(name, ciphertext); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_asymmetricdecrypt_stringbytestring_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/asymmetricsign/AsyncAsymmetricSign.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/asymmetricsign/AsyncAsymmetricSign.java new file mode 100644 index 00000000..2704b48f --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/asymmetricsign/AsyncAsymmetricSign.java @@ -0,0 +1,62 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_asymmetricsign_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.kms.v1.AsymmetricSignRequest; +import com.google.cloud.kms.v1.AsymmetricSignResponse; +import com.google.cloud.kms.v1.CryptoKeyVersionName; +import com.google.cloud.kms.v1.Digest; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.protobuf.ByteString; +import com.google.protobuf.Int64Value; + +public class AsyncAsymmetricSign { + + public static void main(String[] args) throws Exception { + asyncAsymmetricSign(); + } + + public static void asyncAsymmetricSign() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + AsymmetricSignRequest request = + AsymmetricSignRequest.newBuilder() + .setName( + CryptoKeyVersionName.of( + "[PROJECT]", + "[LOCATION]", + "[KEY_RING]", + "[CRYPTO_KEY]", + "[CRYPTO_KEY_VERSION]") + .toString()) + .setDigest(Digest.newBuilder().build()) + .setDigestCrc32C(Int64Value.newBuilder().build()) + .setData(ByteString.EMPTY) + .setDataCrc32C(Int64Value.newBuilder().build()) + .build(); + ApiFuture future = + keyManagementServiceClient.asymmetricSignCallable().futureCall(request); + // Do something. + AsymmetricSignResponse response = future.get(); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_asymmetricsign_async] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/asymmetricsign/SyncAsymmetricSign.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/asymmetricsign/SyncAsymmetricSign.java new file mode 100644 index 00000000..d2609561 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/asymmetricsign/SyncAsymmetricSign.java @@ -0,0 +1,58 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_asymmetricsign_sync] +import com.google.cloud.kms.v1.AsymmetricSignRequest; +import com.google.cloud.kms.v1.AsymmetricSignResponse; +import com.google.cloud.kms.v1.CryptoKeyVersionName; +import com.google.cloud.kms.v1.Digest; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.protobuf.ByteString; +import com.google.protobuf.Int64Value; + +public class SyncAsymmetricSign { + + public static void main(String[] args) throws Exception { + syncAsymmetricSign(); + } + + public static void syncAsymmetricSign() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + AsymmetricSignRequest request = + AsymmetricSignRequest.newBuilder() + .setName( + CryptoKeyVersionName.of( + "[PROJECT]", + "[LOCATION]", + "[KEY_RING]", + "[CRYPTO_KEY]", + "[CRYPTO_KEY_VERSION]") + .toString()) + .setDigest(Digest.newBuilder().build()) + .setDigestCrc32C(Int64Value.newBuilder().build()) + .setData(ByteString.EMPTY) + .setDataCrc32C(Int64Value.newBuilder().build()) + .build(); + AsymmetricSignResponse response = keyManagementServiceClient.asymmetricSign(request); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_asymmetricsign_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/asymmetricsign/SyncAsymmetricSignCryptokeyversionnameDigest.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/asymmetricsign/SyncAsymmetricSignCryptokeyversionnameDigest.java new file mode 100644 index 00000000..ffb27fb3 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/asymmetricsign/SyncAsymmetricSignCryptokeyversionnameDigest.java @@ -0,0 +1,44 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_asymmetricsign_cryptokeyversionnamedigest_sync] +import com.google.cloud.kms.v1.AsymmetricSignResponse; +import com.google.cloud.kms.v1.CryptoKeyVersionName; +import com.google.cloud.kms.v1.Digest; +import com.google.cloud.kms.v1.KeyManagementServiceClient; + +public class SyncAsymmetricSignCryptokeyversionnameDigest { + + public static void main(String[] args) throws Exception { + syncAsymmetricSignCryptokeyversionnameDigest(); + } + + public static void syncAsymmetricSignCryptokeyversionnameDigest() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + CryptoKeyVersionName name = + CryptoKeyVersionName.of( + "[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]", "[CRYPTO_KEY_VERSION]"); + Digest digest = Digest.newBuilder().build(); + AsymmetricSignResponse response = keyManagementServiceClient.asymmetricSign(name, digest); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_asymmetricsign_cryptokeyversionnamedigest_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/asymmetricsign/SyncAsymmetricSignStringDigest.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/asymmetricsign/SyncAsymmetricSignStringDigest.java new file mode 100644 index 00000000..51c506b2 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/asymmetricsign/SyncAsymmetricSignStringDigest.java @@ -0,0 +1,45 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_asymmetricsign_stringdigest_sync] +import com.google.cloud.kms.v1.AsymmetricSignResponse; +import com.google.cloud.kms.v1.CryptoKeyVersionName; +import com.google.cloud.kms.v1.Digest; +import com.google.cloud.kms.v1.KeyManagementServiceClient; + +public class SyncAsymmetricSignStringDigest { + + public static void main(String[] args) throws Exception { + syncAsymmetricSignStringDigest(); + } + + public static void syncAsymmetricSignStringDigest() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + String name = + CryptoKeyVersionName.of( + "[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]", "[CRYPTO_KEY_VERSION]") + .toString(); + Digest digest = Digest.newBuilder().build(); + AsymmetricSignResponse response = keyManagementServiceClient.asymmetricSign(name, digest); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_asymmetricsign_stringdigest_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/create/SyncCreateSetCredentialsProvider.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/create/SyncCreateSetCredentialsProvider.java new file mode 100644 index 00000000..a3b313fc --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/create/SyncCreateSetCredentialsProvider.java @@ -0,0 +1,42 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_create_setcredentialsprovider_sync] +import com.google.api.gax.core.FixedCredentialsProvider; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.KeyManagementServiceSettings; +import com.google.cloud.kms.v1.myCredentials; + +public class SyncCreateSetCredentialsProvider { + + public static void main(String[] args) throws Exception { + syncCreateSetCredentialsProvider(); + } + + public static void syncCreateSetCredentialsProvider() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + KeyManagementServiceSettings keyManagementServiceSettings = + KeyManagementServiceSettings.newBuilder() + .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) + .build(); + KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create(keyManagementServiceSettings); + } +} +// [END kms_v1_generated_keymanagementserviceclient_create_setcredentialsprovider_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/create/SyncCreateSetCredentialsProvider1.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/create/SyncCreateSetCredentialsProvider1.java new file mode 100644 index 00000000..35bbf73e --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/create/SyncCreateSetCredentialsProvider1.java @@ -0,0 +1,41 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_create_setcredentialsprovider1_sync] +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.KeyManagementServiceSettings; + +public class SyncCreateSetCredentialsProvider1 { + + public static void main(String[] args) throws Exception { + syncCreateSetCredentialsProvider1(); + } + + public static void syncCreateSetCredentialsProvider1() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + KeyManagementServiceSettings keyManagementServiceSettings = + KeyManagementServiceSettings.newBuilder() + .setTransportChannelProvider( + KeyManagementServiceSettings.defaultHttpJsonTransportProviderBuilder().build()) + .build(); + KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create(keyManagementServiceSettings); + } +} +// [END kms_v1_generated_keymanagementserviceclient_create_setcredentialsprovider1_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/create/SyncCreateSetEndpoint.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/create/SyncCreateSetEndpoint.java new file mode 100644 index 00000000..a3f0de93 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/create/SyncCreateSetEndpoint.java @@ -0,0 +1,39 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_create_setendpoint_sync] +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.KeyManagementServiceSettings; +import com.google.cloud.kms.v1.myEndpoint; + +public class SyncCreateSetEndpoint { + + public static void main(String[] args) throws Exception { + syncCreateSetEndpoint(); + } + + public static void syncCreateSetEndpoint() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + KeyManagementServiceSettings keyManagementServiceSettings = + KeyManagementServiceSettings.newBuilder().setEndpoint(myEndpoint).build(); + KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create(keyManagementServiceSettings); + } +} +// [END kms_v1_generated_keymanagementserviceclient_create_setendpoint_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/createcryptokey/AsyncCreateCryptoKey.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/createcryptokey/AsyncCreateCryptoKey.java new file mode 100644 index 00000000..219a4e0b --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/createcryptokey/AsyncCreateCryptoKey.java @@ -0,0 +1,51 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_createcryptokey_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.kms.v1.CreateCryptoKeyRequest; +import com.google.cloud.kms.v1.CryptoKey; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.KeyRingName; + +public class AsyncCreateCryptoKey { + + public static void main(String[] args) throws Exception { + asyncCreateCryptoKey(); + } + + public static void asyncCreateCryptoKey() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + CreateCryptoKeyRequest request = + CreateCryptoKeyRequest.newBuilder() + .setParent(KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]").toString()) + .setCryptoKeyId("cryptoKeyId-1643185255") + .setCryptoKey(CryptoKey.newBuilder().build()) + .setSkipInitialVersionCreation(true) + .build(); + ApiFuture future = + keyManagementServiceClient.createCryptoKeyCallable().futureCall(request); + // Do something. + CryptoKey response = future.get(); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_createcryptokey_async] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/createcryptokey/SyncCreateCryptoKey.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/createcryptokey/SyncCreateCryptoKey.java new file mode 100644 index 00000000..0fd2282f --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/createcryptokey/SyncCreateCryptoKey.java @@ -0,0 +1,47 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_createcryptokey_sync] +import com.google.cloud.kms.v1.CreateCryptoKeyRequest; +import com.google.cloud.kms.v1.CryptoKey; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.KeyRingName; + +public class SyncCreateCryptoKey { + + public static void main(String[] args) throws Exception { + syncCreateCryptoKey(); + } + + public static void syncCreateCryptoKey() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + CreateCryptoKeyRequest request = + CreateCryptoKeyRequest.newBuilder() + .setParent(KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]").toString()) + .setCryptoKeyId("cryptoKeyId-1643185255") + .setCryptoKey(CryptoKey.newBuilder().build()) + .setSkipInitialVersionCreation(true) + .build(); + CryptoKey response = keyManagementServiceClient.createCryptoKey(request); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_createcryptokey_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/createcryptokey/SyncCreateCryptoKeyKeyringnameStringCryptokey.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/createcryptokey/SyncCreateCryptoKeyKeyringnameStringCryptokey.java new file mode 100644 index 00000000..9719174a --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/createcryptokey/SyncCreateCryptoKeyKeyringnameStringCryptokey.java @@ -0,0 +1,43 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_createcryptokey_keyringnamestringcryptokey_sync] +import com.google.cloud.kms.v1.CryptoKey; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.KeyRingName; + +public class SyncCreateCryptoKeyKeyringnameStringCryptokey { + + public static void main(String[] args) throws Exception { + syncCreateCryptoKeyKeyringnameStringCryptokey(); + } + + public static void syncCreateCryptoKeyKeyringnameStringCryptokey() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // 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); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_createcryptokey_keyringnamestringcryptokey_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/createcryptokey/SyncCreateCryptoKeyStringStringCryptokey.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/createcryptokey/SyncCreateCryptoKeyStringStringCryptokey.java new file mode 100644 index 00000000..064c0938 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/createcryptokey/SyncCreateCryptoKeyStringStringCryptokey.java @@ -0,0 +1,43 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_createcryptokey_stringstringcryptokey_sync] +import com.google.cloud.kms.v1.CryptoKey; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.KeyRingName; + +public class SyncCreateCryptoKeyStringStringCryptokey { + + public static void main(String[] args) throws Exception { + syncCreateCryptoKeyStringStringCryptokey(); + } + + public static void syncCreateCryptoKeyStringStringCryptokey() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + String parent = KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]").toString(); + String cryptoKeyId = "cryptoKeyId-1643185255"; + CryptoKey cryptoKey = CryptoKey.newBuilder().build(); + CryptoKey response = + keyManagementServiceClient.createCryptoKey(parent, cryptoKeyId, cryptoKey); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_createcryptokey_stringstringcryptokey_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/createcryptokeyversion/AsyncCreateCryptoKeyVersion.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/createcryptokeyversion/AsyncCreateCryptoKeyVersion.java new file mode 100644 index 00000000..154d4cbd --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/createcryptokeyversion/AsyncCreateCryptoKeyVersion.java @@ -0,0 +1,51 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_createcryptokeyversion_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.kms.v1.CreateCryptoKeyVersionRequest; +import com.google.cloud.kms.v1.CryptoKeyName; +import com.google.cloud.kms.v1.CryptoKeyVersion; +import com.google.cloud.kms.v1.KeyManagementServiceClient; + +public class AsyncCreateCryptoKeyVersion { + + public static void main(String[] args) throws Exception { + asyncCreateCryptoKeyVersion(); + } + + public static void asyncCreateCryptoKeyVersion() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + CreateCryptoKeyVersionRequest request = + CreateCryptoKeyVersionRequest.newBuilder() + .setParent( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .setCryptoKeyVersion(CryptoKeyVersion.newBuilder().build()) + .build(); + ApiFuture future = + keyManagementServiceClient.createCryptoKeyVersionCallable().futureCall(request); + // Do something. + CryptoKeyVersion response = future.get(); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_createcryptokeyversion_async] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/createcryptokeyversion/SyncCreateCryptoKeyVersion.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/createcryptokeyversion/SyncCreateCryptoKeyVersion.java new file mode 100644 index 00000000..0d6d7e8c --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/createcryptokeyversion/SyncCreateCryptoKeyVersion.java @@ -0,0 +1,47 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_createcryptokeyversion_sync] +import com.google.cloud.kms.v1.CreateCryptoKeyVersionRequest; +import com.google.cloud.kms.v1.CryptoKeyName; +import com.google.cloud.kms.v1.CryptoKeyVersion; +import com.google.cloud.kms.v1.KeyManagementServiceClient; + +public class SyncCreateCryptoKeyVersion { + + public static void main(String[] args) throws Exception { + syncCreateCryptoKeyVersion(); + } + + public static void syncCreateCryptoKeyVersion() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + CreateCryptoKeyVersionRequest request = + CreateCryptoKeyVersionRequest.newBuilder() + .setParent( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .setCryptoKeyVersion(CryptoKeyVersion.newBuilder().build()) + .build(); + CryptoKeyVersion response = keyManagementServiceClient.createCryptoKeyVersion(request); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_createcryptokeyversion_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/createcryptokeyversion/SyncCreateCryptoKeyVersionCryptokeynameCryptokeyversion.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/createcryptokeyversion/SyncCreateCryptoKeyVersionCryptokeynameCryptokeyversion.java new file mode 100644 index 00000000..bd085983 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/createcryptokeyversion/SyncCreateCryptoKeyVersionCryptokeynameCryptokeyversion.java @@ -0,0 +1,43 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_createcryptokeyversion_cryptokeynamecryptokeyversion_sync] +import com.google.cloud.kms.v1.CryptoKeyName; +import com.google.cloud.kms.v1.CryptoKeyVersion; +import com.google.cloud.kms.v1.KeyManagementServiceClient; + +public class SyncCreateCryptoKeyVersionCryptokeynameCryptokeyversion { + + public static void main(String[] args) throws Exception { + syncCreateCryptoKeyVersionCryptokeynameCryptokeyversion(); + } + + public static void syncCreateCryptoKeyVersionCryptokeynameCryptokeyversion() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + CryptoKeyName parent = + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]"); + CryptoKeyVersion cryptoKeyVersion = CryptoKeyVersion.newBuilder().build(); + CryptoKeyVersion response = + keyManagementServiceClient.createCryptoKeyVersion(parent, cryptoKeyVersion); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_createcryptokeyversion_cryptokeynamecryptokeyversion_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/createcryptokeyversion/SyncCreateCryptoKeyVersionStringCryptokeyversion.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/createcryptokeyversion/SyncCreateCryptoKeyVersionStringCryptokeyversion.java new file mode 100644 index 00000000..6991e442 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/createcryptokeyversion/SyncCreateCryptoKeyVersionStringCryptokeyversion.java @@ -0,0 +1,43 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_createcryptokeyversion_stringcryptokeyversion_sync] +import com.google.cloud.kms.v1.CryptoKeyName; +import com.google.cloud.kms.v1.CryptoKeyVersion; +import com.google.cloud.kms.v1.KeyManagementServiceClient; + +public class SyncCreateCryptoKeyVersionStringCryptokeyversion { + + public static void main(String[] args) throws Exception { + syncCreateCryptoKeyVersionStringCryptokeyversion(); + } + + public static void syncCreateCryptoKeyVersionStringCryptokeyversion() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + String parent = + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]").toString(); + CryptoKeyVersion cryptoKeyVersion = CryptoKeyVersion.newBuilder().build(); + CryptoKeyVersion response = + keyManagementServiceClient.createCryptoKeyVersion(parent, cryptoKeyVersion); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_createcryptokeyversion_stringcryptokeyversion_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/createimportjob/AsyncCreateImportJob.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/createimportjob/AsyncCreateImportJob.java new file mode 100644 index 00000000..2358cca2 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/createimportjob/AsyncCreateImportJob.java @@ -0,0 +1,50 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_createimportjob_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.kms.v1.CreateImportJobRequest; +import com.google.cloud.kms.v1.ImportJob; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.KeyRingName; + +public class AsyncCreateImportJob { + + public static void main(String[] args) throws Exception { + asyncCreateImportJob(); + } + + public static void asyncCreateImportJob() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + CreateImportJobRequest request = + CreateImportJobRequest.newBuilder() + .setParent(KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]").toString()) + .setImportJobId("importJobId1449444627") + .setImportJob(ImportJob.newBuilder().build()) + .build(); + ApiFuture future = + keyManagementServiceClient.createImportJobCallable().futureCall(request); + // Do something. + ImportJob response = future.get(); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_createimportjob_async] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/createimportjob/SyncCreateImportJob.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/createimportjob/SyncCreateImportJob.java new file mode 100644 index 00000000..576caadd --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/createimportjob/SyncCreateImportJob.java @@ -0,0 +1,46 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_createimportjob_sync] +import com.google.cloud.kms.v1.CreateImportJobRequest; +import com.google.cloud.kms.v1.ImportJob; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.KeyRingName; + +public class SyncCreateImportJob { + + public static void main(String[] args) throws Exception { + syncCreateImportJob(); + } + + public static void syncCreateImportJob() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + CreateImportJobRequest request = + CreateImportJobRequest.newBuilder() + .setParent(KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]").toString()) + .setImportJobId("importJobId1449444627") + .setImportJob(ImportJob.newBuilder().build()) + .build(); + ImportJob response = keyManagementServiceClient.createImportJob(request); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_createimportjob_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/createimportjob/SyncCreateImportJobKeyringnameStringImportjob.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/createimportjob/SyncCreateImportJobKeyringnameStringImportjob.java new file mode 100644 index 00000000..ceddcf40 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/createimportjob/SyncCreateImportJobKeyringnameStringImportjob.java @@ -0,0 +1,43 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_createimportjob_keyringnamestringimportjob_sync] +import com.google.cloud.kms.v1.ImportJob; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.KeyRingName; + +public class SyncCreateImportJobKeyringnameStringImportjob { + + public static void main(String[] args) throws Exception { + syncCreateImportJobKeyringnameStringImportjob(); + } + + public static void syncCreateImportJobKeyringnameStringImportjob() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // 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); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_createimportjob_keyringnamestringimportjob_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/createimportjob/SyncCreateImportJobStringStringImportjob.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/createimportjob/SyncCreateImportJobStringStringImportjob.java new file mode 100644 index 00000000..2ecd330c --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/createimportjob/SyncCreateImportJobStringStringImportjob.java @@ -0,0 +1,43 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_createimportjob_stringstringimportjob_sync] +import com.google.cloud.kms.v1.ImportJob; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.KeyRingName; + +public class SyncCreateImportJobStringStringImportjob { + + public static void main(String[] args) throws Exception { + syncCreateImportJobStringStringImportjob(); + } + + public static void syncCreateImportJobStringStringImportjob() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + String parent = KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]").toString(); + String importJobId = "importJobId1449444627"; + ImportJob importJob = ImportJob.newBuilder().build(); + ImportJob response = + keyManagementServiceClient.createImportJob(parent, importJobId, importJob); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_createimportjob_stringstringimportjob_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/createkeyring/AsyncCreateKeyRing.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/createkeyring/AsyncCreateKeyRing.java new file mode 100644 index 00000000..b3603204 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/createkeyring/AsyncCreateKeyRing.java @@ -0,0 +1,50 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_createkeyring_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.kms.v1.CreateKeyRingRequest; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.KeyRing; +import com.google.cloud.kms.v1.LocationName; + +public class AsyncCreateKeyRing { + + public static void main(String[] args) throws Exception { + asyncCreateKeyRing(); + } + + public static void asyncCreateKeyRing() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + CreateKeyRingRequest request = + CreateKeyRingRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setKeyRingId("keyRingId-2027180374") + .setKeyRing(KeyRing.newBuilder().build()) + .build(); + ApiFuture future = + keyManagementServiceClient.createKeyRingCallable().futureCall(request); + // Do something. + KeyRing response = future.get(); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_createkeyring_async] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/createkeyring/SyncCreateKeyRing.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/createkeyring/SyncCreateKeyRing.java new file mode 100644 index 00000000..72e53465 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/createkeyring/SyncCreateKeyRing.java @@ -0,0 +1,46 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_createkeyring_sync] +import com.google.cloud.kms.v1.CreateKeyRingRequest; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.KeyRing; +import com.google.cloud.kms.v1.LocationName; + +public class SyncCreateKeyRing { + + public static void main(String[] args) throws Exception { + syncCreateKeyRing(); + } + + public static void syncCreateKeyRing() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + CreateKeyRingRequest request = + CreateKeyRingRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setKeyRingId("keyRingId-2027180374") + .setKeyRing(KeyRing.newBuilder().build()) + .build(); + KeyRing response = keyManagementServiceClient.createKeyRing(request); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_createkeyring_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/createkeyring/SyncCreateKeyRingLocationnameStringKeyring.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/createkeyring/SyncCreateKeyRingLocationnameStringKeyring.java new file mode 100644 index 00000000..22e23905 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/createkeyring/SyncCreateKeyRingLocationnameStringKeyring.java @@ -0,0 +1,42 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_createkeyring_locationnamestringkeyring_sync] +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.KeyRing; +import com.google.cloud.kms.v1.LocationName; + +public class SyncCreateKeyRingLocationnameStringKeyring { + + public static void main(String[] args) throws Exception { + syncCreateKeyRingLocationnameStringKeyring(); + } + + public static void syncCreateKeyRingLocationnameStringKeyring() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + String keyRingId = "keyRingId-2027180374"; + KeyRing keyRing = KeyRing.newBuilder().build(); + KeyRing response = keyManagementServiceClient.createKeyRing(parent, keyRingId, keyRing); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_createkeyring_locationnamestringkeyring_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/createkeyring/SyncCreateKeyRingStringStringKeyring.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/createkeyring/SyncCreateKeyRingStringStringKeyring.java new file mode 100644 index 00000000..f1b4a3fa --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/createkeyring/SyncCreateKeyRingStringStringKeyring.java @@ -0,0 +1,42 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_createkeyring_stringstringkeyring_sync] +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.KeyRing; +import com.google.cloud.kms.v1.LocationName; + +public class SyncCreateKeyRingStringStringKeyring { + + public static void main(String[] args) throws Exception { + syncCreateKeyRingStringStringKeyring(); + } + + public static void syncCreateKeyRingStringStringKeyring() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString(); + String keyRingId = "keyRingId-2027180374"; + KeyRing keyRing = KeyRing.newBuilder().build(); + KeyRing response = keyManagementServiceClient.createKeyRing(parent, keyRingId, keyRing); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_createkeyring_stringstringkeyring_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/decrypt/AsyncDecrypt.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/decrypt/AsyncDecrypt.java new file mode 100644 index 00000000..9e58b156 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/decrypt/AsyncDecrypt.java @@ -0,0 +1,56 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_decrypt_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.kms.v1.CryptoKeyName; +import com.google.cloud.kms.v1.DecryptRequest; +import com.google.cloud.kms.v1.DecryptResponse; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.protobuf.ByteString; +import com.google.protobuf.Int64Value; + +public class AsyncDecrypt { + + public static void main(String[] args) throws Exception { + asyncDecrypt(); + } + + public static void asyncDecrypt() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + DecryptRequest request = + DecryptRequest.newBuilder() + .setName( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .setCiphertext(ByteString.EMPTY) + .setAdditionalAuthenticatedData(ByteString.EMPTY) + .setCiphertextCrc32C(Int64Value.newBuilder().build()) + .setAdditionalAuthenticatedDataCrc32C(Int64Value.newBuilder().build()) + .build(); + ApiFuture future = + keyManagementServiceClient.decryptCallable().futureCall(request); + // Do something. + DecryptResponse response = future.get(); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_decrypt_async] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/decrypt/SyncDecrypt.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/decrypt/SyncDecrypt.java new file mode 100644 index 00000000..ede21288 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/decrypt/SyncDecrypt.java @@ -0,0 +1,52 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_decrypt_sync] +import com.google.cloud.kms.v1.CryptoKeyName; +import com.google.cloud.kms.v1.DecryptRequest; +import com.google.cloud.kms.v1.DecryptResponse; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.protobuf.ByteString; +import com.google.protobuf.Int64Value; + +public class SyncDecrypt { + + public static void main(String[] args) throws Exception { + syncDecrypt(); + } + + public static void syncDecrypt() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + DecryptRequest request = + DecryptRequest.newBuilder() + .setName( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .setCiphertext(ByteString.EMPTY) + .setAdditionalAuthenticatedData(ByteString.EMPTY) + .setCiphertextCrc32C(Int64Value.newBuilder().build()) + .setAdditionalAuthenticatedDataCrc32C(Int64Value.newBuilder().build()) + .build(); + DecryptResponse response = keyManagementServiceClient.decrypt(request); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_decrypt_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/decrypt/SyncDecryptCryptokeynameBytestring.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/decrypt/SyncDecryptCryptokeynameBytestring.java new file mode 100644 index 00000000..c086ea55 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/decrypt/SyncDecryptCryptokeynameBytestring.java @@ -0,0 +1,43 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_decrypt_cryptokeynamebytestring_sync] +import com.google.cloud.kms.v1.CryptoKeyName; +import com.google.cloud.kms.v1.DecryptResponse; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.protobuf.ByteString; + +public class SyncDecryptCryptokeynameBytestring { + + public static void main(String[] args) throws Exception { + syncDecryptCryptokeynameBytestring(); + } + + public static void syncDecryptCryptokeynameBytestring() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + CryptoKeyName name = + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]"); + ByteString ciphertext = ByteString.EMPTY; + DecryptResponse response = keyManagementServiceClient.decrypt(name, ciphertext); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_decrypt_cryptokeynamebytestring_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/decrypt/SyncDecryptStringBytestring.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/decrypt/SyncDecryptStringBytestring.java new file mode 100644 index 00000000..8b3f1525 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/decrypt/SyncDecryptStringBytestring.java @@ -0,0 +1,43 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_decrypt_stringbytestring_sync] +import com.google.cloud.kms.v1.CryptoKeyName; +import com.google.cloud.kms.v1.DecryptResponse; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.protobuf.ByteString; + +public class SyncDecryptStringBytestring { + + public static void main(String[] args) throws Exception { + syncDecryptStringBytestring(); + } + + public static void syncDecryptStringBytestring() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + String name = + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]").toString(); + ByteString ciphertext = ByteString.EMPTY; + DecryptResponse response = keyManagementServiceClient.decrypt(name, ciphertext); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_decrypt_stringbytestring_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/destroycryptokeyversion/AsyncDestroyCryptoKeyVersion.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/destroycryptokeyversion/AsyncDestroyCryptoKeyVersion.java new file mode 100644 index 00000000..8b39340a --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/destroycryptokeyversion/AsyncDestroyCryptoKeyVersion.java @@ -0,0 +1,55 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_destroycryptokeyversion_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.kms.v1.CryptoKeyVersion; +import com.google.cloud.kms.v1.CryptoKeyVersionName; +import com.google.cloud.kms.v1.DestroyCryptoKeyVersionRequest; +import com.google.cloud.kms.v1.KeyManagementServiceClient; + +public class AsyncDestroyCryptoKeyVersion { + + public static void main(String[] args) throws Exception { + asyncDestroyCryptoKeyVersion(); + } + + public static void asyncDestroyCryptoKeyVersion() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + DestroyCryptoKeyVersionRequest request = + DestroyCryptoKeyVersionRequest.newBuilder() + .setName( + CryptoKeyVersionName.of( + "[PROJECT]", + "[LOCATION]", + "[KEY_RING]", + "[CRYPTO_KEY]", + "[CRYPTO_KEY_VERSION]") + .toString()) + .build(); + ApiFuture future = + keyManagementServiceClient.destroyCryptoKeyVersionCallable().futureCall(request); + // Do something. + CryptoKeyVersion response = future.get(); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_destroycryptokeyversion_async] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/destroycryptokeyversion/SyncDestroyCryptoKeyVersion.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/destroycryptokeyversion/SyncDestroyCryptoKeyVersion.java new file mode 100644 index 00000000..cb7195ef --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/destroycryptokeyversion/SyncDestroyCryptoKeyVersion.java @@ -0,0 +1,51 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_destroycryptokeyversion_sync] +import com.google.cloud.kms.v1.CryptoKeyVersion; +import com.google.cloud.kms.v1.CryptoKeyVersionName; +import com.google.cloud.kms.v1.DestroyCryptoKeyVersionRequest; +import com.google.cloud.kms.v1.KeyManagementServiceClient; + +public class SyncDestroyCryptoKeyVersion { + + public static void main(String[] args) throws Exception { + syncDestroyCryptoKeyVersion(); + } + + public static void syncDestroyCryptoKeyVersion() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + DestroyCryptoKeyVersionRequest request = + DestroyCryptoKeyVersionRequest.newBuilder() + .setName( + CryptoKeyVersionName.of( + "[PROJECT]", + "[LOCATION]", + "[KEY_RING]", + "[CRYPTO_KEY]", + "[CRYPTO_KEY_VERSION]") + .toString()) + .build(); + CryptoKeyVersion response = keyManagementServiceClient.destroyCryptoKeyVersion(request); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_destroycryptokeyversion_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/destroycryptokeyversion/SyncDestroyCryptoKeyVersionCryptokeyversionname.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/destroycryptokeyversion/SyncDestroyCryptoKeyVersionCryptokeyversionname.java new file mode 100644 index 00000000..88330616 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/destroycryptokeyversion/SyncDestroyCryptoKeyVersionCryptokeyversionname.java @@ -0,0 +1,42 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_destroycryptokeyversion_cryptokeyversionname_sync] +import com.google.cloud.kms.v1.CryptoKeyVersion; +import com.google.cloud.kms.v1.CryptoKeyVersionName; +import com.google.cloud.kms.v1.KeyManagementServiceClient; + +public class SyncDestroyCryptoKeyVersionCryptokeyversionname { + + public static void main(String[] args) throws Exception { + syncDestroyCryptoKeyVersionCryptokeyversionname(); + } + + public static void syncDestroyCryptoKeyVersionCryptokeyversionname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + CryptoKeyVersionName name = + CryptoKeyVersionName.of( + "[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]", "[CRYPTO_KEY_VERSION]"); + CryptoKeyVersion response = keyManagementServiceClient.destroyCryptoKeyVersion(name); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_destroycryptokeyversion_cryptokeyversionname_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/destroycryptokeyversion/SyncDestroyCryptoKeyVersionString.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/destroycryptokeyversion/SyncDestroyCryptoKeyVersionString.java new file mode 100644 index 00000000..d1e20992 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/destroycryptokeyversion/SyncDestroyCryptoKeyVersionString.java @@ -0,0 +1,43 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_destroycryptokeyversion_string_sync] +import com.google.cloud.kms.v1.CryptoKeyVersion; +import com.google.cloud.kms.v1.CryptoKeyVersionName; +import com.google.cloud.kms.v1.KeyManagementServiceClient; + +public class SyncDestroyCryptoKeyVersionString { + + public static void main(String[] args) throws Exception { + syncDestroyCryptoKeyVersionString(); + } + + public static void syncDestroyCryptoKeyVersionString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + String name = + CryptoKeyVersionName.of( + "[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]", "[CRYPTO_KEY_VERSION]") + .toString(); + CryptoKeyVersion response = keyManagementServiceClient.destroyCryptoKeyVersion(name); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_destroycryptokeyversion_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/encrypt/AsyncEncrypt.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/encrypt/AsyncEncrypt.java new file mode 100644 index 00000000..d102ca32 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/encrypt/AsyncEncrypt.java @@ -0,0 +1,56 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_encrypt_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.kms.v1.CryptoKeyName; +import com.google.cloud.kms.v1.EncryptRequest; +import com.google.cloud.kms.v1.EncryptResponse; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.protobuf.ByteString; +import com.google.protobuf.Int64Value; + +public class AsyncEncrypt { + + public static void main(String[] args) throws Exception { + asyncEncrypt(); + } + + public static void asyncEncrypt() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + EncryptRequest request = + EncryptRequest.newBuilder() + .setName( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .setPlaintext(ByteString.EMPTY) + .setAdditionalAuthenticatedData(ByteString.EMPTY) + .setPlaintextCrc32C(Int64Value.newBuilder().build()) + .setAdditionalAuthenticatedDataCrc32C(Int64Value.newBuilder().build()) + .build(); + ApiFuture future = + keyManagementServiceClient.encryptCallable().futureCall(request); + // Do something. + EncryptResponse response = future.get(); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_encrypt_async] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/encrypt/SyncEncrypt.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/encrypt/SyncEncrypt.java new file mode 100644 index 00000000..06cfbee2 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/encrypt/SyncEncrypt.java @@ -0,0 +1,52 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_encrypt_sync] +import com.google.cloud.kms.v1.CryptoKeyName; +import com.google.cloud.kms.v1.EncryptRequest; +import com.google.cloud.kms.v1.EncryptResponse; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.protobuf.ByteString; +import com.google.protobuf.Int64Value; + +public class SyncEncrypt { + + public static void main(String[] args) throws Exception { + syncEncrypt(); + } + + public static void syncEncrypt() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + EncryptRequest request = + EncryptRequest.newBuilder() + .setName( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .setPlaintext(ByteString.EMPTY) + .setAdditionalAuthenticatedData(ByteString.EMPTY) + .setPlaintextCrc32C(Int64Value.newBuilder().build()) + .setAdditionalAuthenticatedDataCrc32C(Int64Value.newBuilder().build()) + .build(); + EncryptResponse response = keyManagementServiceClient.encrypt(request); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_encrypt_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/encrypt/SyncEncryptResourcenameBytestring.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/encrypt/SyncEncryptResourcenameBytestring.java new file mode 100644 index 00000000..d2903ac5 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/encrypt/SyncEncryptResourcenameBytestring.java @@ -0,0 +1,43 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_encrypt_resourcenamebytestring_sync] +import com.google.api.resourcenames.ResourceName; +import com.google.cloud.kms.v1.CryptoKeyName; +import com.google.cloud.kms.v1.EncryptResponse; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.protobuf.ByteString; + +public class SyncEncryptResourcenameBytestring { + + public static void main(String[] args) throws Exception { + syncEncryptResourcenameBytestring(); + } + + public static void syncEncryptResourcenameBytestring() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + ResourceName name = CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]"); + ByteString plaintext = ByteString.EMPTY; + EncryptResponse response = keyManagementServiceClient.encrypt(name, plaintext); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_encrypt_resourcenamebytestring_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/encrypt/SyncEncryptStringBytestring.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/encrypt/SyncEncryptStringBytestring.java new file mode 100644 index 00000000..f2f271f8 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/encrypt/SyncEncryptStringBytestring.java @@ -0,0 +1,43 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_encrypt_stringbytestring_sync] +import com.google.cloud.kms.v1.CryptoKeyName; +import com.google.cloud.kms.v1.EncryptResponse; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.protobuf.ByteString; + +public class SyncEncryptStringBytestring { + + public static void main(String[] args) throws Exception { + syncEncryptStringBytestring(); + } + + public static void syncEncryptStringBytestring() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + String name = + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]").toString(); + ByteString plaintext = ByteString.EMPTY; + EncryptResponse response = keyManagementServiceClient.encrypt(name, plaintext); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_encrypt_stringbytestring_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/generaterandombytes/AsyncGenerateRandomBytes.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/generaterandombytes/AsyncGenerateRandomBytes.java new file mode 100644 index 00000000..b4191f98 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/generaterandombytes/AsyncGenerateRandomBytes.java @@ -0,0 +1,50 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_generaterandombytes_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.kms.v1.GenerateRandomBytesRequest; +import com.google.cloud.kms.v1.GenerateRandomBytesResponse; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.ProtectionLevel; + +public class AsyncGenerateRandomBytes { + + public static void main(String[] args) throws Exception { + asyncGenerateRandomBytes(); + } + + public static void asyncGenerateRandomBytes() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + GenerateRandomBytesRequest request = + GenerateRandomBytesRequest.newBuilder() + .setLocation("location1901043637") + .setLengthBytes(-745661998) + .setProtectionLevel(ProtectionLevel.forNumber(0)) + .build(); + ApiFuture future = + keyManagementServiceClient.generateRandomBytesCallable().futureCall(request); + // Do something. + GenerateRandomBytesResponse response = future.get(); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_generaterandombytes_async] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/generaterandombytes/SyncGenerateRandomBytes.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/generaterandombytes/SyncGenerateRandomBytes.java new file mode 100644 index 00000000..bf020349 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/generaterandombytes/SyncGenerateRandomBytes.java @@ -0,0 +1,47 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_generaterandombytes_sync] +import com.google.cloud.kms.v1.GenerateRandomBytesRequest; +import com.google.cloud.kms.v1.GenerateRandomBytesResponse; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.ProtectionLevel; + +public class SyncGenerateRandomBytes { + + public static void main(String[] args) throws Exception { + syncGenerateRandomBytes(); + } + + public static void syncGenerateRandomBytes() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + GenerateRandomBytesRequest request = + GenerateRandomBytesRequest.newBuilder() + .setLocation("location1901043637") + .setLengthBytes(-745661998) + .setProtectionLevel(ProtectionLevel.forNumber(0)) + .build(); + GenerateRandomBytesResponse response = + keyManagementServiceClient.generateRandomBytes(request); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_generaterandombytes_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/generaterandombytes/SyncGenerateRandomBytesStringIntProtectionlevel.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/generaterandombytes/SyncGenerateRandomBytesStringIntProtectionlevel.java new file mode 100644 index 00000000..c66efc8b --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/generaterandombytes/SyncGenerateRandomBytesStringIntProtectionlevel.java @@ -0,0 +1,43 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_generaterandombytes_stringintprotectionlevel_sync] +import com.google.cloud.kms.v1.GenerateRandomBytesResponse; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.ProtectionLevel; + +public class SyncGenerateRandomBytesStringIntProtectionlevel { + + public static void main(String[] args) throws Exception { + syncGenerateRandomBytesStringIntProtectionlevel(); + } + + public static void syncGenerateRandomBytesStringIntProtectionlevel() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + String location = "location1901043637"; + int lengthBytes = -745661998; + ProtectionLevel protectionLevel = ProtectionLevel.forNumber(0); + GenerateRandomBytesResponse response = + keyManagementServiceClient.generateRandomBytes(location, lengthBytes, protectionLevel); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_generaterandombytes_stringintprotectionlevel_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getcryptokey/AsyncGetCryptoKey.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getcryptokey/AsyncGetCryptoKey.java new file mode 100644 index 00000000..afb9247e --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getcryptokey/AsyncGetCryptoKey.java @@ -0,0 +1,50 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_getcryptokey_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.kms.v1.CryptoKey; +import com.google.cloud.kms.v1.CryptoKeyName; +import com.google.cloud.kms.v1.GetCryptoKeyRequest; +import com.google.cloud.kms.v1.KeyManagementServiceClient; + +public class AsyncGetCryptoKey { + + public static void main(String[] args) throws Exception { + asyncGetCryptoKey(); + } + + public static void asyncGetCryptoKey() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + GetCryptoKeyRequest request = + GetCryptoKeyRequest.newBuilder() + .setName( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .build(); + ApiFuture future = + keyManagementServiceClient.getCryptoKeyCallable().futureCall(request); + // Do something. + CryptoKey response = future.get(); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_getcryptokey_async] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getcryptokey/SyncGetCryptoKey.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getcryptokey/SyncGetCryptoKey.java new file mode 100644 index 00000000..7171b932 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getcryptokey/SyncGetCryptoKey.java @@ -0,0 +1,46 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_getcryptokey_sync] +import com.google.cloud.kms.v1.CryptoKey; +import com.google.cloud.kms.v1.CryptoKeyName; +import com.google.cloud.kms.v1.GetCryptoKeyRequest; +import com.google.cloud.kms.v1.KeyManagementServiceClient; + +public class SyncGetCryptoKey { + + public static void main(String[] args) throws Exception { + syncGetCryptoKey(); + } + + public static void syncGetCryptoKey() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + GetCryptoKeyRequest request = + GetCryptoKeyRequest.newBuilder() + .setName( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .build(); + CryptoKey response = keyManagementServiceClient.getCryptoKey(request); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_getcryptokey_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getcryptokey/SyncGetCryptoKeyCryptokeyname.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getcryptokey/SyncGetCryptoKeyCryptokeyname.java new file mode 100644 index 00000000..502e82a3 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getcryptokey/SyncGetCryptoKeyCryptokeyname.java @@ -0,0 +1,41 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_getcryptokey_cryptokeyname_sync] +import com.google.cloud.kms.v1.CryptoKey; +import com.google.cloud.kms.v1.CryptoKeyName; +import com.google.cloud.kms.v1.KeyManagementServiceClient; + +public class SyncGetCryptoKeyCryptokeyname { + + public static void main(String[] args) throws Exception { + syncGetCryptoKeyCryptokeyname(); + } + + public static void syncGetCryptoKeyCryptokeyname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + CryptoKeyName name = + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]"); + CryptoKey response = keyManagementServiceClient.getCryptoKey(name); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_getcryptokey_cryptokeyname_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getcryptokey/SyncGetCryptoKeyString.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getcryptokey/SyncGetCryptoKeyString.java new file mode 100644 index 00000000..29bc7ab9 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getcryptokey/SyncGetCryptoKeyString.java @@ -0,0 +1,41 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_getcryptokey_string_sync] +import com.google.cloud.kms.v1.CryptoKey; +import com.google.cloud.kms.v1.CryptoKeyName; +import com.google.cloud.kms.v1.KeyManagementServiceClient; + +public class SyncGetCryptoKeyString { + + public static void main(String[] args) throws Exception { + syncGetCryptoKeyString(); + } + + public static void syncGetCryptoKeyString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + String name = + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]").toString(); + CryptoKey response = keyManagementServiceClient.getCryptoKey(name); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_getcryptokey_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getcryptokeyversion/AsyncGetCryptoKeyVersion.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getcryptokeyversion/AsyncGetCryptoKeyVersion.java new file mode 100644 index 00000000..65a78ad5 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getcryptokeyversion/AsyncGetCryptoKeyVersion.java @@ -0,0 +1,55 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_getcryptokeyversion_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.kms.v1.CryptoKeyVersion; +import com.google.cloud.kms.v1.CryptoKeyVersionName; +import com.google.cloud.kms.v1.GetCryptoKeyVersionRequest; +import com.google.cloud.kms.v1.KeyManagementServiceClient; + +public class AsyncGetCryptoKeyVersion { + + public static void main(String[] args) throws Exception { + asyncGetCryptoKeyVersion(); + } + + public static void asyncGetCryptoKeyVersion() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + GetCryptoKeyVersionRequest request = + GetCryptoKeyVersionRequest.newBuilder() + .setName( + CryptoKeyVersionName.of( + "[PROJECT]", + "[LOCATION]", + "[KEY_RING]", + "[CRYPTO_KEY]", + "[CRYPTO_KEY_VERSION]") + .toString()) + .build(); + ApiFuture future = + keyManagementServiceClient.getCryptoKeyVersionCallable().futureCall(request); + // Do something. + CryptoKeyVersion response = future.get(); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_getcryptokeyversion_async] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getcryptokeyversion/SyncGetCryptoKeyVersion.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getcryptokeyversion/SyncGetCryptoKeyVersion.java new file mode 100644 index 00000000..1262f133 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getcryptokeyversion/SyncGetCryptoKeyVersion.java @@ -0,0 +1,51 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_getcryptokeyversion_sync] +import com.google.cloud.kms.v1.CryptoKeyVersion; +import com.google.cloud.kms.v1.CryptoKeyVersionName; +import com.google.cloud.kms.v1.GetCryptoKeyVersionRequest; +import com.google.cloud.kms.v1.KeyManagementServiceClient; + +public class SyncGetCryptoKeyVersion { + + public static void main(String[] args) throws Exception { + syncGetCryptoKeyVersion(); + } + + public static void syncGetCryptoKeyVersion() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + GetCryptoKeyVersionRequest request = + GetCryptoKeyVersionRequest.newBuilder() + .setName( + CryptoKeyVersionName.of( + "[PROJECT]", + "[LOCATION]", + "[KEY_RING]", + "[CRYPTO_KEY]", + "[CRYPTO_KEY_VERSION]") + .toString()) + .build(); + CryptoKeyVersion response = keyManagementServiceClient.getCryptoKeyVersion(request); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_getcryptokeyversion_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getcryptokeyversion/SyncGetCryptoKeyVersionCryptokeyversionname.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getcryptokeyversion/SyncGetCryptoKeyVersionCryptokeyversionname.java new file mode 100644 index 00000000..233349f4 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getcryptokeyversion/SyncGetCryptoKeyVersionCryptokeyversionname.java @@ -0,0 +1,42 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_getcryptokeyversion_cryptokeyversionname_sync] +import com.google.cloud.kms.v1.CryptoKeyVersion; +import com.google.cloud.kms.v1.CryptoKeyVersionName; +import com.google.cloud.kms.v1.KeyManagementServiceClient; + +public class SyncGetCryptoKeyVersionCryptokeyversionname { + + public static void main(String[] args) throws Exception { + syncGetCryptoKeyVersionCryptokeyversionname(); + } + + public static void syncGetCryptoKeyVersionCryptokeyversionname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + CryptoKeyVersionName name = + CryptoKeyVersionName.of( + "[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]", "[CRYPTO_KEY_VERSION]"); + CryptoKeyVersion response = keyManagementServiceClient.getCryptoKeyVersion(name); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_getcryptokeyversion_cryptokeyversionname_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getcryptokeyversion/SyncGetCryptoKeyVersionString.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getcryptokeyversion/SyncGetCryptoKeyVersionString.java new file mode 100644 index 00000000..f0cce5d9 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getcryptokeyversion/SyncGetCryptoKeyVersionString.java @@ -0,0 +1,43 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_getcryptokeyversion_string_sync] +import com.google.cloud.kms.v1.CryptoKeyVersion; +import com.google.cloud.kms.v1.CryptoKeyVersionName; +import com.google.cloud.kms.v1.KeyManagementServiceClient; + +public class SyncGetCryptoKeyVersionString { + + public static void main(String[] args) throws Exception { + syncGetCryptoKeyVersionString(); + } + + public static void syncGetCryptoKeyVersionString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + String name = + CryptoKeyVersionName.of( + "[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]", "[CRYPTO_KEY_VERSION]") + .toString(); + CryptoKeyVersion response = keyManagementServiceClient.getCryptoKeyVersion(name); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_getcryptokeyversion_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getiampolicy/AsyncGetIamPolicy.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getiampolicy/AsyncGetIamPolicy.java new file mode 100644 index 00000000..b9de93dc --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getiampolicy/AsyncGetIamPolicy.java @@ -0,0 +1,52 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_getiampolicy_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.kms.v1.CryptoKeyName; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.GetPolicyOptions; +import com.google.iam.v1.Policy; + +public class AsyncGetIamPolicy { + + public static void main(String[] args) throws Exception { + asyncGetIamPolicy(); + } + + public static void asyncGetIamPolicy() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + ApiFuture future = + keyManagementServiceClient.getIamPolicyCallable().futureCall(request); + // Do something. + Policy response = future.get(); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_getiampolicy_async] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getiampolicy/SyncGetIamPolicy.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getiampolicy/SyncGetIamPolicy.java new file mode 100644 index 00000000..3020b367 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getiampolicy/SyncGetIamPolicy.java @@ -0,0 +1,48 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_getiampolicy_sync] +import com.google.cloud.kms.v1.CryptoKeyName; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.GetPolicyOptions; +import com.google.iam.v1.Policy; + +public class SyncGetIamPolicy { + + public static void main(String[] args) throws Exception { + syncGetIamPolicy(); + } + + public static void syncGetIamPolicy() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + Policy response = keyManagementServiceClient.getIamPolicy(request); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_getiampolicy_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getimportjob/AsyncGetImportJob.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getimportjob/AsyncGetImportJob.java new file mode 100644 index 00000000..6d0981ad --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getimportjob/AsyncGetImportJob.java @@ -0,0 +1,50 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_getimportjob_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.kms.v1.GetImportJobRequest; +import com.google.cloud.kms.v1.ImportJob; +import com.google.cloud.kms.v1.ImportJobName; +import com.google.cloud.kms.v1.KeyManagementServiceClient; + +public class AsyncGetImportJob { + + public static void main(String[] args) throws Exception { + asyncGetImportJob(); + } + + public static void asyncGetImportJob() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + GetImportJobRequest request = + GetImportJobRequest.newBuilder() + .setName( + ImportJobName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[IMPORT_JOB]") + .toString()) + .build(); + ApiFuture future = + keyManagementServiceClient.getImportJobCallable().futureCall(request); + // Do something. + ImportJob response = future.get(); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_getimportjob_async] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getimportjob/SyncGetImportJob.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getimportjob/SyncGetImportJob.java new file mode 100644 index 00000000..fab6e0d6 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getimportjob/SyncGetImportJob.java @@ -0,0 +1,46 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_getimportjob_sync] +import com.google.cloud.kms.v1.GetImportJobRequest; +import com.google.cloud.kms.v1.ImportJob; +import com.google.cloud.kms.v1.ImportJobName; +import com.google.cloud.kms.v1.KeyManagementServiceClient; + +public class SyncGetImportJob { + + public static void main(String[] args) throws Exception { + syncGetImportJob(); + } + + public static void syncGetImportJob() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + GetImportJobRequest request = + GetImportJobRequest.newBuilder() + .setName( + ImportJobName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[IMPORT_JOB]") + .toString()) + .build(); + ImportJob response = keyManagementServiceClient.getImportJob(request); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_getimportjob_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getimportjob/SyncGetImportJobImportjobname.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getimportjob/SyncGetImportJobImportjobname.java new file mode 100644 index 00000000..6da1c44c --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getimportjob/SyncGetImportJobImportjobname.java @@ -0,0 +1,41 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_getimportjob_importjobname_sync] +import com.google.cloud.kms.v1.ImportJob; +import com.google.cloud.kms.v1.ImportJobName; +import com.google.cloud.kms.v1.KeyManagementServiceClient; + +public class SyncGetImportJobImportjobname { + + public static void main(String[] args) throws Exception { + syncGetImportJobImportjobname(); + } + + public static void syncGetImportJobImportjobname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + ImportJobName name = + ImportJobName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[IMPORT_JOB]"); + ImportJob response = keyManagementServiceClient.getImportJob(name); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_getimportjob_importjobname_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getimportjob/SyncGetImportJobString.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getimportjob/SyncGetImportJobString.java new file mode 100644 index 00000000..4b1abbc0 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getimportjob/SyncGetImportJobString.java @@ -0,0 +1,41 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_getimportjob_string_sync] +import com.google.cloud.kms.v1.ImportJob; +import com.google.cloud.kms.v1.ImportJobName; +import com.google.cloud.kms.v1.KeyManagementServiceClient; + +public class SyncGetImportJobString { + + public static void main(String[] args) throws Exception { + syncGetImportJobString(); + } + + public static void syncGetImportJobString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + String name = + ImportJobName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[IMPORT_JOB]").toString(); + ImportJob response = keyManagementServiceClient.getImportJob(name); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_getimportjob_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getkeyring/AsyncGetKeyRing.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getkeyring/AsyncGetKeyRing.java new file mode 100644 index 00000000..d11013dd --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getkeyring/AsyncGetKeyRing.java @@ -0,0 +1,48 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_getkeyring_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.kms.v1.GetKeyRingRequest; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.KeyRing; +import com.google.cloud.kms.v1.KeyRingName; + +public class AsyncGetKeyRing { + + public static void main(String[] args) throws Exception { + asyncGetKeyRing(); + } + + public static void asyncGetKeyRing() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + GetKeyRingRequest request = + GetKeyRingRequest.newBuilder() + .setName(KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]").toString()) + .build(); + ApiFuture future = + keyManagementServiceClient.getKeyRingCallable().futureCall(request); + // Do something. + KeyRing response = future.get(); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_getkeyring_async] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getkeyring/SyncGetKeyRing.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getkeyring/SyncGetKeyRing.java new file mode 100644 index 00000000..28470ae2 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getkeyring/SyncGetKeyRing.java @@ -0,0 +1,44 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_getkeyring_sync] +import com.google.cloud.kms.v1.GetKeyRingRequest; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.KeyRing; +import com.google.cloud.kms.v1.KeyRingName; + +public class SyncGetKeyRing { + + public static void main(String[] args) throws Exception { + syncGetKeyRing(); + } + + public static void syncGetKeyRing() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + GetKeyRingRequest request = + GetKeyRingRequest.newBuilder() + .setName(KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]").toString()) + .build(); + KeyRing response = keyManagementServiceClient.getKeyRing(request); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_getkeyring_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getkeyring/SyncGetKeyRingKeyringname.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getkeyring/SyncGetKeyRingKeyringname.java new file mode 100644 index 00000000..fa265fe9 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getkeyring/SyncGetKeyRingKeyringname.java @@ -0,0 +1,40 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_getkeyring_keyringname_sync] +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.KeyRing; +import com.google.cloud.kms.v1.KeyRingName; + +public class SyncGetKeyRingKeyringname { + + public static void main(String[] args) throws Exception { + syncGetKeyRingKeyringname(); + } + + public static void syncGetKeyRingKeyringname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + KeyRingName name = KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]"); + KeyRing response = keyManagementServiceClient.getKeyRing(name); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_getkeyring_keyringname_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getkeyring/SyncGetKeyRingString.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getkeyring/SyncGetKeyRingString.java new file mode 100644 index 00000000..b03662f8 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getkeyring/SyncGetKeyRingString.java @@ -0,0 +1,40 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_getkeyring_string_sync] +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.KeyRing; +import com.google.cloud.kms.v1.KeyRingName; + +public class SyncGetKeyRingString { + + public static void main(String[] args) throws Exception { + syncGetKeyRingString(); + } + + public static void syncGetKeyRingString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + String name = KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]").toString(); + KeyRing response = keyManagementServiceClient.getKeyRing(name); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_getkeyring_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getpublickey/AsyncGetPublicKey.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getpublickey/AsyncGetPublicKey.java new file mode 100644 index 00000000..397ebb1b --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getpublickey/AsyncGetPublicKey.java @@ -0,0 +1,55 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_getpublickey_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.kms.v1.CryptoKeyVersionName; +import com.google.cloud.kms.v1.GetPublicKeyRequest; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.PublicKey; + +public class AsyncGetPublicKey { + + public static void main(String[] args) throws Exception { + asyncGetPublicKey(); + } + + public static void asyncGetPublicKey() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + GetPublicKeyRequest request = + GetPublicKeyRequest.newBuilder() + .setName( + CryptoKeyVersionName.of( + "[PROJECT]", + "[LOCATION]", + "[KEY_RING]", + "[CRYPTO_KEY]", + "[CRYPTO_KEY_VERSION]") + .toString()) + .build(); + ApiFuture future = + keyManagementServiceClient.getPublicKeyCallable().futureCall(request); + // Do something. + PublicKey response = future.get(); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_getpublickey_async] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getpublickey/SyncGetPublicKey.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getpublickey/SyncGetPublicKey.java new file mode 100644 index 00000000..4b6fa329 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getpublickey/SyncGetPublicKey.java @@ -0,0 +1,51 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_getpublickey_sync] +import com.google.cloud.kms.v1.CryptoKeyVersionName; +import com.google.cloud.kms.v1.GetPublicKeyRequest; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.PublicKey; + +public class SyncGetPublicKey { + + public static void main(String[] args) throws Exception { + syncGetPublicKey(); + } + + public static void syncGetPublicKey() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + GetPublicKeyRequest request = + GetPublicKeyRequest.newBuilder() + .setName( + CryptoKeyVersionName.of( + "[PROJECT]", + "[LOCATION]", + "[KEY_RING]", + "[CRYPTO_KEY]", + "[CRYPTO_KEY_VERSION]") + .toString()) + .build(); + PublicKey response = keyManagementServiceClient.getPublicKey(request); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_getpublickey_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getpublickey/SyncGetPublicKeyCryptokeyversionname.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getpublickey/SyncGetPublicKeyCryptokeyversionname.java new file mode 100644 index 00000000..b519b553 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getpublickey/SyncGetPublicKeyCryptokeyversionname.java @@ -0,0 +1,42 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_getpublickey_cryptokeyversionname_sync] +import com.google.cloud.kms.v1.CryptoKeyVersionName; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.PublicKey; + +public class SyncGetPublicKeyCryptokeyversionname { + + public static void main(String[] args) throws Exception { + syncGetPublicKeyCryptokeyversionname(); + } + + public static void syncGetPublicKeyCryptokeyversionname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + CryptoKeyVersionName name = + CryptoKeyVersionName.of( + "[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]", "[CRYPTO_KEY_VERSION]"); + PublicKey response = keyManagementServiceClient.getPublicKey(name); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_getpublickey_cryptokeyversionname_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getpublickey/SyncGetPublicKeyString.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getpublickey/SyncGetPublicKeyString.java new file mode 100644 index 00000000..b3f6a56f --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/getpublickey/SyncGetPublicKeyString.java @@ -0,0 +1,43 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_getpublickey_string_sync] +import com.google.cloud.kms.v1.CryptoKeyVersionName; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.PublicKey; + +public class SyncGetPublicKeyString { + + public static void main(String[] args) throws Exception { + syncGetPublicKeyString(); + } + + public static void syncGetPublicKeyString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + String name = + CryptoKeyVersionName.of( + "[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]", "[CRYPTO_KEY_VERSION]") + .toString(); + PublicKey response = keyManagementServiceClient.getPublicKey(name); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_getpublickey_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/importcryptokeyversion/AsyncImportCryptoKeyVersion.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/importcryptokeyversion/AsyncImportCryptoKeyVersion.java new file mode 100644 index 00000000..2a5126be --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/importcryptokeyversion/AsyncImportCryptoKeyVersion.java @@ -0,0 +1,60 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_importcryptokeyversion_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.kms.v1.CryptoKeyName; +import com.google.cloud.kms.v1.CryptoKeyVersion; +import com.google.cloud.kms.v1.CryptoKeyVersionName; +import com.google.cloud.kms.v1.ImportCryptoKeyVersionRequest; +import com.google.cloud.kms.v1.KeyManagementServiceClient; + +public class AsyncImportCryptoKeyVersion { + + public static void main(String[] args) throws Exception { + asyncImportCryptoKeyVersion(); + } + + public static void asyncImportCryptoKeyVersion() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + ImportCryptoKeyVersionRequest request = + ImportCryptoKeyVersionRequest.newBuilder() + .setParent( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .setCryptoKeyVersion( + CryptoKeyVersionName.of( + "[PROJECT]", + "[LOCATION]", + "[KEY_RING]", + "[CRYPTO_KEY]", + "[CRYPTO_KEY_VERSION]") + .toString()) + .setImportJob("importJob-208547368") + .build(); + ApiFuture future = + keyManagementServiceClient.importCryptoKeyVersionCallable().futureCall(request); + // Do something. + CryptoKeyVersion response = future.get(); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_importcryptokeyversion_async] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/importcryptokeyversion/SyncImportCryptoKeyVersion.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/importcryptokeyversion/SyncImportCryptoKeyVersion.java new file mode 100644 index 00000000..59c4383d --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/importcryptokeyversion/SyncImportCryptoKeyVersion.java @@ -0,0 +1,56 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_importcryptokeyversion_sync] +import com.google.cloud.kms.v1.CryptoKeyName; +import com.google.cloud.kms.v1.CryptoKeyVersion; +import com.google.cloud.kms.v1.CryptoKeyVersionName; +import com.google.cloud.kms.v1.ImportCryptoKeyVersionRequest; +import com.google.cloud.kms.v1.KeyManagementServiceClient; + +public class SyncImportCryptoKeyVersion { + + public static void main(String[] args) throws Exception { + syncImportCryptoKeyVersion(); + } + + public static void syncImportCryptoKeyVersion() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + ImportCryptoKeyVersionRequest request = + ImportCryptoKeyVersionRequest.newBuilder() + .setParent( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .setCryptoKeyVersion( + CryptoKeyVersionName.of( + "[PROJECT]", + "[LOCATION]", + "[KEY_RING]", + "[CRYPTO_KEY]", + "[CRYPTO_KEY_VERSION]") + .toString()) + .setImportJob("importJob-208547368") + .build(); + CryptoKeyVersion response = keyManagementServiceClient.importCryptoKeyVersion(request); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_importcryptokeyversion_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listcryptokeys/AsyncListCryptoKeys.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listcryptokeys/AsyncListCryptoKeys.java new file mode 100644 index 00000000..fe9030fc --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listcryptokeys/AsyncListCryptoKeys.java @@ -0,0 +1,54 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_listcryptokeys_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.kms.v1.CryptoKey; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.KeyRingName; +import com.google.cloud.kms.v1.ListCryptoKeysRequest; + +public class AsyncListCryptoKeys { + + public static void main(String[] args) throws Exception { + asyncListCryptoKeys(); + } + + public static void asyncListCryptoKeys() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + ListCryptoKeysRequest request = + ListCryptoKeysRequest.newBuilder() + .setParent(KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .setOrderBy("orderBy-1207110587") + .build(); + ApiFuture future = + keyManagementServiceClient.listCryptoKeysPagedCallable().futureCall(request); + // Do something. + for (CryptoKey element : future.get().iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_listcryptokeys_async] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listcryptokeys/AsyncListCryptoKeysPaged.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listcryptokeys/AsyncListCryptoKeysPaged.java new file mode 100644 index 00000000..ee2c563f --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listcryptokeys/AsyncListCryptoKeysPaged.java @@ -0,0 +1,62 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_listcryptokeys_paged_async] +import com.google.cloud.kms.v1.CryptoKey; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.KeyRingName; +import com.google.cloud.kms.v1.ListCryptoKeysRequest; +import com.google.cloud.kms.v1.ListCryptoKeysResponse; +import com.google.common.base.Strings; + +public class AsyncListCryptoKeysPaged { + + public static void main(String[] args) throws Exception { + asyncListCryptoKeysPaged(); + } + + public static void asyncListCryptoKeysPaged() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + ListCryptoKeysRequest request = + ListCryptoKeysRequest.newBuilder() + .setParent(KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .setOrderBy("orderBy-1207110587") + .build(); + while (true) { + ListCryptoKeysResponse response = + keyManagementServiceClient.listCryptoKeysCallable().call(request); + for (CryptoKey element : response.getCryptoKeysList()) { + // doThingsWith(element); + } + String nextPageToken = response.getNextPageToken(); + if (!Strings.isNullOrEmpty(nextPageToken)) { + request = request.toBuilder().setPageToken(nextPageToken).build(); + } else { + break; + } + } + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_listcryptokeys_paged_async] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listcryptokeys/SyncListCryptoKeys.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listcryptokeys/SyncListCryptoKeys.java new file mode 100644 index 00000000..b82a7ccd --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listcryptokeys/SyncListCryptoKeys.java @@ -0,0 +1,50 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_listcryptokeys_sync] +import com.google.cloud.kms.v1.CryptoKey; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.KeyRingName; +import com.google.cloud.kms.v1.ListCryptoKeysRequest; + +public class SyncListCryptoKeys { + + public static void main(String[] args) throws Exception { + syncListCryptoKeys(); + } + + public static void syncListCryptoKeys() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + ListCryptoKeysRequest request = + ListCryptoKeysRequest.newBuilder() + .setParent(KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .setOrderBy("orderBy-1207110587") + .build(); + for (CryptoKey element : keyManagementServiceClient.listCryptoKeys(request).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_listcryptokeys_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listcryptokeys/SyncListCryptoKeysKeyringname.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listcryptokeys/SyncListCryptoKeysKeyringname.java new file mode 100644 index 00000000..a2111418 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listcryptokeys/SyncListCryptoKeysKeyringname.java @@ -0,0 +1,42 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_listcryptokeys_keyringname_sync] +import com.google.cloud.kms.v1.CryptoKey; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.KeyRingName; + +public class SyncListCryptoKeysKeyringname { + + public static void main(String[] args) throws Exception { + syncListCryptoKeysKeyringname(); + } + + public static void syncListCryptoKeysKeyringname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + KeyRingName parent = KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]"); + for (CryptoKey element : keyManagementServiceClient.listCryptoKeys(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_listcryptokeys_keyringname_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listcryptokeys/SyncListCryptoKeysString.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listcryptokeys/SyncListCryptoKeysString.java new file mode 100644 index 00000000..e220fe46 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listcryptokeys/SyncListCryptoKeysString.java @@ -0,0 +1,42 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_listcryptokeys_string_sync] +import com.google.cloud.kms.v1.CryptoKey; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.KeyRingName; + +public class SyncListCryptoKeysString { + + public static void main(String[] args) throws Exception { + syncListCryptoKeysString(); + } + + public static void syncListCryptoKeysString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + String parent = KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]").toString(); + for (CryptoKey element : keyManagementServiceClient.listCryptoKeys(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_listcryptokeys_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listcryptokeyversions/AsyncListCryptoKeyVersions.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listcryptokeyversions/AsyncListCryptoKeyVersions.java new file mode 100644 index 00000000..97699e75 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listcryptokeyversions/AsyncListCryptoKeyVersions.java @@ -0,0 +1,56 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_listcryptokeyversions_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.kms.v1.CryptoKeyName; +import com.google.cloud.kms.v1.CryptoKeyVersion; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.ListCryptoKeyVersionsRequest; + +public class AsyncListCryptoKeyVersions { + + public static void main(String[] args) throws Exception { + asyncListCryptoKeyVersions(); + } + + public static void asyncListCryptoKeyVersions() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + ListCryptoKeyVersionsRequest request = + ListCryptoKeyVersionsRequest.newBuilder() + .setParent( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .setOrderBy("orderBy-1207110587") + .build(); + ApiFuture future = + keyManagementServiceClient.listCryptoKeyVersionsPagedCallable().futureCall(request); + // Do something. + for (CryptoKeyVersion element : future.get().iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_listcryptokeyversions_async] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listcryptokeyversions/AsyncListCryptoKeyVersionsPaged.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listcryptokeyversions/AsyncListCryptoKeyVersionsPaged.java new file mode 100644 index 00000000..d86109d1 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listcryptokeyversions/AsyncListCryptoKeyVersionsPaged.java @@ -0,0 +1,64 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_listcryptokeyversions_paged_async] +import com.google.cloud.kms.v1.CryptoKeyName; +import com.google.cloud.kms.v1.CryptoKeyVersion; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.ListCryptoKeyVersionsRequest; +import com.google.cloud.kms.v1.ListCryptoKeyVersionsResponse; +import com.google.common.base.Strings; + +public class AsyncListCryptoKeyVersionsPaged { + + public static void main(String[] args) throws Exception { + asyncListCryptoKeyVersionsPaged(); + } + + public static void asyncListCryptoKeyVersionsPaged() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + ListCryptoKeyVersionsRequest request = + ListCryptoKeyVersionsRequest.newBuilder() + .setParent( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .setOrderBy("orderBy-1207110587") + .build(); + while (true) { + ListCryptoKeyVersionsResponse response = + keyManagementServiceClient.listCryptoKeyVersionsCallable().call(request); + for (CryptoKeyVersion element : response.getCryptoKeyVersionsList()) { + // doThingsWith(element); + } + String nextPageToken = response.getNextPageToken(); + if (!Strings.isNullOrEmpty(nextPageToken)) { + request = request.toBuilder().setPageToken(nextPageToken).build(); + } else { + break; + } + } + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_listcryptokeyversions_paged_async] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listcryptokeyversions/SyncListCryptoKeyVersions.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listcryptokeyversions/SyncListCryptoKeyVersions.java new file mode 100644 index 00000000..fee573a1 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listcryptokeyversions/SyncListCryptoKeyVersions.java @@ -0,0 +1,53 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_listcryptokeyversions_sync] +import com.google.cloud.kms.v1.CryptoKeyName; +import com.google.cloud.kms.v1.CryptoKeyVersion; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.ListCryptoKeyVersionsRequest; + +public class SyncListCryptoKeyVersions { + + public static void main(String[] args) throws Exception { + syncListCryptoKeyVersions(); + } + + public static void syncListCryptoKeyVersions() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + ListCryptoKeyVersionsRequest request = + ListCryptoKeyVersionsRequest.newBuilder() + .setParent( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .setOrderBy("orderBy-1207110587") + .build(); + for (CryptoKeyVersion element : + keyManagementServiceClient.listCryptoKeyVersions(request).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_listcryptokeyversions_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listcryptokeyversions/SyncListCryptoKeyVersionsCryptokeyname.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listcryptokeyversions/SyncListCryptoKeyVersionsCryptokeyname.java new file mode 100644 index 00000000..3732a4bc --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listcryptokeyversions/SyncListCryptoKeyVersionsCryptokeyname.java @@ -0,0 +1,44 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_listcryptokeyversions_cryptokeyname_sync] +import com.google.cloud.kms.v1.CryptoKeyName; +import com.google.cloud.kms.v1.CryptoKeyVersion; +import com.google.cloud.kms.v1.KeyManagementServiceClient; + +public class SyncListCryptoKeyVersionsCryptokeyname { + + public static void main(String[] args) throws Exception { + syncListCryptoKeyVersionsCryptokeyname(); + } + + public static void syncListCryptoKeyVersionsCryptokeyname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + CryptoKeyName parent = + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]"); + for (CryptoKeyVersion element : + keyManagementServiceClient.listCryptoKeyVersions(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_listcryptokeyversions_cryptokeyname_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listcryptokeyversions/SyncListCryptoKeyVersionsString.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listcryptokeyversions/SyncListCryptoKeyVersionsString.java new file mode 100644 index 00000000..7eeb04ea --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listcryptokeyversions/SyncListCryptoKeyVersionsString.java @@ -0,0 +1,44 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_listcryptokeyversions_string_sync] +import com.google.cloud.kms.v1.CryptoKeyName; +import com.google.cloud.kms.v1.CryptoKeyVersion; +import com.google.cloud.kms.v1.KeyManagementServiceClient; + +public class SyncListCryptoKeyVersionsString { + + public static void main(String[] args) throws Exception { + syncListCryptoKeyVersionsString(); + } + + public static void syncListCryptoKeyVersionsString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + String parent = + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]").toString(); + for (CryptoKeyVersion element : + keyManagementServiceClient.listCryptoKeyVersions(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_listcryptokeyversions_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listimportjobs/AsyncListImportJobs.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listimportjobs/AsyncListImportJobs.java new file mode 100644 index 00000000..dcc282f6 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listimportjobs/AsyncListImportJobs.java @@ -0,0 +1,54 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_listimportjobs_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.kms.v1.ImportJob; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.KeyRingName; +import com.google.cloud.kms.v1.ListImportJobsRequest; + +public class AsyncListImportJobs { + + public static void main(String[] args) throws Exception { + asyncListImportJobs(); + } + + public static void asyncListImportJobs() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + ListImportJobsRequest request = + ListImportJobsRequest.newBuilder() + .setParent(KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .setOrderBy("orderBy-1207110587") + .build(); + ApiFuture future = + keyManagementServiceClient.listImportJobsPagedCallable().futureCall(request); + // Do something. + for (ImportJob element : future.get().iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_listimportjobs_async] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listimportjobs/AsyncListImportJobsPaged.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listimportjobs/AsyncListImportJobsPaged.java new file mode 100644 index 00000000..e11d4f37 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listimportjobs/AsyncListImportJobsPaged.java @@ -0,0 +1,62 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_listimportjobs_paged_async] +import com.google.cloud.kms.v1.ImportJob; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.KeyRingName; +import com.google.cloud.kms.v1.ListImportJobsRequest; +import com.google.cloud.kms.v1.ListImportJobsResponse; +import com.google.common.base.Strings; + +public class AsyncListImportJobsPaged { + + public static void main(String[] args) throws Exception { + asyncListImportJobsPaged(); + } + + public static void asyncListImportJobsPaged() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + ListImportJobsRequest request = + ListImportJobsRequest.newBuilder() + .setParent(KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .setOrderBy("orderBy-1207110587") + .build(); + while (true) { + ListImportJobsResponse response = + keyManagementServiceClient.listImportJobsCallable().call(request); + for (ImportJob element : response.getImportJobsList()) { + // doThingsWith(element); + } + String nextPageToken = response.getNextPageToken(); + if (!Strings.isNullOrEmpty(nextPageToken)) { + request = request.toBuilder().setPageToken(nextPageToken).build(); + } else { + break; + } + } + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_listimportjobs_paged_async] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listimportjobs/SyncListImportJobs.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listimportjobs/SyncListImportJobs.java new file mode 100644 index 00000000..a448fc8d --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listimportjobs/SyncListImportJobs.java @@ -0,0 +1,50 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_listimportjobs_sync] +import com.google.cloud.kms.v1.ImportJob; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.KeyRingName; +import com.google.cloud.kms.v1.ListImportJobsRequest; + +public class SyncListImportJobs { + + public static void main(String[] args) throws Exception { + syncListImportJobs(); + } + + public static void syncListImportJobs() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + ListImportJobsRequest request = + ListImportJobsRequest.newBuilder() + .setParent(KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .setOrderBy("orderBy-1207110587") + .build(); + for (ImportJob element : keyManagementServiceClient.listImportJobs(request).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_listimportjobs_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listimportjobs/SyncListImportJobsKeyringname.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listimportjobs/SyncListImportJobsKeyringname.java new file mode 100644 index 00000000..c27b7ebb --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listimportjobs/SyncListImportJobsKeyringname.java @@ -0,0 +1,42 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_listimportjobs_keyringname_sync] +import com.google.cloud.kms.v1.ImportJob; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.KeyRingName; + +public class SyncListImportJobsKeyringname { + + public static void main(String[] args) throws Exception { + syncListImportJobsKeyringname(); + } + + public static void syncListImportJobsKeyringname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + KeyRingName parent = KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]"); + for (ImportJob element : keyManagementServiceClient.listImportJobs(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_listimportjobs_keyringname_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listimportjobs/SyncListImportJobsString.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listimportjobs/SyncListImportJobsString.java new file mode 100644 index 00000000..16a7cf09 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listimportjobs/SyncListImportJobsString.java @@ -0,0 +1,42 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_listimportjobs_string_sync] +import com.google.cloud.kms.v1.ImportJob; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.KeyRingName; + +public class SyncListImportJobsString { + + public static void main(String[] args) throws Exception { + syncListImportJobsString(); + } + + public static void syncListImportJobsString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + String parent = KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]").toString(); + for (ImportJob element : keyManagementServiceClient.listImportJobs(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_listimportjobs_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listkeyrings/AsyncListKeyRings.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listkeyrings/AsyncListKeyRings.java new file mode 100644 index 00000000..c1aec87e --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listkeyrings/AsyncListKeyRings.java @@ -0,0 +1,54 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_listkeyrings_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.KeyRing; +import com.google.cloud.kms.v1.ListKeyRingsRequest; +import com.google.cloud.kms.v1.LocationName; + +public class AsyncListKeyRings { + + public static void main(String[] args) throws Exception { + asyncListKeyRings(); + } + + public static void asyncListKeyRings() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + ListKeyRingsRequest request = + ListKeyRingsRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .setOrderBy("orderBy-1207110587") + .build(); + ApiFuture future = + keyManagementServiceClient.listKeyRingsPagedCallable().futureCall(request); + // Do something. + for (KeyRing element : future.get().iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_listkeyrings_async] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listkeyrings/AsyncListKeyRingsPaged.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listkeyrings/AsyncListKeyRingsPaged.java new file mode 100644 index 00000000..5699e393 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listkeyrings/AsyncListKeyRingsPaged.java @@ -0,0 +1,62 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_listkeyrings_paged_async] +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.KeyRing; +import com.google.cloud.kms.v1.ListKeyRingsRequest; +import com.google.cloud.kms.v1.ListKeyRingsResponse; +import com.google.cloud.kms.v1.LocationName; +import com.google.common.base.Strings; + +public class AsyncListKeyRingsPaged { + + public static void main(String[] args) throws Exception { + asyncListKeyRingsPaged(); + } + + public static void asyncListKeyRingsPaged() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + ListKeyRingsRequest request = + ListKeyRingsRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .setOrderBy("orderBy-1207110587") + .build(); + while (true) { + ListKeyRingsResponse response = + keyManagementServiceClient.listKeyRingsCallable().call(request); + for (KeyRing element : response.getKeyRingsList()) { + // doThingsWith(element); + } + String nextPageToken = response.getNextPageToken(); + if (!Strings.isNullOrEmpty(nextPageToken)) { + request = request.toBuilder().setPageToken(nextPageToken).build(); + } else { + break; + } + } + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_listkeyrings_paged_async] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listkeyrings/SyncListKeyRings.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listkeyrings/SyncListKeyRings.java new file mode 100644 index 00000000..44a39dee --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listkeyrings/SyncListKeyRings.java @@ -0,0 +1,50 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_listkeyrings_sync] +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.KeyRing; +import com.google.cloud.kms.v1.ListKeyRingsRequest; +import com.google.cloud.kms.v1.LocationName; + +public class SyncListKeyRings { + + public static void main(String[] args) throws Exception { + syncListKeyRings(); + } + + public static void syncListKeyRings() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + ListKeyRingsRequest request = + ListKeyRingsRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .setOrderBy("orderBy-1207110587") + .build(); + for (KeyRing element : keyManagementServiceClient.listKeyRings(request).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_listkeyrings_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listkeyrings/SyncListKeyRingsLocationname.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listkeyrings/SyncListKeyRingsLocationname.java new file mode 100644 index 00000000..02099fdc --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listkeyrings/SyncListKeyRingsLocationname.java @@ -0,0 +1,42 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_listkeyrings_locationname_sync] +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.KeyRing; +import com.google.cloud.kms.v1.LocationName; + +public class SyncListKeyRingsLocationname { + + public static void main(String[] args) throws Exception { + syncListKeyRingsLocationname(); + } + + public static void syncListKeyRingsLocationname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + for (KeyRing element : keyManagementServiceClient.listKeyRings(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_listkeyrings_locationname_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listkeyrings/SyncListKeyRingsString.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listkeyrings/SyncListKeyRingsString.java new file mode 100644 index 00000000..5dc2d369 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/listkeyrings/SyncListKeyRingsString.java @@ -0,0 +1,42 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_listkeyrings_string_sync] +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.KeyRing; +import com.google.cloud.kms.v1.LocationName; + +public class SyncListKeyRingsString { + + public static void main(String[] args) throws Exception { + syncListKeyRingsString(); + } + + public static void syncListKeyRingsString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString(); + for (KeyRing element : keyManagementServiceClient.listKeyRings(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_listkeyrings_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/macsign/AsyncMacSign.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/macsign/AsyncMacSign.java new file mode 100644 index 00000000..0c3851b3 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/macsign/AsyncMacSign.java @@ -0,0 +1,59 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_macsign_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.kms.v1.CryptoKeyVersionName; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.MacSignRequest; +import com.google.cloud.kms.v1.MacSignResponse; +import com.google.protobuf.ByteString; +import com.google.protobuf.Int64Value; + +public class AsyncMacSign { + + public static void main(String[] args) throws Exception { + asyncMacSign(); + } + + public static void asyncMacSign() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + MacSignRequest request = + MacSignRequest.newBuilder() + .setName( + CryptoKeyVersionName.of( + "[PROJECT]", + "[LOCATION]", + "[KEY_RING]", + "[CRYPTO_KEY]", + "[CRYPTO_KEY_VERSION]") + .toString()) + .setData(ByteString.EMPTY) + .setDataCrc32C(Int64Value.newBuilder().build()) + .build(); + ApiFuture future = + keyManagementServiceClient.macSignCallable().futureCall(request); + // Do something. + MacSignResponse response = future.get(); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_macsign_async] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/macsign/SyncMacSign.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/macsign/SyncMacSign.java new file mode 100644 index 00000000..d3996e19 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/macsign/SyncMacSign.java @@ -0,0 +1,55 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_macsign_sync] +import com.google.cloud.kms.v1.CryptoKeyVersionName; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.MacSignRequest; +import com.google.cloud.kms.v1.MacSignResponse; +import com.google.protobuf.ByteString; +import com.google.protobuf.Int64Value; + +public class SyncMacSign { + + public static void main(String[] args) throws Exception { + syncMacSign(); + } + + public static void syncMacSign() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + MacSignRequest request = + MacSignRequest.newBuilder() + .setName( + CryptoKeyVersionName.of( + "[PROJECT]", + "[LOCATION]", + "[KEY_RING]", + "[CRYPTO_KEY]", + "[CRYPTO_KEY_VERSION]") + .toString()) + .setData(ByteString.EMPTY) + .setDataCrc32C(Int64Value.newBuilder().build()) + .build(); + MacSignResponse response = keyManagementServiceClient.macSign(request); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_macsign_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/macsign/SyncMacSignCryptokeyversionnameBytestring.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/macsign/SyncMacSignCryptokeyversionnameBytestring.java new file mode 100644 index 00000000..7a51bbc1 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/macsign/SyncMacSignCryptokeyversionnameBytestring.java @@ -0,0 +1,44 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_macsign_cryptokeyversionnamebytestring_sync] +import com.google.cloud.kms.v1.CryptoKeyVersionName; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.MacSignResponse; +import com.google.protobuf.ByteString; + +public class SyncMacSignCryptokeyversionnameBytestring { + + public static void main(String[] args) throws Exception { + syncMacSignCryptokeyversionnameBytestring(); + } + + public static void syncMacSignCryptokeyversionnameBytestring() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + CryptoKeyVersionName name = + CryptoKeyVersionName.of( + "[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]", "[CRYPTO_KEY_VERSION]"); + ByteString data = ByteString.EMPTY; + MacSignResponse response = keyManagementServiceClient.macSign(name, data); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_macsign_cryptokeyversionnamebytestring_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/macsign/SyncMacSignStringBytestring.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/macsign/SyncMacSignStringBytestring.java new file mode 100644 index 00000000..c119e716 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/macsign/SyncMacSignStringBytestring.java @@ -0,0 +1,45 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_macsign_stringbytestring_sync] +import com.google.cloud.kms.v1.CryptoKeyVersionName; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.MacSignResponse; +import com.google.protobuf.ByteString; + +public class SyncMacSignStringBytestring { + + public static void main(String[] args) throws Exception { + syncMacSignStringBytestring(); + } + + public static void syncMacSignStringBytestring() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + String name = + CryptoKeyVersionName.of( + "[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]", "[CRYPTO_KEY_VERSION]") + .toString(); + ByteString data = ByteString.EMPTY; + MacSignResponse response = keyManagementServiceClient.macSign(name, data); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_macsign_stringbytestring_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/macverify/AsyncMacVerify.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/macverify/AsyncMacVerify.java new file mode 100644 index 00000000..55a3f96c --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/macverify/AsyncMacVerify.java @@ -0,0 +1,61 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_macverify_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.kms.v1.CryptoKeyVersionName; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.MacVerifyRequest; +import com.google.cloud.kms.v1.MacVerifyResponse; +import com.google.protobuf.ByteString; +import com.google.protobuf.Int64Value; + +public class AsyncMacVerify { + + public static void main(String[] args) throws Exception { + asyncMacVerify(); + } + + public static void asyncMacVerify() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + MacVerifyRequest request = + MacVerifyRequest.newBuilder() + .setName( + CryptoKeyVersionName.of( + "[PROJECT]", + "[LOCATION]", + "[KEY_RING]", + "[CRYPTO_KEY]", + "[CRYPTO_KEY_VERSION]") + .toString()) + .setData(ByteString.EMPTY) + .setDataCrc32C(Int64Value.newBuilder().build()) + .setMac(ByteString.EMPTY) + .setMacCrc32C(Int64Value.newBuilder().build()) + .build(); + ApiFuture future = + keyManagementServiceClient.macVerifyCallable().futureCall(request); + // Do something. + MacVerifyResponse response = future.get(); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_macverify_async] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/macverify/SyncMacVerify.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/macverify/SyncMacVerify.java new file mode 100644 index 00000000..2ecdbaa0 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/macverify/SyncMacVerify.java @@ -0,0 +1,57 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_macverify_sync] +import com.google.cloud.kms.v1.CryptoKeyVersionName; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.MacVerifyRequest; +import com.google.cloud.kms.v1.MacVerifyResponse; +import com.google.protobuf.ByteString; +import com.google.protobuf.Int64Value; + +public class SyncMacVerify { + + public static void main(String[] args) throws Exception { + syncMacVerify(); + } + + public static void syncMacVerify() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + MacVerifyRequest request = + MacVerifyRequest.newBuilder() + .setName( + CryptoKeyVersionName.of( + "[PROJECT]", + "[LOCATION]", + "[KEY_RING]", + "[CRYPTO_KEY]", + "[CRYPTO_KEY_VERSION]") + .toString()) + .setData(ByteString.EMPTY) + .setDataCrc32C(Int64Value.newBuilder().build()) + .setMac(ByteString.EMPTY) + .setMacCrc32C(Int64Value.newBuilder().build()) + .build(); + MacVerifyResponse response = keyManagementServiceClient.macVerify(request); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_macverify_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/macverify/SyncMacVerifyCryptokeyversionnameBytestringBytestring.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/macverify/SyncMacVerifyCryptokeyversionnameBytestringBytestring.java new file mode 100644 index 00000000..7148b874 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/macverify/SyncMacVerifyCryptokeyversionnameBytestringBytestring.java @@ -0,0 +1,45 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_macverify_cryptokeyversionnamebytestringbytestring_sync] +import com.google.cloud.kms.v1.CryptoKeyVersionName; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.MacVerifyResponse; +import com.google.protobuf.ByteString; + +public class SyncMacVerifyCryptokeyversionnameBytestringBytestring { + + public static void main(String[] args) throws Exception { + syncMacVerifyCryptokeyversionnameBytestringBytestring(); + } + + public static void syncMacVerifyCryptokeyversionnameBytestringBytestring() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + CryptoKeyVersionName name = + CryptoKeyVersionName.of( + "[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]", "[CRYPTO_KEY_VERSION]"); + ByteString data = ByteString.EMPTY; + ByteString mac = ByteString.EMPTY; + MacVerifyResponse response = keyManagementServiceClient.macVerify(name, data, mac); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_macverify_cryptokeyversionnamebytestringbytestring_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/macverify/SyncMacVerifyStringBytestringBytestring.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/macverify/SyncMacVerifyStringBytestringBytestring.java new file mode 100644 index 00000000..069dfe50 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/macverify/SyncMacVerifyStringBytestringBytestring.java @@ -0,0 +1,46 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_macverify_stringbytestringbytestring_sync] +import com.google.cloud.kms.v1.CryptoKeyVersionName; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.MacVerifyResponse; +import com.google.protobuf.ByteString; + +public class SyncMacVerifyStringBytestringBytestring { + + public static void main(String[] args) throws Exception { + syncMacVerifyStringBytestringBytestring(); + } + + public static void syncMacVerifyStringBytestringBytestring() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + String name = + CryptoKeyVersionName.of( + "[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]", "[CRYPTO_KEY_VERSION]") + .toString(); + ByteString data = ByteString.EMPTY; + ByteString mac = ByteString.EMPTY; + MacVerifyResponse response = keyManagementServiceClient.macVerify(name, data, mac); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_macverify_stringbytestringbytestring_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/restorecryptokeyversion/AsyncRestoreCryptoKeyVersion.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/restorecryptokeyversion/AsyncRestoreCryptoKeyVersion.java new file mode 100644 index 00000000..99c01083 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/restorecryptokeyversion/AsyncRestoreCryptoKeyVersion.java @@ -0,0 +1,55 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_restorecryptokeyversion_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.kms.v1.CryptoKeyVersion; +import com.google.cloud.kms.v1.CryptoKeyVersionName; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.RestoreCryptoKeyVersionRequest; + +public class AsyncRestoreCryptoKeyVersion { + + public static void main(String[] args) throws Exception { + asyncRestoreCryptoKeyVersion(); + } + + public static void asyncRestoreCryptoKeyVersion() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + RestoreCryptoKeyVersionRequest request = + RestoreCryptoKeyVersionRequest.newBuilder() + .setName( + CryptoKeyVersionName.of( + "[PROJECT]", + "[LOCATION]", + "[KEY_RING]", + "[CRYPTO_KEY]", + "[CRYPTO_KEY_VERSION]") + .toString()) + .build(); + ApiFuture future = + keyManagementServiceClient.restoreCryptoKeyVersionCallable().futureCall(request); + // Do something. + CryptoKeyVersion response = future.get(); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_restorecryptokeyversion_async] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/restorecryptokeyversion/SyncRestoreCryptoKeyVersion.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/restorecryptokeyversion/SyncRestoreCryptoKeyVersion.java new file mode 100644 index 00000000..db1b5f42 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/restorecryptokeyversion/SyncRestoreCryptoKeyVersion.java @@ -0,0 +1,51 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_restorecryptokeyversion_sync] +import com.google.cloud.kms.v1.CryptoKeyVersion; +import com.google.cloud.kms.v1.CryptoKeyVersionName; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.RestoreCryptoKeyVersionRequest; + +public class SyncRestoreCryptoKeyVersion { + + public static void main(String[] args) throws Exception { + syncRestoreCryptoKeyVersion(); + } + + public static void syncRestoreCryptoKeyVersion() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + RestoreCryptoKeyVersionRequest request = + RestoreCryptoKeyVersionRequest.newBuilder() + .setName( + CryptoKeyVersionName.of( + "[PROJECT]", + "[LOCATION]", + "[KEY_RING]", + "[CRYPTO_KEY]", + "[CRYPTO_KEY_VERSION]") + .toString()) + .build(); + CryptoKeyVersion response = keyManagementServiceClient.restoreCryptoKeyVersion(request); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_restorecryptokeyversion_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/restorecryptokeyversion/SyncRestoreCryptoKeyVersionCryptokeyversionname.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/restorecryptokeyversion/SyncRestoreCryptoKeyVersionCryptokeyversionname.java new file mode 100644 index 00000000..e19636c9 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/restorecryptokeyversion/SyncRestoreCryptoKeyVersionCryptokeyversionname.java @@ -0,0 +1,42 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_restorecryptokeyversion_cryptokeyversionname_sync] +import com.google.cloud.kms.v1.CryptoKeyVersion; +import com.google.cloud.kms.v1.CryptoKeyVersionName; +import com.google.cloud.kms.v1.KeyManagementServiceClient; + +public class SyncRestoreCryptoKeyVersionCryptokeyversionname { + + public static void main(String[] args) throws Exception { + syncRestoreCryptoKeyVersionCryptokeyversionname(); + } + + public static void syncRestoreCryptoKeyVersionCryptokeyversionname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + CryptoKeyVersionName name = + CryptoKeyVersionName.of( + "[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]", "[CRYPTO_KEY_VERSION]"); + CryptoKeyVersion response = keyManagementServiceClient.restoreCryptoKeyVersion(name); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_restorecryptokeyversion_cryptokeyversionname_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/restorecryptokeyversion/SyncRestoreCryptoKeyVersionString.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/restorecryptokeyversion/SyncRestoreCryptoKeyVersionString.java new file mode 100644 index 00000000..bf35052c --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/restorecryptokeyversion/SyncRestoreCryptoKeyVersionString.java @@ -0,0 +1,43 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_restorecryptokeyversion_string_sync] +import com.google.cloud.kms.v1.CryptoKeyVersion; +import com.google.cloud.kms.v1.CryptoKeyVersionName; +import com.google.cloud.kms.v1.KeyManagementServiceClient; + +public class SyncRestoreCryptoKeyVersionString { + + public static void main(String[] args) throws Exception { + syncRestoreCryptoKeyVersionString(); + } + + public static void syncRestoreCryptoKeyVersionString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + String name = + CryptoKeyVersionName.of( + "[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]", "[CRYPTO_KEY_VERSION]") + .toString(); + CryptoKeyVersion response = keyManagementServiceClient.restoreCryptoKeyVersion(name); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_restorecryptokeyversion_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/setiampolicy/AsyncSetIamPolicy.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/setiampolicy/AsyncSetIamPolicy.java new file mode 100644 index 00000000..e7ac24b2 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/setiampolicy/AsyncSetIamPolicy.java @@ -0,0 +1,53 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_setiampolicy_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.kms.v1.CryptoKeyName; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.protobuf.FieldMask; + +public class AsyncSetIamPolicy { + + public static void main(String[] args) throws Exception { + asyncSetIamPolicy(); + } + + public static void asyncSetIamPolicy() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + ApiFuture future = + keyManagementServiceClient.setIamPolicyCallable().futureCall(request); + // Do something. + Policy response = future.get(); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_setiampolicy_async] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/setiampolicy/SyncSetIamPolicy.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/setiampolicy/SyncSetIamPolicy.java new file mode 100644 index 00000000..063f4604 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/setiampolicy/SyncSetIamPolicy.java @@ -0,0 +1,49 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_setiampolicy_sync] +import com.google.cloud.kms.v1.CryptoKeyName; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.protobuf.FieldMask; + +public class SyncSetIamPolicy { + + public static void main(String[] args) throws Exception { + syncSetIamPolicy(); + } + + public static void syncSetIamPolicy() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + Policy response = keyManagementServiceClient.setIamPolicy(request); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_setiampolicy_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/testiampermissions/AsyncTestIamPermissions.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/testiampermissions/AsyncTestIamPermissions.java new file mode 100644 index 00000000..cc00c4a7 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/testiampermissions/AsyncTestIamPermissions.java @@ -0,0 +1,52 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_testiampermissions_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.kms.v1.CryptoKeyName; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; +import java.util.ArrayList; + +public class AsyncTestIamPermissions { + + public static void main(String[] args) throws Exception { + asyncTestIamPermissions(); + } + + public static void asyncTestIamPermissions() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .addAllPermissions(new ArrayList()) + .build(); + ApiFuture future = + keyManagementServiceClient.testIamPermissionsCallable().futureCall(request); + // Do something. + TestIamPermissionsResponse response = future.get(); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_testiampermissions_async] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/testiampermissions/SyncTestIamPermissions.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/testiampermissions/SyncTestIamPermissions.java new file mode 100644 index 00000000..b1db511b --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/testiampermissions/SyncTestIamPermissions.java @@ -0,0 +1,48 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_testiampermissions_sync] +import com.google.cloud.kms.v1.CryptoKeyName; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; +import java.util.ArrayList; + +public class SyncTestIamPermissions { + + public static void main(String[] args) throws Exception { + syncTestIamPermissions(); + } + + public static void syncTestIamPermissions() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .addAllPermissions(new ArrayList()) + .build(); + TestIamPermissionsResponse response = keyManagementServiceClient.testIamPermissions(request); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_testiampermissions_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/updatecryptokey/AsyncUpdateCryptoKey.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/updatecryptokey/AsyncUpdateCryptoKey.java new file mode 100644 index 00000000..d6ffefaa --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/updatecryptokey/AsyncUpdateCryptoKey.java @@ -0,0 +1,49 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_updatecryptokey_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.kms.v1.CryptoKey; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.UpdateCryptoKeyRequest; +import com.google.protobuf.FieldMask; + +public class AsyncUpdateCryptoKey { + + public static void main(String[] args) throws Exception { + asyncUpdateCryptoKey(); + } + + public static void asyncUpdateCryptoKey() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + UpdateCryptoKeyRequest request = + UpdateCryptoKeyRequest.newBuilder() + .setCryptoKey(CryptoKey.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + ApiFuture future = + keyManagementServiceClient.updateCryptoKeyCallable().futureCall(request); + // Do something. + CryptoKey response = future.get(); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_updatecryptokey_async] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/updatecryptokey/SyncUpdateCryptoKey.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/updatecryptokey/SyncUpdateCryptoKey.java new file mode 100644 index 00000000..f9af1159 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/updatecryptokey/SyncUpdateCryptoKey.java @@ -0,0 +1,45 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_updatecryptokey_sync] +import com.google.cloud.kms.v1.CryptoKey; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.UpdateCryptoKeyRequest; +import com.google.protobuf.FieldMask; + +public class SyncUpdateCryptoKey { + + public static void main(String[] args) throws Exception { + syncUpdateCryptoKey(); + } + + public static void syncUpdateCryptoKey() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + UpdateCryptoKeyRequest request = + UpdateCryptoKeyRequest.newBuilder() + .setCryptoKey(CryptoKey.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + CryptoKey response = keyManagementServiceClient.updateCryptoKey(request); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_updatecryptokey_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/updatecryptokey/SyncUpdateCryptoKeyCryptokeyFieldmask.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/updatecryptokey/SyncUpdateCryptoKeyCryptokeyFieldmask.java new file mode 100644 index 00000000..a908aaa8 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/updatecryptokey/SyncUpdateCryptoKeyCryptokeyFieldmask.java @@ -0,0 +1,41 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_updatecryptokey_cryptokeyfieldmask_sync] +import com.google.cloud.kms.v1.CryptoKey; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.protobuf.FieldMask; + +public class SyncUpdateCryptoKeyCryptokeyFieldmask { + + public static void main(String[] args) throws Exception { + syncUpdateCryptoKeyCryptokeyFieldmask(); + } + + public static void syncUpdateCryptoKeyCryptokeyFieldmask() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + CryptoKey cryptoKey = CryptoKey.newBuilder().build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + CryptoKey response = keyManagementServiceClient.updateCryptoKey(cryptoKey, updateMask); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_updatecryptokey_cryptokeyfieldmask_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/updatecryptokeyprimaryversion/AsyncUpdateCryptoKeyPrimaryVersion.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/updatecryptokeyprimaryversion/AsyncUpdateCryptoKeyPrimaryVersion.java new file mode 100644 index 00000000..c60249a2 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/updatecryptokeyprimaryversion/AsyncUpdateCryptoKeyPrimaryVersion.java @@ -0,0 +1,51 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_updatecryptokeyprimaryversion_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.kms.v1.CryptoKey; +import com.google.cloud.kms.v1.CryptoKeyName; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.UpdateCryptoKeyPrimaryVersionRequest; + +public class AsyncUpdateCryptoKeyPrimaryVersion { + + public static void main(String[] args) throws Exception { + asyncUpdateCryptoKeyPrimaryVersion(); + } + + public static void asyncUpdateCryptoKeyPrimaryVersion() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + UpdateCryptoKeyPrimaryVersionRequest request = + UpdateCryptoKeyPrimaryVersionRequest.newBuilder() + .setName( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .setCryptoKeyVersionId("cryptoKeyVersionId987674581") + .build(); + ApiFuture future = + keyManagementServiceClient.updateCryptoKeyPrimaryVersionCallable().futureCall(request); + // Do something. + CryptoKey response = future.get(); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_updatecryptokeyprimaryversion_async] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/updatecryptokeyprimaryversion/SyncUpdateCryptoKeyPrimaryVersion.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/updatecryptokeyprimaryversion/SyncUpdateCryptoKeyPrimaryVersion.java new file mode 100644 index 00000000..9ffc5a16 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/updatecryptokeyprimaryversion/SyncUpdateCryptoKeyPrimaryVersion.java @@ -0,0 +1,47 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_updatecryptokeyprimaryversion_sync] +import com.google.cloud.kms.v1.CryptoKey; +import com.google.cloud.kms.v1.CryptoKeyName; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.UpdateCryptoKeyPrimaryVersionRequest; + +public class SyncUpdateCryptoKeyPrimaryVersion { + + public static void main(String[] args) throws Exception { + syncUpdateCryptoKeyPrimaryVersion(); + } + + public static void syncUpdateCryptoKeyPrimaryVersion() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + UpdateCryptoKeyPrimaryVersionRequest request = + UpdateCryptoKeyPrimaryVersionRequest.newBuilder() + .setName( + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]") + .toString()) + .setCryptoKeyVersionId("cryptoKeyVersionId987674581") + .build(); + CryptoKey response = keyManagementServiceClient.updateCryptoKeyPrimaryVersion(request); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_updatecryptokeyprimaryversion_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/updatecryptokeyprimaryversion/SyncUpdateCryptoKeyPrimaryVersionCryptokeynameString.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/updatecryptokeyprimaryversion/SyncUpdateCryptoKeyPrimaryVersionCryptokeynameString.java new file mode 100644 index 00000000..2c51ac8a --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/updatecryptokeyprimaryversion/SyncUpdateCryptoKeyPrimaryVersionCryptokeynameString.java @@ -0,0 +1,43 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_updatecryptokeyprimaryversion_cryptokeynamestring_sync] +import com.google.cloud.kms.v1.CryptoKey; +import com.google.cloud.kms.v1.CryptoKeyName; +import com.google.cloud.kms.v1.KeyManagementServiceClient; + +public class SyncUpdateCryptoKeyPrimaryVersionCryptokeynameString { + + public static void main(String[] args) throws Exception { + syncUpdateCryptoKeyPrimaryVersionCryptokeynameString(); + } + + public static void syncUpdateCryptoKeyPrimaryVersionCryptokeynameString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + CryptoKeyName name = + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]"); + String cryptoKeyVersionId = "cryptoKeyVersionId987674581"; + CryptoKey response = + keyManagementServiceClient.updateCryptoKeyPrimaryVersion(name, cryptoKeyVersionId); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_updatecryptokeyprimaryversion_cryptokeynamestring_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/updatecryptokeyprimaryversion/SyncUpdateCryptoKeyPrimaryVersionStringString.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/updatecryptokeyprimaryversion/SyncUpdateCryptoKeyPrimaryVersionStringString.java new file mode 100644 index 00000000..7d8e67a6 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/updatecryptokeyprimaryversion/SyncUpdateCryptoKeyPrimaryVersionStringString.java @@ -0,0 +1,43 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_updatecryptokeyprimaryversion_stringstring_sync] +import com.google.cloud.kms.v1.CryptoKey; +import com.google.cloud.kms.v1.CryptoKeyName; +import com.google.cloud.kms.v1.KeyManagementServiceClient; + +public class SyncUpdateCryptoKeyPrimaryVersionStringString { + + public static void main(String[] args) throws Exception { + syncUpdateCryptoKeyPrimaryVersionStringString(); + } + + public static void syncUpdateCryptoKeyPrimaryVersionStringString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + String name = + CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]").toString(); + String cryptoKeyVersionId = "cryptoKeyVersionId987674581"; + CryptoKey response = + keyManagementServiceClient.updateCryptoKeyPrimaryVersion(name, cryptoKeyVersionId); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_updatecryptokeyprimaryversion_stringstring_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/updatecryptokeyversion/AsyncUpdateCryptoKeyVersion.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/updatecryptokeyversion/AsyncUpdateCryptoKeyVersion.java new file mode 100644 index 00000000..eb72033e --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/updatecryptokeyversion/AsyncUpdateCryptoKeyVersion.java @@ -0,0 +1,49 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_updatecryptokeyversion_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.kms.v1.CryptoKeyVersion; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.UpdateCryptoKeyVersionRequest; +import com.google.protobuf.FieldMask; + +public class AsyncUpdateCryptoKeyVersion { + + public static void main(String[] args) throws Exception { + asyncUpdateCryptoKeyVersion(); + } + + public static void asyncUpdateCryptoKeyVersion() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + UpdateCryptoKeyVersionRequest request = + UpdateCryptoKeyVersionRequest.newBuilder() + .setCryptoKeyVersion(CryptoKeyVersion.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + ApiFuture future = + keyManagementServiceClient.updateCryptoKeyVersionCallable().futureCall(request); + // Do something. + CryptoKeyVersion response = future.get(); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_updatecryptokeyversion_async] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/updatecryptokeyversion/SyncUpdateCryptoKeyVersion.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/updatecryptokeyversion/SyncUpdateCryptoKeyVersion.java new file mode 100644 index 00000000..84d39b0e --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/updatecryptokeyversion/SyncUpdateCryptoKeyVersion.java @@ -0,0 +1,45 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_updatecryptokeyversion_sync] +import com.google.cloud.kms.v1.CryptoKeyVersion; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.UpdateCryptoKeyVersionRequest; +import com.google.protobuf.FieldMask; + +public class SyncUpdateCryptoKeyVersion { + + public static void main(String[] args) throws Exception { + syncUpdateCryptoKeyVersion(); + } + + public static void syncUpdateCryptoKeyVersion() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + UpdateCryptoKeyVersionRequest request = + UpdateCryptoKeyVersionRequest.newBuilder() + .setCryptoKeyVersion(CryptoKeyVersion.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + CryptoKeyVersion response = keyManagementServiceClient.updateCryptoKeyVersion(request); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_updatecryptokeyversion_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/updatecryptokeyversion/SyncUpdateCryptoKeyVersionCryptokeyversionFieldmask.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/updatecryptokeyversion/SyncUpdateCryptoKeyVersionCryptokeyversionFieldmask.java new file mode 100644 index 00000000..d6ddd7f8 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementserviceclient/updatecryptokeyversion/SyncUpdateCryptoKeyVersionCryptokeyversionFieldmask.java @@ -0,0 +1,42 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementserviceclient_updatecryptokeyversion_cryptokeyversionfieldmask_sync] +import com.google.cloud.kms.v1.CryptoKeyVersion; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.protobuf.FieldMask; + +public class SyncUpdateCryptoKeyVersionCryptokeyversionFieldmask { + + public static void main(String[] args) throws Exception { + syncUpdateCryptoKeyVersionCryptokeyversionFieldmask(); + } + + public static void syncUpdateCryptoKeyVersionCryptokeyversionFieldmask() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (KeyManagementServiceClient keyManagementServiceClient = + KeyManagementServiceClient.create()) { + CryptoKeyVersion cryptoKeyVersion = CryptoKeyVersion.newBuilder().build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + CryptoKeyVersion response = + keyManagementServiceClient.updateCryptoKeyVersion(cryptoKeyVersion, updateMask); + } + } +} +// [END kms_v1_generated_keymanagementserviceclient_updatecryptokeyversion_cryptokeyversionfieldmask_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementservicesettings/getkeyring/SyncGetKeyRing.java b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementservicesettings/getkeyring/SyncGetKeyRing.java new file mode 100644 index 00000000..65a3a772 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/keymanagementservicesettings/getkeyring/SyncGetKeyRing.java @@ -0,0 +1,47 @@ +/* + * Copyright 2022 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.samples; + +// [START kms_v1_generated_keymanagementservicesettings_getkeyring_sync] +import com.google.cloud.kms.v1.KeyManagementServiceSettings; +import java.time.Duration; + +public class SyncGetKeyRing { + + public static void main(String[] args) throws Exception { + syncGetKeyRing(); + } + + public static void syncGetKeyRing() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + KeyManagementServiceSettings.Builder keyManagementServiceSettingsBuilder = + KeyManagementServiceSettings.newBuilder(); + keyManagementServiceSettingsBuilder + .getKeyRingSettings() + .setRetrySettings( + keyManagementServiceSettingsBuilder + .getKeyRingSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + KeyManagementServiceSettings keyManagementServiceSettings = + keyManagementServiceSettingsBuilder.build(); + } +} +// [END kms_v1_generated_keymanagementservicesettings_getkeyring_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/stub/ekmservicestubsettings/getekmconnection/SyncGetEkmConnection.java b/samples/snippets/generated/com/google/cloud/kms/v1/stub/ekmservicestubsettings/getekmconnection/SyncGetEkmConnection.java new file mode 100644 index 00000000..213e33f9 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/stub/ekmservicestubsettings/getekmconnection/SyncGetEkmConnection.java @@ -0,0 +1,45 @@ +/* + * Copyright 2022 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.stub.samples; + +// [START kms_v1_generated_ekmservicestubsettings_getekmconnection_sync] +import com.google.cloud.kms.v1.stub.EkmServiceStubSettings; +import java.time.Duration; + +public class SyncGetEkmConnection { + + public static void main(String[] args) throws Exception { + syncGetEkmConnection(); + } + + public static void syncGetEkmConnection() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + EkmServiceStubSettings.Builder ekmServiceSettingsBuilder = EkmServiceStubSettings.newBuilder(); + ekmServiceSettingsBuilder + .getEkmConnectionSettings() + .setRetrySettings( + ekmServiceSettingsBuilder + .getEkmConnectionSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + EkmServiceStubSettings ekmServiceSettings = ekmServiceSettingsBuilder.build(); + } +} +// [END kms_v1_generated_ekmservicestubsettings_getekmconnection_sync] diff --git a/samples/snippets/generated/com/google/cloud/kms/v1/stub/keymanagementservicestubsettings/getkeyring/SyncGetKeyRing.java b/samples/snippets/generated/com/google/cloud/kms/v1/stub/keymanagementservicestubsettings/getkeyring/SyncGetKeyRing.java new file mode 100644 index 00000000..511287cf --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/kms/v1/stub/keymanagementservicestubsettings/getkeyring/SyncGetKeyRing.java @@ -0,0 +1,47 @@ +/* + * Copyright 2022 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.stub.samples; + +// [START kms_v1_generated_keymanagementservicestubsettings_getkeyring_sync] +import com.google.cloud.kms.v1.stub.KeyManagementServiceStubSettings; +import java.time.Duration; + +public class SyncGetKeyRing { + + public static void main(String[] args) throws Exception { + syncGetKeyRing(); + } + + public static void syncGetKeyRing() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + KeyManagementServiceStubSettings.Builder keyManagementServiceSettingsBuilder = + KeyManagementServiceStubSettings.newBuilder(); + keyManagementServiceSettingsBuilder + .getKeyRingSettings() + .setRetrySettings( + keyManagementServiceSettingsBuilder + .getKeyRingSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + KeyManagementServiceStubSettings keyManagementServiceSettings = + keyManagementServiceSettingsBuilder.build(); + } +} +// [END kms_v1_generated_keymanagementservicestubsettings_getkeyring_sync]