Revoke access and/or refresh token(s) for Leap API.
(*, config_file, profile, token_type, json_output, output)
| 1103 | @json_output |
| 1104 | @standardized_output |
| 1105 | def revoke(*, config_file, profile, token_type, json_output, output): |
| 1106 | """Revoke access and/or refresh token(s) for Leap API.""" |
| 1107 | |
| 1108 | token_key = token_type.replace('-', '_') |
| 1109 | token_pretty = token_type.replace('-', ' ').capitalize() |
| 1110 | |
| 1111 | config = validate_config_v1(load_config(config_file=config_file, profile=profile)) |
| 1112 | |
| 1113 | with LeapAuthFlow.from_config_model(config) as flow: |
| 1114 | if not flow.token or not token_key in flow.token: |
| 1115 | raise CLIError('Token not found. Please run "dwave auth login".', code=100) |
| 1116 | |
| 1117 | # revoke |
| 1118 | revoked = flow.revoke_token(token=flow.token[token_key], token_type_hint=token_key) |
| 1119 | |
| 1120 | if not revoked: |
| 1121 | raise CLIError(f'{token_pretty} revocation failed.', code=102) |
| 1122 | |
| 1123 | output(f'{token_pretty} successfully revoked.') |
| 1124 | |
| 1125 | |
| 1126 | @cli.group() |
nothing calls this directly
no test coverage detected