1212import cs3 .rpc .v1beta1 .code_pb2 as cs3code
1313import cs3 .rpc .v1beta1 .status_pb2 as cs3status
1414
15- from .exceptions import AuthenticationException , NotFoundException , \
15+ from .exceptions import AuthenticationException , PermissionDeniedException , NotFoundException , \
1616 UnknownException , AlreadyExistsException , FileLockedException , UnimplementedException
1717from .config import Config
1818
@@ -38,6 +38,15 @@ def _log_authentication_error(
3838 f'trace="{ status .trace } " reason="{ status_msg } "'
3939 )
4040
41+ def _log_permission_denied_info (
42+ self , status : cs3status .Status , operation : str , status_msg : str , msg : Optional [str ] = None
43+ ) -> None :
44+ self ._log .info (
45+ f'msg="Permission denied on { operation } " { msg + " " if msg else "" } '
46+ f'userid="{ self ._config .auth_client_id if self ._config .auth_client_id else "no_id_set" } " '
47+ f'trace="{ status .trace } " reason="{ status_msg } "'
48+ )
49+
4150 def _log_unknown_error (self , status : cs3status .Status , operation : str , status_msg : str , msg : Optional [str ] = None ) -> None :
4251 self ._log .error (
4352 f'msg="Failed to { operation } , unknown error" { msg + " " if msg else "" } '
@@ -90,6 +99,9 @@ def handle_errors(self, status: cs3status.Status, operation: str, msg: Optional[
9099 if status .code == cs3code .CODE_UNAUTHENTICATED :
91100 self ._log_authentication_error (status , operation , status_message , msg )
92101 raise AuthenticationException
102+ if status .code == cs3code .CODE_PERMISSION_DENIED :
103+ self ._log_permission_denied_info (status , operation , status_message , msg )
104+ raise PermissionDeniedException
93105 if status .code != cs3code .CODE_OK :
94106 if "path not found" in str (status .message ).lower ():
95107 self ._log .info (f'msg="Invoked { operation } on missing file" ' )
0 commit comments