GCP Secret Manager Script
GCP Secret Manager secret automation
1 Minute, 10 Seconds
2024-07-18 17:25 +0000
GCP Secret Manager Script
This script manages secrets in Google Cloud Platform’s Secret Manager. It can create, overwrite, and delete secrets based on the provided YAML configuration file and environment variables.
Prerequisites
- Python 3.6 or higher
- Google Cloud SDK installed and authenticated
- Necessary Python packages installed (
google-cloud-secret-manager
,python-dotenv
,pyyaml
)
Installation
Clone the repository:
git clone https://github.com/justin-napolitano/gcp-secret-creation.py.git cd your-repo-directory
Create a virtual environment and activate it:
python -m venv venv source venv/bin/activate # On Windows, use `venv\\Scripts\\activate`
Install the required packages:
pip install google-cloud-secret-manager python-dotenv pyyaml
Setup
Create a
.env
file in the root directory with the following structure:PROJECT_NAME=your_project_name FAKE_MASTODON_USERNAME=fake_username FAKE_MASTODON_PASSWORD=fake_password
Create a
secrets.yaml
file in the root directory with the following structure:secrets: - id: "FAKE_MASTODON_USERNAME" env_var: "FAKE_MASTODON_USERNAME" - id: "FAKE_MASTODON_PASSWORD" env_var: "FAKE_MASTODON_PASSWORD"
Usage
The script provides several command-line arguments to control its behavior.
Arguments
--url
: Base URL for the API endpoint (default:http://localhost:8080
)--test
: Flag to delete secrets after testing--overwrite
: Flag to overwrite existing secrets--delete
: Flag to delete secrets specified in the YAML file--secrets-file
: Path to the YAML file with secrets configuration (default:secrets.yaml
)
Running the Script
Run the script without deleting or overwriting secrets:
python your_script.py --secrets-file secrets.yaml
Run the script and delete secrets after testing:
python your_script.py --secrets-file secrets.yaml --test
Run the script with the
--overwrite
flag to overwrite existing secrets:python your_script.py --secrets-file secrets.yaml --overwrite
Run the script to delete secrets specified in the YAML file:
python your_script.py --secrets-file secrets.yaml --delete
Example
Here is an example of running the script to manage secrets:
python your_script.py --secrets-file secrets.yaml --overwrite --test