Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 0 additions & 32 deletions sdks/python/apache_beam/internal/gcp/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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'
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down