2525from logging import getLogger
2626from copy import deepcopy
2727
28- # pylint:disable=unused-import # To prevent cyclical import errors forward referencing is used
2928# pylint:disable=cyclic-import # but pylint doesn't understand this feature
30- from . import archivist as type_helper
29+ from . import archivist as type_helper # pylint:disable=unused-import
3130
3231from .assets import Asset
3332from .constants import (
34- SEP ,
3533 ACCESS_POLICIES_SUBPATH ,
3634 ACCESS_POLICIES_LABEL ,
3735 ASSETS_LABEL ,
@@ -65,6 +63,8 @@ class _AccessPoliciesClient:
6563
6664 def __init__ (self , archivist : "type_helper.Archivist" ):
6765 self ._archivist = archivist
66+ self ._subpath = f"{ archivist .root } /{ ACCESS_POLICIES_SUBPATH } "
67+ self ._label = f"{ self ._subpath } /{ ACCESS_POLICIES_LABEL } "
6868
6969 def __str__ (self ) -> str :
7070 return f"AccessPoliciesClient({ self ._archivist .url } )"
@@ -107,7 +107,7 @@ def create_from_data(self, data: Dict) -> AccessPolicy:
107107 """
108108 return AccessPolicy (
109109 ** self ._archivist .post (
110- f"{ ACCESS_POLICIES_SUBPATH } /{ ACCESS_POLICIES_LABEL } " ,
110+ f"{ self . _subpath } /{ ACCESS_POLICIES_LABEL } " ,
111111 data ,
112112 )
113113 )
@@ -124,12 +124,7 @@ def read(self, identity: str) -> AccessPolicy:
124124 :class:`AccessPolicy` instance
125125
126126 """
127- return AccessPolicy (
128- ** self ._archivist .get (
129- ACCESS_POLICIES_SUBPATH ,
130- identity ,
131- )
132- )
127+ return AccessPolicy (** self ._archivist .get (f"{ self ._subpath } /{ identity } " ))
133128
134129 def update (
135130 self ,
@@ -154,8 +149,7 @@ def update(
154149 """
155150 return AccessPolicy (
156151 ** self ._archivist .patch (
157- ACCESS_POLICIES_SUBPATH ,
158- identity ,
152+ f"{ self ._subpath } /{ identity } " ,
159153 self .__params (
160154 props , filters = filters , access_permissions = access_permissions
161155 ),
@@ -174,7 +168,7 @@ def delete(self, identity: str) -> Dict:
174168 :class:`AccessPolicy` instance - empty?
175169
176170 """
177- return self ._archivist .delete (ACCESS_POLICIES_SUBPATH , identity )
171+ return self ._archivist .delete (f" { self . _subpath } / { identity } " )
178172
179173 def __params (
180174 self ,
@@ -205,10 +199,7 @@ def count(self, *, display_name: Optional[str] = None) -> int:
205199
206200 """
207201 params = {"display_name" : display_name } if display_name is not None else None
208- return self ._archivist .count (
209- f"{ ACCESS_POLICIES_SUBPATH } /{ ACCESS_POLICIES_LABEL } " ,
210- params = params ,
211- )
202+ return self ._archivist .count (self ._label , params = params )
212203
213204 def list (
214205 self , * , page_size : Optional [int ] = None , display_name : Optional [str ] = None
@@ -229,7 +220,7 @@ def list(
229220 return (
230221 AccessPolicy (** a )
231222 for a in self ._archivist .list (
232- f" { ACCESS_POLICIES_SUBPATH } / { ACCESS_POLICIES_LABEL } " ,
223+ self . _label ,
233224 ACCESS_POLICIES_LABEL ,
234225 page_size = page_size ,
235226 params = params ,
@@ -250,7 +241,7 @@ def count_matching_assets(self, access_policy_id: str) -> int:
250241
251242 """
252243 return self ._archivist .count (
253- SEP . join (( ACCESS_POLICIES_SUBPATH , access_policy_id , ASSETS_LABEL )),
244+ f" { self . _subpath } / { access_policy_id } / { ASSETS_LABEL } "
254245 )
255246
256247 def list_matching_assets (
@@ -271,7 +262,7 @@ def list_matching_assets(
271262 return (
272263 Asset (** a )
273264 for a in self ._archivist .list (
274- SEP . join (( ACCESS_POLICIES_SUBPATH , access_policy_id , ASSETS_LABEL )) ,
265+ f" { self . _subpath } / { access_policy_id } / { ASSETS_LABEL } " ,
275266 ASSETS_LABEL ,
276267 page_size = page_size ,
277268 )
@@ -290,7 +281,7 @@ def count_matching_access_policies(self, asset_id: str) -> int:
290281
291282 """
292283 return self ._archivist .count (
293- SEP . join (( ACCESS_POLICIES_SUBPATH , asset_id , ACCESS_POLICIES_LABEL )),
284+ f" { self . _subpath } / { asset_id } / { ACCESS_POLICIES_LABEL } "
294285 )
295286
296287 def list_matching_access_policies (
@@ -311,7 +302,7 @@ def list_matching_access_policies(
311302 return (
312303 AccessPolicy (** a )
313304 for a in self ._archivist .list (
314- SEP . join (( ACCESS_POLICIES_SUBPATH , asset_id , ACCESS_POLICIES_LABEL )) ,
305+ f" { self . _subpath } / { asset_id } / { ACCESS_POLICIES_LABEL } " ,
315306 ACCESS_POLICIES_LABEL ,
316307 page_size = page_size ,
317308 )
0 commit comments