A Python script that generates signed URLs for files stored in Google Cloud Storage, allowing temporary access without exposing credentials.
- Search files in Google Cloud Storage using phone number and timestamp.
- Generate signed URLs for temporary file access (default: 1 hour).
- Secure access to files without exposing storage credentials.
- Formatted JSON output for easy integration with other applications.
Ensure Python is installed. If not, download it from Python.org.
Then, install the required dependencies:
pip3 install google-cloud-storageTo use Google Cloud Storage, follow these steps:
- Go to Google Cloud Console: Google Cloud Console
- Enable APIs:
- Go to APIs & Services > Enable APIs & Services.
- Search for and enable:
- Cloud Storage API
- Create a Service Account:
- Go to APIs & Services > Credentials.
- Click Create Credentials > Service Account.
- Fill in the details and click Done.
- Generate a JSON Key File:
- Click on the created service account.
- Go to Keys and click Add Key > Create New Key.
- Select JSON and download the file.
- Save it in the project folder as
service_account.json.
git clone https://github.com/bharatcj/gcp-signed-url-generator.git
cd gcp-signed-url-generatorSet the environment variable for authentication:
set GOOGLE_APPLICATION_CREDENTIALS="C:\path\to\service_account.json"export GOOGLE_APPLICATION_CREDENTIALS="/path/to/service_account.json"python3 google_cloud_storage.py <bucket_name> <folder_path> <search_term>Replace:
<bucket_name>: Google Cloud Storage bucket name.<folder_path>: Folder inside the bucket.<search_term>: A string (e.g., phone number + timestamp) to find the file.
Example:
python3 google_cloud_storage.py my-bucket recordings 1234567890_20240215If an error occurs:
- The script prints a detailed error message.
- It verifies search terms before querying the bucket.
- Returns formatted JSON responses for easy debugging.
- Modify
google_cloud_storage.pyto change the signed URL expiration time (default: 1 hour). - Adjust search logic to match custom file naming conventions.
This project is licensed under the MIT License.
Contributions are welcome! Feel free to fork this repository and submit pull requests.
Developed by Bharat CJ
GitHub: https://github.com/bharatcj
💡 Did you know? Google Cloud signed URLs provide temporary, time-limited access to your files, meaning you can securely share them without making them public! 🔒🚀