From b3f948e5773860bdce75e098efd6115c62263ce7 Mon Sep 17 00:00:00 2001 From: Dan Allan Date: Thu, 9 Jan 2025 10:12:07 -0500 Subject: [PATCH] Add whoami --- tiled/commandline/main.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tiled/commandline/main.py b/tiled/commandline/main.py index 41af9643b..f7a229232 100644 --- a/tiled/commandline/main.py +++ b/tiled/commandline/main.py @@ -78,6 +78,28 @@ def login( typer.echo(json.dumps(dict(context.tokens), indent=4)) +@cli_app.command("whoami") +def whoami( + profile: Optional[str] = typer.Option( + None, help="If you use more than one Tiled server, use this to specify which." + ), +): + """ + Show logged in identity. + """ + from ..client.context import Context + + profile_name, profile_content = get_profile(profile) + options = {"verify": profile_content.get("verify", True)} + context, _ = Context.from_any_uri(profile_content["uri"], **options) + context.use_cached_tokens() + whoami = context.whoami() + if whoami is None: + typer.echo("Not authenticated.") + else: + typer.echo(",".join(identity["id"] for identity in whoami["identities"])) + + @cli_app.command("logout") def logout( profile: Optional[str] = typer.Option(