Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a2d8238

Browse filesBrowse files
author
Jon Wayne Parrott
authored
Remove usage of GoogleCredentials (GoogleCloudPlatform#810)
1 parent 0924ff0 commit a2d8238
Copy full SHA for a2d8238

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree

52 files changed

+164
-324
lines changed
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
Flask==0.12
22
google-cloud-datastore==0.22.1
33
gunicorn==19.6.0
4-
oauth2client==4.0.0

‎appengine/flexible/endpoints/clients/service_to_service_non_default/main.py

Copy file name to clipboardExpand all lines: appengine/flexible/endpoints/clients/service_to_service_non_default/main.py
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import json
2121
import time
2222

23-
from googleapiclient.discovery import build
23+
import googleapiclient.discovery
2424
import httplib2
2525
from oauth2client.contrib.appengine import AppAssertionCredentials
2626
import webapp2
@@ -36,7 +36,8 @@ def generate_jwt():
3636
credentials = AppAssertionCredentials(
3737
'https://www.googleapis.com/auth/iam')
3838
http_auth = credentials.authorize(httplib2.Http())
39-
service = build(serviceName='iam', version='v1', http=http_auth)
39+
service = googleapiclient.discovery.build(
40+
serviceName='iam', version='v1', http=http_auth)
4041

4142
now = int(time.time())
4243

-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
gunicorn==19.6.0
2-
oauth2client==4.0.0
32
kinto==5.3.5
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
Flask==0.12
22
google-cloud-pubsub==0.22.0
33
gunicorn==19.6.0
4-
oauth2client==4.0.0

‎appengine/standard/bigquery/main.py

Copy file name to clipboardExpand all lines: appengine/standard/bigquery/main.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import json
2525
import os
2626

27-
from googleapiclient.discovery import build
27+
import googleapiclient.discovery
2828
from oauth2client.contrib.appengine import OAuth2DecoratorFromClientSecrets
2929
import webapp2
3030

@@ -38,7 +38,7 @@
3838
scope='https://www.googleapis.com/auth/bigquery')
3939

4040
# Create the bigquery api client
41-
service = build('bigquery', 'v2')
41+
service = googleapiclient.discovery.build('bigquery', 'v2')
4242

4343

4444
class MainPage(webapp2.RequestHandler):

‎appengine/standard/storage/api-client/main.py

Copy file name to clipboardExpand all lines: appengine/standard/storage/api-client/main.py
+5-6Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,15 @@
2525
import json
2626
import StringIO
2727

28-
from googleapiclient import discovery
29-
from googleapiclient import http
30-
from oauth2client.client import GoogleCredentials
28+
import googleapiclient.discovery
29+
import googleapiclient.http
3130
import webapp2
3231

3332

3433
# The bucket that will be used to list objects.
3534
BUCKET_NAME = '<your-bucket-name>'
3635

37-
credentials = GoogleCredentials.get_application_default()
38-
storage = discovery.build('storage', 'v1', credentials=credentials)
36+
storage = googleapiclient.discovery.build('storage', 'v1')
3937

4038

4139
class MainPage(webapp2.RequestHandler):
@@ -44,7 +42,8 @@ def upload_object(self, bucket, file_object):
4442
'name': 'storage-api-client-sample-file.txt',
4543
}
4644
req = storage.objects().insert(
47-
bucket=bucket, body=body, media_body=http.MediaIoBaseUpload(
45+
bucket=bucket, body=body,
46+
media_body=googleapiclient.http.MediaIoBaseUpload(
4847
file_object, 'application/octet-stream'))
4948
resp = req.execute()
5049
return resp

‎bigquery/api/async_query.py

Copy file name to clipboardExpand all lines: bigquery/api/async_query.py
+2-6Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323
import time
2424
import uuid
2525

26-
from googleapiclient import discovery
27-
from oauth2client.client import GoogleCredentials
26+
import googleapiclient.discovery
2827

2928

3029
# [START async_query]
@@ -82,11 +81,8 @@ def main(
8281
project_id, query_string, batch, num_retries, interval,
8382
use_legacy_sql):
8483
# [START build_service]
85-
# Grab the application's default credentials from the environment.
86-
credentials = GoogleCredentials.get_application_default()
87-
8884
# Construct the service object for interacting with the BigQuery API.
89-
bigquery = discovery.build('bigquery', 'v2', credentials=credentials)
85+
bigquery = googleapiclient.discovery.build('bigquery', 'v2')
9086
# [END build_service]
9187

9288
# Submit the job and wait for it to complete.

‎bigquery/api/export_data_to_cloud_storage.py

Copy file name to clipboardExpand all lines: bigquery/api/export_data_to_cloud_storage.py
+2-6Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@
2727
import time
2828
import uuid
2929

30-
from googleapiclient import discovery
31-
from oauth2client.client import GoogleCredentials
30+
import googleapiclient.discovery
3231

3332

3433
# [START export_table]
@@ -107,11 +106,8 @@ def poll_job(bigquery, job):
107106
def main(cloud_storage_path, project_id, dataset_id, table_id,
108107
num_retries, interval, export_format="CSV", compression="NONE"):
109108
# [START build_service]
110-
# Grab the application's default credentials from the environment.
111-
credentials = GoogleCredentials.get_application_default()
112-
113109
# Construct the service object for interacting with the BigQuery API.
114-
bigquery = discovery.build('bigquery', 'v2', credentials=credentials)
110+
bigquery = googleapiclient.discovery.build('bigquery', 'v2')
115111
# [END build_service]
116112

117113
job = export_table(

‎bigquery/api/getting_started.py

Copy file name to clipboardExpand all lines: bigquery/api/getting_started.py
+2-5Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,14 @@
2727
# [START all]
2828
import argparse
2929

30-
from googleapiclient.discovery import build
30+
import googleapiclient.discovery
3131
from googleapiclient.errors import HttpError
32-
from oauth2client.client import GoogleCredentials
3332

3433

3534
def main(project_id):
3635
# [START build_service]
37-
# Grab the application's default credentials from the environment.
38-
credentials = GoogleCredentials.get_application_default()
3936
# Construct the service object for interacting with the BigQuery API.
40-
bigquery_service = build('bigquery', 'v2', credentials=credentials)
37+
bigquery_service = googleapiclient.discovery.build('bigquery', 'v2')
4138
# [END build_service]
4239

4340
try:

‎bigquery/api/installed_app.py

Copy file name to clipboardExpand all lines: bigquery/api/installed_app.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import argparse
2828
import pprint
2929

30-
from googleapiclient import discovery
30+
import googleapiclient.discovery
3131
from googleapiclient.errors import HttpError
3232
from oauth2client import tools
3333
from oauth2client.client import AccessTokenRefreshError
@@ -51,7 +51,7 @@ def main(args):
5151
credentials = tools.run_flow(flow, storage, args)
5252

5353
# Create a BigQuery client using the credentials.
54-
bigquery_service = discovery.build(
54+
bigquery_service = googleapiclient.discovery.build(
5555
'bigquery', 'v2', credentials=credentials)
5656

5757
# List all datasets in BigQuery

‎bigquery/api/list_datasets_projects.py

Copy file name to clipboardExpand all lines: bigquery/api/list_datasets_projects.py
+2-4Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
import argparse
2626
from pprint import pprint
2727

28-
from googleapiclient import discovery
29-
from oauth2client.client import GoogleCredentials
28+
import googleapiclient.discovery
3029
from six.moves.urllib.error import HTTPError
3130

3231

@@ -60,9 +59,8 @@ def list_projects(bigquery):
6059

6160

6261
def main(project_id):
63-
credentials = GoogleCredentials.get_application_default()
6462
# Construct the service object for interacting with the BigQuery API.
65-
bigquery = discovery.build('bigquery', 'v2', credentials=credentials)
63+
bigquery = googleapiclient.discovery.build('bigquery', 'v2')
6664

6765
list_datasets(bigquery, project_id)
6866
list_projects(bigquery)

‎bigquery/api/load_data_by_post.py

Copy file name to clipboardExpand all lines: bigquery/api/load_data_by_post.py
+5-7Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@
2626
import json
2727
import time
2828

29-
from googleapiclient import discovery
30-
from googleapiclient.http import MediaFileUpload
31-
from oauth2client.client import GoogleCredentials
29+
import googleapiclient.discovery
30+
import googleapiclient.http
3231

3332

3433
# [START make_post]
@@ -44,9 +43,8 @@ def load_data(schema_path, data_path, project_id, dataset_id, table_id):
4443
dataset_id: The dataset id of the destination table.
4544
table_id: The table id to load data into.
4645
"""
47-
# Create a bigquery service object, using the application's default auth
48-
credentials = GoogleCredentials.get_application_default()
49-
bigquery = discovery.build('bigquery', 'v2', credentials=credentials)
46+
# Create a bigquery service object.
47+
bigquery = googleapiclient.discovery.build('bigquery', 'v2')
5048

5149
# Infer the data format from the name of the data file.
5250
source_format = 'CSV'
@@ -74,7 +72,7 @@ def load_data(schema_path, data_path, project_id, dataset_id, table_id):
7472
}
7573
}
7674
},
77-
media_body=MediaFileUpload(
75+
media_body=googleapiclient.http.MediaFileUpload(
7876
data_path,
7977
mimetype='application/octet-stream'))
8078
job = insert_request.execute()

‎bigquery/api/load_data_from_csv.py

Copy file name to clipboardExpand all lines: bigquery/api/load_data_from_csv.py
+2-6Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
import time
2929
import uuid
3030

31-
from googleapiclient import discovery
32-
from oauth2client.client import GoogleCredentials
31+
import googleapiclient.discovery
3332

3433

3534
# [START load_table]
@@ -105,11 +104,8 @@ def poll_job(bigquery, job):
105104
def main(project_id, dataset_id, table_name, schema_file, data_path,
106105
poll_interval, num_retries):
107106
# [START build_service]
108-
# Grab the application's default credentials from the environment.
109-
credentials = GoogleCredentials.get_application_default()
110-
111107
# Construct the service object for interacting with the BigQuery API.
112-
bigquery = discovery.build('bigquery', 'v2', credentials=credentials)
108+
bigquery = googleapiclient.discovery.build('bigquery', 'v2')
113109
# [END build_service]
114110

115111
with open(schema_file, 'r') as f:

‎bigquery/api/streaming.py

Copy file name to clipboardExpand all lines: bigquery/api/streaming.py
+2-6Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@
2727
import json
2828
import uuid
2929

30-
from googleapiclient import discovery
31-
from oauth2client.client import GoogleCredentials
30+
import googleapiclient.discovery
3231
from six.moves import input
3332

3433

@@ -54,11 +53,8 @@ def stream_row_to_bigquery(bigquery, project_id, dataset_id, table_name, row,
5453
# [START run]
5554
def main(project_id, dataset_id, table_name, num_retries):
5655
# [START build_service]
57-
# Grab the application's default credentials from the environment.
58-
credentials = GoogleCredentials.get_application_default()
59-
6056
# Construct the service object for interacting with the BigQuery API.
61-
bigquery = discovery.build('bigquery', 'v2', credentials=credentials)
57+
bigquery = googleapiclient.discovery.build('bigquery', 'v2')
6258
# [END build_service]
6359

6460
for row in get_rows():

‎bigquery/api/sync_query.py

Copy file name to clipboardExpand all lines: bigquery/api/sync_query.py
+2-6Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
import argparse
2222
import json
2323

24-
from googleapiclient import discovery
25-
from oauth2client.client import GoogleCredentials
24+
import googleapiclient.discovery
2625

2726

2827
# [START sync_query]
@@ -45,11 +44,8 @@ def sync_query(
4544
# [START run]
4645
def main(project_id, query, timeout, num_retries, use_legacy_sql):
4746
# [START build_service]
48-
# Grab the application's default credentials from the environment.
49-
credentials = GoogleCredentials.get_application_default()
50-
5147
# Construct the service object for interacting with the BigQuery API.
52-
bigquery = discovery.build('bigquery', 'v2', credentials=credentials)
48+
bigquery = googleapiclient.discovery.build('bigquery', 'v2')
5349
# [END build_service]
5450

5551
query_job = sync_query(

‎compute/api/create_instance.py

Copy file name to clipboardExpand all lines: compute/api/create_instance.py
+2-4Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
import os
2929
import time
3030

31-
from googleapiclient import discovery
32-
from oauth2client.client import GoogleCredentials
31+
import googleapiclient.discovery
3332
from six.moves import input
3433

3534

@@ -146,8 +145,7 @@ def wait_for_operation(compute, project, zone, operation):
146145

147146
# [START run]
148147
def main(project, bucket, zone, instance_name, wait=True):
149-
credentials = GoogleCredentials.get_application_default()
150-
compute = discovery.build('compute', 'v1', credentials=credentials)
148+
compute = googleapiclient.discovery.build('compute', 'v1')
151149

152150
print('Creating instance.')
153151

‎compute/auth/application_default.py

Copy file name to clipboardExpand all lines: compute/auth/application_default.py
+6-8Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,17 @@
2424

2525
import argparse
2626

27-
from googleapiclient import discovery
28-
from oauth2client.client import GoogleCredentials
27+
import googleapiclient.discovery
2928

3029

3130
def create_service():
32-
# Get the application default credentials. When running locally, these are
33-
# available after running `gcloud auth`. When running on compute
34-
# engine, these are available from the environment.
35-
credentials = GoogleCredentials.get_application_default()
36-
3731
# Construct the service object for interacting with the Cloud Storage API -
3832
# the 'storage' service, at version 'v1'.
39-
return discovery.build('storage', 'v1', credentials=credentials)
33+
# Authentication is provided by application default credentials.
34+
# When running locally, these are available after running
35+
# `gcloud auth application-default login`. When running on Compute
36+
# Engine, these are available from the environment.
37+
return googleapiclient.discovery.build('storage', 'v1')
4038

4139

4240
def list_buckets(service, project_id):

‎compute/encryption/generate_wrapped_rsa_key_test.py

Copy file name to clipboardExpand all lines: compute/encryption/generate_wrapped_rsa_key_test.py
+2-4Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313

1414
import os
1515

16-
from googleapiclient import discovery
17-
from oauth2client.client import GoogleCredentials
16+
import googleapiclient.discovery
1817

1918
import generate_wrapped_rsa_key
2019

@@ -24,8 +23,7 @@ def test_main():
2423

2524

2625
def test_create_disk(cloud_config):
27-
credentials = GoogleCredentials.get_application_default()
28-
compute = discovery.build('compute', 'beta', credentials=credentials)
26+
compute = googleapiclient.discovery.build('compute', 'beta')
2927

3028
# Generate the key.
3129
key_bytes = os.urandom(32)

‎dataproc/create_cluster_and_submit_job.py

Copy file name to clipboardExpand all lines: dataproc/create_cluster_and_submit_job.py
+2-4Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@
1616
import argparse
1717
import os
1818

19-
from apiclient import discovery
2019
from google.cloud import storage
21-
from oauth2client.client import GoogleCredentials
20+
import googleapiclient.discovery
2221

2322
# Currently only the "global" region is supported
2423
REGION = 'global'
@@ -177,8 +176,7 @@ def wait_for_job(dataproc, project, job_id):
177176
def get_client():
178177
"""Builds an http client authenticated with the service account
179178
credentials."""
180-
credentials = GoogleCredentials.get_application_default()
181-
dataproc = discovery.build('dataproc', 'v1', credentials=credentials)
179+
dataproc = googleapiclient.discovery.build('dataproc', 'v1')
182180
return dataproc
183181
# [END get_client]
184182

‎dataproc/list_clusters.py

Copy file name to clipboardExpand all lines: dataproc/list_clusters.py
+3-6Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616

1717
import argparse
1818

19-
from apiclient import discovery
20-
from oauth2client.client import GoogleCredentials
19+
import googleapiclient.discovery
2120

2221
# Currently only the "global" region is supported
2322
REGION = 'global'
@@ -34,10 +33,8 @@ def list_clusters(dataproc, project):
3433

3534
# [START get_client]
3635
def get_client():
37-
"""Builds an http client authenticated with the service account
38-
credentials."""
39-
credentials = GoogleCredentials.get_application_default()
40-
dataproc = discovery.build('dataproc', 'v1', credentials=credentials)
36+
"""Builds a client to the dataproc API."""
37+
dataproc = googleapiclient.discovery.build('dataproc', 'v1')
4138
return dataproc
4239
# [END get_client]
4340

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.