All Secret Manager code samples

Stay organized with collections Save and categorize content based on your preferences.

This page contains code samples for Secret Manager. To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.

Access secret version

Gets the version of a secret.

View in documentation

Add secret version

Adds a new version of the secret.

View in documentation

View in documentation

Delete a secret with ETags

Shows how to delete a secret with a given name, ETag, and all of its versions.

View in documentation

Destroy a secret with an ETag

Shows how to destroy the given secret version that contains an ETag, making the payload irrecoverable.

Destroy secret version

Destroys one of the versions of a secret.

View in documentation

Disable a secret with ETags

Shows how to disable a given secret version that contains ETags.

Disable secret version

Makes a specific version of a secret inaccessible.

View in documentation

Enable a secret with ETags

Shows how to enable a given secret version that contains ETags.

Enable secret version

Makes a specific version of a secret accessible.

View in documentation

Get secret version

Gets a secret's version metadata.

View in documentation

IAM grant access

Sets roles/secretmanager.secretAccessor policy.

View in documentation

IAM revoke access

Revokes roles/secretmanager.secretAccessor policy.

View in documentation

List secret versions

Lists all versions of a secret.

View in documentation

List secret versions containing a filter

Shows how to list all secret versions and metadata for a secret with a specified filter.

List secrets with a filter

Shows how to list all secrets in a project that match a filter.

Update a secret with ETags

Shows how to update a given secret version that contains ETags.

View in documentation