Skip to content

Commit

Permalink
Merge pull request #219 from ynput/enhancement/allow-to-bypass-servic…
Browse files Browse the repository at this point in the history
…e-error

As username functionality can ignore service user error
  • Loading branch information
iLLiCiTiT authored Nov 28, 2024
2 parents bf7b938 + c153eef commit 7e2b9b4
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion ayon_api/server_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -842,13 +842,15 @@ def set_default_service_username(self, username=None):
self._update_session_headers()

@contextmanager
def as_username(self, username):
def as_username(self, username, ignore_service_error=False):
"""Service API will temporarily work as other user.
This method can be used only if service API key is logged in.
Args:
username (Union[str, None]): Username to work as when service.
ignore_service_error (Optional[bool]): Ignore error when service
API key is not used.
Raises:
ValueError: When connection is not yet authenticated or api key
Expand All @@ -861,6 +863,9 @@ def as_username(self, username):
)

if not self._access_token_is_service:
if ignore_service_error:
yield None
return
raise ValueError(
"Can't set service username. API key is not a service token."
)
Expand Down

0 comments on commit 7e2b9b4

Please sign in to comment.