Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace oauth2client by google-auth #2361

Merged
merged 4 commits into from
Mar 5, 2018
Merged
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
2 changes: 1 addition & 1 deletion luigi/contrib/bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def __init__(self, oauth_credentials=None, descriptor='', http_=None):
if descriptor:
self.client = discovery.build_from_document(descriptor, **authenticate_kwargs)
else:
self.client = discovery.build('bigquery', 'v2', **authenticate_kwargs)
self.client = discovery.build('bigquery', 'v2', cache_discovery=False, **authenticate_kwargs)

def dataset_exists(self, dataset):
"""Returns whether the given dataset exists.
Expand Down
8 changes: 4 additions & 4 deletions luigi/contrib/dataproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
_dataproc_client = None

try:
import oauth2client.client
import google.auth
from googleapiclient import discovery
from googleapiclient.errors import HttpError

DEFAULT_CREDENTIALS = oauth2client.client.GoogleCredentials.get_application_default()
DEFAULT_CREDENTIALS, _ = google.auth.default()
authenticate_kwargs = gcp.get_authenticate_kwargs(DEFAULT_CREDENTIALS)
_dataproc_client = discovery.build('dataproc', 'v1', **authenticate_kwargs)
_dataproc_client = discovery.build('dataproc', 'v1', cache_discovery=False, **authenticate_kwargs)
except ImportError:
logger.warning("Loading Dataproc module without the python packages googleapiclient & oauth2client. \
logger.warning("Loading Dataproc module without the python packages googleapiclient & google-auth. \
This will crash at runtime if Dataproc functionality is used.")


Expand Down
10 changes: 5 additions & 5 deletions luigi/contrib/gcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

try:
import httplib2
import oauth2client
import google.auth
except ImportError:
logger.warning("Loading GCP module without the python packages httplib2, oauth2client. \
logger.warning("Loading GCP module without the python packages httplib2, google-auth. \
This *could* crash at runtime if no other credentials are provided.")


Expand All @@ -33,11 +33,11 @@ def get_authenticate_kwargs(oauth_credentials=None, http_=None):
# neither http_ or credentials provided
try:
# try default credentials
oauth_credentials = oauth2client.client.GoogleCredentials.get_application_default()
credentials, _ = google.auth.default()
authenticate_kwargs = {
"credentials": oauth_credentials
"credentials": credentials
}
except oauth2client.client.GoogleCredentials.ApplicationDefaultCredentialsError:
except google.auth.exceptions.DefaultCredentialsError:
# try http using httplib2
authenticate_kwargs = {
"http": httplib2.Http()
Expand Down
8 changes: 4 additions & 4 deletions luigi/contrib/gcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
from googleapiclient import discovery
from googleapiclient import http
except ImportError:
logger.warning("Loading GCS module without the python packages googleapiclient & oauth2client. \
logger.warning("Loading GCS module without the python packages googleapiclient & google-auth. \
This will crash at runtime if GCS functionality is used.")
else:
# Retry transport and file IO errors.
Expand Down Expand Up @@ -89,9 +89,9 @@ class GCSClient(luigi.target.FileSystem):

There are several ways to use this class. By default it will use the app
default credentials, as described at https://developers.google.com/identity/protocols/application-default-credentials .
Alternatively, you may pass an oauth2client credentials object. e.g. to use a service account::
Alternatively, you may pass an google-auth credentials object. e.g. to use a service account::

credentials = oauth2client.client.SignedJwtAssertionCredentials(
credentials = google.auth.jwt.Credentials.from_service_account_info(
'012345678912-ThisIsARandomServiceAccountEmail@developer.gserviceaccount.com',
'These are the contents of the p12 file that came with the service account',
scope='https://www.googleapis.com/auth/devstorage.read_write')
Expand All @@ -115,7 +115,7 @@ def __init__(self, oauth_credentials=None, descriptor='', http_=None,
if descriptor:
self.client = discovery.build_from_document(descriptor, **authenticate_kwargs)
else:
self.client = discovery.build('storage', 'v1', **authenticate_kwargs)
self.client = discovery.build('storage', 'v1', cache_discovery=False, **authenticate_kwargs)

def _path_to_bucket_and_key(self, path):
(scheme, netloc, path, _, _) = urlsplit(path)
Expand Down
4 changes: 2 additions & 2 deletions test/contrib/bigquery_gcloud_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

try:
import googleapiclient.errors
import oauth2client
import google.auth
except ImportError:
raise unittest.SkipTest('Unable to load googleapiclient module')
from luigi.contrib import bigquery, bigquery_avro, gcs
Expand All @@ -52,7 +52,7 @@
EU_LOCATION = 'EU'
US_LOCATION = 'US'

CREDENTIALS = oauth2client.client.GoogleCredentials.get_application_default()
CREDENTIALS, _ = google.auth.default()


def bucket_url(suffix):
Expand Down
6 changes: 3 additions & 3 deletions test/contrib/dataproc_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
import unittest

try:
import oauth2client
import google.auth
from luigi.contrib import dataproc
from googleapiclient import discovery

default_credentials = oauth2client.client.GoogleCredentials.get_application_default()
default_client = discovery.build('dataproc', 'v1', credentials=default_credentials)
default_credentials, _ = google.auth.default()
default_client = discovery.build('dataproc', 'v1', cache_discovery=False, credentials=default_credentials)
dataproc.set_dataproc_client(default_client)
except ImportError:
raise unittest.SkipTest('Unable to load google cloud dependencies')
Expand Down
4 changes: 2 additions & 2 deletions test/contrib/gcs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from helpers import unittest
try:
import googleapiclient.errors
import oauth2client
import google.auth
except ImportError:
raise unittest.SkipTest('Unable to load googleapiclient module')
import os
Expand All @@ -41,7 +41,7 @@
BUCKET_NAME = os.environ.get('GCS_TEST_BUCKET', 'your_test_bucket_here')
TEST_FOLDER = os.environ.get('TRAVIS_BUILD_ID', 'gcs_test_folder')

CREDENTIALS = oauth2client.client.GoogleCredentials.get_application_default()
CREDENTIALS, _ = google.auth.default()
ATTEMPTED_BUCKET_CREATE = False


Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ deps=
gcloud: google-api-python-client>=1.4.0,<2.0
py27-gcloud: avro
py33-gcloud,py34-gcloud,py35-gcloud,py36-gcloud: avro-python3
gcloud: oauth2client<4.0.0
gcloud: google-auth==1.4.1
google-compute-engine
coverage>=4.1,<4.2
codecov>=1.4.0
Expand Down