Skip to content

Commit

Permalink
#7 store the new token
Browse files Browse the repository at this point in the history
  • Loading branch information
hjacobs committed Nov 19, 2015
1 parent 1ad9629 commit db30400
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions zign/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ def get_existing_token(name: str) -> dict:
return existing_token


def store_token(name: str, result: dict):
data = get_tokens()

data[name] = result
data[name]['creation_time'] = time.time()

with open(TOKENS_FILE_PATH, 'w') as fd:
yaml.safe_dump(data, fd)


def get_named_token(scope, realm, name, user, password, url=None,
insecure=False, refresh=False, use_keyring=True, prompt=False):
'''get named access token, return existing if still valid'''
Expand Down Expand Up @@ -126,13 +136,7 @@ def get_named_token(scope, realm, name, user, password, url=None,
keyring.set_password(KEYRING_KEY, user, password)

if name:
data = get_tokens()

data[name] = result
data[name]['creation_time'] = time.time()

with open(TOKENS_FILE_PATH, 'w') as fd:
yaml.safe_dump(data, fd)
store_token(name, result)

return result

Expand Down Expand Up @@ -178,4 +182,5 @@ def get_token(name: str, scopes: list):
token = get_new_token(config.get('realm'), scopes, user, password,
url=config.get('url'), insecure=config.get('insecure'))
if token:
store_token(name, token)
return token['access_token']

0 comments on commit db30400

Please sign in to comment.