Skip to content

Commit

Permalink
Show auth state in Context repr.
Browse files Browse the repository at this point in the history
  • Loading branch information
danielballan committed May 16, 2024
1 parent 307524d commit 545f055
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tiled/client/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,23 @@ def __init__(
self.api_key = api_key # property setter sets Authorization header
self.admin = Admin(self) # accessor for admin-related requests

def __repr__(self):
auth_info = []
if (self.api_key is None) and (self.http_client.auth is None):
auth_info.append("(unauthenticated)")
else:
auth_info.append("authenticated")
identities = self.whoami()["identities"]
if identities:
auth_info.append("as")
auth_info.append(
",".join(f"'{identity['id']}'" for identity in identities)
)
if self.api_key is not None:
auth_info.append(f"with API key '{self.api_key[:8]}...'")
auth_repr = " ".join(auth_info)
return f"<{type(self).__name__} {auth_repr}>"

def __enter__(self):
return self

Expand Down

0 comments on commit 545f055

Please sign in to comment.