From b77b53a3531ad3926a02b404054b47099c5b1ce1 Mon Sep 17 00:00:00 2001 From: Shivanand masne <82639825+shivanand007@users.noreply.github.com> Date: Tue, 8 Oct 2024 09:09:47 +0000 Subject: [PATCH 1/3] google-auth Made as optional dependency --- requirements.txt | 1 - setup.py | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index bc6dc4dc00..da405abdc7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 diff --git a/setup.py b/setup.py index 74eb82d631..31cab1748b 100644 --- a/setup.py +++ b/setup.py @@ -29,6 +29,7 @@ EXTRAS = { 'adal': ['adal>=1.0.2'] + 'google-auth': ['google-auth>=1.0.0'] } REQUIRES = [] with open('requirements.txt') as f: From cc9ab0e010169bef41e4518cc345e5ccb50b5f31 Mon Sep 17 00:00:00 2001 From: Shivanand masne <82639825+shivanand007@users.noreply.github.com> Date: Tue, 8 Oct 2024 09:14:36 +0000 Subject: [PATCH 2/3] google-auth Made as optional dependency --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 31cab1748b..7d8943b7b2 100644 --- a/setup.py +++ b/setup.py @@ -28,7 +28,7 @@ # http://pypi.python.org/pypi/setuptools EXTRAS = { - 'adal': ['adal>=1.0.2'] + 'adal': ['adal>=1.0.2'], 'google-auth': ['google-auth>=1.0.0'] } REQUIRES = [] From 4522098b30b753bcf016baaca7a7200f3c65d7fb Mon Sep 17 00:00:00 2001 From: Shivanand masne <82639825+shivanand007@users.noreply.github.com> Date: Wed, 9 Oct 2024 10:30:32 +0000 Subject: [PATCH 3/3] Made google_auth Depedent Code Block Optional, It will execute only if google_auth is installed. --- kubernetes/base/config/kube_config.py | 33 ++++++++++++++++++--------- setup.py | 2 +- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/kubernetes/base/config/kube_config.py b/kubernetes/base/config/kube_config.py index 09cda8bda0..4f68c94064 100644 --- a/kubernetes/base/config/kube_config.py +++ b/kubernetes/base/config/kube_config.py @@ -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 @@ -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 ':' @@ -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: diff --git a/setup.py b/setup.py index 7d8943b7b2..67eb782be5 100644 --- a/setup.py +++ b/setup.py @@ -29,7 +29,7 @@ EXTRAS = { 'adal': ['adal>=1.0.2'], - 'google-auth': ['google-auth>=1.0.0'] + 'google-auth': ['google-auth>=1.0.1'] } REQUIRES = [] with open('requirements.txt') as f: