From 86ea3351b25df7725485fc57e540c0aa22552eac Mon Sep 17 00:00:00 2001 From: Dan Allan Date: Tue, 18 Jun 2024 14:09:07 -0400 Subject: [PATCH] Fix Context repr when authenticated as service (#760) --- CHANGELOG.md | 6 ++++++ tiled/_tests/test_authentication.py | 3 +++ tiled/client/context.py | 11 ++++++++--- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 86d8982d8..77521a652 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,12 @@ Write the date in place of the "Unreleased" in the case a new version is release # Changelog +## Unreleased + +### Fixed +- When authenticated as a Service Principal, display the SP's uuid in + the client Context repr. + ## v0.1.0b4 (2024-06-18) ### Changed diff --git a/tiled/_tests/test_authentication.py b/tiled/_tests/test_authentication.py index 5ad3fd3a1..519ec5261 100644 --- a/tiled/_tests/test_authentication.py +++ b/tiled/_tests/test_authentication.py @@ -591,6 +591,9 @@ def test_admin_create_service_principal(enter_password, principals_context): context.api_key = service_api_key_info["secret"] assert context.whoami()["type"] == "service" + # Test service repr + assert f"authenticated as service '{principal_uuid}'" in repr(context) + def test_admin_api_key_any_principal_exceeds_scopes(enter_password, principals_context): """ diff --git a/tiled/client/context.py b/tiled/client/context.py index a5ae197d9..8cfb2baa2 100644 --- a/tiled/client/context.py +++ b/tiled/client/context.py @@ -168,9 +168,14 @@ def __repr__(self): if self.server_info["authentication"].get("links"): whoami = self.whoami() auth_info.append("as") - auth_info.append( - ",".join(f"'{identity['id']}'" for identity in whoami["identities"]) - ) + if whoami["type"] == "service": + auth_info.append(f"service '{whoami['uuid']}'") + else: + auth_info.append( + ",".join( + f"'{identity['id']}'" for identity in whoami["identities"] + ) + ) if self.api_key is not None: auth_info.append( f"with API key '{self.api_key[:min(len(self.api_key)//2, 8)]}...'"