Search code examples
google-mapsgoogle-cloud-platformgcloudgoogle-iamgcloud-cli

Adding restrictions to API Keys using the gcloud alpha CLI


Using gcloud alpha services It's now perfectly possible to generate keys programatically:

gcloud alpha services api-keys create

I can then enable the Maps JavaScript API using

gcloud services enable maps-backend.googleapis.com

At this point I need to set some HTTP referrer restrictions on that key but the services api-keys update command only updates an API key's metadata.

How do I proceed?


Solution

  • It looks (haven't tried the API) as though you can do this at create and update with --allowed-referrers:

    https://cloud.google.com/sdk/gcloud/reference/alpha/services/api-keys/create

    https://cloud.google.com/sdk/gcloud/reference/alpha/services/api-keys/update