Skip to content

Commit 6d46363

Browse files
committed
Introduced a permission denied exception
1 parent 897250d commit 6d46363

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

cs3client/exceptions/__init__.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ def __init__(self, message: str = "Operation not permitted"):
1919
super().__init__(message)
2020

2121

22+
class PermissionDeniedException(IOError):
23+
"""
24+
Standard permission denied message
25+
"""
26+
27+
def __init__(self, message: str = "Permission denied"):
28+
super().__init__(message)
29+
30+
2231
class NotFoundException(IOError):
2332
"""
2433
Standard file missing message
@@ -47,15 +56,6 @@ def __init__(self, message: str = "Lock mismatch"):
4756
super().__init__(message)
4857

4958

50-
class UnknownException(Exception):
51-
"""
52-
Standard exception to be thrown when we get an error that is unknown, e.g. not defined in the cs3api
53-
"""
54-
55-
def __init__(self, message: str = ""):
56-
super().__init__(message)
57-
58-
5959
class AlreadyExistsException(IOError):
6060
"""
6161
Standard error thrown when attempting to create a resource that already exists
@@ -72,3 +72,13 @@ class UnimplementedException(Exception):
7272

7373
def __init__(self, message: str = "Not implemented"):
7474
super().__init__(message)
75+
76+
77+
class UnknownException(Exception):
78+
"""
79+
Standard exception to be thrown when we get an error that is unknown, e.g. not defined in the cs3api
80+
"""
81+
82+
def __init__(self, message: str = ""):
83+
super().__init__(message)
84+

cs3client/statuscodehandler.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import cs3.rpc.v1beta1.code_pb2 as cs3code
1313
import 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
1717
from .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

Comments
 (0)