Skip to content

Commit

Permalink
Fix Context repr when authenticated as service (bluesky#760)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielballan authored Jun 18, 2024
1 parent ef22635 commit 86ea335
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions tiled/_tests/test_authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
11 changes: 8 additions & 3 deletions tiled/client/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)]}...'"
Expand Down

0 comments on commit 86ea335

Please sign in to comment.