A wrapper for executing commands with Google Cloud CLI authentication and project management
Project description
gcloud2-wrap
A Python wrapper for executing commands with Google Cloud CLI authentication and project management.
Overview
gcloud2-wrap is a Python tool that provides enhanced functionality for running commands with Google Cloud Platform (GCP) authentication and project context. It's designed as a more robust and feature-rich replacement for bash-based wrappers.
Features
- Automatic Project Management: Seamlessly switch between GCP projects for command execution
- Quota Project Handling: Automatically sets quota project if not specified
- Authentication Recovery: Detects authentication errors and automatically triggers
gcloud auth application-default login - State Restoration: Automatically restores original gcloud configuration after command execution
- Signal Handling: Properly forwards signals (SIGINT, SIGTERM) to child processes
- Environment Variable Management: Sets appropriate Google Cloud environment variables
- Error Handling: Comprehensive error handling with meaningful error messages
Installation
From PyPI (recommended)
pip install gcloud2-wrap
From Source
git clone https://github.com/ravishtiwari/gcloud2-wrap.git
cd gcloud2-wrap
pip install -e .
Usage
Basic Usage
gcloud2-wrap --project PROJECT_ID --credentials /path/to/credentials.json -- COMMAND [ARGS...]
With Quota Project
gcloud2-wrap --project PROJECT_ID --quota-project QUOTA_PROJECT_ID --credentials /path/to/credentials.json -- COMMAND [ARGS...]
Examples
Run a gcloud command with specific project context:
gcloud2-wrap --project my-project --credentials ./service-account.json -- gcloud compute instances list
Run a Python script with GCP authentication:
gcloud2-wrap --project my-project --credentials ./service-account.json -- python my_gcp_script.py
Run with different quota project:
gcloud2-wrap --project my-project --quota-project billing-project --credentials ./service-account.json -- gcloud storage ls
Command Line Options
--project PROJECT_ID: (Required) GCP project ID to use for the command--credentials PATH: (Required) Path to the service account credentials JSON file--quota-project PROJECT_ID: (Optional) GCP quota project ID (defaults to the value of--project)--version, -v: Show version information--: Separator between wrapper options and the command to execute
Environment Variables
The tool automatically sets the following environment variables for the executed command:
GOOGLE_APPLICATION_CREDENTIALS: Path to the credentials fileGOOGLE_CLOUD_PROJECT: The specified project IDGOOGLE_CLOUD_QUOTA_PROJECT: The specified quota project ID
Enhanced Features
Automatic Quota Project
If --quota-project is not specified, the tool automatically uses the same value as --project.
Authentication Error Recovery
When the tool detects authentication-related errors in command output, it automatically runs:
gcloud auth application-default login
This helps recover from expired or invalid authentication tokens.
State Restoration
The tool saves the current gcloud configuration before making changes and restores it after command execution, ensuring your local gcloud setup remains unchanged.
Signal Handling
Proper signal forwarding ensures that interrupting the wrapper (Ctrl+C) correctly terminates the child process.
Development
For information on setting up the development environment, running tests, and the CI/CD pipeline, please refer to DEVELOPMENT.md.
Requirements
- Python 3.9 or higher
- Google Cloud CLI (
gcloud) installed and available in PATH psutilpackage (automatically installed with the package)
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Support
If you encounter any issues or have questions, please file an issue on the GitHub repository.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gcloud2_wrap-1.0.0.tar.gz.
File metadata
- Download URL: gcloud2_wrap-1.0.0.tar.gz
- Upload date:
- Size: 13.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7941b19e307859d0661092e3efd26aa67693d6851273dc869306fdae3f69964d
|
|
| MD5 |
7b38689a2b7c9c17a51d87c9d4973b49
|
|
| BLAKE2b-256 |
808c236de98f08673bdc4b7f6149f029d8e87185221899e11267ba6b588d9033
|
File details
Details for the file gcloud2_wrap-1.0.0-py3-none-any.whl.
File metadata
- Download URL: gcloud2_wrap-1.0.0-py3-none-any.whl
- Upload date:
- Size: 12.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
77dba1d1a4039b8a83ab9556c1a99575cd3fce63261f9733460bfbfe4213670d
|
|
| MD5 |
85bfaaed9aa484bdb7c93ca2404cb541
|
|
| BLAKE2b-256 |
6b05a0c971a8c3ce06b275a40487a86b6da9d79acb4ee8d5c7ae7c39c3d2f319
|