Skip to content

Commit 4522098

Browse files
committed
Made google_auth Depedent Code Block Optional, It will execute only if google_auth is installed.
1 parent cc9ab0e commit 4522098

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

kubernetes/base/config/kube_config.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
import time
2626
from collections import namedtuple
2727

28-
import google.auth
29-
import google.auth.transport.requests
3028
import oauthlib.oauth2
3129
import urllib3
3230
import yaml
@@ -44,6 +42,15 @@
4442
except ImportError:
4543
pass
4644

45+
try:
46+
import google.auth
47+
import google.auth.transport.requests
48+
google_auth_available = True
49+
except ImportError:
50+
google_auth_available = False
51+
52+
53+
4754
EXPIRY_SKEW_PREVENTION_DELAY = datetime.timedelta(minutes=5)
4855
KUBE_CONFIG_DEFAULT_LOCATION = os.environ.get('KUBECONFIG', '~/.kube/config')
4956
ENV_KUBECONFIG_PATH_SEPARATOR = ';' if platform.system() == 'Windows' else ':'
@@ -239,15 +246,19 @@ def _refresh_credentials():
239246
'config' in self._user['auth-provider'] and
240247
'cmd-path' in self._user['auth-provider']['config']):
241248
return _refresh_credentials_with_cmd_path()
242-
243-
credentials, project_id = google.auth.default(scopes=[
244-
'https://www.googleapis.com/auth/cloud-platform',
245-
'https://www.googleapis.com/auth/userinfo.email'
246-
])
247-
request = google.auth.transport.requests.Request()
248-
credentials.refresh(request)
249-
return credentials
250-
249+
250+
# Make the Google auth block optional.
251+
if google_auth_available:
252+
credentials, project_id = google.auth.default(scopes=[
253+
'https://www.googleapis.com/auth/cloud-platform',
254+
'https://www.googleapis.com/auth/userinfo.email'
255+
])
256+
request = google.auth.transport.requests.Request()
257+
credentials.refresh(request)
258+
return credentials
259+
else:
260+
return None
261+
251262
if get_google_credentials:
252263
self._get_google_credentials = get_google_credentials
253264
else:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
EXTRAS = {
3131
'adal': ['adal>=1.0.2'],
32-
'google-auth': ['google-auth>=1.0.0']
32+
'google-auth': ['google-auth>=1.0.1']
3333
}
3434
REQUIRES = []
3535
with open('requirements.txt') as f:

0 commit comments

Comments
 (0)