Skip to content

Commit 129cd63

Browse files
committed
Public assets interface
Problem: Old design of public assets interface considered sub-optimal. Solution: New design reflects current API for restricted assets substituting a root class 'ArchivistPublic' which has no URL or auth parameters. Public assets have been removed from the story runner. Corrected some minor code in the assetsattachments endpoint. Split testevents unittests into separate files for better manageability. Signed-off-by: Paul Hewlett <[email protected]>
1 parent 4c3acab commit 129cd63

File tree

113 files changed

+4446
-3077
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+4446
-3077
lines changed

archivist/access_policies.py

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,11 @@
2525
from logging import getLogger
2626
from 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

3231
from .assets import Asset
3332
from .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
)

archivist/appidp.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,14 @@
2424
from logging import getLogger
2525

2626
# pylint:disable=cyclic-import # but pylint doesn't understand this feature
27-
# pylint:disable=unused-import # To prevent cyclical import errors forward referencing is used
2827
# pylint:disable=too-few-public-methods
29-
from . import archivist as type_helper
28+
from . import archivist as type_helper # pylint:disable=unused-import
3029

3130
from .constants import (
3231
APPIDP_SUBPATH,
3332
APPIDP_LABEL,
3433
APPIDP_TOKEN,
3534
)
36-
from .dictmerge import _deepmerge
37-
from .type_aliases import NoneOnError
3835

3936
LOGGER = getLogger(__name__)
4037

@@ -56,6 +53,8 @@ class _AppIDPClient:
5653

5754
def __init__(self, archivist: "type_helper.Archivist"):
5855
self._archivist = archivist
56+
self._subpath = f"{archivist.root}/{APPIDP_SUBPATH}"
57+
self._label = f"{self._subpath}/{APPIDP_LABEL}"
5958

6059
def __str__(self) -> str:
6160
return f"AppIDPClient({self._archivist.url})"
@@ -73,7 +72,7 @@ def token(self, client_id: str, client_secret: str) -> AppIDP:
7372
"""
7473
return AppIDP(
7574
**self._archivist.post(
76-
f"{APPIDP_SUBPATH}/{APPIDP_LABEL}/{APPIDP_TOKEN}",
75+
f"{self._label}/{APPIDP_TOKEN}",
7776
{
7877
"grant_type": "client_credentials",
7978
"client_id": client_id,

archivist/applications.py

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@
2424
from logging import getLogger
2525
from typing import Dict, Optional
2626

27-
# pylint:disable=unused-import # To prevent cyclical import errors forward referencing is used
2827
# pylint:disable=cyclic-import # but pylint doesn't understand this feature
29-
from . import archivist as type_helper
28+
from . import archivist as type_helper # pylint:disable=unused-import
3029

3130
from .constants import (
3231
APPLICATIONS_SUBPATH,
@@ -56,6 +55,8 @@ class _ApplicationsClient:
5655

5756
def __init__(self, archivist: "type_helper.Archivist"):
5857
self._archivist = archivist
58+
self._subpath = f"{archivist.root}/{APPLICATIONS_SUBPATH}"
59+
self._label = f"{self._subpath}/{APPLICATIONS_LABEL}"
5960

6061
def __str__(self) -> str:
6162
return f"ApplicationsClient({self._archivist.url})"
@@ -94,12 +95,7 @@ def create_from_data(self, data: Dict) -> Application:
9495
:class:`Application` instance
9596
9697
"""
97-
return Application(
98-
**self._archivist.post(
99-
f"{APPLICATIONS_SUBPATH}/{APPLICATIONS_LABEL}",
100-
data,
101-
)
102-
)
98+
return Application(**self._archivist.post(self._label, data))
10399

104100
def read(self, identity: str) -> Application:
105101
"""Read Application
@@ -113,12 +109,7 @@ def read(self, identity: str) -> Application:
113109
:class:`Application` instance
114110
115111
"""
116-
return Application(
117-
**self._archivist.get(
118-
APPLICATIONS_SUBPATH,
119-
identity,
120-
)
121-
)
112+
return Application(**self._archivist.get(f"{self._subpath}/{identity}"))
122113

123114
def update(
124115
self,
@@ -142,8 +133,7 @@ def update(
142133
"""
143134
return Application(
144135
**self._archivist.patch(
145-
APPLICATIONS_SUBPATH,
146-
identity,
136+
f"{self._subpath}/{identity}",
147137
self.__params(
148138
display_name=display_name,
149139
custom_claims=custom_claims,
@@ -163,7 +153,7 @@ def delete(self, identity: str) -> Dict:
163153
:class:`Application` instance - empty?
164154
165155
"""
166-
return self._archivist.delete(APPLICATIONS_SUBPATH, identity)
156+
return self._archivist.delete(f"{self._subpath}/{identity}")
167157

168158
def __params(
169159
self,
@@ -203,7 +193,7 @@ def list(
203193
return (
204194
Application(**a)
205195
for a in self._archivist.list(
206-
f"{APPLICATIONS_SUBPATH}/{APPLICATIONS_LABEL}",
196+
self._label,
207197
APPLICATIONS_LABEL,
208198
page_size=page_size,
209199
params=self.__params(display_name=display_name),
@@ -225,8 +215,7 @@ def regenerate(self, identity: str) -> Application:
225215
LOGGER.debug("Regenerate %s", identity)
226216
return Application(
227217
**self._archivist.post(
228-
f"{APPLICATIONS_SUBPATH}/{identity}",
218+
f"{self._subpath}/{identity}:{APPLICATIONS_REGENERATE}",
229219
None,
230-
verb=APPLICATIONS_REGENERATE,
231220
)
232221
)

0 commit comments

Comments
 (0)