GCP Secret Manager Script
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:
-
Create a virtual environment and activate it:
-
Install the required packages:
Setup
-
Create a
.envfile 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.yamlfile 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:
-
Run the script and delete secrets after testing:
-
Run the script with the
--overwriteflag to overwrite existing secrets: -
Run the script to delete secrets specified in the YAML file:
Example
Here is an example of running the script to manage secrets: