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

google-auth Made as optional dependency #2294

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
33 changes: 22 additions & 11 deletions kubernetes/base/config/kube_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
import time
from collections import namedtuple

import google.auth
import google.auth.transport.requests
import oauthlib.oauth2
import urllib3
import yaml
Expand All @@ -44,6 +42,15 @@
except ImportError:
pass

try:
import google.auth
import google.auth.transport.requests
google_auth_available = True
except ImportError:
google_auth_available = False



EXPIRY_SKEW_PREVENTION_DELAY = datetime.timedelta(minutes=5)
KUBE_CONFIG_DEFAULT_LOCATION = os.environ.get('KUBECONFIG', '~/.kube/config')
ENV_KUBECONFIG_PATH_SEPARATOR = ';' if platform.system() == 'Windows' else ':'
Expand Down Expand Up @@ -239,15 +246,19 @@ def _refresh_credentials():
'config' in self._user['auth-provider'] and
'cmd-path' in self._user['auth-provider']['config']):
return _refresh_credentials_with_cmd_path()

credentials, project_id = google.auth.default(scopes=[
'https://www.googleapis.com/auth/cloud-platform',
'https://www.googleapis.com/auth/userinfo.email'
])
request = google.auth.transport.requests.Request()
credentials.refresh(request)
return credentials


# Make the Google auth block optional.
if google_auth_available:
credentials, project_id = google.auth.default(scopes=[
'https://www.googleapis.com/auth/cloud-platform',
'https://www.googleapis.com/auth/userinfo.email'
])
request = google.auth.transport.requests.Request()
credentials.refresh(request)
return credentials
else:
return None

if get_google_credentials:
self._get_google_credentials = get_google_credentials
else:
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ six>=1.9.0 # MIT
python-dateutil>=2.5.3 # BSD
setuptools>=21.0.0 # PSF/ZPL
pyyaml>=5.4.1 # MIT
google-auth>=1.0.1 # Apache-2.0
websocket-client>=0.32.0,!=0.40.0,!=0.41.*,!=0.42.* # LGPLv2+
requests # Apache-2.0
requests-oauthlib # ISC
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
# http://pypi.python.org/pypi/setuptools

EXTRAS = {
'adal': ['adal>=1.0.2']
'adal': ['adal>=1.0.2'],
'google-auth': ['google-auth>=1.0.1']
}
REQUIRES = []
with open('requirements.txt') as f:
Expand Down