This directory contains samples for Google Secret Manager. Google Secret Manager is a service that allows you to store, manage, and secure access to application secrets.
This sample requires you to have authentication setup. Refer to the Authentication Getting Started Guide for instructions on setting up credentials for applications.
Clone python-docs-samples and change directory to the sample directory you want to use.
$ git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git
Install pip and virtualenv if you do not already have them. You may want to refer to the Python Development Environment Setup Guide for Google Cloud Platform for instructions.
Create a virtualenv. Samples are compatible with Python 2.7 and 3.4+.
$ virtualenv env $ source env/bin/activate
Install the dependencies needed to run the samples.
$ pip install -r requirements.txt
To run this sample:
$ python quickstart.py
To run this sample:
$ python access_secret_version.py
usage: access_secret_version.py [-h] project_id secret_id version_id
command line application and sample code for accessing a secret version.
positional arguments:
project_id id of the GCP project
secret_id id of the secret to access
version_id version to access
optional arguments:
-h, --help show this help message and exit
To run this sample:
$ python add_secret_version.py
usage: add_secret_version.py [-h] project_id secret_id payload
command line application and sample code for adding a secret version with the
specified payload to an existing secret.
positional arguments:
project_id id of the GCP project
secret_id id of the secret in which to add
payload secret material payload
optional arguments:
-h, --help show this help message and exit
To run this sample:
$ python create_secret.py
usage: create_secret.py [-h] project_id secret_id
command line application and sample code for creating a new secret.
positional arguments:
project_id id of the GCP project
secret_id id of the secret to create
optional arguments:
-h, --help show this help message and exit
To run this sample:
$ python delete_secret.py
usage: delete_secret.py [-h] project_id secret_id
command line application and sample code for deleting an existing secret.
positional arguments:
project_id id of the GCP project
secret_id id of the secret to delete
optional arguments:
-h, --help show this help message and exit
To run this sample:
$ python destroy_secret_version.py
usage: destroy_secret_version.py [-h] project_id secret_id version_id
command line application and sample code for destroying a secret verison.
positional arguments:
project_id id of the GCP project
secret_id id of the secret from which to act
version_id id of the version to destroy
optional arguments:
-h, --help show this help message and exit
To run this sample:
$ python enable_secret_version.py
usage: enable_secret_version.py [-h] project_id secret_id version_id
command line application and sample code for enabling a secret version.
positional arguments:
project_id id of the GCP project
secret_id id of the secret from which to act
version_id id of the version to enable
optional arguments:
-h, --help show this help message and exit
To run this sample:
$ python get_secret_version.py
usage: get_secret_version.py [-h] project_id secret_id version_id
command line application and sample code for getting metdata about a secret
version, but not the secret payload.
positional arguments:
project_id id of the GCP project
secret_id id of the secret from which to act
version_id id of the version to get
optional arguments:
-h, --help show this help message and exit
To run this sample:
$ python iam_grant_access.py
usage: iam_grant_access.py [-h] project_id secret_id member
command line application and sample code for granting access to a secret.
positional arguments:
project_id id of the GCP project
secret_id id of the secret to get
member member to grant access
optional arguments:
-h, --help show this help message and exit
To run this sample:
$ python iam_revoke_access.py
usage: iam_revoke_access.py [-h] project_id secret_id member
command line application and sample code for revoking access to a secret.
positional arguments:
project_id id of the GCP project
secret_id id of the secret to get
member member to revoke access
optional arguments:
-h, --help show this help message and exit
To run this sample:
$ python get_secret.py
usage: get_secret.py [-h] project_id secret_id
command line application and sample code for getting metadata about a secret.
positional arguments:
project_id id of the GCP project
secret_id id of the secret to get
optional arguments:
-h, --help show this help message and exit
To run this sample:
$ python list_secret_versions.py
usage: list_secret_versions.py [-h] project_id secret_id
command line application and sample code for listing secret versions of a
secret.
positional arguments:
project_id id of the GCP project
secret_id id of the secret in which to list
optional arguments:
-h, --help show this help message and exit
To run this sample:
$ python list_secrets.py
usage: list_secrets.py [-h] project_id
command line application and sample code for listing secrets in a project.
positional arguments:
project_id id of the GCP project
optional arguments:
-h, --help show this help message and exit
To run this sample:
$ python update_secret.py
usage: update_secret.py [-h] --secret-id SECRET_ID project_id
positional arguments:
project_id id of the GCP project
optional arguments:
-h, --help show this help message and exit
--secret-id SECRET_ID