Search code examples
gogoogle-cloud-platformgcloudgoogle-cloud-sdk

Where can I find which APIs gcloud calls?


I'm working on a new project where I plan to replace a collection of one-off shell scripts that call gcloud and gsutil with Google Cloud Go APIs and client libraries. The main driver behind this is so I can have easier to maintain and testable code to manage a large scale GCP automation project.

I've dug through all of the Google doc and cannot seem to find anything that covers what underlying APIs glcoud calls, or the glcoud source code. To add to this, the GCP go APIs don't seem to cover what I'm looking for. I have been able to find some of what I need offered in the REST APIs, but even then, it's not entirely clear what gcloud commands map to what REST API endpoints.

An example would be: gcloud addresses describe gce_vm_foo

The only thing I can find that fits is this endpoint from the REST API, found through digging through the enormous pile of documentation and trial and error: https://godoc.org/google.golang.org/api/compute/v1#InstancesService.Get

I realize this is a very open ended question, but any pointing in the right right direction is much appreciated.


Solution

  • If you would like to know what calls gcloud is making add --log-http flag and maybe grep for something to narrow down your search, for example:

    ~ gcloud --log-http compute addresses list 2>&1 | grep "GET" \
    GET /compute/v1/projects/<redacted>/aggregated/addresses?alt=json HTTP/1.1
    

    then possibly go to the Compute Engine API page and search (or just google) for the distinguishing part of the request uri from above, like 'aggregated/addresses', which should get you to the REST Resource: v1.addresses portion of the page and from here it should be relatively easy.