Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
209 views
in Technique[技术] by (71.8m points)

go - 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.

question from:https://stackoverflow.com/questions/65623699/where-can-i-find-which-apis-gcloud-calls

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...