Skip to content
This repository was archived by the owner on Mar 13, 2022. It is now read-only.

Commit cfae0d6

Browse files
committed
Make dependancy adal optional
1 parent 5c242ea commit cfae0d6

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

config/kube_config.py

+23-16
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import tempfile
2222
import time
2323

24-
import adal
2524
import google.auth
2625
import google.auth.transport.requests
2726
import oauthlib.oauth2
@@ -36,6 +35,11 @@
3635
from .config_exception import ConfigException
3736
from .dateutil import UTC, format_rfc3339, parse_rfc3339
3837

38+
try:
39+
import adal
40+
except ImportError:
41+
pass
42+
3943
EXPIRY_SKEW_PREVENTION_DELAY = datetime.timedelta(minutes=5)
4044
KUBE_CONFIG_DEFAULT_LOCATION = os.environ.get('KUBECONFIG', '~/.kube/config')
4145
_temp_files = {}
@@ -218,21 +222,24 @@ def _load_azure_token(self, provider):
218222
return self.token
219223

220224
def _refresh_azure_token(self, config):
221-
tenant = config['tenant-id']
222-
authority = 'https://login.microsoftonline.com/{}'.format(tenant)
223-
context = adal.AuthenticationContext(
224-
authority, validate_authority=True,
225-
)
226-
refresh_token = config['refresh-token']
227-
client_id = config['client-id']
228-
token_response = context.acquire_token_with_refresh_token(
229-
refresh_token, client_id, '00000002-0000-0000-c000-000000000000')
230-
231-
provider = self._user['auth-provider']['config']
232-
provider.value['access-token'] = token_response['accessToken']
233-
provider.value['expires-on'] = token_response['expiresOn']
234-
if self._config_persister:
235-
self._config_persister(self._config.value)
225+
if 'adal' not in globals():
226+
raise ImportError('refresh token error, adal library not imported')
227+
else:
228+
tenant = config['tenant-id']
229+
authority = 'https://login.microsoftonline.com/{}'.format(tenant)
230+
context = adal.AuthenticationContext(
231+
authority, validate_authority=True,
232+
)
233+
refresh_token = config['refresh-token']
234+
client_id = config['client-id']
235+
token_response = context.acquire_token_with_refresh_token(
236+
refresh_token, client_id, '00000002-0000-0000-c000-000000000000')
237+
238+
provider = self._user['auth-provider']['config']
239+
provider.value['access-token'] = token_response['accessToken']
240+
provider.value['expires-on'] = token_response['expiresOn']
241+
if self._config_persister:
242+
self._config_persister(self._config.value)
236243

237244
def _load_gcp_token(self, provider):
238245
if (('config' not in provider) or

0 commit comments

Comments
 (0)