diff options
author | Orest Bolohan <orest@google.com> | 2014-05-30 11:05:24 -0700 |
---|---|---|
committer | Orest Bolohan <orest@google.com> | 2014-05-30 11:05:24 -0700 |
commit | 569f4e0d23a1aa0e5c15ce5dab872afe31006bb5 (patch) | |
tree | cc2c3b96f20a612b2966d3a88179212d447e757d /samples | |
parent | e48d95189d8f8a7dcaff103c01de053536d47c60 (diff) | |
download | oauth2client-569f4e0d23a1aa0e5c15ce5dab872afe31006bb5.tar.gz |
Add support for Google Default Credentials.
Diffstat (limited to 'samples')
-rw-r--r-- | samples/call_compute_service.py | 15 | ||||
-rw-r--r-- | samples/googleappengine/app.yaml | 10 | ||||
-rw-r--r-- | samples/googleappengine/call_compute_service_from_gae.py | 21 |
3 files changed, 46 insertions, 0 deletions
diff --git a/samples/call_compute_service.py b/samples/call_compute_service.py new file mode 100644 index 0000000..aaa4f38 --- /dev/null +++ b/samples/call_compute_service.py @@ -0,0 +1,15 @@ +# To be used to test GoogleCredential.GetDefaultCredential() +# from local machine and GCE. + +from googleapiclient.discovery import build +from oauth2client.client import GoogleCredentials + +PROJECT = "bamboo-machine-422" # Provide your own GCE project here +ZONE = "us-central1-a" # Put here a zone which has some VMs + +service = build("compute", "v1", credentials=GoogleCredentials.get_default()) + +request = service.instances().list(project=PROJECT, zone=ZONE) +response = request.execute() + +print response diff --git a/samples/googleappengine/app.yaml b/samples/googleappengine/app.yaml new file mode 100644 index 0000000..a299030 --- /dev/null +++ b/samples/googleappengine/app.yaml @@ -0,0 +1,10 @@ +application: bamboo-machine-422 +version: 2 +runtime: python27 +api_version: 1 +threadsafe: true + +handlers: +- url: /.* + script: call_compute_service_from_gae.app + diff --git a/samples/googleappengine/call_compute_service_from_gae.py b/samples/googleappengine/call_compute_service_from_gae.py new file mode 100644 index 0000000..e2b01d2 --- /dev/null +++ b/samples/googleappengine/call_compute_service_from_gae.py @@ -0,0 +1,21 @@ +# To be used to test GoogleCredential.GetDefaultCredential() +# from devel GAE (ie, dev_appserver.py). + +import webapp2 +from googleapiclient.discovery import build +from oauth2client.client import GoogleCredentials + +PROJECT = "bamboo-machine-422" # Provide your own GCE project here +ZONE = "us-central1-a" # Put here a zone which has some VMs + +def get_instances(): + service = build("compute", "v1", credentials=GoogleCredentials.get_default()) + request = service.instances().list(project=PROJECT, zone=ZONE) + return request.execute() + +class MainPage(webapp2.RequestHandler): + + def get(self): + self.response.write(get_instances()) + +app = webapp2.WSGIApplication([('/', MainPage),], debug=True) |