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.
- Python 3.6 or higher
- Google Cloud SDK installed and authenticated
- Necessary Python packages installed (
google-cloud-secret-manager
,python-dotenv
,pyyaml
)
-
Clone the repository:
git clone https://your-repo-url.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
-
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"
The script provides several command-line arguments to control its behavior.
--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
)
-
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
Here is an example of running the script to manage secrets:
python your_script.py --secrets-file secrets.yaml --overwrite --test