Skip to content

Commit

Permalink
Always try to refresh token, start flow if fail (#965)
Browse files Browse the repository at this point in the history
Signed-off-by: Yee Hing Tong <[email protected]>
  • Loading branch information
wild-endeavor authored Apr 20, 2022
1 parent f975f27 commit 7a7d723
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
6 changes: 3 additions & 3 deletions flytekit/clients/raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ def handler(*args, **kwargs):
elif e.code() == grpc.StatusCode.NOT_FOUND:
raise _user_exceptions.FlyteEntityNotExistException(e)
else:
print(e)
# No more retries if retry=False or max_retries reached.
if (retry is False) or i == (max_retries - 1):
raise
Expand Down Expand Up @@ -195,9 +194,10 @@ def _refresh_credentials_standard(self):
# metadata field yet. Therefore, if there's a mismatch, copy it over.
self.set_access_token(client.credentials.access_token, authorization_header_key)
return
elif client.can_refresh_token:

try:
client.refresh_access_token()
else:
except ValueError:
client.start_authorization_flow()

self.set_access_token(client.credentials.access_token, authorization_header_key)
Expand Down
6 changes: 1 addition & 5 deletions flytekit/clis/auth/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,6 @@ def set_tokens_from_store(self):
def has_valid_credentials(self) -> bool:
return self._credentials is not None

@property
def can_refresh_token(self) -> bool:
return self._refresh_token is not None

def start_authorization_flow(self):
# In the absence of globally-set token values, initiate the token request flow
ctx = _mp_get_context("fork")
Expand Down Expand Up @@ -292,7 +288,7 @@ def refresh_access_token(self):

_keyring.delete_password(_keyring_service_name, _keyring_access_token_storage_key)
_keyring.delete_password(_keyring_service_name, _keyring_refresh_token_storage_key)
return
raise ValueError(f"Non-200 returned from refresh token endpoint {resp.status_code}")
self._initialize_credentials(resp)

@property
Expand Down

0 comments on commit 7a7d723

Please sign in to comment.