diff --git a/java-secretmanager/google-cloud-secretmanager/pom.xml b/java-secretmanager/google-cloud-secretmanager/pom.xml index 1096ca53c813..d9de6b8764de 100644 --- a/java-secretmanager/google-cloud-secretmanager/pom.xml +++ b/java-secretmanager/google-cloud-secretmanager/pom.xml @@ -65,6 +65,10 @@ com.google.api gax-grpc + + com.google.api + gax-httpjson + org.threeten threetenbp @@ -92,12 +96,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/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 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 accessSecretVersionExceptionTest2() 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.accessSecretVersion(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void disableSecretVersionTest() 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.disableSecretVersion(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 disableSecretVersionExceptionTest() 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.disableSecretVersion(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void disableSecretVersionTest2() 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.disableSecretVersion(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 disableSecretVersionExceptionTest2() 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.disableSecretVersion(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void enableSecretVersionTest() 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.enableSecretVersion(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 enableSecretVersionExceptionTest() 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.enableSecretVersion(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void enableSecretVersionTest2() 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.enableSecretVersion(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 enableSecretVersionExceptionTest2() 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.enableSecretVersion(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void destroySecretVersionTest() 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.destroySecretVersion(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 destroySecretVersionExceptionTest() 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.destroySecretVersion(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void destroySecretVersionTest2() 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.destroySecretVersion(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 destroySecretVersionExceptionTest2() 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.destroySecretVersion(name); + 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(SecretName.of("[PROJECT]", "[SECRET]").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(SecretName.of("[PROJECT]", "[SECRET]").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(SecretName.of("[PROJECT]", "[SECRET]").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(SecretName.of("[PROJECT]", "[SECRET]").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(SecretName.of("[PROJECT]", "[SECRET]").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(SecretName.of("[PROJECT]", "[SECRET]").toString()) + .addAllPermissions(new ArrayList()) + .build(); + client.testIamPermissions(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } +} diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/accesssecretversion/AsyncAccessSecretVersion.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/accesssecretversion/AsyncAccessSecretVersion.java new file mode 100644 index 000000000000..289aac3c77b0 --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/accesssecretversion/AsyncAccessSecretVersion.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.secretmanager.v1.samples; + +// [START secretmanager_v1_generated_secretmanagerserviceclient_accesssecretversion_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.secretmanager.v1.AccessSecretVersionRequest; +import com.google.cloud.secretmanager.v1.AccessSecretVersionResponse; +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; +import com.google.cloud.secretmanager.v1.SecretVersionName; + +public class AsyncAccessSecretVersion { + + public static void main(String[] args) throws Exception { + asyncAccessSecretVersion(); + } + + public static void asyncAccessSecretVersion() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create()) { + AccessSecretVersionRequest request = + AccessSecretVersionRequest.newBuilder() + .setName(SecretVersionName.of("[PROJECT]", "[SECRET]", "[SECRET_VERSION]").toString()) + .build(); + ApiFuture future = + secretManagerServiceClient.accessSecretVersionCallable().futureCall(request); + // Do something. + AccessSecretVersionResponse response = future.get(); + } + } +} +// [END secretmanager_v1_generated_secretmanagerserviceclient_accesssecretversion_async] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/accesssecretversion/SyncAccessSecretVersion.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/accesssecretversion/SyncAccessSecretVersion.java new file mode 100644 index 000000000000..a3958303e9bb --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/accesssecretversion/SyncAccessSecretVersion.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.secretmanager.v1.samples; + +// [START secretmanager_v1_generated_secretmanagerserviceclient_accesssecretversion_sync] +import com.google.cloud.secretmanager.v1.AccessSecretVersionRequest; +import com.google.cloud.secretmanager.v1.AccessSecretVersionResponse; +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; +import com.google.cloud.secretmanager.v1.SecretVersionName; + +public class SyncAccessSecretVersion { + + public static void main(String[] args) throws Exception { + syncAccessSecretVersion(); + } + + public static void syncAccessSecretVersion() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create()) { + AccessSecretVersionRequest request = + AccessSecretVersionRequest.newBuilder() + .setName(SecretVersionName.of("[PROJECT]", "[SECRET]", "[SECRET_VERSION]").toString()) + .build(); + AccessSecretVersionResponse response = + secretManagerServiceClient.accessSecretVersion(request); + } + } +} +// [END secretmanager_v1_generated_secretmanagerserviceclient_accesssecretversion_sync] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/accesssecretversion/SyncAccessSecretVersionSecretversionname.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/accesssecretversion/SyncAccessSecretVersionSecretversionname.java new file mode 100644 index 000000000000..1ce94d5f6d17 --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/accesssecretversion/SyncAccessSecretVersionSecretversionname.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.secretmanager.v1.samples; + +// [START +// secretmanager_v1_generated_secretmanagerserviceclient_accesssecretversion_secretversionname_sync] +import com.google.cloud.secretmanager.v1.AccessSecretVersionResponse; +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; +import com.google.cloud.secretmanager.v1.SecretVersionName; + +public class SyncAccessSecretVersionSecretversionname { + + public static void main(String[] args) throws Exception { + syncAccessSecretVersionSecretversionname(); + } + + public static void syncAccessSecretVersionSecretversionname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create()) { + SecretVersionName name = SecretVersionName.of("[PROJECT]", "[SECRET]", "[SECRET_VERSION]"); + AccessSecretVersionResponse response = secretManagerServiceClient.accessSecretVersion(name); + } + } +} +// [END +// secretmanager_v1_generated_secretmanagerserviceclient_accesssecretversion_secretversionname_sync] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/accesssecretversion/SyncAccessSecretVersionString.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/accesssecretversion/SyncAccessSecretVersionString.java new file mode 100644 index 000000000000..bfe2c2c17dc0 --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/accesssecretversion/SyncAccessSecretVersionString.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.secretmanager.v1.samples; + +// [START secretmanager_v1_generated_secretmanagerserviceclient_accesssecretversion_string_sync] +import com.google.cloud.secretmanager.v1.AccessSecretVersionResponse; +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; +import com.google.cloud.secretmanager.v1.SecretVersionName; + +public class SyncAccessSecretVersionString { + + public static void main(String[] args) throws Exception { + syncAccessSecretVersionString(); + } + + public static void syncAccessSecretVersionString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create()) { + String name = SecretVersionName.of("[PROJECT]", "[SECRET]", "[SECRET_VERSION]").toString(); + AccessSecretVersionResponse response = secretManagerServiceClient.accessSecretVersion(name); + } + } +} +// [END secretmanager_v1_generated_secretmanagerserviceclient_accesssecretversion_string_sync] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/addsecretversion/AsyncAddSecretVersion.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/addsecretversion/AsyncAddSecretVersion.java new file mode 100644 index 000000000000..d599c43ebf99 --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/addsecretversion/AsyncAddSecretVersion.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.secretmanager.v1.samples; + +// [START secretmanager_v1_generated_secretmanagerserviceclient_addsecretversion_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.secretmanager.v1.AddSecretVersionRequest; +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; +import com.google.cloud.secretmanager.v1.SecretName; +import com.google.cloud.secretmanager.v1.SecretPayload; +import com.google.cloud.secretmanager.v1.SecretVersion; + +public class AsyncAddSecretVersion { + + public static void main(String[] args) throws Exception { + asyncAddSecretVersion(); + } + + public static void asyncAddSecretVersion() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create()) { + AddSecretVersionRequest request = + AddSecretVersionRequest.newBuilder() + .setParent(SecretName.of("[PROJECT]", "[SECRET]").toString()) + .setPayload(SecretPayload.newBuilder().build()) + .build(); + ApiFuture future = + secretManagerServiceClient.addSecretVersionCallable().futureCall(request); + // Do something. + SecretVersion response = future.get(); + } + } +} +// [END secretmanager_v1_generated_secretmanagerserviceclient_addsecretversion_async] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/addsecretversion/SyncAddSecretVersion.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/addsecretversion/SyncAddSecretVersion.java new file mode 100644 index 000000000000..90490f7e6cd0 --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/addsecretversion/SyncAddSecretVersion.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.secretmanager.v1.samples; + +// [START secretmanager_v1_generated_secretmanagerserviceclient_addsecretversion_sync] +import com.google.cloud.secretmanager.v1.AddSecretVersionRequest; +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; +import com.google.cloud.secretmanager.v1.SecretName; +import com.google.cloud.secretmanager.v1.SecretPayload; +import com.google.cloud.secretmanager.v1.SecretVersion; + +public class SyncAddSecretVersion { + + public static void main(String[] args) throws Exception { + syncAddSecretVersion(); + } + + public static void syncAddSecretVersion() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create()) { + AddSecretVersionRequest request = + AddSecretVersionRequest.newBuilder() + .setParent(SecretName.of("[PROJECT]", "[SECRET]").toString()) + .setPayload(SecretPayload.newBuilder().build()) + .build(); + SecretVersion response = secretManagerServiceClient.addSecretVersion(request); + } + } +} +// [END secretmanager_v1_generated_secretmanagerserviceclient_addsecretversion_sync] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/addsecretversion/SyncAddSecretVersionSecretnameSecretpayload.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/addsecretversion/SyncAddSecretVersionSecretnameSecretpayload.java new file mode 100644 index 000000000000..a6f7ff039f64 --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/addsecretversion/SyncAddSecretVersionSecretnameSecretpayload.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.secretmanager.v1.samples; + +// [START +// secretmanager_v1_generated_secretmanagerserviceclient_addsecretversion_secretnamesecretpayload_sync] +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; +import com.google.cloud.secretmanager.v1.SecretName; +import com.google.cloud.secretmanager.v1.SecretPayload; +import com.google.cloud.secretmanager.v1.SecretVersion; + +public class SyncAddSecretVersionSecretnameSecretpayload { + + public static void main(String[] args) throws Exception { + syncAddSecretVersionSecretnameSecretpayload(); + } + + public static void syncAddSecretVersionSecretnameSecretpayload() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create()) { + SecretName parent = SecretName.of("[PROJECT]", "[SECRET]"); + SecretPayload payload = SecretPayload.newBuilder().build(); + SecretVersion response = secretManagerServiceClient.addSecretVersion(parent, payload); + } + } +} +// [END +// secretmanager_v1_generated_secretmanagerserviceclient_addsecretversion_secretnamesecretpayload_sync] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/addsecretversion/SyncAddSecretVersionStringSecretpayload.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/addsecretversion/SyncAddSecretVersionStringSecretpayload.java new file mode 100644 index 000000000000..2ad83b31f279 --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/addsecretversion/SyncAddSecretVersionStringSecretpayload.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.secretmanager.v1.samples; + +// [START +// secretmanager_v1_generated_secretmanagerserviceclient_addsecretversion_stringsecretpayload_sync] +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; +import com.google.cloud.secretmanager.v1.SecretName; +import com.google.cloud.secretmanager.v1.SecretPayload; +import com.google.cloud.secretmanager.v1.SecretVersion; + +public class SyncAddSecretVersionStringSecretpayload { + + public static void main(String[] args) throws Exception { + syncAddSecretVersionStringSecretpayload(); + } + + public static void syncAddSecretVersionStringSecretpayload() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create()) { + String parent = SecretName.of("[PROJECT]", "[SECRET]").toString(); + SecretPayload payload = SecretPayload.newBuilder().build(); + SecretVersion response = secretManagerServiceClient.addSecretVersion(parent, payload); + } + } +} +// [END +// secretmanager_v1_generated_secretmanagerserviceclient_addsecretversion_stringsecretpayload_sync] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/create/SyncCreateSetCredentialsProvider.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/create/SyncCreateSetCredentialsProvider.java new file mode 100644 index 000000000000..c4c7e8edc867 --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/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.secretmanager.v1.samples; + +// [START secretmanager_v1_generated_secretmanagerserviceclient_create_setcredentialsprovider_sync] +import com.google.api.gax.core.FixedCredentialsProvider; +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; +import com.google.cloud.secretmanager.v1.SecretManagerServiceSettings; +import com.google.cloud.secretmanager.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. + SecretManagerServiceSettings secretManagerServiceSettings = + SecretManagerServiceSettings.newBuilder() + .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) + .build(); + SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create(secretManagerServiceSettings); + } +} +// [END secretmanager_v1_generated_secretmanagerserviceclient_create_setcredentialsprovider_sync] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/create/SyncCreateSetCredentialsProvider1.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/create/SyncCreateSetCredentialsProvider1.java new file mode 100644 index 000000000000..8aea5af9177c --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/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.secretmanager.v1.samples; + +// [START secretmanager_v1_generated_secretmanagerserviceclient_create_setcredentialsprovider1_sync] +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; +import com.google.cloud.secretmanager.v1.SecretManagerServiceSettings; + +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. + SecretManagerServiceSettings secretManagerServiceSettings = + SecretManagerServiceSettings.newBuilder() + .setTransportChannelProvider( + SecretManagerServiceSettings.defaultHttpJsonTransportProviderBuilder().build()) + .build(); + SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create(secretManagerServiceSettings); + } +} +// [END secretmanager_v1_generated_secretmanagerserviceclient_create_setcredentialsprovider1_sync] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/create/SyncCreateSetEndpoint.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/create/SyncCreateSetEndpoint.java new file mode 100644 index 000000000000..930efd790ef0 --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/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.secretmanager.v1.samples; + +// [START secretmanager_v1_generated_secretmanagerserviceclient_create_setendpoint_sync] +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; +import com.google.cloud.secretmanager.v1.SecretManagerServiceSettings; +import com.google.cloud.secretmanager.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. + SecretManagerServiceSettings secretManagerServiceSettings = + SecretManagerServiceSettings.newBuilder().setEndpoint(myEndpoint).build(); + SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create(secretManagerServiceSettings); + } +} +// [END secretmanager_v1_generated_secretmanagerserviceclient_create_setendpoint_sync] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/createsecret/AsyncCreateSecret.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/createsecret/AsyncCreateSecret.java new file mode 100644 index 000000000000..f4e9d8791532 --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/createsecret/AsyncCreateSecret.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.secretmanager.v1.samples; + +// [START secretmanager_v1_generated_secretmanagerserviceclient_createsecret_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.secretmanager.v1.CreateSecretRequest; +import com.google.cloud.secretmanager.v1.ProjectName; +import com.google.cloud.secretmanager.v1.Secret; +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; + +public class AsyncCreateSecret { + + public static void main(String[] args) throws Exception { + asyncCreateSecret(); + } + + public static void asyncCreateSecret() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create()) { + CreateSecretRequest request = + CreateSecretRequest.newBuilder() + .setParent(ProjectName.of("[PROJECT]").toString()) + .setSecretId("secretId945974251") + .setSecret(Secret.newBuilder().build()) + .build(); + ApiFuture future = + secretManagerServiceClient.createSecretCallable().futureCall(request); + // Do something. + Secret response = future.get(); + } + } +} +// [END secretmanager_v1_generated_secretmanagerserviceclient_createsecret_async] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/createsecret/SyncCreateSecret.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/createsecret/SyncCreateSecret.java new file mode 100644 index 000000000000..7538ac33f534 --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/createsecret/SyncCreateSecret.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.secretmanager.v1.samples; + +// [START secretmanager_v1_generated_secretmanagerserviceclient_createsecret_sync] +import com.google.cloud.secretmanager.v1.CreateSecretRequest; +import com.google.cloud.secretmanager.v1.ProjectName; +import com.google.cloud.secretmanager.v1.Secret; +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; + +public class SyncCreateSecret { + + public static void main(String[] args) throws Exception { + syncCreateSecret(); + } + + public static void syncCreateSecret() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create()) { + CreateSecretRequest request = + CreateSecretRequest.newBuilder() + .setParent(ProjectName.of("[PROJECT]").toString()) + .setSecretId("secretId945974251") + .setSecret(Secret.newBuilder().build()) + .build(); + Secret response = secretManagerServiceClient.createSecret(request); + } + } +} +// [END secretmanager_v1_generated_secretmanagerserviceclient_createsecret_sync] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/createsecret/SyncCreateSecretProjectnameStringSecret.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/createsecret/SyncCreateSecretProjectnameStringSecret.java new file mode 100644 index 000000000000..5dd195ed9685 --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/createsecret/SyncCreateSecretProjectnameStringSecret.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.secretmanager.v1.samples; + +// [START +// secretmanager_v1_generated_secretmanagerserviceclient_createsecret_projectnamestringsecret_sync] +import com.google.cloud.secretmanager.v1.ProjectName; +import com.google.cloud.secretmanager.v1.Secret; +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; + +public class SyncCreateSecretProjectnameStringSecret { + + public static void main(String[] args) throws Exception { + syncCreateSecretProjectnameStringSecret(); + } + + public static void syncCreateSecretProjectnameStringSecret() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create()) { + ProjectName parent = ProjectName.of("[PROJECT]"); + String secretId = "secretId945974251"; + Secret secret = Secret.newBuilder().build(); + Secret response = secretManagerServiceClient.createSecret(parent, secretId, secret); + } + } +} +// [END +// secretmanager_v1_generated_secretmanagerserviceclient_createsecret_projectnamestringsecret_sync] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/createsecret/SyncCreateSecretStringStringSecret.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/createsecret/SyncCreateSecretStringStringSecret.java new file mode 100644 index 000000000000..979aff243091 --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/createsecret/SyncCreateSecretStringStringSecret.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.secretmanager.v1.samples; + +// [START +// secretmanager_v1_generated_secretmanagerserviceclient_createsecret_stringstringsecret_sync] +import com.google.cloud.secretmanager.v1.ProjectName; +import com.google.cloud.secretmanager.v1.Secret; +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; + +public class SyncCreateSecretStringStringSecret { + + public static void main(String[] args) throws Exception { + syncCreateSecretStringStringSecret(); + } + + public static void syncCreateSecretStringStringSecret() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create()) { + String parent = ProjectName.of("[PROJECT]").toString(); + String secretId = "secretId945974251"; + Secret secret = Secret.newBuilder().build(); + Secret response = secretManagerServiceClient.createSecret(parent, secretId, secret); + } + } +} +// [END secretmanager_v1_generated_secretmanagerserviceclient_createsecret_stringstringsecret_sync] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/deletesecret/AsyncDeleteSecret.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/deletesecret/AsyncDeleteSecret.java new file mode 100644 index 000000000000..3fd469cf6348 --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/deletesecret/AsyncDeleteSecret.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.secretmanager.v1.samples; + +// [START secretmanager_v1_generated_secretmanagerserviceclient_deletesecret_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.secretmanager.v1.DeleteSecretRequest; +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; +import com.google.cloud.secretmanager.v1.SecretName; +import com.google.protobuf.Empty; + +public class AsyncDeleteSecret { + + public static void main(String[] args) throws Exception { + asyncDeleteSecret(); + } + + public static void asyncDeleteSecret() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create()) { + DeleteSecretRequest request = + DeleteSecretRequest.newBuilder() + .setName(SecretName.of("[PROJECT]", "[SECRET]").toString()) + .setEtag("etag3123477") + .build(); + ApiFuture future = + secretManagerServiceClient.deleteSecretCallable().futureCall(request); + // Do something. + future.get(); + } + } +} +// [END secretmanager_v1_generated_secretmanagerserviceclient_deletesecret_async] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/deletesecret/SyncDeleteSecret.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/deletesecret/SyncDeleteSecret.java new file mode 100644 index 000000000000..6bd952dc6909 --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/deletesecret/SyncDeleteSecret.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.secretmanager.v1.samples; + +// [START secretmanager_v1_generated_secretmanagerserviceclient_deletesecret_sync] +import com.google.cloud.secretmanager.v1.DeleteSecretRequest; +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; +import com.google.cloud.secretmanager.v1.SecretName; + +public class SyncDeleteSecret { + + public static void main(String[] args) throws Exception { + syncDeleteSecret(); + } + + public static void syncDeleteSecret() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create()) { + DeleteSecretRequest request = + DeleteSecretRequest.newBuilder() + .setName(SecretName.of("[PROJECT]", "[SECRET]").toString()) + .setEtag("etag3123477") + .build(); + secretManagerServiceClient.deleteSecret(request); + } + } +} +// [END secretmanager_v1_generated_secretmanagerserviceclient_deletesecret_sync] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/deletesecret/SyncDeleteSecretSecretname.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/deletesecret/SyncDeleteSecretSecretname.java new file mode 100644 index 000000000000..32b5f19781d9 --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/deletesecret/SyncDeleteSecretSecretname.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.secretmanager.v1.samples; + +// [START secretmanager_v1_generated_secretmanagerserviceclient_deletesecret_secretname_sync] +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; +import com.google.cloud.secretmanager.v1.SecretName; + +public class SyncDeleteSecretSecretname { + + public static void main(String[] args) throws Exception { + syncDeleteSecretSecretname(); + } + + public static void syncDeleteSecretSecretname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create()) { + SecretName name = SecretName.of("[PROJECT]", "[SECRET]"); + secretManagerServiceClient.deleteSecret(name); + } + } +} +// [END secretmanager_v1_generated_secretmanagerserviceclient_deletesecret_secretname_sync] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/deletesecret/SyncDeleteSecretString.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/deletesecret/SyncDeleteSecretString.java new file mode 100644 index 000000000000..c40027cf70fa --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/deletesecret/SyncDeleteSecretString.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.secretmanager.v1.samples; + +// [START secretmanager_v1_generated_secretmanagerserviceclient_deletesecret_string_sync] +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; +import com.google.cloud.secretmanager.v1.SecretName; + +public class SyncDeleteSecretString { + + public static void main(String[] args) throws Exception { + syncDeleteSecretString(); + } + + public static void syncDeleteSecretString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create()) { + String name = SecretName.of("[PROJECT]", "[SECRET]").toString(); + secretManagerServiceClient.deleteSecret(name); + } + } +} +// [END secretmanager_v1_generated_secretmanagerserviceclient_deletesecret_string_sync] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/destroysecretversion/AsyncDestroySecretVersion.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/destroysecretversion/AsyncDestroySecretVersion.java new file mode 100644 index 000000000000..1d53ab024892 --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/destroysecretversion/AsyncDestroySecretVersion.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.secretmanager.v1.samples; + +// [START secretmanager_v1_generated_secretmanagerserviceclient_destroysecretversion_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.secretmanager.v1.DestroySecretVersionRequest; +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; +import com.google.cloud.secretmanager.v1.SecretVersion; +import com.google.cloud.secretmanager.v1.SecretVersionName; + +public class AsyncDestroySecretVersion { + + public static void main(String[] args) throws Exception { + asyncDestroySecretVersion(); + } + + public static void asyncDestroySecretVersion() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create()) { + DestroySecretVersionRequest request = + DestroySecretVersionRequest.newBuilder() + .setName(SecretVersionName.of("[PROJECT]", "[SECRET]", "[SECRET_VERSION]").toString()) + .setEtag("etag3123477") + .build(); + ApiFuture future = + secretManagerServiceClient.destroySecretVersionCallable().futureCall(request); + // Do something. + SecretVersion response = future.get(); + } + } +} +// [END secretmanager_v1_generated_secretmanagerserviceclient_destroysecretversion_async] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/destroysecretversion/SyncDestroySecretVersion.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/destroysecretversion/SyncDestroySecretVersion.java new file mode 100644 index 000000000000..02112f537667 --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/destroysecretversion/SyncDestroySecretVersion.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.secretmanager.v1.samples; + +// [START secretmanager_v1_generated_secretmanagerserviceclient_destroysecretversion_sync] +import com.google.cloud.secretmanager.v1.DestroySecretVersionRequest; +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; +import com.google.cloud.secretmanager.v1.SecretVersion; +import com.google.cloud.secretmanager.v1.SecretVersionName; + +public class SyncDestroySecretVersion { + + public static void main(String[] args) throws Exception { + syncDestroySecretVersion(); + } + + public static void syncDestroySecretVersion() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create()) { + DestroySecretVersionRequest request = + DestroySecretVersionRequest.newBuilder() + .setName(SecretVersionName.of("[PROJECT]", "[SECRET]", "[SECRET_VERSION]").toString()) + .setEtag("etag3123477") + .build(); + SecretVersion response = secretManagerServiceClient.destroySecretVersion(request); + } + } +} +// [END secretmanager_v1_generated_secretmanagerserviceclient_destroysecretversion_sync] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/destroysecretversion/SyncDestroySecretVersionSecretversionname.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/destroysecretversion/SyncDestroySecretVersionSecretversionname.java new file mode 100644 index 000000000000..79804ac2c5cf --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/destroysecretversion/SyncDestroySecretVersionSecretversionname.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.secretmanager.v1.samples; + +// [START +// secretmanager_v1_generated_secretmanagerserviceclient_destroysecretversion_secretversionname_sync] +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; +import com.google.cloud.secretmanager.v1.SecretVersion; +import com.google.cloud.secretmanager.v1.SecretVersionName; + +public class SyncDestroySecretVersionSecretversionname { + + public static void main(String[] args) throws Exception { + syncDestroySecretVersionSecretversionname(); + } + + public static void syncDestroySecretVersionSecretversionname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create()) { + SecretVersionName name = SecretVersionName.of("[PROJECT]", "[SECRET]", "[SECRET_VERSION]"); + SecretVersion response = secretManagerServiceClient.destroySecretVersion(name); + } + } +} +// [END +// secretmanager_v1_generated_secretmanagerserviceclient_destroysecretversion_secretversionname_sync] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/destroysecretversion/SyncDestroySecretVersionString.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/destroysecretversion/SyncDestroySecretVersionString.java new file mode 100644 index 000000000000..ed3f7376a60b --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/destroysecretversion/SyncDestroySecretVersionString.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.secretmanager.v1.samples; + +// [START secretmanager_v1_generated_secretmanagerserviceclient_destroysecretversion_string_sync] +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; +import com.google.cloud.secretmanager.v1.SecretVersion; +import com.google.cloud.secretmanager.v1.SecretVersionName; + +public class SyncDestroySecretVersionString { + + public static void main(String[] args) throws Exception { + syncDestroySecretVersionString(); + } + + public static void syncDestroySecretVersionString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create()) { + String name = SecretVersionName.of("[PROJECT]", "[SECRET]", "[SECRET_VERSION]").toString(); + SecretVersion response = secretManagerServiceClient.destroySecretVersion(name); + } + } +} +// [END secretmanager_v1_generated_secretmanagerserviceclient_destroysecretversion_string_sync] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/disablesecretversion/AsyncDisableSecretVersion.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/disablesecretversion/AsyncDisableSecretVersion.java new file mode 100644 index 000000000000..ffc7e7bfa371 --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/disablesecretversion/AsyncDisableSecretVersion.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.secretmanager.v1.samples; + +// [START secretmanager_v1_generated_secretmanagerserviceclient_disablesecretversion_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.secretmanager.v1.DisableSecretVersionRequest; +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; +import com.google.cloud.secretmanager.v1.SecretVersion; +import com.google.cloud.secretmanager.v1.SecretVersionName; + +public class AsyncDisableSecretVersion { + + public static void main(String[] args) throws Exception { + asyncDisableSecretVersion(); + } + + public static void asyncDisableSecretVersion() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create()) { + DisableSecretVersionRequest request = + DisableSecretVersionRequest.newBuilder() + .setName(SecretVersionName.of("[PROJECT]", "[SECRET]", "[SECRET_VERSION]").toString()) + .setEtag("etag3123477") + .build(); + ApiFuture future = + secretManagerServiceClient.disableSecretVersionCallable().futureCall(request); + // Do something. + SecretVersion response = future.get(); + } + } +} +// [END secretmanager_v1_generated_secretmanagerserviceclient_disablesecretversion_async] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/disablesecretversion/SyncDisableSecretVersion.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/disablesecretversion/SyncDisableSecretVersion.java new file mode 100644 index 000000000000..1e5b38078ace --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/disablesecretversion/SyncDisableSecretVersion.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.secretmanager.v1.samples; + +// [START secretmanager_v1_generated_secretmanagerserviceclient_disablesecretversion_sync] +import com.google.cloud.secretmanager.v1.DisableSecretVersionRequest; +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; +import com.google.cloud.secretmanager.v1.SecretVersion; +import com.google.cloud.secretmanager.v1.SecretVersionName; + +public class SyncDisableSecretVersion { + + public static void main(String[] args) throws Exception { + syncDisableSecretVersion(); + } + + public static void syncDisableSecretVersion() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create()) { + DisableSecretVersionRequest request = + DisableSecretVersionRequest.newBuilder() + .setName(SecretVersionName.of("[PROJECT]", "[SECRET]", "[SECRET_VERSION]").toString()) + .setEtag("etag3123477") + .build(); + SecretVersion response = secretManagerServiceClient.disableSecretVersion(request); + } + } +} +// [END secretmanager_v1_generated_secretmanagerserviceclient_disablesecretversion_sync] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/disablesecretversion/SyncDisableSecretVersionSecretversionname.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/disablesecretversion/SyncDisableSecretVersionSecretversionname.java new file mode 100644 index 000000000000..76b0376d7433 --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/disablesecretversion/SyncDisableSecretVersionSecretversionname.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.secretmanager.v1.samples; + +// [START +// secretmanager_v1_generated_secretmanagerserviceclient_disablesecretversion_secretversionname_sync] +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; +import com.google.cloud.secretmanager.v1.SecretVersion; +import com.google.cloud.secretmanager.v1.SecretVersionName; + +public class SyncDisableSecretVersionSecretversionname { + + public static void main(String[] args) throws Exception { + syncDisableSecretVersionSecretversionname(); + } + + public static void syncDisableSecretVersionSecretversionname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create()) { + SecretVersionName name = SecretVersionName.of("[PROJECT]", "[SECRET]", "[SECRET_VERSION]"); + SecretVersion response = secretManagerServiceClient.disableSecretVersion(name); + } + } +} +// [END +// secretmanager_v1_generated_secretmanagerserviceclient_disablesecretversion_secretversionname_sync] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/disablesecretversion/SyncDisableSecretVersionString.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/disablesecretversion/SyncDisableSecretVersionString.java new file mode 100644 index 000000000000..c44efcf578d9 --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/disablesecretversion/SyncDisableSecretVersionString.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.secretmanager.v1.samples; + +// [START secretmanager_v1_generated_secretmanagerserviceclient_disablesecretversion_string_sync] +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; +import com.google.cloud.secretmanager.v1.SecretVersion; +import com.google.cloud.secretmanager.v1.SecretVersionName; + +public class SyncDisableSecretVersionString { + + public static void main(String[] args) throws Exception { + syncDisableSecretVersionString(); + } + + public static void syncDisableSecretVersionString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create()) { + String name = SecretVersionName.of("[PROJECT]", "[SECRET]", "[SECRET_VERSION]").toString(); + SecretVersion response = secretManagerServiceClient.disableSecretVersion(name); + } + } +} +// [END secretmanager_v1_generated_secretmanagerserviceclient_disablesecretversion_string_sync] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/enablesecretversion/AsyncEnableSecretVersion.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/enablesecretversion/AsyncEnableSecretVersion.java new file mode 100644 index 000000000000..b02a9f9a3cd5 --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/enablesecretversion/AsyncEnableSecretVersion.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.secretmanager.v1.samples; + +// [START secretmanager_v1_generated_secretmanagerserviceclient_enablesecretversion_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.secretmanager.v1.EnableSecretVersionRequest; +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; +import com.google.cloud.secretmanager.v1.SecretVersion; +import com.google.cloud.secretmanager.v1.SecretVersionName; + +public class AsyncEnableSecretVersion { + + public static void main(String[] args) throws Exception { + asyncEnableSecretVersion(); + } + + public static void asyncEnableSecretVersion() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create()) { + EnableSecretVersionRequest request = + EnableSecretVersionRequest.newBuilder() + .setName(SecretVersionName.of("[PROJECT]", "[SECRET]", "[SECRET_VERSION]").toString()) + .setEtag("etag3123477") + .build(); + ApiFuture future = + secretManagerServiceClient.enableSecretVersionCallable().futureCall(request); + // Do something. + SecretVersion response = future.get(); + } + } +} +// [END secretmanager_v1_generated_secretmanagerserviceclient_enablesecretversion_async] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/enablesecretversion/SyncEnableSecretVersion.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/enablesecretversion/SyncEnableSecretVersion.java new file mode 100644 index 000000000000..cc6acfcabee8 --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/enablesecretversion/SyncEnableSecretVersion.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.secretmanager.v1.samples; + +// [START secretmanager_v1_generated_secretmanagerserviceclient_enablesecretversion_sync] +import com.google.cloud.secretmanager.v1.EnableSecretVersionRequest; +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; +import com.google.cloud.secretmanager.v1.SecretVersion; +import com.google.cloud.secretmanager.v1.SecretVersionName; + +public class SyncEnableSecretVersion { + + public static void main(String[] args) throws Exception { + syncEnableSecretVersion(); + } + + public static void syncEnableSecretVersion() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create()) { + EnableSecretVersionRequest request = + EnableSecretVersionRequest.newBuilder() + .setName(SecretVersionName.of("[PROJECT]", "[SECRET]", "[SECRET_VERSION]").toString()) + .setEtag("etag3123477") + .build(); + SecretVersion response = secretManagerServiceClient.enableSecretVersion(request); + } + } +} +// [END secretmanager_v1_generated_secretmanagerserviceclient_enablesecretversion_sync] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/enablesecretversion/SyncEnableSecretVersionSecretversionname.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/enablesecretversion/SyncEnableSecretVersionSecretversionname.java new file mode 100644 index 000000000000..82956813317d --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/enablesecretversion/SyncEnableSecretVersionSecretversionname.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.secretmanager.v1.samples; + +// [START +// secretmanager_v1_generated_secretmanagerserviceclient_enablesecretversion_secretversionname_sync] +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; +import com.google.cloud.secretmanager.v1.SecretVersion; +import com.google.cloud.secretmanager.v1.SecretVersionName; + +public class SyncEnableSecretVersionSecretversionname { + + public static void main(String[] args) throws Exception { + syncEnableSecretVersionSecretversionname(); + } + + public static void syncEnableSecretVersionSecretversionname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create()) { + SecretVersionName name = SecretVersionName.of("[PROJECT]", "[SECRET]", "[SECRET_VERSION]"); + SecretVersion response = secretManagerServiceClient.enableSecretVersion(name); + } + } +} +// [END +// secretmanager_v1_generated_secretmanagerserviceclient_enablesecretversion_secretversionname_sync] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/enablesecretversion/SyncEnableSecretVersionString.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/enablesecretversion/SyncEnableSecretVersionString.java new file mode 100644 index 000000000000..8016728bd6f4 --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/enablesecretversion/SyncEnableSecretVersionString.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.secretmanager.v1.samples; + +// [START secretmanager_v1_generated_secretmanagerserviceclient_enablesecretversion_string_sync] +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; +import com.google.cloud.secretmanager.v1.SecretVersion; +import com.google.cloud.secretmanager.v1.SecretVersionName; + +public class SyncEnableSecretVersionString { + + public static void main(String[] args) throws Exception { + syncEnableSecretVersionString(); + } + + public static void syncEnableSecretVersionString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create()) { + String name = SecretVersionName.of("[PROJECT]", "[SECRET]", "[SECRET_VERSION]").toString(); + SecretVersion response = secretManagerServiceClient.enableSecretVersion(name); + } + } +} +// [END secretmanager_v1_generated_secretmanagerserviceclient_enablesecretversion_string_sync] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/getiampolicy/AsyncGetIamPolicy.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/getiampolicy/AsyncGetIamPolicy.java new file mode 100644 index 000000000000..2a4dd3bceee1 --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/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.secretmanager.v1.samples; + +// [START secretmanager_v1_generated_secretmanagerserviceclient_getiampolicy_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; +import com.google.cloud.secretmanager.v1.SecretName; +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 (SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create()) { + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource(SecretName.of("[PROJECT]", "[SECRET]").toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + ApiFuture future = + secretManagerServiceClient.getIamPolicyCallable().futureCall(request); + // Do something. + Policy response = future.get(); + } + } +} +// [END secretmanager_v1_generated_secretmanagerserviceclient_getiampolicy_async] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/getiampolicy/SyncGetIamPolicy.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/getiampolicy/SyncGetIamPolicy.java new file mode 100644 index 000000000000..7d6489ddbc51 --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/getiampolicy/SyncGetIamPolicy.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.secretmanager.v1.samples; + +// [START secretmanager_v1_generated_secretmanagerserviceclient_getiampolicy_sync] +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; +import com.google.cloud.secretmanager.v1.SecretName; +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 (SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create()) { + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource(SecretName.of("[PROJECT]", "[SECRET]").toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + Policy response = secretManagerServiceClient.getIamPolicy(request); + } + } +} +// [END secretmanager_v1_generated_secretmanagerserviceclient_getiampolicy_sync] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/getsecret/AsyncGetSecret.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/getsecret/AsyncGetSecret.java new file mode 100644 index 000000000000..0741dc187dcd --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/getsecret/AsyncGetSecret.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.secretmanager.v1.samples; + +// [START secretmanager_v1_generated_secretmanagerserviceclient_getsecret_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.secretmanager.v1.GetSecretRequest; +import com.google.cloud.secretmanager.v1.Secret; +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; +import com.google.cloud.secretmanager.v1.SecretName; + +public class AsyncGetSecret { + + public static void main(String[] args) throws Exception { + asyncGetSecret(); + } + + public static void asyncGetSecret() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create()) { + GetSecretRequest request = + GetSecretRequest.newBuilder() + .setName(SecretName.of("[PROJECT]", "[SECRET]").toString()) + .build(); + ApiFuture future = secretManagerServiceClient.getSecretCallable().futureCall(request); + // Do something. + Secret response = future.get(); + } + } +} +// [END secretmanager_v1_generated_secretmanagerserviceclient_getsecret_async] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/getsecret/SyncGetSecret.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/getsecret/SyncGetSecret.java new file mode 100644 index 000000000000..5f94c5ab00fc --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/getsecret/SyncGetSecret.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.secretmanager.v1.samples; + +// [START secretmanager_v1_generated_secretmanagerserviceclient_getsecret_sync] +import com.google.cloud.secretmanager.v1.GetSecretRequest; +import com.google.cloud.secretmanager.v1.Secret; +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; +import com.google.cloud.secretmanager.v1.SecretName; + +public class SyncGetSecret { + + public static void main(String[] args) throws Exception { + syncGetSecret(); + } + + public static void syncGetSecret() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create()) { + GetSecretRequest request = + GetSecretRequest.newBuilder() + .setName(SecretName.of("[PROJECT]", "[SECRET]").toString()) + .build(); + Secret response = secretManagerServiceClient.getSecret(request); + } + } +} +// [END secretmanager_v1_generated_secretmanagerserviceclient_getsecret_sync] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/getsecret/SyncGetSecretSecretname.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/getsecret/SyncGetSecretSecretname.java new file mode 100644 index 000000000000..724aa14880ef --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/getsecret/SyncGetSecretSecretname.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.secretmanager.v1.samples; + +// [START secretmanager_v1_generated_secretmanagerserviceclient_getsecret_secretname_sync] +import com.google.cloud.secretmanager.v1.Secret; +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; +import com.google.cloud.secretmanager.v1.SecretName; + +public class SyncGetSecretSecretname { + + public static void main(String[] args) throws Exception { + syncGetSecretSecretname(); + } + + public static void syncGetSecretSecretname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create()) { + SecretName name = SecretName.of("[PROJECT]", "[SECRET]"); + Secret response = secretManagerServiceClient.getSecret(name); + } + } +} +// [END secretmanager_v1_generated_secretmanagerserviceclient_getsecret_secretname_sync] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/getsecret/SyncGetSecretString.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/getsecret/SyncGetSecretString.java new file mode 100644 index 000000000000..05c3506fa2c7 --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/getsecret/SyncGetSecretString.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.secretmanager.v1.samples; + +// [START secretmanager_v1_generated_secretmanagerserviceclient_getsecret_string_sync] +import com.google.cloud.secretmanager.v1.Secret; +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; +import com.google.cloud.secretmanager.v1.SecretName; + +public class SyncGetSecretString { + + public static void main(String[] args) throws Exception { + syncGetSecretString(); + } + + public static void syncGetSecretString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create()) { + String name = SecretName.of("[PROJECT]", "[SECRET]").toString(); + Secret response = secretManagerServiceClient.getSecret(name); + } + } +} +// [END secretmanager_v1_generated_secretmanagerserviceclient_getsecret_string_sync] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/getsecretversion/AsyncGetSecretVersion.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/getsecretversion/AsyncGetSecretVersion.java new file mode 100644 index 000000000000..70723261f895 --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/getsecretversion/AsyncGetSecretVersion.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.secretmanager.v1.samples; + +// [START secretmanager_v1_generated_secretmanagerserviceclient_getsecretversion_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.secretmanager.v1.GetSecretVersionRequest; +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; +import com.google.cloud.secretmanager.v1.SecretVersion; +import com.google.cloud.secretmanager.v1.SecretVersionName; + +public class AsyncGetSecretVersion { + + public static void main(String[] args) throws Exception { + asyncGetSecretVersion(); + } + + public static void asyncGetSecretVersion() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create()) { + GetSecretVersionRequest request = + GetSecretVersionRequest.newBuilder() + .setName(SecretVersionName.of("[PROJECT]", "[SECRET]", "[SECRET_VERSION]").toString()) + .build(); + ApiFuture future = + secretManagerServiceClient.getSecretVersionCallable().futureCall(request); + // Do something. + SecretVersion response = future.get(); + } + } +} +// [END secretmanager_v1_generated_secretmanagerserviceclient_getsecretversion_async] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/getsecretversion/SyncGetSecretVersion.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/getsecretversion/SyncGetSecretVersion.java new file mode 100644 index 000000000000..3af6008c263d --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/getsecretversion/SyncGetSecretVersion.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.secretmanager.v1.samples; + +// [START secretmanager_v1_generated_secretmanagerserviceclient_getsecretversion_sync] +import com.google.cloud.secretmanager.v1.GetSecretVersionRequest; +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; +import com.google.cloud.secretmanager.v1.SecretVersion; +import com.google.cloud.secretmanager.v1.SecretVersionName; + +public class SyncGetSecretVersion { + + public static void main(String[] args) throws Exception { + syncGetSecretVersion(); + } + + public static void syncGetSecretVersion() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create()) { + GetSecretVersionRequest request = + GetSecretVersionRequest.newBuilder() + .setName(SecretVersionName.of("[PROJECT]", "[SECRET]", "[SECRET_VERSION]").toString()) + .build(); + SecretVersion response = secretManagerServiceClient.getSecretVersion(request); + } + } +} +// [END secretmanager_v1_generated_secretmanagerserviceclient_getsecretversion_sync] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/getsecretversion/SyncGetSecretVersionSecretversionname.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/getsecretversion/SyncGetSecretVersionSecretversionname.java new file mode 100644 index 000000000000..dbaf07168226 --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/getsecretversion/SyncGetSecretVersionSecretversionname.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.secretmanager.v1.samples; + +// [START +// secretmanager_v1_generated_secretmanagerserviceclient_getsecretversion_secretversionname_sync] +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; +import com.google.cloud.secretmanager.v1.SecretVersion; +import com.google.cloud.secretmanager.v1.SecretVersionName; + +public class SyncGetSecretVersionSecretversionname { + + public static void main(String[] args) throws Exception { + syncGetSecretVersionSecretversionname(); + } + + public static void syncGetSecretVersionSecretversionname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create()) { + SecretVersionName name = SecretVersionName.of("[PROJECT]", "[SECRET]", "[SECRET_VERSION]"); + SecretVersion response = secretManagerServiceClient.getSecretVersion(name); + } + } +} +// [END +// secretmanager_v1_generated_secretmanagerserviceclient_getsecretversion_secretversionname_sync] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/getsecretversion/SyncGetSecretVersionString.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/getsecretversion/SyncGetSecretVersionString.java new file mode 100644 index 000000000000..adb157f38b81 --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/getsecretversion/SyncGetSecretVersionString.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.secretmanager.v1.samples; + +// [START secretmanager_v1_generated_secretmanagerserviceclient_getsecretversion_string_sync] +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; +import com.google.cloud.secretmanager.v1.SecretVersion; +import com.google.cloud.secretmanager.v1.SecretVersionName; + +public class SyncGetSecretVersionString { + + public static void main(String[] args) throws Exception { + syncGetSecretVersionString(); + } + + public static void syncGetSecretVersionString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create()) { + String name = SecretVersionName.of("[PROJECT]", "[SECRET]", "[SECRET_VERSION]").toString(); + SecretVersion response = secretManagerServiceClient.getSecretVersion(name); + } + } +} +// [END secretmanager_v1_generated_secretmanagerserviceclient_getsecretversion_string_sync] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/listsecrets/AsyncListSecrets.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/listsecrets/AsyncListSecrets.java new file mode 100644 index 000000000000..f65f68146e78 --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/listsecrets/AsyncListSecrets.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.secretmanager.v1.samples; + +// [START secretmanager_v1_generated_secretmanagerserviceclient_listsecrets_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.secretmanager.v1.ListSecretsRequest; +import com.google.cloud.secretmanager.v1.ProjectName; +import com.google.cloud.secretmanager.v1.Secret; +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; + +public class AsyncListSecrets { + + public static void main(String[] args) throws Exception { + asyncListSecrets(); + } + + public static void asyncListSecrets() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create()) { + ListSecretsRequest request = + ListSecretsRequest.newBuilder() + .setParent(ProjectName.of("[PROJECT]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .build(); + ApiFuture future = + secretManagerServiceClient.listSecretsPagedCallable().futureCall(request); + // Do something. + for (Secret element : future.get().iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END secretmanager_v1_generated_secretmanagerserviceclient_listsecrets_async] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/listsecrets/AsyncListSecretsPaged.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/listsecrets/AsyncListSecretsPaged.java new file mode 100644 index 000000000000..4b41446dcd6d --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/listsecrets/AsyncListSecretsPaged.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.secretmanager.v1.samples; + +// [START secretmanager_v1_generated_secretmanagerserviceclient_listsecrets_paged_async] +import com.google.cloud.secretmanager.v1.ListSecretsRequest; +import com.google.cloud.secretmanager.v1.ListSecretsResponse; +import com.google.cloud.secretmanager.v1.ProjectName; +import com.google.cloud.secretmanager.v1.Secret; +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; +import com.google.common.base.Strings; + +public class AsyncListSecretsPaged { + + public static void main(String[] args) throws Exception { + asyncListSecretsPaged(); + } + + public static void asyncListSecretsPaged() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create()) { + ListSecretsRequest request = + ListSecretsRequest.newBuilder() + .setParent(ProjectName.of("[PROJECT]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .build(); + while (true) { + ListSecretsResponse response = + secretManagerServiceClient.listSecretsCallable().call(request); + for (Secret element : response.getSecretsList()) { + // doThingsWith(element); + } + String nextPageToken = response.getNextPageToken(); + if (!Strings.isNullOrEmpty(nextPageToken)) { + request = request.toBuilder().setPageToken(nextPageToken).build(); + } else { + break; + } + } + } + } +} +// [END secretmanager_v1_generated_secretmanagerserviceclient_listsecrets_paged_async] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/listsecrets/SyncListSecrets.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/listsecrets/SyncListSecrets.java new file mode 100644 index 000000000000..0bd6d3798559 --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/listsecrets/SyncListSecrets.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.secretmanager.v1.samples; + +// [START secretmanager_v1_generated_secretmanagerserviceclient_listsecrets_sync] +import com.google.cloud.secretmanager.v1.ListSecretsRequest; +import com.google.cloud.secretmanager.v1.ProjectName; +import com.google.cloud.secretmanager.v1.Secret; +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; + +public class SyncListSecrets { + + public static void main(String[] args) throws Exception { + syncListSecrets(); + } + + public static void syncListSecrets() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create()) { + ListSecretsRequest request = + ListSecretsRequest.newBuilder() + .setParent(ProjectName.of("[PROJECT]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .build(); + for (Secret element : secretManagerServiceClient.listSecrets(request).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END secretmanager_v1_generated_secretmanagerserviceclient_listsecrets_sync] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/listsecrets/SyncListSecretsProjectname.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/listsecrets/SyncListSecretsProjectname.java new file mode 100644 index 000000000000..c60ac40f479f --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/listsecrets/SyncListSecretsProjectname.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.secretmanager.v1.samples; + +// [START secretmanager_v1_generated_secretmanagerserviceclient_listsecrets_projectname_sync] +import com.google.cloud.secretmanager.v1.ProjectName; +import com.google.cloud.secretmanager.v1.Secret; +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; + +public class SyncListSecretsProjectname { + + public static void main(String[] args) throws Exception { + syncListSecretsProjectname(); + } + + public static void syncListSecretsProjectname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create()) { + ProjectName parent = ProjectName.of("[PROJECT]"); + for (Secret element : secretManagerServiceClient.listSecrets(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END secretmanager_v1_generated_secretmanagerserviceclient_listsecrets_projectname_sync] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/listsecrets/SyncListSecretsString.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/listsecrets/SyncListSecretsString.java new file mode 100644 index 000000000000..d491818d4daa --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/listsecrets/SyncListSecretsString.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.secretmanager.v1.samples; + +// [START secretmanager_v1_generated_secretmanagerserviceclient_listsecrets_string_sync] +import com.google.cloud.secretmanager.v1.ProjectName; +import com.google.cloud.secretmanager.v1.Secret; +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; + +public class SyncListSecretsString { + + public static void main(String[] args) throws Exception { + syncListSecretsString(); + } + + public static void syncListSecretsString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create()) { + String parent = ProjectName.of("[PROJECT]").toString(); + for (Secret element : secretManagerServiceClient.listSecrets(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END secretmanager_v1_generated_secretmanagerserviceclient_listsecrets_string_sync] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/listsecretversions/AsyncListSecretVersions.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/listsecretversions/AsyncListSecretVersions.java new file mode 100644 index 000000000000..464744331539 --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/listsecretversions/AsyncListSecretVersions.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.secretmanager.v1.samples; + +// [START secretmanager_v1_generated_secretmanagerserviceclient_listsecretversions_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.secretmanager.v1.ListSecretVersionsRequest; +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; +import com.google.cloud.secretmanager.v1.SecretName; +import com.google.cloud.secretmanager.v1.SecretVersion; + +public class AsyncListSecretVersions { + + public static void main(String[] args) throws Exception { + asyncListSecretVersions(); + } + + public static void asyncListSecretVersions() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create()) { + ListSecretVersionsRequest request = + ListSecretVersionsRequest.newBuilder() + .setParent(SecretName.of("[PROJECT]", "[SECRET]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .build(); + ApiFuture future = + secretManagerServiceClient.listSecretVersionsPagedCallable().futureCall(request); + // Do something. + for (SecretVersion element : future.get().iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END secretmanager_v1_generated_secretmanagerserviceclient_listsecretversions_async] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/listsecretversions/AsyncListSecretVersionsPaged.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/listsecretversions/AsyncListSecretVersionsPaged.java new file mode 100644 index 000000000000..b54fabac975f --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/listsecretversions/AsyncListSecretVersionsPaged.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.secretmanager.v1.samples; + +// [START secretmanager_v1_generated_secretmanagerserviceclient_listsecretversions_paged_async] +import com.google.cloud.secretmanager.v1.ListSecretVersionsRequest; +import com.google.cloud.secretmanager.v1.ListSecretVersionsResponse; +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; +import com.google.cloud.secretmanager.v1.SecretName; +import com.google.cloud.secretmanager.v1.SecretVersion; +import com.google.common.base.Strings; + +public class AsyncListSecretVersionsPaged { + + public static void main(String[] args) throws Exception { + asyncListSecretVersionsPaged(); + } + + public static void asyncListSecretVersionsPaged() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create()) { + ListSecretVersionsRequest request = + ListSecretVersionsRequest.newBuilder() + .setParent(SecretName.of("[PROJECT]", "[SECRET]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .build(); + while (true) { + ListSecretVersionsResponse response = + secretManagerServiceClient.listSecretVersionsCallable().call(request); + for (SecretVersion element : response.getVersionsList()) { + // doThingsWith(element); + } + String nextPageToken = response.getNextPageToken(); + if (!Strings.isNullOrEmpty(nextPageToken)) { + request = request.toBuilder().setPageToken(nextPageToken).build(); + } else { + break; + } + } + } + } +} +// [END secretmanager_v1_generated_secretmanagerserviceclient_listsecretversions_paged_async] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/listsecretversions/SyncListSecretVersions.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/listsecretversions/SyncListSecretVersions.java new file mode 100644 index 000000000000..60e9dea75e0d --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/listsecretversions/SyncListSecretVersions.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.secretmanager.v1.samples; + +// [START secretmanager_v1_generated_secretmanagerserviceclient_listsecretversions_sync] +import com.google.cloud.secretmanager.v1.ListSecretVersionsRequest; +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; +import com.google.cloud.secretmanager.v1.SecretName; +import com.google.cloud.secretmanager.v1.SecretVersion; + +public class SyncListSecretVersions { + + public static void main(String[] args) throws Exception { + syncListSecretVersions(); + } + + public static void syncListSecretVersions() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create()) { + ListSecretVersionsRequest request = + ListSecretVersionsRequest.newBuilder() + .setParent(SecretName.of("[PROJECT]", "[SECRET]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .build(); + for (SecretVersion element : + secretManagerServiceClient.listSecretVersions(request).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END secretmanager_v1_generated_secretmanagerserviceclient_listsecretversions_sync] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/listsecretversions/SyncListSecretVersionsSecretname.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/listsecretversions/SyncListSecretVersionsSecretname.java new file mode 100644 index 000000000000..29f9b0368666 --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/listsecretversions/SyncListSecretVersionsSecretname.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.secretmanager.v1.samples; + +// [START secretmanager_v1_generated_secretmanagerserviceclient_listsecretversions_secretname_sync] +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; +import com.google.cloud.secretmanager.v1.SecretName; +import com.google.cloud.secretmanager.v1.SecretVersion; + +public class SyncListSecretVersionsSecretname { + + public static void main(String[] args) throws Exception { + syncListSecretVersionsSecretname(); + } + + public static void syncListSecretVersionsSecretname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create()) { + SecretName parent = SecretName.of("[PROJECT]", "[SECRET]"); + for (SecretVersion element : + secretManagerServiceClient.listSecretVersions(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END secretmanager_v1_generated_secretmanagerserviceclient_listsecretversions_secretname_sync] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/listsecretversions/SyncListSecretVersionsString.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/listsecretversions/SyncListSecretVersionsString.java new file mode 100644 index 000000000000..86f8e8ea1f9f --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/listsecretversions/SyncListSecretVersionsString.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.secretmanager.v1.samples; + +// [START secretmanager_v1_generated_secretmanagerserviceclient_listsecretversions_string_sync] +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; +import com.google.cloud.secretmanager.v1.SecretName; +import com.google.cloud.secretmanager.v1.SecretVersion; + +public class SyncListSecretVersionsString { + + public static void main(String[] args) throws Exception { + syncListSecretVersionsString(); + } + + public static void syncListSecretVersionsString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create()) { + String parent = SecretName.of("[PROJECT]", "[SECRET]").toString(); + for (SecretVersion element : + secretManagerServiceClient.listSecretVersions(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END secretmanager_v1_generated_secretmanagerserviceclient_listsecretversions_string_sync] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/setiampolicy/AsyncSetIamPolicy.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/setiampolicy/AsyncSetIamPolicy.java new file mode 100644 index 000000000000..a9e5d82d2e46 --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/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.secretmanager.v1.samples; + +// [START secretmanager_v1_generated_secretmanagerserviceclient_setiampolicy_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; +import com.google.cloud.secretmanager.v1.SecretName; +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 (SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create()) { + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource(SecretName.of("[PROJECT]", "[SECRET]").toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + ApiFuture future = + secretManagerServiceClient.setIamPolicyCallable().futureCall(request); + // Do something. + Policy response = future.get(); + } + } +} +// [END secretmanager_v1_generated_secretmanagerserviceclient_setiampolicy_async] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/setiampolicy/SyncSetIamPolicy.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/setiampolicy/SyncSetIamPolicy.java new file mode 100644 index 000000000000..ea6ff3f1221b --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/setiampolicy/SyncSetIamPolicy.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.secretmanager.v1.samples; + +// [START secretmanager_v1_generated_secretmanagerserviceclient_setiampolicy_sync] +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; +import com.google.cloud.secretmanager.v1.SecretName; +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 (SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create()) { + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource(SecretName.of("[PROJECT]", "[SECRET]").toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + Policy response = secretManagerServiceClient.setIamPolicy(request); + } + } +} +// [END secretmanager_v1_generated_secretmanagerserviceclient_setiampolicy_sync] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/testiampermissions/AsyncTestIamPermissions.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/testiampermissions/AsyncTestIamPermissions.java new file mode 100644 index 000000000000..ec826530ab81 --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/testiampermissions/AsyncTestIamPermissions.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.secretmanager.v1.samples; + +// [START secretmanager_v1_generated_secretmanagerserviceclient_testiampermissions_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; +import com.google.cloud.secretmanager.v1.SecretName; +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 (SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create()) { + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource(SecretName.of("[PROJECT]", "[SECRET]").toString()) + .addAllPermissions(new ArrayList()) + .build(); + ApiFuture future = + secretManagerServiceClient.testIamPermissionsCallable().futureCall(request); + // Do something. + TestIamPermissionsResponse response = future.get(); + } + } +} +// [END secretmanager_v1_generated_secretmanagerserviceclient_testiampermissions_async] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/testiampermissions/SyncTestIamPermissions.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/testiampermissions/SyncTestIamPermissions.java new file mode 100644 index 000000000000..eebef3a28133 --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/testiampermissions/SyncTestIamPermissions.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.secretmanager.v1.samples; + +// [START secretmanager_v1_generated_secretmanagerserviceclient_testiampermissions_sync] +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; +import com.google.cloud.secretmanager.v1.SecretName; +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 (SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create()) { + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource(SecretName.of("[PROJECT]", "[SECRET]").toString()) + .addAllPermissions(new ArrayList()) + .build(); + TestIamPermissionsResponse response = secretManagerServiceClient.testIamPermissions(request); + } + } +} +// [END secretmanager_v1_generated_secretmanagerserviceclient_testiampermissions_sync] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/updatesecret/AsyncUpdateSecret.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/updatesecret/AsyncUpdateSecret.java new file mode 100644 index 000000000000..b28e8421462e --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/updatesecret/AsyncUpdateSecret.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.secretmanager.v1.samples; + +// [START secretmanager_v1_generated_secretmanagerserviceclient_updatesecret_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.secretmanager.v1.Secret; +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; +import com.google.cloud.secretmanager.v1.UpdateSecretRequest; +import com.google.protobuf.FieldMask; + +public class AsyncUpdateSecret { + + public static void main(String[] args) throws Exception { + asyncUpdateSecret(); + } + + public static void asyncUpdateSecret() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create()) { + UpdateSecretRequest request = + UpdateSecretRequest.newBuilder() + .setSecret(Secret.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + ApiFuture future = + secretManagerServiceClient.updateSecretCallable().futureCall(request); + // Do something. + Secret response = future.get(); + } + } +} +// [END secretmanager_v1_generated_secretmanagerserviceclient_updatesecret_async] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/updatesecret/SyncUpdateSecret.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/updatesecret/SyncUpdateSecret.java new file mode 100644 index 000000000000..3b88952aa777 --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/updatesecret/SyncUpdateSecret.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.secretmanager.v1.samples; + +// [START secretmanager_v1_generated_secretmanagerserviceclient_updatesecret_sync] +import com.google.cloud.secretmanager.v1.Secret; +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; +import com.google.cloud.secretmanager.v1.UpdateSecretRequest; +import com.google.protobuf.FieldMask; + +public class SyncUpdateSecret { + + public static void main(String[] args) throws Exception { + syncUpdateSecret(); + } + + public static void syncUpdateSecret() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create()) { + UpdateSecretRequest request = + UpdateSecretRequest.newBuilder() + .setSecret(Secret.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + Secret response = secretManagerServiceClient.updateSecret(request); + } + } +} +// [END secretmanager_v1_generated_secretmanagerserviceclient_updatesecret_sync] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/updatesecret/SyncUpdateSecretSecretFieldmask.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/updatesecret/SyncUpdateSecretSecretFieldmask.java new file mode 100644 index 000000000000..fa11b4aad97c --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerserviceclient/updatesecret/SyncUpdateSecretSecretFieldmask.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.secretmanager.v1.samples; + +// [START secretmanager_v1_generated_secretmanagerserviceclient_updatesecret_secretfieldmask_sync] +import com.google.cloud.secretmanager.v1.Secret; +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; +import com.google.protobuf.FieldMask; + +public class SyncUpdateSecretSecretFieldmask { + + public static void main(String[] args) throws Exception { + syncUpdateSecretSecretFieldmask(); + } + + public static void syncUpdateSecretSecretFieldmask() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (SecretManagerServiceClient secretManagerServiceClient = + SecretManagerServiceClient.create()) { + Secret secret = Secret.newBuilder().build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + Secret response = secretManagerServiceClient.updateSecret(secret, updateMask); + } + } +} +// [END secretmanager_v1_generated_secretmanagerserviceclient_updatesecret_secretfieldmask_sync] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerservicesettings/createsecret/SyncCreateSecret.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerservicesettings/createsecret/SyncCreateSecret.java new file mode 100644 index 000000000000..1a254305b479 --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/secretmanagerservicesettings/createsecret/SyncCreateSecret.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.secretmanager.v1.samples; + +// [START secretmanager_v1_generated_secretmanagerservicesettings_createsecret_sync] +import com.google.cloud.secretmanager.v1.SecretManagerServiceSettings; +import java.time.Duration; + +public class SyncCreateSecret { + + public static void main(String[] args) throws Exception { + syncCreateSecret(); + } + + public static void syncCreateSecret() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + SecretManagerServiceSettings.Builder secretManagerServiceSettingsBuilder = + SecretManagerServiceSettings.newBuilder(); + secretManagerServiceSettingsBuilder + .createSecretSettings() + .setRetrySettings( + secretManagerServiceSettingsBuilder + .createSecretSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + SecretManagerServiceSettings secretManagerServiceSettings = + secretManagerServiceSettingsBuilder.build(); + } +} +// [END secretmanager_v1_generated_secretmanagerservicesettings_createsecret_sync] diff --git a/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/stub/secretmanagerservicestubsettings/createsecret/SyncCreateSecret.java b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/stub/secretmanagerservicestubsettings/createsecret/SyncCreateSecret.java new file mode 100644 index 000000000000..799ca1051ffe --- /dev/null +++ b/java-secretmanager/samples/snippets/generated/com/google/cloud/secretmanager/v1/stub/secretmanagerservicestubsettings/createsecret/SyncCreateSecret.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.secretmanager.v1.stub.samples; + +// [START secretmanager_v1_generated_secretmanagerservicestubsettings_createsecret_sync] +import com.google.cloud.secretmanager.v1.stub.SecretManagerServiceStubSettings; +import java.time.Duration; + +public class SyncCreateSecret { + + public static void main(String[] args) throws Exception { + syncCreateSecret(); + } + + public static void syncCreateSecret() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + SecretManagerServiceStubSettings.Builder secretManagerServiceSettingsBuilder = + SecretManagerServiceStubSettings.newBuilder(); + secretManagerServiceSettingsBuilder + .createSecretSettings() + .setRetrySettings( + secretManagerServiceSettingsBuilder + .createSecretSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + SecretManagerServiceStubSettings secretManagerServiceSettings = + secretManagerServiceSettingsBuilder.build(); + } +} +// [END secretmanager_v1_generated_secretmanagerservicestubsettings_createsecret_sync]