12
12
import cs3 .rpc .v1beta1 .code_pb2 as cs3code
13
13
import cs3 .rpc .v1beta1 .status_pb2 as cs3status
14
14
15
- from .exceptions import AuthenticationException , NotFoundException , \
15
+ from .exceptions import AuthenticationException , PermissionDeniedException , NotFoundException , \
16
16
UnknownException , AlreadyExistsException , FileLockedException , UnimplementedException
17
17
from .config import Config
18
18
@@ -38,6 +38,15 @@ def _log_authentication_error(
38
38
f'trace="{ status .trace } " reason="{ status_msg } "'
39
39
)
40
40
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
+
41
50
def _log_unknown_error (self , status : cs3status .Status , operation : str , status_msg : str , msg : Optional [str ] = None ) -> None :
42
51
self ._log .error (
43
52
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[
90
99
if status .code == cs3code .CODE_UNAUTHENTICATED :
91
100
self ._log_authentication_error (status , operation , status_message , msg )
92
101
raise AuthenticationException
102
+ if status .code == cs3code .CODE_PERMISSION_DENIED :
103
+ self ._log_permission_denied_info (status , operation , status_message , msg )
104
+ raise PermissionDeniedException
93
105
if status .code != cs3code .CODE_OK :
94
106
if "path not found" in str (status .message ).lower ():
95
107
self ._log .info (f'msg="Invoked { operation } on missing file" ' )
0 commit comments