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.

Community
  • 1
  • 1
Toby 1 Kenobi
  • 4,717
  • 2
  • 29
  • 43

1 Answers1

0

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

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

Mete Atamel
  • 821
  • 5
  • 11
  • 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? – Toby 1 Kenobi Jun 15 '16 at 13:00