From 189d73471f5924c3622fa014f658757d736373af Mon Sep 17 00:00:00 2001 From: Sourabh Bajaj Date: Wed, 3 May 2017 13:50:46 -0700 Subject: [PATCH] [BEAM-2152] Remove gcloud auth as application default credentials does it --- sdks/python/apache_beam/internal/gcp/auth.py | 32 ------------------- .../runners/dataflow/internal/apiclient.py | 3 +- 2 files changed, 1 insertion(+), 34 deletions(-) diff --git a/sdks/python/apache_beam/internal/gcp/auth.py b/sdks/python/apache_beam/internal/gcp/auth.py index 53c2d077c8aa..3c8dd64d9759 100644 --- a/sdks/python/apache_beam/internal/gcp/auth.py +++ b/sdks/python/apache_beam/internal/gcp/auth.py @@ -26,7 +26,6 @@ from oauth2client.client import GoogleCredentials from oauth2client.client import OAuth2Credentials -from apache_beam.utils import processes from apache_beam.utils import retry @@ -94,27 +93,6 @@ def _refresh(self, http_request): datetime.timedelta(seconds=token_data['expires_in'])) -class _GCloudWrapperCredentials(OAuth2Credentials): - """Credentials class wrapping gcloud credentials via shell.""" - - def __init__(self, user_agent, **kwds): - super(_GCloudWrapperCredentials, self).__init__( - None, None, None, None, None, None, user_agent, **kwds) - - def _refresh(self, http_request): - """Gets an access token using the gcloud client.""" - try: - gcloud_process = processes.Popen( - ['gcloud', 'auth', 'print-access-token'], stdout=processes.PIPE) - except OSError: - message = 'gcloud tool not found so falling back to using ' +\ - 'application default credentials' - logging.warning(message) - raise AuthenticationException(message) - output, _ = gcloud_process.communicate() - self.access_token = output.strip() - - def get_service_credentials(): """Get credentials to access Google services.""" user_agent = 'beam-python-sdk/1.0' @@ -134,16 +112,6 @@ def get_service_credentials(): 'https://www.googleapis.com/auth/datastore' ] - try: - credentials = _GCloudWrapperCredentials(user_agent) - # Check if we are able to get an access token. If not fallback to - # application default credentials. - credentials.get_access_token() - return credentials - except AuthenticationException: - logging.warning('Unable to find credentials from gcloud.') - - # Falling back to application default credentials. try: credentials = GoogleCredentials.get_application_default() credentials = credentials.create_scoped(client_scopes) diff --git a/sdks/python/apache_beam/runners/dataflow/internal/apiclient.py b/sdks/python/apache_beam/runners/dataflow/internal/apiclient.py index 26ed7b694d9a..e64cf8da3a13 100644 --- a/sdks/python/apache_beam/runners/dataflow/internal/apiclient.py +++ b/sdks/python/apache_beam/runners/dataflow/internal/apiclient.py @@ -411,8 +411,7 @@ def stage_file(self, gcs_or_local_path, file_name, stream, if e.status_code in reportable_errors: raise IOError(('Could not upload to GCS path %s: %s. Please verify ' 'that credentials are valid and that you have write ' - 'access to the specified path. Stale credentials can be ' - 'refreshed by executing "gcloud auth login".') % + 'access to the specified path.') % (gcs_or_local_path, reportable_errors[e.status_code])) raise logging.info('Completed GCS upload to %s', gcs_location)