diff --git a/java-secretmanager/google-cloud-secretmanager/src/main/java/com/google/cloud/secretmanager/v1/SecretManagerServiceClient.java b/java-secretmanager/google-cloud-secretmanager/src/main/java/com/google/cloud/secretmanager/v1/SecretManagerServiceClient.java
index 3d5ee677188e..6fa339b7e403 100644
--- a/java-secretmanager/google-cloud-secretmanager/src/main/java/com/google/cloud/secretmanager/v1/SecretManagerServiceClient.java
+++ b/java-secretmanager/google-cloud-secretmanager/src/main/java/com/google/cloud/secretmanager/v1/SecretManagerServiceClient.java
@@ -117,6 +117,21 @@
* SecretManagerServiceClient.create(secretManagerServiceSettings);
* }
*
+ * 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.
+ * SecretManagerServiceSettings secretManagerServiceSettings =
+ * SecretManagerServiceSettings.newBuilder()
+ * .setTransportChannelProvider(
+ * SecretManagerServiceSettings.defaultHttpJsonTransportProviderBuilder().build())
+ * .build();
+ * SecretManagerServiceClient secretManagerServiceClient =
+ * SecretManagerServiceClient.create(secretManagerServiceSettings);
+ * }
+ *
* Please refer to the GitHub repository's samples for more quickstart code snippets.
*/
@Generated("by gapic-generator-java")
diff --git a/java-secretmanager/google-cloud-secretmanager/src/main/java/com/google/cloud/secretmanager/v1/SecretManagerServiceSettings.java b/java-secretmanager/google-cloud-secretmanager/src/main/java/com/google/cloud/secretmanager/v1/SecretManagerServiceSettings.java
index 6dc35d865322..2ea377e69731 100644
--- a/java-secretmanager/google-cloud-secretmanager/src/main/java/com/google/cloud/secretmanager/v1/SecretManagerServiceSettings.java
+++ b/java-secretmanager/google-cloud-secretmanager/src/main/java/com/google/cloud/secretmanager/v1/SecretManagerServiceSettings.java
@@ -24,6 +24,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;
@@ -187,11 +188,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde
return SecretManagerServiceStubSettings.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 SecretManagerServiceStubSettings.defaultGrpcTransportProviderBuilder();
}
+ /** Returns a builder for the default REST ChannelProvider for this service. */
+ @BetaApi
+ public static InstantiatingHttpJsonChannelProvider.Builder
+ defaultHttpJsonTransportProviderBuilder() {
+ return SecretManagerServiceStubSettings.defaultHttpJsonTransportProviderBuilder();
+ }
+
public static TransportChannelProvider defaultTransportChannelProvider() {
return SecretManagerServiceStubSettings.defaultTransportChannelProvider();
}
@@ -201,11 +209,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil
return SecretManagerServiceStubSettings.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);
@@ -244,6 +258,11 @@ private static Builder createDefault() {
return new Builder(SecretManagerServiceStubSettings.newBuilder());
}
+ @BetaApi
+ private static Builder createHttpJsonDefault() {
+ return new Builder(SecretManagerServiceStubSettings.newHttpJsonBuilder());
+ }
+
public SecretManagerServiceStubSettings.Builder getStubSettingsBuilder() {
return ((SecretManagerServiceStubSettings.Builder) getStubSettings());
}
diff --git a/java-secretmanager/google-cloud-secretmanager/src/main/java/com/google/cloud/secretmanager/v1/stub/HttpJsonSecretManagerServiceCallableFactory.java b/java-secretmanager/google-cloud-secretmanager/src/main/java/com/google/cloud/secretmanager/v1/stub/HttpJsonSecretManagerServiceCallableFactory.java
new file mode 100644
index 000000000000..ddd37849eeb5
--- /dev/null
+++ b/java-secretmanager/google-cloud-secretmanager/src/main/java/com/google/cloud/secretmanager/v1/stub/HttpJsonSecretManagerServiceCallableFactory.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.secretmanager.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 SecretManagerService service API.
+ *
+ *
This class is for advanced usage.
+ */
+@Generated("by gapic-generator-java")
+@BetaApi
+public class HttpJsonSecretManagerServiceCallableFactory
+ 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/java-secretmanager/google-cloud-secretmanager/src/main/java/com/google/cloud/secretmanager/v1/stub/HttpJsonSecretManagerServiceStub.java b/java-secretmanager/google-cloud-secretmanager/src/main/java/com/google/cloud/secretmanager/v1/stub/HttpJsonSecretManagerServiceStub.java
new file mode 100644
index 000000000000..66d404367d2a
--- /dev/null
+++ b/java-secretmanager/google-cloud-secretmanager/src/main/java/com/google/cloud/secretmanager/v1/stub/HttpJsonSecretManagerServiceStub.java
@@ -0,0 +1,980 @@
+/*
+ * 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.secretmanager.v1.stub;
+
+import static com.google.cloud.secretmanager.v1.SecretManagerServiceClient.ListSecretVersionsPagedResponse;
+import static com.google.cloud.secretmanager.v1.SecretManagerServiceClient.ListSecretsPagedResponse;
+
+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.secretmanager.v1.AccessSecretVersionRequest;
+import com.google.cloud.secretmanager.v1.AccessSecretVersionResponse;
+import com.google.cloud.secretmanager.v1.AddSecretVersionRequest;
+import com.google.cloud.secretmanager.v1.CreateSecretRequest;
+import com.google.cloud.secretmanager.v1.DeleteSecretRequest;
+import com.google.cloud.secretmanager.v1.DestroySecretVersionRequest;
+import com.google.cloud.secretmanager.v1.DisableSecretVersionRequest;
+import com.google.cloud.secretmanager.v1.EnableSecretVersionRequest;
+import com.google.cloud.secretmanager.v1.GetSecretRequest;
+import com.google.cloud.secretmanager.v1.GetSecretVersionRequest;
+import com.google.cloud.secretmanager.v1.ListSecretVersionsRequest;
+import com.google.cloud.secretmanager.v1.ListSecretVersionsResponse;
+import com.google.cloud.secretmanager.v1.ListSecretsRequest;
+import com.google.cloud.secretmanager.v1.ListSecretsResponse;
+import com.google.cloud.secretmanager.v1.Secret;
+import com.google.cloud.secretmanager.v1.SecretVersion;
+import com.google.cloud.secretmanager.v1.UpdateSecretRequest;
+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.Empty;
+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 SecretManagerService service API.
+ *
+ * This class is for advanced usage and reflects the underlying API directly.
+ */
+@Generated("by gapic-generator-java")
+@BetaApi
+public class HttpJsonSecretManagerServiceStub extends SecretManagerServiceStub {
+ private static final TypeRegistry typeRegistry = TypeRegistry.newBuilder().build();
+
+ private static final ApiMethodDescriptor
+ listSecretsMethodDescriptor =
+ ApiMethodDescriptor.newBuilder()
+ .setFullMethodName("google.cloud.secretmanager.v1.SecretManagerService/ListSecrets")
+ .setHttpMethod("GET")
+ .setType(ApiMethodDescriptor.MethodType.UNARY)
+ .setRequestFormatter(
+ ProtoMessageRequestFormatter.newBuilder()
+ .setPath(
+ "/v1/{parent=projects/*}/secrets",
+ 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, "pageSize", request.getPageSize());
+ serializer.putQueryParam(fields, "pageToken", request.getPageToken());
+ return fields;
+ })
+ .setRequestBodyExtractor(request -> null)
+ .build())
+ .setResponseParser(
+ ProtoMessageResponseParser.newBuilder()
+ .setDefaultInstance(ListSecretsResponse.getDefaultInstance())
+ .setDefaultTypeRegistry(typeRegistry)
+ .build())
+ .build();
+
+ private static final ApiMethodDescriptor
+ createSecretMethodDescriptor =
+ ApiMethodDescriptor.newBuilder()
+ .setFullMethodName("google.cloud.secretmanager.v1.SecretManagerService/CreateSecret")
+ .setHttpMethod("POST")
+ .setType(ApiMethodDescriptor.MethodType.UNARY)
+ .setRequestFormatter(
+ ProtoMessageRequestFormatter.newBuilder()
+ .setPath(
+ "/v1/{parent=projects/*}/secrets",
+ 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, "secretId", request.getSecretId());
+ return fields;
+ })
+ .setRequestBodyExtractor(
+ request ->
+ ProtoRestSerializer.create().toBody("secret", request.getSecret()))
+ .build())
+ .setResponseParser(
+ ProtoMessageResponseParser.newBuilder()
+ .setDefaultInstance(Secret.getDefaultInstance())
+ .setDefaultTypeRegistry(typeRegistry)
+ .build())
+ .build();
+
+ private static final ApiMethodDescriptor
+ addSecretVersionMethodDescriptor =
+ ApiMethodDescriptor.newBuilder()
+ .setFullMethodName(
+ "google.cloud.secretmanager.v1.SecretManagerService/AddSecretVersion")
+ .setHttpMethod("POST")
+ .setType(ApiMethodDescriptor.MethodType.UNARY)
+ .setRequestFormatter(
+ ProtoMessageRequestFormatter.newBuilder()
+ .setPath(
+ "/v1/{parent=projects/*/secrets/*}:addVersion",
+ 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(SecretVersion.getDefaultInstance())
+ .setDefaultTypeRegistry(typeRegistry)
+ .build())
+ .build();
+
+ private static final ApiMethodDescriptor getSecretMethodDescriptor =
+ ApiMethodDescriptor.newBuilder()
+ .setFullMethodName("google.cloud.secretmanager.v1.SecretManagerService/GetSecret")
+ .setHttpMethod("GET")
+ .setType(ApiMethodDescriptor.MethodType.UNARY)
+ .setRequestFormatter(
+ ProtoMessageRequestFormatter.newBuilder()
+ .setPath(
+ "/v1/{name=projects/*/secrets/*}",
+ 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(Secret.getDefaultInstance())
+ .setDefaultTypeRegistry(typeRegistry)
+ .build())
+ .build();
+
+ private static final ApiMethodDescriptor
+ updateSecretMethodDescriptor =
+ ApiMethodDescriptor.newBuilder()
+ .setFullMethodName("google.cloud.secretmanager.v1.SecretManagerService/UpdateSecret")
+ .setHttpMethod("PATCH")
+ .setType(ApiMethodDescriptor.MethodType.UNARY)
+ .setRequestFormatter(
+ ProtoMessageRequestFormatter.newBuilder()
+ .setPath(
+ "/v1/{secret.name=projects/*/secrets/*}",
+ request -> {
+ Map fields = new HashMap<>();
+ ProtoRestSerializer serializer =
+ ProtoRestSerializer.create();
+ serializer.putPathParam(
+ fields, "secret.name", request.getSecret().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("secret", request.getSecret()))
+ .build())
+ .setResponseParser(
+ ProtoMessageResponseParser.newBuilder()
+ .setDefaultInstance(Secret.getDefaultInstance())
+ .setDefaultTypeRegistry(typeRegistry)
+ .build())
+ .build();
+
+ private static final ApiMethodDescriptor
+ deleteSecretMethodDescriptor =
+ ApiMethodDescriptor.newBuilder()
+ .setFullMethodName("google.cloud.secretmanager.v1.SecretManagerService/DeleteSecret")
+ .setHttpMethod("DELETE")
+ .setType(ApiMethodDescriptor.MethodType.UNARY)
+ .setRequestFormatter(
+ ProtoMessageRequestFormatter.newBuilder()
+ .setPath(
+ "/v1/{name=projects/*/secrets/*}",
+ 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();
+ serializer.putQueryParam(fields, "etag", request.getEtag());
+ return fields;
+ })
+ .setRequestBodyExtractor(request -> null)
+ .build())
+ .setResponseParser(
+ ProtoMessageResponseParser.newBuilder()
+ .setDefaultInstance(Empty.getDefaultInstance())
+ .setDefaultTypeRegistry(typeRegistry)
+ .build())
+ .build();
+
+ private static final ApiMethodDescriptor
+ listSecretVersionsMethodDescriptor =
+ ApiMethodDescriptor.newBuilder()
+ .setFullMethodName(
+ "google.cloud.secretmanager.v1.SecretManagerService/ListSecretVersions")
+ .setHttpMethod("GET")
+ .setType(ApiMethodDescriptor.MethodType.UNARY)
+ .setRequestFormatter(
+ ProtoMessageRequestFormatter.newBuilder()
+ .setPath(
+ "/v1/{parent=projects/*/secrets/*}/versions",
+ 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, "pageSize", request.getPageSize());
+ serializer.putQueryParam(fields, "pageToken", request.getPageToken());
+ return fields;
+ })
+ .setRequestBodyExtractor(request -> null)
+ .build())
+ .setResponseParser(
+ ProtoMessageResponseParser.newBuilder()
+ .setDefaultInstance(ListSecretVersionsResponse.getDefaultInstance())
+ .setDefaultTypeRegistry(typeRegistry)
+ .build())
+ .build();
+
+ private static final ApiMethodDescriptor
+ getSecretVersionMethodDescriptor =
+ ApiMethodDescriptor.newBuilder()
+ .setFullMethodName(
+ "google.cloud.secretmanager.v1.SecretManagerService/GetSecretVersion")
+ .setHttpMethod("GET")
+ .setType(ApiMethodDescriptor.MethodType.UNARY)
+ .setRequestFormatter(
+ ProtoMessageRequestFormatter.newBuilder()
+ .setPath(
+ "/v1/{name=projects/*/secrets/*/versions/*}",
+ 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(SecretVersion.getDefaultInstance())
+ .setDefaultTypeRegistry(typeRegistry)
+ .build())
+ .build();
+
+ private static final ApiMethodDescriptor
+ accessSecretVersionMethodDescriptor =
+ ApiMethodDescriptor.newBuilder()
+ .setFullMethodName(
+ "google.cloud.secretmanager.v1.SecretManagerService/AccessSecretVersion")
+ .setHttpMethod("GET")
+ .setType(ApiMethodDescriptor.MethodType.UNARY)
+ .setRequestFormatter(
+ ProtoMessageRequestFormatter.newBuilder()
+ .setPath(
+ "/v1/{name=projects/*/secrets/*/versions/*}:access",
+ 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(AccessSecretVersionResponse.getDefaultInstance())
+ .setDefaultTypeRegistry(typeRegistry)
+ .build())
+ .build();
+
+ private static final ApiMethodDescriptor
+ disableSecretVersionMethodDescriptor =
+ ApiMethodDescriptor.newBuilder()
+ .setFullMethodName(
+ "google.cloud.secretmanager.v1.SecretManagerService/DisableSecretVersion")
+ .setHttpMethod("POST")
+ .setType(ApiMethodDescriptor.MethodType.UNARY)
+ .setRequestFormatter(
+ ProtoMessageRequestFormatter.newBuilder()
+ .setPath(
+ "/v1/{name=projects/*/secrets/*/versions/*}:disable",
+ 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(SecretVersion.getDefaultInstance())
+ .setDefaultTypeRegistry(typeRegistry)
+ .build())
+ .build();
+
+ private static final ApiMethodDescriptor
+ enableSecretVersionMethodDescriptor =
+ ApiMethodDescriptor.newBuilder()
+ .setFullMethodName(
+ "google.cloud.secretmanager.v1.SecretManagerService/EnableSecretVersion")
+ .setHttpMethod("POST")
+ .setType(ApiMethodDescriptor.MethodType.UNARY)
+ .setRequestFormatter(
+ ProtoMessageRequestFormatter.newBuilder()
+ .setPath(
+ "/v1/{name=projects/*/secrets/*/versions/*}:enable",
+ 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(SecretVersion.getDefaultInstance())
+ .setDefaultTypeRegistry(typeRegistry)
+ .build())
+ .build();
+
+ private static final ApiMethodDescriptor
+ destroySecretVersionMethodDescriptor =
+ ApiMethodDescriptor.newBuilder()
+ .setFullMethodName(
+ "google.cloud.secretmanager.v1.SecretManagerService/DestroySecretVersion")
+ .setHttpMethod("POST")
+ .setType(ApiMethodDescriptor.MethodType.UNARY)
+ .setRequestFormatter(
+ ProtoMessageRequestFormatter.newBuilder()
+ .setPath(
+ "/v1/{name=projects/*/secrets/*/versions/*}: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(SecretVersion.getDefaultInstance())
+ .setDefaultTypeRegistry(typeRegistry)
+ .build())
+ .build();
+
+ private static final ApiMethodDescriptor
+ setIamPolicyMethodDescriptor =
+ ApiMethodDescriptor.newBuilder()
+ .setFullMethodName("google.cloud.secretmanager.v1.SecretManagerService/SetIamPolicy")
+ .setHttpMethod("POST")
+ .setType(ApiMethodDescriptor.MethodType.UNARY)
+ .setRequestFormatter(
+ ProtoMessageRequestFormatter.newBuilder()
+ .setPath(
+ "/v1/{resource=projects/*/secrets/*}:setIamPolicy",
+ request -> {
+ Map fields = new HashMap<>();
+ ProtoRestSerializer serializer =
+ ProtoRestSerializer.create();
+ serializer.putPathParam(fields, "resource", request.getResource());
+ return fields;
+ })
+ .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.cloud.secretmanager.v1.SecretManagerService/GetIamPolicy")
+ .setHttpMethod("GET")
+ .setType(ApiMethodDescriptor.MethodType.UNARY)
+ .setRequestFormatter(
+ ProtoMessageRequestFormatter.newBuilder()
+ .setPath(
+ "/v1/{resource=projects/*/secrets/*}:getIamPolicy",
+ request -> {
+ Map fields = new HashMap<>();
+ ProtoRestSerializer serializer =
+ ProtoRestSerializer.create();
+ serializer.putPathParam(fields, "resource", request.getResource());
+ return fields;
+ })
+ .setQueryParamsExtractor(
+ request -> {
+ Map> fields = new HashMap<>();
+ ProtoRestSerializer serializer =
+ ProtoRestSerializer.create();
+ serializer.putQueryParam(fields, "options", request.getOptions());
+ 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.cloud.secretmanager.v1.SecretManagerService/TestIamPermissions")
+ .setHttpMethod("POST")
+ .setType(ApiMethodDescriptor.MethodType.UNARY)
+ .setRequestFormatter(
+ ProtoMessageRequestFormatter.newBuilder()
+ .setPath(
+ "/v1/{resource=projects/*/secrets/*}:testIamPermissions",
+ request -> {
+ Map fields = new HashMap<>();
+ ProtoRestSerializer serializer =
+ ProtoRestSerializer.create();
+ serializer.putPathParam(fields, "resource", request.getResource());
+ return fields;
+ })
+ .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 listSecretsCallable;
+ private final UnaryCallable
+ listSecretsPagedCallable;
+ private final UnaryCallable createSecretCallable;
+ private final UnaryCallable addSecretVersionCallable;
+ private final UnaryCallable getSecretCallable;
+ private final UnaryCallable updateSecretCallable;
+ private final UnaryCallable deleteSecretCallable;
+ private final UnaryCallable
+ listSecretVersionsCallable;
+ private final UnaryCallable
+ listSecretVersionsPagedCallable;
+ private final UnaryCallable getSecretVersionCallable;
+ private final UnaryCallable
+ accessSecretVersionCallable;
+ private final UnaryCallable
+ disableSecretVersionCallable;
+ private final UnaryCallable
+ enableSecretVersionCallable;
+ private final UnaryCallable
+ destroySecretVersionCallable;
+ private final UnaryCallable setIamPolicyCallable;
+ private final UnaryCallable getIamPolicyCallable;
+ private final UnaryCallable
+ testIamPermissionsCallable;
+
+ private final BackgroundResource backgroundResources;
+ private final HttpJsonStubCallableFactory callableFactory;
+
+ public static final HttpJsonSecretManagerServiceStub create(
+ SecretManagerServiceStubSettings settings) throws IOException {
+ return new HttpJsonSecretManagerServiceStub(settings, ClientContext.create(settings));
+ }
+
+ public static final HttpJsonSecretManagerServiceStub create(ClientContext clientContext)
+ throws IOException {
+ return new HttpJsonSecretManagerServiceStub(
+ SecretManagerServiceStubSettings.newHttpJsonBuilder().build(), clientContext);
+ }
+
+ public static final HttpJsonSecretManagerServiceStub create(
+ ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException {
+ return new HttpJsonSecretManagerServiceStub(
+ SecretManagerServiceStubSettings.newHttpJsonBuilder().build(),
+ clientContext,
+ callableFactory);
+ }
+
+ /**
+ * Constructs an instance of HttpJsonSecretManagerServiceStub, 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 HttpJsonSecretManagerServiceStub(
+ SecretManagerServiceStubSettings settings, ClientContext clientContext) throws IOException {
+ this(settings, clientContext, new HttpJsonSecretManagerServiceCallableFactory());
+ }
+
+ /**
+ * Constructs an instance of HttpJsonSecretManagerServiceStub, 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 HttpJsonSecretManagerServiceStub(
+ SecretManagerServiceStubSettings settings,
+ ClientContext clientContext,
+ HttpJsonStubCallableFactory callableFactory)
+ throws IOException {
+ this.callableFactory = callableFactory;
+
+ HttpJsonCallSettings listSecretsTransportSettings =
+ HttpJsonCallSettings.newBuilder()
+ .setMethodDescriptor(listSecretsMethodDescriptor)
+ .setTypeRegistry(typeRegistry)
+ .build();
+ HttpJsonCallSettings createSecretTransportSettings =
+ HttpJsonCallSettings.newBuilder()
+ .setMethodDescriptor(createSecretMethodDescriptor)
+ .setTypeRegistry(typeRegistry)
+ .build();
+ HttpJsonCallSettings addSecretVersionTransportSettings =
+ HttpJsonCallSettings.newBuilder()
+ .setMethodDescriptor(addSecretVersionMethodDescriptor)
+ .setTypeRegistry(typeRegistry)
+ .build();
+ HttpJsonCallSettings getSecretTransportSettings =
+ HttpJsonCallSettings.newBuilder()
+ .setMethodDescriptor(getSecretMethodDescriptor)
+ .setTypeRegistry(typeRegistry)
+ .build();
+ HttpJsonCallSettings updateSecretTransportSettings =
+ HttpJsonCallSettings.newBuilder()
+ .setMethodDescriptor(updateSecretMethodDescriptor)
+ .setTypeRegistry(typeRegistry)
+ .build();
+ HttpJsonCallSettings deleteSecretTransportSettings =
+ HttpJsonCallSettings.newBuilder()
+ .setMethodDescriptor(deleteSecretMethodDescriptor)
+ .setTypeRegistry(typeRegistry)
+ .build();
+ HttpJsonCallSettings
+ listSecretVersionsTransportSettings =
+ HttpJsonCallSettings.newBuilder()
+ .setMethodDescriptor(listSecretVersionsMethodDescriptor)
+ .setTypeRegistry(typeRegistry)
+ .build();
+ HttpJsonCallSettings getSecretVersionTransportSettings =
+ HttpJsonCallSettings.newBuilder()
+ .setMethodDescriptor(getSecretVersionMethodDescriptor)
+ .setTypeRegistry(typeRegistry)
+ .build();
+ HttpJsonCallSettings
+ accessSecretVersionTransportSettings =
+ HttpJsonCallSettings
+ .newBuilder()
+ .setMethodDescriptor(accessSecretVersionMethodDescriptor)
+ .setTypeRegistry(typeRegistry)
+ .build();
+ HttpJsonCallSettings
+ disableSecretVersionTransportSettings =
+ HttpJsonCallSettings.newBuilder()
+ .setMethodDescriptor(disableSecretVersionMethodDescriptor)
+ .setTypeRegistry(typeRegistry)
+ .build();
+ HttpJsonCallSettings
+ enableSecretVersionTransportSettings =
+ HttpJsonCallSettings.newBuilder()
+ .setMethodDescriptor(enableSecretVersionMethodDescriptor)
+ .setTypeRegistry(typeRegistry)
+ .build();
+ HttpJsonCallSettings
+ destroySecretVersionTransportSettings =
+ HttpJsonCallSettings.newBuilder()
+ .setMethodDescriptor(destroySecretVersionMethodDescriptor)
+ .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.listSecretsCallable =
+ callableFactory.createUnaryCallable(
+ listSecretsTransportSettings, settings.listSecretsSettings(), clientContext);
+ this.listSecretsPagedCallable =
+ callableFactory.createPagedCallable(
+ listSecretsTransportSettings, settings.listSecretsSettings(), clientContext);
+ this.createSecretCallable =
+ callableFactory.createUnaryCallable(
+ createSecretTransportSettings, settings.createSecretSettings(), clientContext);
+ this.addSecretVersionCallable =
+ callableFactory.createUnaryCallable(
+ addSecretVersionTransportSettings, settings.addSecretVersionSettings(), clientContext);
+ this.getSecretCallable =
+ callableFactory.createUnaryCallable(
+ getSecretTransportSettings, settings.getSecretSettings(), clientContext);
+ this.updateSecretCallable =
+ callableFactory.createUnaryCallable(
+ updateSecretTransportSettings, settings.updateSecretSettings(), clientContext);
+ this.deleteSecretCallable =
+ callableFactory.createUnaryCallable(
+ deleteSecretTransportSettings, settings.deleteSecretSettings(), clientContext);
+ this.listSecretVersionsCallable =
+ callableFactory.createUnaryCallable(
+ listSecretVersionsTransportSettings,
+ settings.listSecretVersionsSettings(),
+ clientContext);
+ this.listSecretVersionsPagedCallable =
+ callableFactory.createPagedCallable(
+ listSecretVersionsTransportSettings,
+ settings.listSecretVersionsSettings(),
+ clientContext);
+ this.getSecretVersionCallable =
+ callableFactory.createUnaryCallable(
+ getSecretVersionTransportSettings, settings.getSecretVersionSettings(), clientContext);
+ this.accessSecretVersionCallable =
+ callableFactory.createUnaryCallable(
+ accessSecretVersionTransportSettings,
+ settings.accessSecretVersionSettings(),
+ clientContext);
+ this.disableSecretVersionCallable =
+ callableFactory.createUnaryCallable(
+ disableSecretVersionTransportSettings,
+ settings.disableSecretVersionSettings(),
+ clientContext);
+ this.enableSecretVersionCallable =
+ callableFactory.createUnaryCallable(
+ enableSecretVersionTransportSettings,
+ settings.enableSecretVersionSettings(),
+ clientContext);
+ this.destroySecretVersionCallable =
+ callableFactory.createUnaryCallable(
+ destroySecretVersionTransportSettings,
+ settings.destroySecretVersionSettings(),
+ 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(listSecretsMethodDescriptor);
+ methodDescriptors.add(createSecretMethodDescriptor);
+ methodDescriptors.add(addSecretVersionMethodDescriptor);
+ methodDescriptors.add(getSecretMethodDescriptor);
+ methodDescriptors.add(updateSecretMethodDescriptor);
+ methodDescriptors.add(deleteSecretMethodDescriptor);
+ methodDescriptors.add(listSecretVersionsMethodDescriptor);
+ methodDescriptors.add(getSecretVersionMethodDescriptor);
+ methodDescriptors.add(accessSecretVersionMethodDescriptor);
+ methodDescriptors.add(disableSecretVersionMethodDescriptor);
+ methodDescriptors.add(enableSecretVersionMethodDescriptor);
+ methodDescriptors.add(destroySecretVersionMethodDescriptor);
+ methodDescriptors.add(setIamPolicyMethodDescriptor);
+ methodDescriptors.add(getIamPolicyMethodDescriptor);
+ methodDescriptors.add(testIamPermissionsMethodDescriptor);
+ return methodDescriptors;
+ }
+
+ @Override
+ public UnaryCallable listSecretsCallable() {
+ return listSecretsCallable;
+ }
+
+ @Override
+ public UnaryCallable listSecretsPagedCallable() {
+ return listSecretsPagedCallable;
+ }
+
+ @Override
+ public UnaryCallable createSecretCallable() {
+ return createSecretCallable;
+ }
+
+ @Override
+ public UnaryCallable addSecretVersionCallable() {
+ return addSecretVersionCallable;
+ }
+
+ @Override
+ public UnaryCallable getSecretCallable() {
+ return getSecretCallable;
+ }
+
+ @Override
+ public UnaryCallable updateSecretCallable() {
+ return updateSecretCallable;
+ }
+
+ @Override
+ public UnaryCallable deleteSecretCallable() {
+ return deleteSecretCallable;
+ }
+
+ @Override
+ public UnaryCallable
+ listSecretVersionsCallable() {
+ return listSecretVersionsCallable;
+ }
+
+ @Override
+ public UnaryCallable
+ listSecretVersionsPagedCallable() {
+ return listSecretVersionsPagedCallable;
+ }
+
+ @Override
+ public UnaryCallable getSecretVersionCallable() {
+ return getSecretVersionCallable;
+ }
+
+ @Override
+ public UnaryCallable
+ accessSecretVersionCallable() {
+ return accessSecretVersionCallable;
+ }
+
+ @Override
+ public UnaryCallable disableSecretVersionCallable() {
+ return disableSecretVersionCallable;
+ }
+
+ @Override
+ public UnaryCallable enableSecretVersionCallable() {
+ return enableSecretVersionCallable;
+ }
+
+ @Override
+ public UnaryCallable destroySecretVersionCallable() {
+ return destroySecretVersionCallable;
+ }
+
+ @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/java-secretmanager/google-cloud-secretmanager/src/main/java/com/google/cloud/secretmanager/v1/stub/SecretManagerServiceStubSettings.java b/java-secretmanager/google-cloud-secretmanager/src/main/java/com/google/cloud/secretmanager/v1/stub/SecretManagerServiceStubSettings.java
index 40db86496880..a0855ceadf23 100644
--- a/java-secretmanager/google-cloud-secretmanager/src/main/java/com/google/cloud/secretmanager/v1/stub/SecretManagerServiceStubSettings.java
+++ b/java-secretmanager/google-cloud-secretmanager/src/main/java/com/google/cloud/secretmanager/v1/stub/SecretManagerServiceStubSettings.java
@@ -28,6 +28,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;
@@ -342,6 +345,11 @@ public SecretManagerServiceStub createStub() throws IOException {
.equals(GrpcTransportChannel.getGrpcTransportName())) {
return GrpcSecretManagerServiceStub.create(this);
}
+ if (getTransportChannelProvider()
+ .getTransportName()
+ .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) {
+ return HttpJsonSecretManagerServiceStub.create(this);
+ }
throw new UnsupportedOperationException(
String.format(
"Transport not supported: %s", getTransportChannelProvider().getTransportName()));
@@ -374,18 +382,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(SecretManagerServiceStubSettings.class))
@@ -393,11 +408,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(SecretManagerServiceStubSettings.class))
+ .setTransportToken(
+ GaxHttpJsonProperties.getHttpJsonTokenName(),
+ GaxHttpJsonProperties.getHttpJsonVersion());
+ }
+
+ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() {
+ return SecretManagerServiceStubSettings.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);
@@ -595,6 +629,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
.listSecretsSettings()
diff --git a/java-secretmanager/google-cloud-secretmanager/src/test/java/com/google/cloud/secretmanager/v1/SecretManagerServiceClientHttpJsonTest.java b/java-secretmanager/google-cloud-secretmanager/src/test/java/com/google/cloud/secretmanager/v1/SecretManagerServiceClientHttpJsonTest.java
new file mode 100644
index 000000000000..4ed8e5b5d9f4
--- /dev/null
+++ b/java-secretmanager/google-cloud-secretmanager/src/test/java/com/google/cloud/secretmanager/v1/SecretManagerServiceClientHttpJsonTest.java
@@ -0,0 +1,1403 @@
+/*
+ * 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.secretmanager.v1;
+
+import static com.google.cloud.secretmanager.v1.SecretManagerServiceClient.ListSecretVersionsPagedResponse;
+import static com.google.cloud.secretmanager.v1.SecretManagerServiceClient.ListSecretsPagedResponse;
+
+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.secretmanager.v1.stub.HttpJsonSecretManagerServiceStub;
+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.Empty;
+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.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 SecretManagerServiceClientHttpJsonTest {
+ private static MockHttpService mockService;
+ private static SecretManagerServiceClient client;
+
+ @BeforeClass
+ public static void startStaticServer() throws IOException {
+ mockService =
+ new MockHttpService(
+ HttpJsonSecretManagerServiceStub.getMethodDescriptors(),
+ SecretManagerServiceSettings.getDefaultEndpoint());
+ SecretManagerServiceSettings settings =
+ SecretManagerServiceSettings.newHttpJsonBuilder()
+ .setTransportChannelProvider(
+ SecretManagerServiceSettings.defaultHttpJsonTransportProviderBuilder()
+ .setHttpTransport(mockService)
+ .build())
+ .setCredentialsProvider(NoCredentialsProvider.create())
+ .build();
+ client = SecretManagerServiceClient.create(settings);
+ }
+
+ @AfterClass
+ public static void stopServer() {
+ client.close();
+ }
+
+ @Before
+ public void setUp() {}
+
+ @After
+ public void tearDown() throws Exception {
+ mockService.reset();
+ }
+
+ @Test
+ public void listSecretsTest() throws Exception {
+ Secret responsesElement = Secret.newBuilder().build();
+ ListSecretsResponse expectedResponse =
+ ListSecretsResponse.newBuilder()
+ .setNextPageToken("")
+ .addAllSecrets(Arrays.asList(responsesElement))
+ .build();
+ mockService.addResponse(expectedResponse);
+
+ ProjectName parent = ProjectName.of("[PROJECT]");
+
+ ListSecretsPagedResponse pagedListResponse = client.listSecrets(parent);
+
+ List resources = Lists.newArrayList(pagedListResponse.iterateAll());
+
+ Assert.assertEquals(1, resources.size());
+ Assert.assertEquals(expectedResponse.getSecretsList().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 listSecretsExceptionTest() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ ProjectName parent = ProjectName.of("[PROJECT]");
+ client.listSecrets(parent);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void listSecretsTest2() throws Exception {
+ Secret responsesElement = Secret.newBuilder().build();
+ ListSecretsResponse expectedResponse =
+ ListSecretsResponse.newBuilder()
+ .setNextPageToken("")
+ .addAllSecrets(Arrays.asList(responsesElement))
+ .build();
+ mockService.addResponse(expectedResponse);
+
+ String parent = "projects/project-2353";
+
+ ListSecretsPagedResponse pagedListResponse = client.listSecrets(parent);
+
+ List resources = Lists.newArrayList(pagedListResponse.iterateAll());
+
+ Assert.assertEquals(1, resources.size());
+ Assert.assertEquals(expectedResponse.getSecretsList().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 listSecretsExceptionTest2() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ String parent = "projects/project-2353";
+ client.listSecrets(parent);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void createSecretTest() throws Exception {
+ Secret expectedResponse =
+ Secret.newBuilder()
+ .setName(SecretName.of("[PROJECT]", "[SECRET]").toString())
+ .setReplication(Replication.newBuilder().build())
+ .setCreateTime(Timestamp.newBuilder().build())
+ .putAllLabels(new HashMap())
+ .addAllTopics(new ArrayList())
+ .setEtag("etag3123477")
+ .setRotation(Rotation.newBuilder().build())
+ .putAllVersionAliases(new HashMap())
+ .build();
+ mockService.addResponse(expectedResponse);
+
+ ProjectName parent = ProjectName.of("[PROJECT]");
+ String secretId = "secretId945974251";
+ Secret secret = Secret.newBuilder().build();
+
+ Secret actualResponse = client.createSecret(parent, secretId, secret);
+ 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 createSecretExceptionTest() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ ProjectName parent = ProjectName.of("[PROJECT]");
+ String secretId = "secretId945974251";
+ Secret secret = Secret.newBuilder().build();
+ client.createSecret(parent, secretId, secret);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void createSecretTest2() throws Exception {
+ Secret expectedResponse =
+ Secret.newBuilder()
+ .setName(SecretName.of("[PROJECT]", "[SECRET]").toString())
+ .setReplication(Replication.newBuilder().build())
+ .setCreateTime(Timestamp.newBuilder().build())
+ .putAllLabels(new HashMap())
+ .addAllTopics(new ArrayList())
+ .setEtag("etag3123477")
+ .setRotation(Rotation.newBuilder().build())
+ .putAllVersionAliases(new HashMap())
+ .build();
+ mockService.addResponse(expectedResponse);
+
+ String parent = "projects/project-2353";
+ String secretId = "secretId945974251";
+ Secret secret = Secret.newBuilder().build();
+
+ Secret actualResponse = client.createSecret(parent, secretId, secret);
+ 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 createSecretExceptionTest2() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ String parent = "projects/project-2353";
+ String secretId = "secretId945974251";
+ Secret secret = Secret.newBuilder().build();
+ client.createSecret(parent, secretId, secret);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void addSecretVersionTest() throws Exception {
+ SecretVersion expectedResponse =
+ SecretVersion.newBuilder()
+ .setName(SecretVersionName.of("[PROJECT]", "[SECRET]", "[SECRET_VERSION]").toString())
+ .setCreateTime(Timestamp.newBuilder().build())
+ .setDestroyTime(Timestamp.newBuilder().build())
+ .setReplicationStatus(ReplicationStatus.newBuilder().build())
+ .setEtag("etag3123477")
+ .setClientSpecifiedPayloadChecksum(true)
+ .build();
+ mockService.addResponse(expectedResponse);
+
+ SecretName parent = SecretName.of("[PROJECT]", "[SECRET]");
+ SecretPayload payload = SecretPayload.newBuilder().build();
+
+ SecretVersion actualResponse = client.addSecretVersion(parent, payload);
+ 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 addSecretVersionExceptionTest() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ SecretName parent = SecretName.of("[PROJECT]", "[SECRET]");
+ SecretPayload payload = SecretPayload.newBuilder().build();
+ client.addSecretVersion(parent, payload);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void addSecretVersionTest2() throws Exception {
+ SecretVersion expectedResponse =
+ SecretVersion.newBuilder()
+ .setName(SecretVersionName.of("[PROJECT]", "[SECRET]", "[SECRET_VERSION]").toString())
+ .setCreateTime(Timestamp.newBuilder().build())
+ .setDestroyTime(Timestamp.newBuilder().build())
+ .setReplicationStatus(ReplicationStatus.newBuilder().build())
+ .setEtag("etag3123477")
+ .setClientSpecifiedPayloadChecksum(true)
+ .build();
+ mockService.addResponse(expectedResponse);
+
+ String parent = "projects/project-3502/secrets/secret-3502";
+ SecretPayload payload = SecretPayload.newBuilder().build();
+
+ SecretVersion actualResponse = client.addSecretVersion(parent, payload);
+ 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 addSecretVersionExceptionTest2() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ String parent = "projects/project-3502/secrets/secret-3502";
+ SecretPayload payload = SecretPayload.newBuilder().build();
+ client.addSecretVersion(parent, payload);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void getSecretTest() throws Exception {
+ Secret expectedResponse =
+ Secret.newBuilder()
+ .setName(SecretName.of("[PROJECT]", "[SECRET]").toString())
+ .setReplication(Replication.newBuilder().build())
+ .setCreateTime(Timestamp.newBuilder().build())
+ .putAllLabels(new HashMap())
+ .addAllTopics(new ArrayList())
+ .setEtag("etag3123477")
+ .setRotation(Rotation.newBuilder().build())
+ .putAllVersionAliases(new HashMap())
+ .build();
+ mockService.addResponse(expectedResponse);
+
+ SecretName name = SecretName.of("[PROJECT]", "[SECRET]");
+
+ Secret actualResponse = client.getSecret(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 getSecretExceptionTest() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ SecretName name = SecretName.of("[PROJECT]", "[SECRET]");
+ client.getSecret(name);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void getSecretTest2() throws Exception {
+ Secret expectedResponse =
+ Secret.newBuilder()
+ .setName(SecretName.of("[PROJECT]", "[SECRET]").toString())
+ .setReplication(Replication.newBuilder().build())
+ .setCreateTime(Timestamp.newBuilder().build())
+ .putAllLabels(new HashMap())
+ .addAllTopics(new ArrayList())
+ .setEtag("etag3123477")
+ .setRotation(Rotation.newBuilder().build())
+ .putAllVersionAliases(new HashMap())
+ .build();
+ mockService.addResponse(expectedResponse);
+
+ String name = "projects/project-5249/secrets/secret-5249";
+
+ Secret actualResponse = client.getSecret(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 getSecretExceptionTest2() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ String name = "projects/project-5249/secrets/secret-5249";
+ client.getSecret(name);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void updateSecretTest() throws Exception {
+ Secret expectedResponse =
+ Secret.newBuilder()
+ .setName(SecretName.of("[PROJECT]", "[SECRET]").toString())
+ .setReplication(Replication.newBuilder().build())
+ .setCreateTime(Timestamp.newBuilder().build())
+ .putAllLabels(new HashMap())
+ .addAllTopics(new ArrayList())
+ .setEtag("etag3123477")
+ .setRotation(Rotation.newBuilder().build())
+ .putAllVersionAliases(new HashMap())
+ .build();
+ mockService.addResponse(expectedResponse);
+
+ Secret secret =
+ Secret.newBuilder()
+ .setName(SecretName.of("[PROJECT]", "[SECRET]").toString())
+ .setReplication(Replication.newBuilder().build())
+ .setCreateTime(Timestamp.newBuilder().build())
+ .putAllLabels(new HashMap())
+ .addAllTopics(new ArrayList())
+ .setEtag("etag3123477")
+ .setRotation(Rotation.newBuilder().build())
+ .putAllVersionAliases(new HashMap())
+ .build();
+ FieldMask updateMask = FieldMask.newBuilder().build();
+
+ Secret actualResponse = client.updateSecret(secret, 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 updateSecretExceptionTest() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ Secret secret =
+ Secret.newBuilder()
+ .setName(SecretName.of("[PROJECT]", "[SECRET]").toString())
+ .setReplication(Replication.newBuilder().build())
+ .setCreateTime(Timestamp.newBuilder().build())
+ .putAllLabels(new HashMap())
+ .addAllTopics(new ArrayList())
+ .setEtag("etag3123477")
+ .setRotation(Rotation.newBuilder().build())
+ .putAllVersionAliases(new HashMap())
+ .build();
+ FieldMask updateMask = FieldMask.newBuilder().build();
+ client.updateSecret(secret, updateMask);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void deleteSecretTest() throws Exception {
+ Empty expectedResponse = Empty.newBuilder().build();
+ mockService.addResponse(expectedResponse);
+
+ SecretName name = SecretName.of("[PROJECT]", "[SECRET]");
+
+ client.deleteSecret(name);
+
+ 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 deleteSecretExceptionTest() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ SecretName name = SecretName.of("[PROJECT]", "[SECRET]");
+ client.deleteSecret(name);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void deleteSecretTest2() throws Exception {
+ Empty expectedResponse = Empty.newBuilder().build();
+ mockService.addResponse(expectedResponse);
+
+ String name = "projects/project-5249/secrets/secret-5249";
+
+ client.deleteSecret(name);
+
+ 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 deleteSecretExceptionTest2() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ String name = "projects/project-5249/secrets/secret-5249";
+ client.deleteSecret(name);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void listSecretVersionsTest() throws Exception {
+ SecretVersion responsesElement = SecretVersion.newBuilder().build();
+ ListSecretVersionsResponse expectedResponse =
+ ListSecretVersionsResponse.newBuilder()
+ .setNextPageToken("")
+ .addAllVersions(Arrays.asList(responsesElement))
+ .build();
+ mockService.addResponse(expectedResponse);
+
+ SecretName parent = SecretName.of("[PROJECT]", "[SECRET]");
+
+ ListSecretVersionsPagedResponse pagedListResponse = client.listSecretVersions(parent);
+
+ List resources = Lists.newArrayList(pagedListResponse.iterateAll());
+
+ Assert.assertEquals(1, resources.size());
+ Assert.assertEquals(expectedResponse.getVersionsList().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 listSecretVersionsExceptionTest() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ SecretName parent = SecretName.of("[PROJECT]", "[SECRET]");
+ client.listSecretVersions(parent);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void listSecretVersionsTest2() throws Exception {
+ SecretVersion responsesElement = SecretVersion.newBuilder().build();
+ ListSecretVersionsResponse expectedResponse =
+ ListSecretVersionsResponse.newBuilder()
+ .setNextPageToken("")
+ .addAllVersions(Arrays.asList(responsesElement))
+ .build();
+ mockService.addResponse(expectedResponse);
+
+ String parent = "projects/project-3502/secrets/secret-3502";
+
+ ListSecretVersionsPagedResponse pagedListResponse = client.listSecretVersions(parent);
+
+ List resources = Lists.newArrayList(pagedListResponse.iterateAll());
+
+ Assert.assertEquals(1, resources.size());
+ Assert.assertEquals(expectedResponse.getVersionsList().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 listSecretVersionsExceptionTest2() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ String parent = "projects/project-3502/secrets/secret-3502";
+ client.listSecretVersions(parent);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void getSecretVersionTest() throws Exception {
+ SecretVersion expectedResponse =
+ SecretVersion.newBuilder()
+ .setName(SecretVersionName.of("[PROJECT]", "[SECRET]", "[SECRET_VERSION]").toString())
+ .setCreateTime(Timestamp.newBuilder().build())
+ .setDestroyTime(Timestamp.newBuilder().build())
+ .setReplicationStatus(ReplicationStatus.newBuilder().build())
+ .setEtag("etag3123477")
+ .setClientSpecifiedPayloadChecksum(true)
+ .build();
+ mockService.addResponse(expectedResponse);
+
+ SecretVersionName name = SecretVersionName.of("[PROJECT]", "[SECRET]", "[SECRET_VERSION]");
+
+ SecretVersion actualResponse = client.getSecretVersion(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 getSecretVersionExceptionTest() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ SecretVersionName name = SecretVersionName.of("[PROJECT]", "[SECRET]", "[SECRET_VERSION]");
+ client.getSecretVersion(name);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void getSecretVersionTest2() throws Exception {
+ SecretVersion expectedResponse =
+ SecretVersion.newBuilder()
+ .setName(SecretVersionName.of("[PROJECT]", "[SECRET]", "[SECRET_VERSION]").toString())
+ .setCreateTime(Timestamp.newBuilder().build())
+ .setDestroyTime(Timestamp.newBuilder().build())
+ .setReplicationStatus(ReplicationStatus.newBuilder().build())
+ .setEtag("etag3123477")
+ .setClientSpecifiedPayloadChecksum(true)
+ .build();
+ mockService.addResponse(expectedResponse);
+
+ String name = "projects/project-4186/secrets/secret-4186/versions/version-4186";
+
+ SecretVersion actualResponse = client.getSecretVersion(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 getSecretVersionExceptionTest2() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ String name = "projects/project-4186/secrets/secret-4186/versions/version-4186";
+ client.getSecretVersion(name);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void accessSecretVersionTest() throws Exception {
+ AccessSecretVersionResponse expectedResponse =
+ AccessSecretVersionResponse.newBuilder()
+ .setName(SecretVersionName.of("[PROJECT]", "[SECRET]", "[SECRET_VERSION]").toString())
+ .setPayload(SecretPayload.newBuilder().build())
+ .build();
+ mockService.addResponse(expectedResponse);
+
+ SecretVersionName name = SecretVersionName.of("[PROJECT]", "[SECRET]", "[SECRET_VERSION]");
+
+ AccessSecretVersionResponse actualResponse = client.accessSecretVersion(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 accessSecretVersionExceptionTest() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ SecretVersionName name = SecretVersionName.of("[PROJECT]", "[SECRET]", "[SECRET_VERSION]");
+ client.accessSecretVersion(name);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void accessSecretVersionTest2() throws Exception {
+ AccessSecretVersionResponse expectedResponse =
+ AccessSecretVersionResponse.newBuilder()
+ .setName(SecretVersionName.of("[PROJECT]", "[SECRET]", "[SECRET_VERSION]").toString())
+ .setPayload(SecretPayload.newBuilder().build())
+ .build();
+ mockService.addResponse(expectedResponse);
+
+ String name = "projects/project-4186/secrets/secret-4186/versions/version-4186";
+
+ AccessSecretVersionResponse actualResponse = client.accessSecretVersion(name);
+ Assert.assertEquals(expectedResponse, actualResponse);
+
+ List