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
BUCKET=<bucket name>
gcloud projects describe $(curl -s -X GET -H "Authorization: Bearer $(gcloud auth print-access-token)" "https://storage.googleapis.com/storage/v1/b/$BUCKET" | jq -r .projectNumber) --format="value(name)"
Example
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
Want to make this site better? Open a PR, help fund hosting costs or message me on Matrix