Get project name of GCS bucket
Why
Sometimes when you are managing many GCS buckets ⧉ - You may lose the project they exist in.
If you aren't using a swanky naming convention like <proj-name>-<name>
then this is for you.
How
We are able to use the GCS API ⧉ to get information about the bucket.
Required permissions
As this is using the GCP API, you will have to at least have the below permissions/roles
storage.buckets.get
storage.buckets.list
- View access on the project
Get project Number
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://storage.googleapis.com/storage/v1/b/<>" | jq ."projectNumber"
Convert number to project name
Example
# Get the project number
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://storage.googleapis.com/storage/v1/b/kubernetes-release" | jq ."projectNumber"
Want to make this site better? Open a PR or help fund hosting costs