Class SecretManagerServiceClient (2.22.0)

public class SecretManagerServiceClient implements BackgroundResource

Service Description: Secret Manager Service

Manages secrets and operations using those secrets. Implements a REST model with the following objects:

  • Secret
  • SecretVersion

This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:


 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);
 }
 

Note: close() needs to be called on the SecretManagerServiceClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().

The surface of this class includes several types of Java methods for each of the API's methods:

  1. A "flattened" method. With this type of method, the fields of the request type have been converted into function parameters. It may be the case that not all fields are available as parameters, and not every API method will have a flattened method entry point.
  2. A "request object" method. This type of method only takes one parameter, a request object, which must be constructed before the call. Not every API method will have a request object method.
  3. A "callable" method. This type of method takes no parameters and returns an immutable API callable object, which can be used to initiate calls to the service.

See the individual methods for example code.

Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parse method to extract the individual identifiers contained within names that are returned.

This class can be customized by passing in a custom instance of SecretManagerServiceSettings to create(). For example:

To customize credentials:


 SecretManagerServiceSettings secretManagerServiceSettings =
     SecretManagerServiceSettings.newBuilder()
         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
         .build();
 SecretManagerServiceClient secretManagerServiceClient =
     SecretManagerServiceClient.create(secretManagerServiceSettings);
 

To customize the endpoint:


 SecretManagerServiceSettings secretManagerServiceSettings =
     SecretManagerServiceSettings.newBuilder().setEndpoint(myEndpoint).build();
 SecretManagerServiceClient secretManagerServiceClient =
     SecretManagerServiceClient.create(secretManagerServiceSettings);
 

Please refer to the GitHub repository's samples for more quickstart code snippets.

Inheritance

java.lang.Object > SecretManagerServiceClient

Implements

BackgroundResource

Static Methods

create()

public static final SecretManagerServiceClient create()

Constructs an instance of SecretManagerServiceClient with default settings.

Returns
TypeDescription
SecretManagerServiceClient
Exceptions
TypeDescription
IOException

create(SecretManagerServiceSettings settings)

public static final SecretManagerServiceClient create(SecretManagerServiceSettings settings)

Constructs an instance of SecretManagerServiceClient, using the given settings. The channels are created based on the settings passed in, or defaults for any settings that are not set.

Parameter
NameDescription
settingsSecretManagerServiceSettings
Returns
TypeDescription
SecretManagerServiceClient
Exceptions
TypeDescription
IOException

create(SecretManagerServiceStub stub)

public static final SecretManagerServiceClient create(SecretManagerServiceStub stub)

Constructs an instance of SecretManagerServiceClient, using the given stub for making calls. This is for advanced usage - prefer using create(SecretManagerServiceSettings).

Parameter
NameDescription
stubSecretManagerServiceStub
Returns
TypeDescription
SecretManagerServiceClient

Constructors

SecretManagerServiceClient(SecretManagerServiceSettings settings)

protected SecretManagerServiceClient(SecretManagerServiceSettings settings)

Constructs an instance of SecretManagerServiceClient, 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.

Parameter
NameDescription
settingsSecretManagerServiceSettings

SecretManagerServiceClient(SecretManagerServiceStub stub)

protected SecretManagerServiceClient(SecretManagerServiceStub stub)
Parameter
NameDescription
stubSecretManagerServiceStub

Methods

accessSecretVersion(AccessSecretVersionRequest request)

public final AccessSecretVersionResponse accessSecretVersion(AccessSecretVersionRequest request)

Accesses a SecretVersion. This call returns the secret data.

projects/*/secrets/*/versions/latest is an alias to the latest SecretVersion.

Sample code:


 try (SecretManagerServiceClient secretManagerServiceClient =
     SecretManagerServiceClient.create()) {
   AccessSecretVersionRequest request =
       AccessSecretVersionRequest.newBuilder()
           .setName(SecretVersionName.of("[PROJECT]", "[SECRET]", "[SECRET_VERSION]").toString())
           .build();
   AccessSecretVersionResponse response =
       secretManagerServiceClient.accessSecretVersion(request);
 }
 
Parameter
NameDescription
requestAccessSecretVersionRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
AccessSecretVersionResponse

accessSecretVersion(SecretVersionName name)

public final AccessSecretVersionResponse accessSecretVersion(SecretVersionName name)

Accesses a SecretVersion. This call returns the secret data.

projects/*/secrets/*/versions/latest is an alias to the latest SecretVersion.

Sample code:


 try (SecretManagerServiceClient secretManagerServiceClient =
     SecretManagerServiceClient.create()) {
   SecretVersionName name = SecretVersionName.of("[PROJECT]", "[SECRET]", "[SECRET_VERSION]");
   AccessSecretVersionResponse response = secretManagerServiceClient.accessSecretVersion(name);
 }
 
Parameter
NameDescription
nameSecretVersionName

Required. The resource name of the SecretVersion in the format projects/*/secrets/*/versions/*.

Returns
TypeDescription
AccessSecretVersionResponse

accessSecretVersion(String name)

public final AccessSecretVersionResponse accessSecretVersion(String name)

Accesses a SecretVersion. This call returns the secret data.

projects/*/secrets/*/versions/latest is an alias to the latest SecretVersion.

Sample code:


 try (SecretManagerServiceClient secretManagerServiceClient =
     SecretManagerServiceClient.create()) {
   String name = SecretVersionName.of("[PROJECT]", "[SECRET]", "[SECRET_VERSION]").toString();
   AccessSecretVersionResponse response = secretManagerServiceClient.accessSecretVersion(name);
 }
 
Parameter
NameDescription
nameString

Required. The resource name of the SecretVersion in the format projects/*/secrets/*/versions/*.

Returns
TypeDescription
AccessSecretVersionResponse

accessSecretVersionCallable()

public final UnaryCallable<AccessSecretVersionRequest,AccessSecretVersionResponse> accessSecretVersionCallable()

Accesses a SecretVersion. This call returns the secret data.

projects/*/secrets/*/versions/latest is an alias to the latest SecretVersion.

Sample code:


 try (SecretManagerServiceClient secretManagerServiceClient =
     SecretManagerServiceClient.create()) {
   AccessSecretVersionRequest request =
       AccessSecretVersionRequest.newBuilder()
           .setName(SecretVersionName.of("[PROJECT]", "[SECRET]", "[SECRET_VERSION]").toString())
           .build();
   ApiFuture<AccessSecretVersionResponse> future =
       secretManagerServiceClient.accessSecretVersionCallable().futureCall(request);
   // Do something.
   AccessSecretVersionResponse response = future.get();
 }
 
Returns
TypeDescription
UnaryCallable<AccessSecretVersionRequest,AccessSecretVersionResponse>

addSecretVersion(AddSecretVersionRequest request)

public final SecretVersion addSecretVersion(AddSecretVersionRequest request)

Creates a new SecretVersion containing secret data and attaches it to an existing Secret.

Sample code:


 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);
 }
 
Parameter
NameDescription
requestAddSecretVersionRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
SecretVersion

addSecretVersion(SecretName parent, SecretPayload payload)

public final SecretVersion addSecretVersion(SecretName parent, SecretPayload payload)

Creates a new SecretVersion containing secret data and attaches it to an existing Secret.

Sample code:


 try (SecretManagerServiceClient secretManagerServiceClient =
     SecretManagerServiceClient.create()) {
   SecretName parent = SecretName.of("[PROJECT]", "[SECRET]");
   SecretPayload payload = SecretPayload.newBuilder().build();
   SecretVersion response = secretManagerServiceClient.addSecretVersion(parent, payload);
 }
 
Parameters
NameDescription
parentSecretName

Required. The resource name of the Secret to associate with the SecretVersion in the format projects/*/secrets/*.

payloadSecretPayload

Required. The secret payload of the SecretVersion.

Returns
TypeDescription
SecretVersion

addSecretVersion(String parent, SecretPayload payload)

public final SecretVersion addSecretVersion(String parent, SecretPayload payload)

Creates a new SecretVersion containing secret data and attaches it to an existing Secret.

Sample code:


 try (SecretManagerServiceClient secretManagerServiceClient =
     SecretManagerServiceClient.create()) {
   String parent = SecretName.of("[PROJECT]", "[SECRET]").toString();
   SecretPayload payload = SecretPayload.newBuilder().build();
   SecretVersion response = secretManagerServiceClient.addSecretVersion(parent, payload);
 }
 
Parameters
NameDescription
parentString

Required. The resource name of the Secret to associate with the SecretVersion in the format projects/*/secrets/*.

payloadSecretPayload

Required. The secret payload of the SecretVersion.

Returns
TypeDescription
SecretVersion

addSecretVersionCallable()

public final UnaryCallable<AddSecretVersionRequest,SecretVersion> addSecretVersionCallable()

Creates a new SecretVersion containing secret data and attaches it to an existing Secret.

Sample code:


 try (SecretManagerServiceClient secretManagerServiceClient =
     SecretManagerServiceClient.create()) {
   AddSecretVersionRequest request =
       AddSecretVersionRequest.newBuilder()
           .setParent(SecretName.of("[PROJECT]", "[SECRET]").toString())
           .setPayload(SecretPayload.newBuilder().build())
           .build();
   ApiFuture<SecretVersion> future =
       secretManagerServiceClient.addSecretVersionCallable().futureCall(request);
   // Do something.
   SecretVersion response = future.get();
 }
 
Returns
TypeDescription
UnaryCallable<AddSecretVersionRequest,SecretVersion>

awaitTermination(long duration, TimeUnit unit)

public boolean awaitTermination(long duration, TimeUnit unit)
Parameters
NameDescription
durationlong
unitTimeUnit
Returns
TypeDescription
boolean
Exceptions
TypeDescription
InterruptedException

close()

public final void close()

createSecret(CreateSecretRequest request)

public final Secret createSecret(CreateSecretRequest request)

Creates a new Secret containing no SecretVersions.

Sample code:


 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);
 }
 
Parameter
NameDescription
requestCreateSecretRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
Secret

createSecret(ProjectName parent, String secretId, Secret secret)

public final Secret createSecret(ProjectName parent, String secretId, Secret secret)

Creates a new Secret containing no SecretVersions.

Sample code:


 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);
 }
 
Parameters
NameDescription
parentProjectName

Required. The resource name of the project to associate with the Secret, in the format projects/*.

secretIdString

Required. This must be unique within the project.

A secret ID is a string with a maximum length of 255 characters and can contain uppercase and lowercase letters, numerals, and the hyphen (-) and underscore (_) characters.

secretSecret

Required. A Secret with initial field values.

Returns
TypeDescription
Secret

createSecret(String parent, String secretId, Secret secret)

public final Secret createSecret(String parent, String secretId, Secret secret)

Creates a new Secret containing no SecretVersions.

Sample code:


 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);
 }
 
Parameters
NameDescription
parentString

Required. The resource name of the project to associate with the Secret, in the format projects/*.

secretIdString

Required. This must be unique within the project.

A secret ID is a string with a maximum length of 255 characters and can contain uppercase and lowercase letters, numerals, and the hyphen (-) and underscore (_) characters.

secretSecret

Required. A Secret with initial field values.

Returns
TypeDescription
Secret

createSecretCallable()

public final UnaryCallable<CreateSecretRequest,Secret> createSecretCallable()

Creates a new Secret containing no SecretVersions.

Sample code:


 try (SecretManagerServiceClient secretManagerServiceClient =
     SecretManagerServiceClient.create()) {
   CreateSecretRequest request =
       CreateSecretRequest.newBuilder()
           .setParent(ProjectName.of("[PROJECT]").toString())
           .setSecretId("secretId945974251")
           .setSecret(Secret.newBuilder().build())
           .build();
   ApiFuture<Secret> future =
       secretManagerServiceClient.createSecretCallable().futureCall(request);
   // Do something.
   Secret response = future.get();
 }
 
Returns
TypeDescription
UnaryCallable<CreateSecretRequest,Secret>

deleteSecret(DeleteSecretRequest request)

public final void deleteSecret(DeleteSecretRequest request)

Deletes a Secret.

Sample code:


 try (SecretManagerServiceClient secretManagerServiceClient =
     SecretManagerServiceClient.create()) {
   DeleteSecretRequest request =
       DeleteSecretRequest.newBuilder()
           .setName(SecretName.of("[PROJECT]", "[SECRET]").toString())
           .build();
   secretManagerServiceClient.deleteSecret(request);
 }
 
Parameter
NameDescription
requestDeleteSecretRequest

The request object containing all of the parameters for the API call.

deleteSecret(SecretName name)

public final void deleteSecret(SecretName name)

Deletes a Secret.

Sample code:


 try (SecretManagerServiceClient secretManagerServiceClient =
     SecretManagerServiceClient.create()) {
   SecretName name = SecretName.of("[PROJECT]", "[SECRET]");
   secretManagerServiceClient.deleteSecret(name);
 }
 
Parameter
NameDescription
nameSecretName

Required. The resource name of the Secret to delete in the format projects/*/secrets/*.

deleteSecret(String name)

public final void deleteSecret(String name)

Deletes a Secret.

Sample code:


 try (SecretManagerServiceClient secretManagerServiceClient =
     SecretManagerServiceClient.create()) {
   String name = SecretName.of("[PROJECT]", "[SECRET]").toString();
   secretManagerServiceClient.deleteSecret(name);
 }
 
Parameter
NameDescription
nameString

Required. The resource name of the Secret to delete in the format projects/*/secrets/*.

deleteSecretCallable()

public final UnaryCallable<DeleteSecretRequest,Empty> deleteSecretCallable()

Deletes a Secret.

Sample code:


 try (SecretManagerServiceClient secretManagerServiceClient =
     SecretManagerServiceClient.create()) {
   DeleteSecretRequest request =
       DeleteSecretRequest.newBuilder()
           .setName(SecretName.of("[PROJECT]", "[SECRET]").toString())
           .build();
   ApiFuture<Empty> future =
       secretManagerServiceClient.deleteSecretCallable().futureCall(request);
   // Do something.
   future.get();
 }
 
Returns
TypeDescription
UnaryCallable<DeleteSecretRequest,Empty>

destroySecretVersion(DestroySecretVersionRequest request)

public final SecretVersion destroySecretVersion(DestroySecretVersionRequest request)

Destroys a SecretVersion.

Sets the state of the SecretVersion to DESTROYED and irrevocably destroys the secret data.

Sample code:


 try (SecretManagerServiceClient secretManagerServiceClient =
     SecretManagerServiceClient.create()) {
   DestroySecretVersionRequest request =
       DestroySecretVersionRequest.newBuilder()
           .setName(SecretVersionName.of("[PROJECT]", "[SECRET]", "[SECRET_VERSION]").toString())
           .build();
   SecretVersion response = secretManagerServiceClient.destroySecretVersion(request);
 }
 
Parameter
NameDescription
requestDestroySecretVersionRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
SecretVersion

destroySecretVersion(SecretVersionName name)

public final SecretVersion destroySecretVersion(SecretVersionName name)

Destroys a SecretVersion.

Sets the state of the SecretVersion to DESTROYED and irrevocably destroys the secret data.

Sample code:


 try (SecretManagerServiceClient secretManagerServiceClient =
     SecretManagerServiceClient.create()) {
   SecretVersionName name = SecretVersionName.of("[PROJECT]", "[SECRET]", "[SECRET_VERSION]");
   SecretVersion response = secretManagerServiceClient.destroySecretVersion(name);
 }
 
Parameter
NameDescription
nameSecretVersionName

Required. The resource name of the SecretVersion to destroy in the format projects/*/secrets/*/versions/*.

Returns
TypeDescription
SecretVersion

destroySecretVersion(String name)

public final SecretVersion destroySecretVersion(String name)

Destroys a SecretVersion.

Sets the state of the SecretVersion to DESTROYED and irrevocably destroys the secret data.

Sample code:


 try (SecretManagerServiceClient secretManagerServiceClient =
     SecretManagerServiceClient.create()) {
   String name = SecretVersionName.of("[PROJECT]", "[SECRET]", "[SECRET_VERSION]").toString();
   SecretVersion response = secretManagerServiceClient.destroySecretVersion(name);
 }
 
Parameter
NameDescription
nameString

Required. The resource name of the SecretVersion to destroy in the format projects/*/secrets/*/versions/*.

Returns
TypeDescription
SecretVersion

destroySecretVersionCallable()

public final UnaryCallable<DestroySecretVersionRequest,SecretVersion> destroySecretVersionCallable()

Destroys a SecretVersion.

Sets the state of the SecretVersion to DESTROYED and irrevocably destroys the secret data.

Sample code:


 try (SecretManagerServiceClient secretManagerServiceClient =
     SecretManagerServiceClient.create()) {
   DestroySecretVersionRequest request =
       DestroySecretVersionRequest.newBuilder()
           .setName(SecretVersionName.of("[PROJECT]", "[SECRET]", "[SECRET_VERSION]").toString())
           .build();
   ApiFuture<SecretVersion> future =
       secretManagerServiceClient.destroySecretVersionCallable().futureCall(request);
   // Do something.
   SecretVersion response = future.get();
 }
 
Returns
TypeDescription
UnaryCallable<DestroySecretVersionRequest,SecretVersion>

disableSecretVersion(DisableSecretVersionRequest request)

public final SecretVersion disableSecretVersion(DisableSecretVersionRequest request)

Disables a SecretVersion.

Sets the state of the SecretVersion to DISABLED.

Sample code:


 try (SecretManagerServiceClient secretManagerServiceClient =
     SecretManagerServiceClient.create()) {
   DisableSecretVersionRequest request =
       DisableSecretVersionRequest.newBuilder()
           .setName(SecretVersionName.of("[PROJECT]", "[SECRET]", "[SECRET_VERSION]").toString())
           .build();
   SecretVersion response = secretManagerServiceClient.disableSecretVersion(request);
 }
 
Parameter
NameDescription
requestDisableSecretVersionRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
SecretVersion

disableSecretVersion(SecretVersionName name)

public final SecretVersion disableSecretVersion(SecretVersionName name)

Disables a SecretVersion.

Sets the state of the SecretVersion to DISABLED.

Sample code:


 try (SecretManagerServiceClient secretManagerServiceClient =
     SecretManagerServiceClient.create()) {
   SecretVersionName name = SecretVersionName.of("[PROJECT]", "[SECRET]", "[SECRET_VERSION]");
   SecretVersion response = secretManagerServiceClient.disableSecretVersion(name);
 }
 
Parameter
NameDescription
nameSecretVersionName

Required. The resource name of the SecretVersion to disable in the format projects/*/secrets/*/versions/*.

Returns
TypeDescription
SecretVersion

disableSecretVersion(String name)

public final SecretVersion disableSecretVersion(String name)

Disables a SecretVersion.

Sets the state of the SecretVersion to DISABLED.

Sample code:


 try (SecretManagerServiceClient secretManagerServiceClient =
     SecretManagerServiceClient.create()) {
   String name = SecretVersionName.of("[PROJECT]", "[SECRET]", "[SECRET_VERSION]").toString();
   SecretVersion response = secretManagerServiceClient.disableSecretVersion(name);
 }
 
Parameter
NameDescription
nameString

Required. The resource name of the SecretVersion to disable in the format projects/*/secrets/*/versions/*.

Returns
TypeDescription
SecretVersion

disableSecretVersionCallable()

public final UnaryCallable<DisableSecretVersionRequest,SecretVersion> disableSecretVersionCallable()

Disables a SecretVersion.

Sets the state of the SecretVersion to DISABLED.

Sample code:


 try (SecretManagerServiceClient secretManagerServiceClient =
     SecretManagerServiceClient.create()) {
   DisableSecretVersionRequest request =
       DisableSecretVersionRequest.newBuilder()
           .setName(SecretVersionName.of("[PROJECT]", "[SECRET]", "[SECRET_VERSION]").toString())
           .build();
   ApiFuture<SecretVersion> future =
       secretManagerServiceClient.disableSecretVersionCallable().futureCall(request);
   // Do something.
   SecretVersion response = future.get();
 }
 
Returns
TypeDescription
UnaryCallable<DisableSecretVersionRequest,SecretVersion>

enableSecretVersion(EnableSecretVersionRequest request)

public final SecretVersion enableSecretVersion(EnableSecretVersionRequest request)

Enables a SecretVersion.

Sets the state of the SecretVersion to ENABLED.

Sample code:


 try (SecretManagerServiceClient secretManagerServiceClient =
     SecretManagerServiceClient.create()) {
   EnableSecretVersionRequest request =
       EnableSecretVersionRequest.newBuilder()
           .setName(SecretVersionName.of("[PROJECT]", "[SECRET]", "[SECRET_VERSION]").toString())
           .build();
   SecretVersion response = secretManagerServiceClient.enableSecretVersion(request);
 }
 
Parameter
NameDescription
requestEnableSecretVersionRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
SecretVersion

enableSecretVersion(SecretVersionName name)

public final SecretVersion enableSecretVersion(SecretVersionName name)

Enables a SecretVersion.

Sets the state of the SecretVersion to ENABLED.

Sample code:


 try (SecretManagerServiceClient secretManagerServiceClient =
     SecretManagerServiceClient.create()) {
   SecretVersionName name = SecretVersionName.of("[PROJECT]", "[SECRET]", "[SECRET_VERSION]");
   SecretVersion response = secretManagerServiceClient.enableSecretVersion(name);
 }
 
Parameter
NameDescription
nameSecretVersionName

Required. The resource name of the SecretVersion to enable in the format projects/*/secrets/*/versions/*.

Returns
TypeDescription
SecretVersion

enableSecretVersion(String name)

public final SecretVersion enableSecretVersion(String name)

Enables a SecretVersion.

Sets the state of the SecretVersion to ENABLED.

Sample code:


 try (SecretManagerServiceClient secretManagerServiceClient =
     SecretManagerServiceClient.create()) {
   String name = SecretVersionName.of("[PROJECT]", "[SECRET]", "[SECRET_VERSION]").toString();
   SecretVersion response = secretManagerServiceClient.enableSecretVersion(name);
 }
 
Parameter
NameDescription
nameString

Required. The resource name of the SecretVersion to enable in the format projects/*/secrets/*/versions/*.

Returns
TypeDescription
SecretVersion

enableSecretVersionCallable()

public final UnaryCallable<EnableSecretVersionRequest,SecretVersion> enableSecretVersionCallable()

Enables a SecretVersion.

Sets the state of the SecretVersion to ENABLED.

Sample code:


 try (SecretManagerServiceClient secretManagerServiceClient =
     SecretManagerServiceClient.create()) {
   EnableSecretVersionRequest request =
       EnableSecretVersionRequest.newBuilder()
           .setName(SecretVersionName.of("[PROJECT]", "[SECRET]", "[SECRET_VERSION]").toString())
           .build();
   ApiFuture<SecretVersion> future =
       secretManagerServiceClient.enableSecretVersionCallable().futureCall(request);
   // Do something.
   SecretVersion response = future.get();
 }
 
Returns
TypeDescription
UnaryCallable<EnableSecretVersionRequest,SecretVersion>

getIamPolicy(GetIamPolicyRequest request)

public final Policy getIamPolicy(GetIamPolicyRequest request)

Gets the access control policy for a secret. Returns empty policy if the secret exists and does not have a policy set.

Sample code:


 try (SecretManagerServiceClient secretManagerServiceClient =
     SecretManagerServiceClient.create()) {
   GetIamPolicyRequest request =
       GetIamPolicyRequest.newBuilder()
           .setResource(ProjectName.of("[PROJECT]").toString())
           .setOptions(GetPolicyOptions.newBuilder().build())
           .build();
   Policy response = secretManagerServiceClient.getIamPolicy(request);
 }
 
Parameter
NameDescription
requestcom.google.iam.v1.GetIamPolicyRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
com.google.iam.v1.Policy

getIamPolicyCallable()

public final UnaryCallable<GetIamPolicyRequest,Policy> getIamPolicyCallable()

Gets the access control policy for a secret. Returns empty policy if the secret exists and does not have a policy set.

Sample code:


 try (SecretManagerServiceClient secretManagerServiceClient =
     SecretManagerServiceClient.create()) {
   GetIamPolicyRequest request =
       GetIamPolicyRequest.newBuilder()
           .setResource(ProjectName.of("[PROJECT]").toString())
           .setOptions(GetPolicyOptions.newBuilder().build())
           .build();
   ApiFuture<Policy> future =
       secretManagerServiceClient.getIamPolicyCallable().futureCall(request);
   // Do something.
   Policy response = future.get();
 }
 
Returns
TypeDescription
UnaryCallable<com.google.iam.v1.GetIamPolicyRequest,com.google.iam.v1.Policy>

getSecret(GetSecretRequest request)

public final Secret getSecret(GetSecretRequest request)

Gets metadata for a given Secret.

Sample code:


 try (SecretManagerServiceClient secretManagerServiceClient =
     SecretManagerServiceClient.create()) {
   GetSecretRequest request =
       GetSecretRequest.newBuilder()
           .setName(SecretName.of("[PROJECT]", "[SECRET]").toString())
           .build();
   Secret response = secretManagerServiceClient.getSecret(request);
 }
 
Parameter
NameDescription
requestGetSecretRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
Secret

getSecret(SecretName name)

public final Secret getSecret(SecretName name)

Gets metadata for a given Secret.

Sample code:


 try (SecretManagerServiceClient secretManagerServiceClient =
     SecretManagerServiceClient.create()) {
   SecretName name = SecretName.of("[PROJECT]", "[SECRET]");
   Secret response = secretManagerServiceClient.getSecret(name);
 }
 
Parameter
NameDescription
nameSecretName

Required. The resource name of the Secret, in the format projects/*/secrets/*.

Returns
TypeDescription
Secret

getSecret(String name)

public final Secret getSecret(String name)

Gets metadata for a given Secret.

Sample code:


 try (SecretManagerServiceClient secretManagerServiceClient =
     SecretManagerServiceClient.create()) {
   String name = SecretName.of("[PROJECT]", "[SECRET]").toString();
   Secret response = secretManagerServiceClient.getSecret(name);
 }
 
Parameter
NameDescription
nameString

Required. The resource name of the Secret, in the format projects/*/secrets/*.

Returns
TypeDescription
Secret

getSecretCallable()

public final UnaryCallable<GetSecretRequest,Secret> getSecretCallable()

Gets metadata for a given Secret.

Sample code:


 try (SecretManagerServiceClient secretManagerServiceClient =
     SecretManagerServiceClient.create()) {
   GetSecretRequest request =
       GetSecretRequest.newBuilder()
           .setName(SecretName.of("[PROJECT]", "[SECRET]").toString())
           .build();
   ApiFuture<Secret> future = secretManagerServiceClient.getSecretCallable().futureCall(request);
   // Do something.
   Secret response = future.get();
 }
 
Returns
TypeDescription
UnaryCallable<GetSecretRequest,Secret>

getSecretVersion(GetSecretVersionRequest request)

public final SecretVersion getSecretVersion(GetSecretVersionRequest request)

Gets metadata for a SecretVersion.

projects/*/secrets/*/versions/latest is an alias to the latest SecretVersion.

Sample code:


 try (SecretManagerServiceClient secretManagerServiceClient =
     SecretManagerServiceClient.create()) {
   GetSecretVersionRequest request =
       GetSecretVersionRequest.newBuilder()
           .setName(SecretVersionName.of("[PROJECT]", "[SECRET]", "[SECRET_VERSION]").toString())
           .build();
   SecretVersion response = secretManagerServiceClient.getSecretVersion(request);
 }
 
Parameter
NameDescription
requestGetSecretVersionRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
SecretVersion

getSecretVersion(SecretVersionName name)

public final SecretVersion getSecretVersion(SecretVersionName name)

Gets metadata for a SecretVersion.

projects/*/secrets/*/versions/latest is an alias to the latest SecretVersion.

Sample code:


 try (SecretManagerServiceClient secretManagerServiceClient =
     SecretManagerServiceClient.create()) {
   SecretVersionName name = SecretVersionName.of("[PROJECT]", "[SECRET]", "[SECRET_VERSION]");
   SecretVersion response = secretManagerServiceClient.getSecretVersion(name);
 }
 
Parameter
NameDescription
nameSecretVersionName

Required. The resource name of the SecretVersion in the format projects/*/secrets/*/versions/*. projects/*/secrets/*/versions/latest is an alias to the latest SecretVersion.

Returns
TypeDescription
SecretVersion

getSecretVersion(String name)

public final SecretVersion getSecretVersion(String name)

Gets metadata for a SecretVersion.

projects/*/secrets/*/versions/latest is an alias to the latest SecretVersion.

Sample code:


 try (SecretManagerServiceClient secretManagerServiceClient =
     SecretManagerServiceClient.create()) {
   String name = SecretVersionName.of("[PROJECT]", "[SECRET]", "[SECRET_VERSION]").toString();
   SecretVersion response = secretManagerServiceClient.getSecretVersion(name);
 }
 
Parameter
NameDescription
nameString

Required. The resource name of the SecretVersion in the format projects/*/secrets/*/versions/*. projects/*/secrets/*/versions/latest is an alias to the latest SecretVersion.

Returns
TypeDescription
SecretVersion

getSecretVersionCallable()

public final UnaryCallable<GetSecretVersionRequest,SecretVersion> getSecretVersionCallable()

Gets metadata for a SecretVersion.

projects/*/secrets/*/versions/latest is an alias to the latest SecretVersion.

Sample code:


 try (SecretManagerServiceClient secretManagerServiceClient =
     SecretManagerServiceClient.create()) {
   GetSecretVersionRequest request =
       GetSecretVersionRequest.newBuilder()
           .setName(SecretVersionName.of("[PROJECT]", "[SECRET]", "[SECRET_VERSION]").toString())
           .build();
   ApiFuture<SecretVersion> future =
       secretManagerServiceClient.getSecretVersionCallable().futureCall(request);
   // Do something.
   SecretVersion response = future.get();
 }
 
Returns
TypeDescription
UnaryCallable<GetSecretVersionRequest,SecretVersion>

getSettings()

public final SecretManagerServiceSettings getSettings()
Returns
TypeDescription
SecretManagerServiceSettings

getStub()

public SecretManagerServiceStub getStub()
Returns
TypeDescription
SecretManagerServiceStub

isShutdown()

public boolean isShutdown()
Returns
TypeDescription
boolean

isTerminated()

public boolean isTerminated()
Returns
TypeDescription
boolean

listSecretVersions(ListSecretVersionsRequest request)

public final SecretManagerServiceClient.ListSecretVersionsPagedResponse listSecretVersions(ListSecretVersionsRequest request)

Lists SecretVersions. This call does not return secret data.

Sample code:


 try (SecretManagerServiceClient secretManagerServiceClient =
     SecretManagerServiceClient.create()) {
   ListSecretVersionsRequest request =
       ListSecretVersionsRequest.newBuilder()
           .setParent(SecretName.of("[PROJECT]", "[SECRET]").toString())
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .build();
   for (SecretVersion element :
       secretManagerServiceClient.listSecretVersions(request).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
NameDescription
requestListSecretVersionsRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
SecretManagerServiceClient.ListSecretVersionsPagedResponse

listSecretVersions(SecretName parent)

public final SecretManagerServiceClient.ListSecretVersionsPagedResponse listSecretVersions(SecretName parent)

Lists SecretVersions. This call does not return secret data.

Sample code:


 try (SecretManagerServiceClient secretManagerServiceClient =
     SecretManagerServiceClient.create()) {
   SecretName parent = SecretName.of("[PROJECT]", "[SECRET]");
   for (SecretVersion element :
       secretManagerServiceClient.listSecretVersions(parent).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
NameDescription
parentSecretName

Required. The resource name of the Secret associated with the SecretVersions to list, in the format projects/*/secrets/*.

Returns
TypeDescription
SecretManagerServiceClient.ListSecretVersionsPagedResponse

listSecretVersions(String parent)

public final SecretManagerServiceClient.ListSecretVersionsPagedResponse listSecretVersions(String parent)

Lists SecretVersions. This call does not return secret data.

Sample code:


 try (SecretManagerServiceClient secretManagerServiceClient =
     SecretManagerServiceClient.create()) {
   String parent = SecretName.of("[PROJECT]", "[SECRET]").toString();
   for (SecretVersion element :
       secretManagerServiceClient.listSecretVersions(parent).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
NameDescription
parentString

Required. The resource name of the Secret associated with the SecretVersions to list, in the format projects/*/secrets/*.

Returns
TypeDescription
SecretManagerServiceClient.ListSecretVersionsPagedResponse

listSecretVersionsCallable()

public final UnaryCallable<ListSecretVersionsRequest,ListSecretVersionsResponse> listSecretVersionsCallable()

Lists SecretVersions. This call does not return secret data.

Sample code:


 try (SecretManagerServiceClient secretManagerServiceClient =
     SecretManagerServiceClient.create()) {
   ListSecretVersionsRequest request =
       ListSecretVersionsRequest.newBuilder()
           .setParent(SecretName.of("[PROJECT]", "[SECRET]").toString())
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .build();
   while (true) {
     ListSecretVersionsResponse response =
         secretManagerServiceClient.listSecretVersionsCallable().call(request);
     for (SecretVersion element : response.getResponsesList()) {
       // doThingsWith(element);
     }
     String nextPageToken = response.getNextPageToken();
     if (!Strings.isNullOrEmpty(nextPageToken)) {
       request = request.toBuilder().setPageToken(nextPageToken).build();
     } else {
       break;
     }
   }
 }
 
Returns
TypeDescription
UnaryCallable<ListSecretVersionsRequest,ListSecretVersionsResponse>

listSecretVersionsPagedCallable()

public final UnaryCallable<ListSecretVersionsRequest,SecretManagerServiceClient.ListSecretVersionsPagedResponse> listSecretVersionsPagedCallable()

Lists SecretVersions. This call does not return secret data.

Sample code:


 try (SecretManagerServiceClient secretManagerServiceClient =
     SecretManagerServiceClient.create()) {
   ListSecretVersionsRequest request =
       ListSecretVersionsRequest.newBuilder()
           .setParent(SecretName.of("[PROJECT]", "[SECRET]").toString())
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .build();
   ApiFuture<SecretVersion> future =
       secretManagerServiceClient.listSecretVersionsPagedCallable().futureCall(request);
   // Do something.
   for (SecretVersion element : future.get().iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Returns
TypeDescription
UnaryCallable<ListSecretVersionsRequest,ListSecretVersionsPagedResponse>

listSecrets(ListSecretsRequest request)

public final SecretManagerServiceClient.ListSecretsPagedResponse listSecrets(ListSecretsRequest request)

Lists Secrets.

Sample code:


 try (SecretManagerServiceClient secretManagerServiceClient =
     SecretManagerServiceClient.create()) {
   ListSecretsRequest request =
       ListSecretsRequest.newBuilder()
           .setParent(ProjectName.of("[PROJECT]").toString())
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .build();
   for (Secret element : secretManagerServiceClient.listSecrets(request).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
NameDescription
requestListSecretsRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
SecretManagerServiceClient.ListSecretsPagedResponse

listSecrets(ProjectName parent)

public final SecretManagerServiceClient.ListSecretsPagedResponse listSecrets(ProjectName parent)

Lists Secrets.

Sample code:


 try (SecretManagerServiceClient secretManagerServiceClient =
     SecretManagerServiceClient.create()) {
   ProjectName parent = ProjectName.of("[PROJECT]");
   for (Secret element : secretManagerServiceClient.listSecrets(parent).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
NameDescription
parentProjectName

Required. The resource name of the project associated with the Secrets, in the format projects/*.

Returns
TypeDescription
SecretManagerServiceClient.ListSecretsPagedResponse

listSecrets(String parent)

public final SecretManagerServiceClient.ListSecretsPagedResponse listSecrets(String parent)

Lists Secrets.

Sample code:


 try (SecretManagerServiceClient secretManagerServiceClient =
     SecretManagerServiceClient.create()) {
   String parent = ProjectName.of("[PROJECT]").toString();
   for (Secret element : secretManagerServiceClient.listSecrets(parent).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
NameDescription
parentString

Required. The resource name of the project associated with the Secrets, in the format projects/*.

Returns
TypeDescription
SecretManagerServiceClient.ListSecretsPagedResponse

listSecretsCallable()

public final UnaryCallable<ListSecretsRequest,ListSecretsResponse> listSecretsCallable()

Lists Secrets.

Sample code:


 try (SecretManagerServiceClient secretManagerServiceClient =
     SecretManagerServiceClient.create()) {
   ListSecretsRequest request =
       ListSecretsRequest.newBuilder()
           .setParent(ProjectName.of("[PROJECT]").toString())
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .build();
   while (true) {
     ListSecretsResponse response =
         secretManagerServiceClient.listSecretsCallable().call(request);
     for (Secret element : response.getResponsesList()) {
       // doThingsWith(element);
     }
     String nextPageToken = response.getNextPageToken();
     if (!Strings.isNullOrEmpty(nextPageToken)) {
       request = request.toBuilder().setPageToken(nextPageToken).build();
     } else {
       break;
     }
   }
 }
 
Returns
TypeDescription
UnaryCallable<ListSecretsRequest,ListSecretsResponse>

listSecretsPagedCallable()

public final UnaryCallable<ListSecretsRequest,SecretManagerServiceClient.ListSecretsPagedResponse> listSecretsPagedCallable()

Lists Secrets.

Sample code:


 try (SecretManagerServiceClient secretManagerServiceClient =
     SecretManagerServiceClient.create()) {
   ListSecretsRequest request =
       ListSecretsRequest.newBuilder()
           .setParent(ProjectName.of("[PROJECT]").toString())
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .build();
   ApiFuture<Secret> future =
       secretManagerServiceClient.listSecretsPagedCallable().futureCall(request);
   // Do something.
   for (Secret element : future.get().iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Returns
TypeDescription
UnaryCallable<ListSecretsRequest,ListSecretsPagedResponse>

setIamPolicy(SetIamPolicyRequest request)

public final Policy setIamPolicy(SetIamPolicyRequest request)

Sets the access control policy on the specified secret. Replaces any existing policy.

Permissions on SecretVersions are enforced according to the policy set on the associated Secret.

Sample code:


 try (SecretManagerServiceClient secretManagerServiceClient =
     SecretManagerServiceClient.create()) {
   SetIamPolicyRequest request =
       SetIamPolicyRequest.newBuilder()
           .setResource(ProjectName.of("[PROJECT]").toString())
           .setPolicy(Policy.newBuilder().build())
           .build();
   Policy response = secretManagerServiceClient.setIamPolicy(request);
 }
 
Parameter
NameDescription
requestcom.google.iam.v1.SetIamPolicyRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
com.google.iam.v1.Policy

setIamPolicyCallable()

public final UnaryCallable<SetIamPolicyRequest,Policy> setIamPolicyCallable()

Sets the access control policy on the specified secret. Replaces any existing policy.

Permissions on SecretVersions are enforced according to the policy set on the associated Secret.

Sample code:


 try (SecretManagerServiceClient secretManagerServiceClient =
     SecretManagerServiceClient.create()) {
   SetIamPolicyRequest request =
       SetIamPolicyRequest.newBuilder()
           .setResource(ProjectName.of("[PROJECT]").toString())
           .setPolicy(Policy.newBuilder().build())
           .build();
   ApiFuture<Policy> future =
       secretManagerServiceClient.setIamPolicyCallable().futureCall(request);
   // Do something.
   Policy response = future.get();
 }
 
Returns
TypeDescription
UnaryCallable<com.google.iam.v1.SetIamPolicyRequest,com.google.iam.v1.Policy>

shutdown()

public void shutdown()

shutdownNow()

public void shutdownNow()

testIamPermissions(TestIamPermissionsRequest request)

public final TestIamPermissionsResponse testIamPermissions(TestIamPermissionsRequest request)

Returns permissions that a caller has for the specified secret. If the secret does not exist, this call returns an empty set of permissions, not a NOT_FOUND error.

Note: This operation is designed to be used for building permission-aware UIs and command-line tools, not for authorization checking. This operation may "fail open" without warning.

Sample code:


 try (SecretManagerServiceClient secretManagerServiceClient =
     SecretManagerServiceClient.create()) {
   TestIamPermissionsRequest request =
       TestIamPermissionsRequest.newBuilder()
           .setResource(ProjectName.of("[PROJECT]").toString())
           .addAllPermissions(new ArrayList<String>())
           .build();
   TestIamPermissionsResponse response = secretManagerServiceClient.testIamPermissions(request);
 }
 
Parameter
NameDescription
requestcom.google.iam.v1.TestIamPermissionsRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
com.google.iam.v1.TestIamPermissionsResponse

testIamPermissionsCallable()

public final UnaryCallable<TestIamPermissionsRequest,TestIamPermissionsResponse> testIamPermissionsCallable()

Returns permissions that a caller has for the specified secret. If the secret does not exist, this call returns an empty set of permissions, not a NOT_FOUND error.

Note: This operation is designed to be used for building permission-aware UIs and command-line tools, not for authorization checking. This operation may "fail open" without warning.

Sample code:


 try (SecretManagerServiceClient secretManagerServiceClient =
     SecretManagerServiceClient.create()) {
   TestIamPermissionsRequest request =
       TestIamPermissionsRequest.newBuilder()
           .setResource(ProjectName.of("[PROJECT]").toString())
           .addAllPermissions(new ArrayList<String>())
           .build();
   ApiFuture<TestIamPermissionsResponse> future =
       secretManagerServiceClient.testIamPermissionsCallable().futureCall(request);
   // Do something.
   TestIamPermissionsResponse response = future.get();
 }
 
Returns
TypeDescription
UnaryCallable<com.google.iam.v1.TestIamPermissionsRequest,com.google.iam.v1.TestIamPermissionsResponse>

updateSecret(Secret secret, FieldMask updateMask)

public final Secret updateSecret(Secret secret, FieldMask updateMask)

Updates metadata of an existing Secret.

Sample code:


 try (SecretManagerServiceClient secretManagerServiceClient =
     SecretManagerServiceClient.create()) {
   Secret secret = Secret.newBuilder().build();
   FieldMask updateMask = FieldMask.newBuilder().build();
   Secret response = secretManagerServiceClient.updateSecret(secret, updateMask);
 }
 
Parameters
NameDescription
secretSecret

Required. Secret with updated field values.

updateMaskFieldMask

Required. Specifies the fields to be updated.

Returns
TypeDescription
Secret

updateSecret(UpdateSecretRequest request)

public final Secret updateSecret(UpdateSecretRequest request)

Updates metadata of an existing Secret.

Sample code:


 try (SecretManagerServiceClient secretManagerServiceClient =
     SecretManagerServiceClient.create()) {
   UpdateSecretRequest request =
       UpdateSecretRequest.newBuilder()
           .setSecret(Secret.newBuilder().build())
           .setUpdateMask(FieldMask.newBuilder().build())
           .build();
   Secret response = secretManagerServiceClient.updateSecret(request);
 }
 
Parameter
NameDescription
requestUpdateSecretRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
Secret

updateSecretCallable()

public final UnaryCallable<UpdateSecretRequest,Secret> updateSecretCallable()

Updates metadata of an existing Secret.

Sample code:


 try (SecretManagerServiceClient secretManagerServiceClient =
     SecretManagerServiceClient.create()) {
   UpdateSecretRequest request =
       UpdateSecretRequest.newBuilder()
           .setSecret(Secret.newBuilder().build())
           .setUpdateMask(FieldMask.newBuilder().build())
           .build();
   ApiFuture<Secret> future =
       secretManagerServiceClient.updateSecretCallable().futureCall(request);
   // Do something.
   Secret response = future.get();
 }
 
Returns
TypeDescription
UnaryCallable<UpdateSecretRequest,Secret>