From 89840a049edf7e25cf802a4995a8d22be93987cc Mon Sep 17 00:00:00 2001 From: Bu Sun Kim <8822365+busunkim96@users.noreply.github.com> Date: Fri, 3 Apr 2020 14:51:02 -0700 Subject: [PATCH] Remove oauth2client from IoT and Functions samples (#3255) * chore: remove oauth2client from functions and iot * fix: fix import * fix: correct syntax * fix: correct import for service_account * fix: fix path --- functions/billing/main.py | 6 +----- functions/billing/requirements.txt | 1 - functions/slack/requirements.txt | 1 - .../end_to_end_example/cloudiot_pubsub_example_server.py | 6 +++--- iot/api-client/end_to_end_example/requirements.txt | 1 - iot/api-client/manager/requirements.txt | 1 - 6 files changed, 4 insertions(+), 12 deletions(-) diff --git a/functions/billing/main.py b/functions/billing/main.py index 9f5c5069bb0b..9d0a10e4ae9f 100644 --- a/functions/billing/main.py +++ b/functions/billing/main.py @@ -26,7 +26,6 @@ # [START functions_billing_limit_appengine] # [START functions_billing_stop] from googleapiclient import discovery -from oauth2client.client import GoogleCredentials # [END functions_billing_stop] # [END functions_billing_limit] # [END functions_billing_limit_appengine] @@ -80,7 +79,6 @@ def stop_billing(data, context): 'cloudbilling', 'v1', cache_discovery=False, - credentials=GoogleCredentials.get_application_default() ) projects = billing.projects() @@ -130,7 +128,6 @@ def limit_use(data, context): 'compute', 'v1', cache_discovery=False, - credentials=GoogleCredentials.get_application_default() ) instances = compute.instances() @@ -190,8 +187,7 @@ def limit_use_appengine(data, context): appengine = discovery.build( 'appengine', 'v1', - cache_discovery=False, - credentials=GoogleCredentials.get_application_default() + cache_discovery=False ) apps = appengine.apps() diff --git a/functions/billing/requirements.txt b/functions/billing/requirements.txt index b7c54be587d4..ccde2ed93d5b 100644 --- a/functions/billing/requirements.txt +++ b/functions/billing/requirements.txt @@ -1,5 +1,4 @@ slackclient==2.5.0 # [START functions_billing_limit_appengine_deps] -oauth2client==4.1.3 google-api-python-client==1.7.11 # [START functions_billing_limit_appengine_deps] \ No newline at end of file diff --git a/functions/slack/requirements.txt b/functions/slack/requirements.txt index 531c3121b649..6fc04a641f65 100644 --- a/functions/slack/requirements.txt +++ b/functions/slack/requirements.txt @@ -1,4 +1,3 @@ google-api-python-client==1.7.11 flask==1.1.1 -oauth2client==4.1.3 slackeventsapi==2.1.0 diff --git a/iot/api-client/end_to_end_example/cloudiot_pubsub_example_server.py b/iot/api-client/end_to_end_example/cloudiot_pubsub_example_server.py index cbac82869bb7..c04a2b9e1af8 100644 --- a/iot/api-client/end_to_end_example/cloudiot_pubsub_example_server.py +++ b/iot/api-client/end_to_end_example/cloudiot_pubsub_example_server.py @@ -45,7 +45,7 @@ from google.cloud import pubsub from googleapiclient import discovery from googleapiclient.errors import HttpError -from oauth2client.service_account import ServiceAccountCredentials +from google.oauth2 import service_account API_SCOPES = ['https://www.googleapis.com/auth/cloud-platform'] @@ -58,8 +58,8 @@ class Server(object): """Represents the state of the server.""" def __init__(self, service_account_json): - credentials = ServiceAccountCredentials.from_json_keyfile_name( - service_account_json, API_SCOPES) + credentials = service_account.Credentials.from_service_account_file( + service_account_json).with_scopes(API_SCOPES) if not credentials: sys.exit('Could not load service account credential ' 'from {}'.format(service_account_json)) diff --git a/iot/api-client/end_to_end_example/requirements.txt b/iot/api-client/end_to_end_example/requirements.txt index e828bbcd011f..5a438c5490b6 100644 --- a/iot/api-client/end_to_end_example/requirements.txt +++ b/iot/api-client/end_to_end_example/requirements.txt @@ -3,6 +3,5 @@ google-api-python-client==1.7.11 google-auth-httplib2==0.0.3 google-auth==1.11.2 google-cloud-pubsub==1.1.0 -oauth2client==4.1.3 pyjwt==1.7.1 paho-mqtt==1.5.0 diff --git a/iot/api-client/manager/requirements.txt b/iot/api-client/manager/requirements.txt index cb7e7e6fbf35..57e32880a911 100644 --- a/iot/api-client/manager/requirements.txt +++ b/iot/api-client/manager/requirements.txt @@ -5,6 +5,5 @@ google-auth-httplib2==0.0.3 google-auth==1.11.2 google-cloud-iot==1.0.0 google-cloud-pubsub==1.1.0 -oauth2client==4.1.3 paho-mqtt==1.5.0 pyjwt==1.7.1