MCPcopy Create free account
hub / github.com/dwavesystems/dwave-cloud-client / get

Function get

dwave/cloud/cli.py:1048–1076  ·  view source on GitHub ↗

Fetch Leap API token.

(*, config_file, profile, token_type, json_output, raw_output, output)

Source from the content-addressed store, hash-verified

1046@raw_output
1047@standardized_output
1048def get(*, config_file, profile, token_type, json_output, raw_output, output):
1049 """Fetch Leap API token."""
1050
1051 config = validate_config_v1(load_config(config_file=config_file, profile=profile))
1052
1053 with LeapAuthFlow.from_config_model(config) as flow:
1054 token_key = token_type.replace('-', '_')
1055 if not flow.token or not token_key in flow.token:
1056 raise CLIError('Token not found. Please run "dwave auth login".', code=100)
1057
1058 token_pretty = token_type.replace('-', ' ').capitalize()
1059 token_val = flow.token[token_key]
1060 output(f"{token_pretty}: {{%s}}" % token_key, **{token_key: token_val})
1061 output(raw=token_val)
1062
1063 if token_type == 'access-token':
1064 expires_at = flow.token.get('expires_at')
1065 if not expires_at:
1066 return
1067 expires_at = int(expires_at)
1068 expired = expires_at < epochnow()
1069
1070 output("Expires at: {expires_at_iso}Z (timestamp={expires_at}) ({is_valid})",
1071 expires_at_iso=datetime.utcfromtimestamp(expires_at).isoformat(),
1072 expires_at=expires_at,
1073 is_valid="expired" if expired else "valid")
1074
1075 if expired:
1076 output('\nTo refresh the token, please run "dwave auth refresh".')
1077
1078
1079@auth.command()

Callers

nothing calls this directly

Calls 7

validate_config_v1Function · 0.90
load_configFunction · 0.90
CLIErrorClass · 0.90
epochnowFunction · 0.90
outputFunction · 0.85
from_config_modelMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected