Show the current authentication status.
()
| 1081 | |
| 1082 | @app.command() |
| 1083 | def whoami() -> None: |
| 1084 | """Show the current authentication status.""" |
| 1085 | from opentrace_agent.cli.auth import load_tokens |
| 1086 | from opentrace_agent.cli.config import find_config, load_config |
| 1087 | from opentrace_agent.cli.credentials import load_org_token |
| 1088 | |
| 1089 | tokens = load_tokens() |
| 1090 | if not tokens: |
| 1091 | click.echo("Not logged in. Run 'opentraceai login' to authenticate.") |
| 1092 | return |
| 1093 | |
| 1094 | issuer = tokens.get("issuer", "unknown") |
| 1095 | scope = tokens.get("scope", "none") |
| 1096 | access_token = tokens.get("access_token", "") |
| 1097 | token_type = "user (otuat)" if access_token.startswith("otuat_") else "org-scoped (legacy)" |
| 1098 | created = tokens.get("created_at") |
| 1099 | |
| 1100 | click.echo(f"Issuer: {issuer}") |
| 1101 | click.echo(f"Type: {token_type}") |
| 1102 | click.echo(f"Scope: {scope}") |
| 1103 | if isinstance(created, (int, float)): |
| 1104 | from datetime import datetime, timezone |
| 1105 | |
| 1106 | dt = datetime.fromtimestamp(created, tz=timezone.utc) |
| 1107 | click.echo(f"Issued: {dt:%Y-%m-%d %H:%M:%S UTC}") |
| 1108 | |
| 1109 | # Show project org context |
| 1110 | ot_dir = _find_opentrace_dir() |
| 1111 | config_path = find_config(ot_dir) |
| 1112 | if config_path is not None: |
| 1113 | config = load_config(config_path) |
| 1114 | org = config.get("org") |
| 1115 | if org: |
| 1116 | org_token = load_org_token(org) |
| 1117 | if org_token: |
| 1118 | click.echo(f"Org: {org} (token cached)") |
| 1119 | else: |
| 1120 | try: |
| 1121 | from opentrace_agent.cli.auth import resolve_org_token |
| 1122 | |
| 1123 | resolve_org_token(org) |
| 1124 | click.echo(f"Org: {org} (token resolved)") |
| 1125 | except RuntimeError as exc: |
| 1126 | click.echo(f"Org: {org} (exchange failed: {exc})") |
| 1127 | |
| 1128 | |
| 1129 | @app.command() |
nothing calls this directly
no test coverage detected