Skip to content

Commit a5754d5

Browse files
authored
Saimon/identify task perm error (#357)
1 parent 65883d5 commit a5754d5

4 files changed

Lines changed: 49 additions & 7 deletions

File tree

cterasdk/cio/common.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ def __getitem__(self, key):
110110
def __eq__(self, p):
111111
return self.absolute == p.absolute
112112

113+
def __repr__(self):
114+
return str(f"'{self}'")
115+
113116
def __str__(self):
114117
return self.relative
115118

cterasdk/cio/core/commands.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,25 +1027,40 @@ def _before_command(self):
10271027
def _task_complete(self, task):
10281028
return [str(path) for path in self.paths]
10291029

1030+
@property
1031+
@abstractmethod
1032+
def _error_object(self):
1033+
raise NotImplementedError('Subclass must implement the "_error_object" property.')
1034+
1035+
def _task_error(self, task):
1036+
cursor = task.cursor
1037+
error = self._error_object(self.paths, cursor)
1038+
1039+
if task.error_type == ResourceError.PermissionDenied:
1040+
resource = automatic_resolution(cursor).relative
1041+
raise error from exceptions.io.core.PrivilegeError(resource)
1042+
1043+
raise error
1044+
10301045

10311046
class Delete(MultiResourceCommand):
10321047

10331048
def _progress_str(self):
10341049
return 'Deleting'
10351050

1036-
def _task_error(self, task):
1037-
cursor = task.cursor
1038-
raise exceptions.io.core.DeleteError(self.paths, cursor)
1051+
@property
1052+
def _error_object(self):
1053+
return exceptions.io.core.DeleteError
10391054

10401055

10411056
class Recover(MultiResourceCommand):
10421057

10431058
def _progress_str(self):
10441059
return 'Recovering'
10451060

1046-
def _task_error(self, task):
1047-
cursor = task.cursor
1048-
raise exceptions.io.core.RecoverError(self.paths, cursor)
1061+
@property
1062+
def _error_object(self):
1063+
return exceptions.io.core.RecoverError
10491064

10501065

10511066
class ResolverCommand(TaskCommand):
@@ -1132,7 +1147,7 @@ def _task_error(self, task):
11321147
)
11331148
raise error from exceptions.io.core.FolderNotFoundError(directory.relative)
11341149

1135-
raise self._error_object(self.paths, cursor)
1150+
raise error
11361151

11371152

11381153
class Copy(ResolverCommand):

cterasdk/clients/clients.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,3 +436,24 @@ def new():
436436
async def new_response(response):
437437
return SyncResponse(response)
438438
return new_response
439+
440+
441+
class RestrictedAPI:
442+
443+
def __init__(self, name):
444+
self._name = name
445+
446+
def _raise_error(self):
447+
raise RuntimeError(f'{self._name} is unavailable in the current context.')
448+
449+
def __getattr__(self, _):
450+
self._raise_error()
451+
452+
def __call__(self, *_args, **_kwargs):
453+
self._raise_error()
454+
455+
def __bool__(self):
456+
return False
457+
458+
def __repr__(self):
459+
return f'<{self._name} is unavailable in the current context>'

cterasdk/objects/synchronous/edge.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ def __init__(self, edge, Portal):
2323
edge._Portal = Portal
2424
edge.default.close()
2525
edge._ctera_session.start_remote_session(Portal.session())
26+
self.migrate = clients.RestrictedAPI('migrate')
2627
self.api = Portal.default.clone(clients.API, EndpointBuilder.new(edge.base), authenticator=lambda *_: True)
28+
self.stats = clients.RestrictedAPI('stats')
29+
self.io = clients.RestrictedAPI('io')
2730
else:
2831
self.migrate = edge.default.clone(clients.Migrate, EndpointBuilder.new(edge.base, '/migration/rest/v1'))
2932
self.api = edge.default.clone(clients.API, EndpointBuilder.new(edge.base, '/admingui/api'))

0 commit comments

Comments
 (0)