|
21 | 21 | import tempfile
|
22 | 22 | import time
|
23 | 23 |
|
24 |
| -import adal |
25 | 24 | import google.auth
|
26 | 25 | import google.auth.transport.requests
|
27 | 26 | import oauthlib.oauth2
|
|
36 | 35 | from .config_exception import ConfigException
|
37 | 36 | from .dateutil import UTC, format_rfc3339, parse_rfc3339
|
38 | 37 |
|
| 38 | +try: |
| 39 | + import adal |
| 40 | +except ImportError: |
| 41 | + pass |
| 42 | + |
39 | 43 | EXPIRY_SKEW_PREVENTION_DELAY = datetime.timedelta(minutes=5)
|
40 | 44 | KUBE_CONFIG_DEFAULT_LOCATION = os.environ.get('KUBECONFIG', '~/.kube/config')
|
41 | 45 | _temp_files = {}
|
@@ -218,21 +222,24 @@ def _load_azure_token(self, provider):
|
218 | 222 | return self.token
|
219 | 223 |
|
220 | 224 | 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) |
236 | 243 |
|
237 | 244 | def _load_gcp_token(self, provider):
|
238 | 245 | if (('config' not in provider) or
|
|
0 commit comments