Skip to content

Commit

Permalink
Remove usage of GoogleCredentials (#810)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Wayne Parrott authored Feb 17, 2017
1 parent 0924ff0 commit a2d8238
Show file tree
Hide file tree
Showing 52 changed files with 164 additions and 324 deletions.
1 change: 0 additions & 1 deletion appengine/flexible/datastore/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
Flask==0.12
google-cloud-datastore==0.22.1
gunicorn==19.6.0
oauth2client==4.0.0
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import json
import time

from googleapiclient.discovery import build
import googleapiclient.discovery
import httplib2
from oauth2client.contrib.appengine import AppAssertionCredentials
import webapp2
Expand All @@ -36,7 +36,8 @@ def generate_jwt():
credentials = AppAssertionCredentials(
'https://www.googleapis.com/auth/iam')
http_auth = credentials.authorize(httplib2.Http())
service = build(serviceName='iam', version='v1', http=http_auth)
service = googleapiclient.discovery.build(
serviceName='iam', version='v1', http=http_auth)

now = int(time.time())

Expand Down
1 change: 0 additions & 1 deletion appengine/flexible/kinto/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
gunicorn==19.6.0
oauth2client==4.0.0
kinto==5.3.5
1 change: 0 additions & 1 deletion appengine/flexible/pubsub/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
Flask==0.12
google-cloud-pubsub==0.22.0
gunicorn==19.6.0
oauth2client==4.0.0
4 changes: 2 additions & 2 deletions appengine/standard/bigquery/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import json
import os

from googleapiclient.discovery import build
import googleapiclient.discovery
from oauth2client.contrib.appengine import OAuth2DecoratorFromClientSecrets
import webapp2

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

# Create the bigquery api client
service = build('bigquery', 'v2')
service = googleapiclient.discovery.build('bigquery', 'v2')


class MainPage(webapp2.RequestHandler):
Expand Down
11 changes: 5 additions & 6 deletions appengine/standard/storage/api-client/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,15 @@
import json
import StringIO

from googleapiclient import discovery
from googleapiclient import http
from oauth2client.client import GoogleCredentials
import googleapiclient.discovery
import googleapiclient.http
import webapp2


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

credentials = GoogleCredentials.get_application_default()
storage = discovery.build('storage', 'v1', credentials=credentials)
storage = googleapiclient.discovery.build('storage', 'v1')


class MainPage(webapp2.RequestHandler):
Expand All @@ -44,7 +42,8 @@ def upload_object(self, bucket, file_object):
'name': 'storage-api-client-sample-file.txt',
}
req = storage.objects().insert(
bucket=bucket, body=body, media_body=http.MediaIoBaseUpload(
bucket=bucket, body=body,
media_body=googleapiclient.http.MediaIoBaseUpload(
file_object, 'application/octet-stream'))
resp = req.execute()
return resp
Expand Down
8 changes: 2 additions & 6 deletions bigquery/api/async_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
import time
import uuid

from googleapiclient import discovery
from oauth2client.client import GoogleCredentials
import googleapiclient.discovery


# [START async_query]
Expand Down Expand Up @@ -82,11 +81,8 @@ def main(
project_id, query_string, batch, num_retries, interval,
use_legacy_sql):
# [START build_service]
# Grab the application's default credentials from the environment.
credentials = GoogleCredentials.get_application_default()

# Construct the service object for interacting with the BigQuery API.
bigquery = discovery.build('bigquery', 'v2', credentials=credentials)
bigquery = googleapiclient.discovery.build('bigquery', 'v2')
# [END build_service]

# Submit the job and wait for it to complete.
Expand Down
8 changes: 2 additions & 6 deletions bigquery/api/export_data_to_cloud_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
import time
import uuid

from googleapiclient import discovery
from oauth2client.client import GoogleCredentials
import googleapiclient.discovery


# [START export_table]
Expand Down Expand Up @@ -107,11 +106,8 @@ def poll_job(bigquery, job):
def main(cloud_storage_path, project_id, dataset_id, table_id,
num_retries, interval, export_format="CSV", compression="NONE"):
# [START build_service]
# Grab the application's default credentials from the environment.
credentials = GoogleCredentials.get_application_default()

# Construct the service object for interacting with the BigQuery API.
bigquery = discovery.build('bigquery', 'v2', credentials=credentials)
bigquery = googleapiclient.discovery.build('bigquery', 'v2')
# [END build_service]

job = export_table(
Expand Down
7 changes: 2 additions & 5 deletions bigquery/api/getting_started.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,14 @@
# [START all]
import argparse

from googleapiclient.discovery import build
import googleapiclient.discovery
from googleapiclient.errors import HttpError
from oauth2client.client import GoogleCredentials


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

try:
Expand Down
4 changes: 2 additions & 2 deletions bigquery/api/installed_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import argparse
import pprint

from googleapiclient import discovery
import googleapiclient.discovery
from googleapiclient.errors import HttpError
from oauth2client import tools
from oauth2client.client import AccessTokenRefreshError
Expand All @@ -51,7 +51,7 @@ def main(args):
credentials = tools.run_flow(flow, storage, args)

# Create a BigQuery client using the credentials.
bigquery_service = discovery.build(
bigquery_service = googleapiclient.discovery.build(
'bigquery', 'v2', credentials=credentials)

# List all datasets in BigQuery
Expand Down
6 changes: 2 additions & 4 deletions bigquery/api/list_datasets_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
import argparse
from pprint import pprint

from googleapiclient import discovery
from oauth2client.client import GoogleCredentials
import googleapiclient.discovery
from six.moves.urllib.error import HTTPError


Expand Down Expand Up @@ -60,9 +59,8 @@ def list_projects(bigquery):


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

list_datasets(bigquery, project_id)
list_projects(bigquery)
Expand Down
12 changes: 5 additions & 7 deletions bigquery/api/load_data_by_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@
import json
import time

from googleapiclient import discovery
from googleapiclient.http import MediaFileUpload
from oauth2client.client import GoogleCredentials
import googleapiclient.discovery
import googleapiclient.http


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

# Infer the data format from the name of the data file.
source_format = 'CSV'
Expand Down Expand Up @@ -74,7 +72,7 @@ def load_data(schema_path, data_path, project_id, dataset_id, table_id):
}
}
},
media_body=MediaFileUpload(
media_body=googleapiclient.http.MediaFileUpload(
data_path,
mimetype='application/octet-stream'))
job = insert_request.execute()
Expand Down
8 changes: 2 additions & 6 deletions bigquery/api/load_data_from_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
import time
import uuid

from googleapiclient import discovery
from oauth2client.client import GoogleCredentials
import googleapiclient.discovery


# [START load_table]
Expand Down Expand Up @@ -105,11 +104,8 @@ def poll_job(bigquery, job):
def main(project_id, dataset_id, table_name, schema_file, data_path,
poll_interval, num_retries):
# [START build_service]
# Grab the application's default credentials from the environment.
credentials = GoogleCredentials.get_application_default()

# Construct the service object for interacting with the BigQuery API.
bigquery = discovery.build('bigquery', 'v2', credentials=credentials)
bigquery = googleapiclient.discovery.build('bigquery', 'v2')
# [END build_service]

with open(schema_file, 'r') as f:
Expand Down
8 changes: 2 additions & 6 deletions bigquery/api/streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
import json
import uuid

from googleapiclient import discovery
from oauth2client.client import GoogleCredentials
import googleapiclient.discovery
from six.moves import input


Expand All @@ -54,11 +53,8 @@ def stream_row_to_bigquery(bigquery, project_id, dataset_id, table_name, row,
# [START run]
def main(project_id, dataset_id, table_name, num_retries):
# [START build_service]
# Grab the application's default credentials from the environment.
credentials = GoogleCredentials.get_application_default()

# Construct the service object for interacting with the BigQuery API.
bigquery = discovery.build('bigquery', 'v2', credentials=credentials)
bigquery = googleapiclient.discovery.build('bigquery', 'v2')
# [END build_service]

for row in get_rows():
Expand Down
8 changes: 2 additions & 6 deletions bigquery/api/sync_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
import argparse
import json

from googleapiclient import discovery
from oauth2client.client import GoogleCredentials
import googleapiclient.discovery


# [START sync_query]
Expand All @@ -45,11 +44,8 @@ def sync_query(
# [START run]
def main(project_id, query, timeout, num_retries, use_legacy_sql):
# [START build_service]
# Grab the application's default credentials from the environment.
credentials = GoogleCredentials.get_application_default()

# Construct the service object for interacting with the BigQuery API.
bigquery = discovery.build('bigquery', 'v2', credentials=credentials)
bigquery = googleapiclient.discovery.build('bigquery', 'v2')
# [END build_service]

query_job = sync_query(
Expand Down
6 changes: 2 additions & 4 deletions compute/api/create_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
import os
import time

from googleapiclient import discovery
from oauth2client.client import GoogleCredentials
import googleapiclient.discovery
from six.moves import input


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

# [START run]
def main(project, bucket, zone, instance_name, wait=True):
credentials = GoogleCredentials.get_application_default()
compute = discovery.build('compute', 'v1', credentials=credentials)
compute = googleapiclient.discovery.build('compute', 'v1')

print('Creating instance.')

Expand Down
14 changes: 6 additions & 8 deletions compute/auth/application_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,17 @@

import argparse

from googleapiclient import discovery
from oauth2client.client import GoogleCredentials
import googleapiclient.discovery


def create_service():
# Get the application default credentials. When running locally, these are
# available after running `gcloud auth`. When running on compute
# engine, these are available from the environment.
credentials = GoogleCredentials.get_application_default()

# Construct the service object for interacting with the Cloud Storage API -
# the 'storage' service, at version 'v1'.
return discovery.build('storage', 'v1', credentials=credentials)
# Authentication is provided by application default credentials.
# When running locally, these are available after running
# `gcloud auth application-default login`. When running on Compute
# Engine, these are available from the environment.
return googleapiclient.discovery.build('storage', 'v1')


def list_buckets(service, project_id):
Expand Down
6 changes: 2 additions & 4 deletions compute/encryption/generate_wrapped_rsa_key_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@

import os

from googleapiclient import discovery
from oauth2client.client import GoogleCredentials
import googleapiclient.discovery

import generate_wrapped_rsa_key

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


def test_create_disk(cloud_config):
credentials = GoogleCredentials.get_application_default()
compute = discovery.build('compute', 'beta', credentials=credentials)
compute = googleapiclient.discovery.build('compute', 'beta')

# Generate the key.
key_bytes = os.urandom(32)
Expand Down
6 changes: 2 additions & 4 deletions dataproc/create_cluster_and_submit_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
import argparse
import os

from apiclient import discovery
from google.cloud import storage
from oauth2client.client import GoogleCredentials
import googleapiclient.discovery

# Currently only the "global" region is supported
REGION = 'global'
Expand Down Expand Up @@ -177,8 +176,7 @@ def wait_for_job(dataproc, project, job_id):
def get_client():
"""Builds an http client authenticated with the service account
credentials."""
credentials = GoogleCredentials.get_application_default()
dataproc = discovery.build('dataproc', 'v1', credentials=credentials)
dataproc = googleapiclient.discovery.build('dataproc', 'v1')
return dataproc
# [END get_client]

Expand Down
9 changes: 3 additions & 6 deletions dataproc/list_clusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@

import argparse

from apiclient import discovery
from oauth2client.client import GoogleCredentials
import googleapiclient.discovery

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

# [START get_client]
def get_client():
"""Builds an http client authenticated with the service account
credentials."""
credentials = GoogleCredentials.get_application_default()
dataproc = discovery.build('dataproc', 'v1', credentials=credentials)
"""Builds a client to the dataproc API."""
dataproc = googleapiclient.discovery.build('dataproc', 'v1')
return dataproc
# [END get_client]

Expand Down
Loading

0 comments on commit a2d8238

Please sign in to comment.