0

I've set up a Google Compute Engine Instance and I want to be able to turn it on and off using a script on my home computer. I see that there's an API that lets me do that by sending a POST request like this:

curl --data '' https://www.googleapis.com/compute/v1/projects/my-project/zones/asia-east1-a/instances/my-instance/stop

but the response I get from that is this:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "required",
    "message": "Login Required",
    "locationType": "header",
    "location": "Authorization"
   }
  ],
  "code": 401,
  "message": "Login Required"
 }
}

So I'm trying to see how I can allow my script authorisation to use the API on the compute engine without having user interaction. How do I do this?

It looks like Google requires OAuth 2.0 authentication, but it seems really complex.

The closest thing I can find in Google's docs is this page but I can't work out how to make it a bunch of curl statements.

This SO thread gets closer, but glancing over the scripts there - it looks like they need user interaction.

1 Answer 1

0

I think you need Application Default Credentials. Have you seen this page?

https://developers.google.com/identity/protocols/application-default-credentials

Sign up to request clarification or add additional context in comments.

1 Comment

I pored over that page many times but couldn't make sense of how I would do it in my situation. "The credentials returned are determined by the environment the code is running in." How does the google server have access to the environment of my shell script that's just sending an http request?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.