Skip to content

Commit c153eef

Browse files
committed
as_username does allow to ignore service user error
1 parent bf7b938 commit c153eef

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

ayon_api/server_api.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -842,13 +842,15 @@ def set_default_service_username(self, username=None):
842842
self._update_session_headers()
843843

844844
@contextmanager
845-
def as_username(self, username):
845+
def as_username(self, username, ignore_service_error=False):
846846
"""Service API will temporarily work as other user.
847847
848848
This method can be used only if service API key is logged in.
849849
850850
Args:
851851
username (Union[str, None]): Username to work as when service.
852+
ignore_service_error (Optional[bool]): Ignore error when service
853+
API key is not used.
852854
853855
Raises:
854856
ValueError: When connection is not yet authenticated or api key
@@ -861,6 +863,9 @@ def as_username(self, username):
861863
)
862864

863865
if not self._access_token_is_service:
866+
if ignore_service_error:
867+
yield None
868+
return
864869
raise ValueError(
865870
"Can't set service username. API key is not a service token."
866871
)

0 commit comments

Comments
 (0)