Skip to content

Commit 718d598

Browse files
committed
Update verify parameter
- Instead of passing in a verify parameter for every request, set it on startup - update unit tests to reflect this - black formatting
1 parent f7f3af9 commit 718d598

36 files changed

Lines changed: 39 additions & 228 deletions

archivist/archivist.py

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,35 @@
11
# -*- coding: utf-8 -*-
22
"""Archivist connection interface
33
4-
This module contains the base Archivist class which manages
5-
the connection parameters to a DataTrails instance and
6-
the basic REST verbs to GET, POST, PATCH and DELETE entities..
4+
This module contains the base Archivist class which manages
5+
the connection parameters to a DataTrails instance and
6+
the basic REST verbs to GET, POST, PATCH and DELETE entities..
77
8-
The REST methods in this class should only be used directly when
9-
a CRUD endpoint for the specific type of entity is unavailable.
10-
Current CRUD endpoints are assets, events, locations, attachments.
11-
IAM subjects and IAM access policies.
8+
The REST methods in this class should only be used directly when
9+
a CRUD endpoint for the specific type of entity is unavailable.
10+
Current CRUD endpoints are assets, events, locations, attachments.
11+
IAM subjects and IAM access policies.
1212
13-
Instantiation of this class encapsulates the URL and authentication
14-
parameters (the max_time parameter is optional):
13+
Instantiation of this class encapsulates the URL and authentication
14+
parameters (the max_time parameter is optional):
1515
16-
.. code-block:: python
16+
.. code-block:: python
1717
18-
with open(".auth_token", mode="r", encoding="utf-8") as tokenfile:
19-
authtoken = tokenfile.read().strip()
18+
with open(".auth_token", mode="r", encoding="utf-8") as tokenfile:
19+
authtoken = tokenfile.read().strip()
2020
21-
# Initialize connection to Archivist
22-
arch = Archivist(
23-
"https://app.datatrails.ai",
24-
authtoken,
25-
max_time=300.0,
26-
)
21+
# Initialize connection to Archivist
22+
arch = Archivist(
23+
"https://app.datatrails.ai",
24+
authtoken,
25+
max_time=300.0,
26+
)
2727
28-
The arch variable now has additional endpoints assets,events,locations,
29-
attachments, IAM subjects and IAM access policies documented elsewhere.
28+
The arch variable now has additional endpoints assets,events,locations,
29+
attachments, IAM subjects and IAM access policies documented elsewhere.
3030
3131
"""
32+
3233
from copy import deepcopy
3334
from logging import getLogger
3435
from time import time
@@ -253,14 +254,12 @@ def post(
253254
response = self.session.post(
254255
url,
255256
data=request,
256-
verify=self.verify,
257257
)
258258
else:
259259
response = self.session.post(
260260
url,
261261
json=request,
262262
headers=self._add_headers(headers),
263-
verify=self.verify,
264263
)
265264

266265
error = _parse_response(response)
@@ -305,7 +304,6 @@ def post_file(
305304
url,
306305
data=multipart, # pyright: ignore https://github.com/requests/toolbelt/issues/312
307306
headers=self._add_headers(headers),
308-
verify=self.verify,
309307
params=_dotdict(params),
310308
)
311309

@@ -335,7 +333,6 @@ def delete(
335333
response = self.session.delete(
336334
url,
337335
headers=self._add_headers(headers),
338-
verify=self.verify,
339336
)
340337

341338
self._response_ring_buffer.appendleft(response)
@@ -371,7 +368,6 @@ def patch(
371368
url,
372369
json=request,
373370
headers=self._add_headers(headers),
374-
verify=self.verify,
375371
)
376372

377373
self._response_ring_buffer.appendleft(response)

archivist/archivistpublic.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ def session(self) -> requests.Session:
122122
"""creates and returns session"""
123123
if self._session is None:
124124
self._session = requests.Session()
125+
self._session.verify = self.verify
125126
return self._session
126127

127128
def close(self):
@@ -197,7 +198,6 @@ def get(
197198
response = self.session.get(
198199
url,
199200
headers=self._add_headers(headers),
200-
verify=self.verify,
201201
params=_dotdict(params),
202202
)
203203

@@ -237,7 +237,6 @@ def get_file(
237237
response = self.session.get(
238238
url,
239239
headers=self._add_headers(headers),
240-
verify=self.verify,
241240
stream=True,
242241
params=_dotdict(params),
243242
)
@@ -272,7 +271,6 @@ def __list(
272271
response = self.session.get(
273272
url,
274273
headers=self._add_headers(headers),
275-
verify=self.verify,
276274
params=_dotdict(params),
277275
)
278276

archivist/confirmer.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,32 +52,28 @@ def __on_giveup_confirmation(details: "Details"):
5252
def _wait_for_confirmation(
5353
self: "_AssetsRestricted",
5454
identity: str,
55-
) -> "Asset":
56-
... # pragma: no cover
55+
) -> "Asset": ... # pragma: no cover
5756

5857

5958
@overload
6059
def _wait_for_confirmation(
6160
self: "_AssetsPublic",
6261
identity: str,
63-
) -> "Asset":
64-
... # pragma: no cover
62+
) -> "Asset": ... # pragma: no cover
6563

6664

6765
@overload
6866
def _wait_for_confirmation(
6967
self: "_EventsRestricted",
7068
identity: str,
71-
) -> "Event":
72-
... # pragma: no cover
69+
) -> "Event": ... # pragma: no cover
7370

7471

7572
@overload
7673
def _wait_for_confirmation(
7774
self: "_EventsPublic",
7875
identity: str,
79-
) -> "Event":
80-
... # pragma: no cover
76+
) -> "Event": ... # pragma: no cover
8177

8278

8379
@backoff.on_predicate(

functests/execassets.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ def setUp(self):
129129
self.traffic_light = deepcopy(ATTRS)
130130
self.traffic_light["arc_display_type"] = "Traffic light with violation camera"
131131
self.traffic_light_merkle_log = deepcopy(ATTRS)
132-
self.traffic_light_merkle_log[
133-
"arc_display_type"
134-
] = "Traffic light with violation camera (merkle_log)"
132+
self.traffic_light_merkle_log["arc_display_type"] = (
133+
"Traffic light with violation camera (merkle_log)"
134+
)
135135

136136
def tearDown(self):
137137
self.arch.close()

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ flatten-dict~=0.4
88
iso8601~=2.1
99
Jinja2~=3.1
1010
pyaml-env~=1.2
11-
requests~=2.31.0
11+
requests~=2.32.0
1212
requests-toolbelt~=1.0
1313
rfc3339~=6.2
1414
xmltodict~=0.13

unittests/testaccess_policies.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ def test_access_policies_create(self):
127127
"headers": {
128128
"authorization": "Bearer authauthauth",
129129
},
130-
"verify": True,
131130
},
132131
msg="CREATE method called incorrectly",
133132
)
@@ -159,7 +158,6 @@ def test_access_policies_read(self):
159158
"authorization": "Bearer authauthauth",
160159
},
161160
"params": None,
162-
"verify": True,
163161
},
164162
),
165163
msg="GET method called incorrectly",
@@ -181,7 +179,6 @@ def test_access_policies_delete(self):
181179
"headers": {
182180
"authorization": "Bearer authauthauth",
183181
},
184-
"verify": True,
185182
},
186183
),
187184
msg="DELETE method called incorrectly",
@@ -211,7 +208,6 @@ def test_access_policies_update(self):
211208
"headers": {
212209
"authorization": "Bearer authauthauth",
213210
},
214-
"verify": True,
215211
},
216212
msg="PATCH method kwargs called incorrectly",
217213
)
@@ -249,7 +245,6 @@ def test_access_policies_count(self):
249245
HEADERS_REQUEST_TOTAL_COUNT: "true",
250246
},
251247
"params": {"page_size": 1},
252-
"verify": True,
253248
},
254249
),
255250
msg="GET method called incorrectly",
@@ -289,7 +284,6 @@ def test_access_policies_count_by_name(self):
289284
"page_size": 1,
290285
"display_name": "Policy display name",
291286
},
292-
"verify": True,
293287
},
294288
),
295289
msg="GET method called incorrectly",
@@ -330,7 +324,6 @@ def test_access_policies_list(self):
330324
"authorization": "Bearer authauthauth",
331325
},
332326
"params": None,
333-
"verify": True,
334327
},
335328
),
336329
msg="GET method called incorrectly",
@@ -375,7 +368,6 @@ def test_access_policies_list_by_name(self):
375368
"authorization": "Bearer authauthauth",
376369
},
377370
"params": {"display_name": "Policy display name"},
378-
"verify": True,
379371
},
380372
),
381373
msg="GET method called incorrectly",
@@ -421,7 +413,6 @@ def test_access_policies_list_matching_access_policies(self):
421413
"authorization": "Bearer authauthauth",
422414
},
423415
"params": None,
424-
"verify": True,
425416
},
426417
),
427418
msg="GET method called incorrectly",
@@ -464,7 +455,6 @@ def test_access_policies_list_matching_assets(self):
464455
"authorization": "Bearer authauthauth",
465456
},
466457
"params": None,
467-
"verify": True,
468458
},
469459
),
470460
msg="GET method called incorrectly",

unittests/testappidp.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ def test_appidp_token_create(self):
7979
kwargs,
8080
{
8181
"data": REQUEST,
82-
"verify": True,
8382
},
8483
msg="CREATE method kwargs called incorrectly",
8584
)

unittests/testapplications.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ def test_applications_create(self):
9595
"headers": {
9696
"authorization": "Bearer authauthauth",
9797
},
98-
"verify": True,
9998
},
10099
msg="CREATE method kwargs called incorrectly",
101100
)
@@ -122,7 +121,6 @@ def test_applications_read(self):
122121
"authorization": "Bearer authauthauth",
123122
},
124123
"params": None,
125-
"verify": True,
126124
},
127125
),
128126
msg="GET method called incorrectly",
@@ -144,7 +142,6 @@ def test_applications_delete(self):
144142
"headers": {
145143
"authorization": "Bearer authauthauth",
146144
},
147-
"verify": True,
148145
},
149146
),
150147
msg="DELETE method called incorrectly",
@@ -170,7 +167,6 @@ def test_applications_update(self):
170167
"headers": {
171168
"authorization": "Bearer authauthauth",
172169
},
173-
"verify": True,
174170
},
175171
),
176172
msg="PATCH method called incorrectly",
@@ -220,7 +216,6 @@ def test_applications_list(self):
220216
"authorization": "Bearer authauthauth",
221217
},
222218
"params": {},
223-
"verify": True,
224219
},
225220
),
226221
msg="GET method called incorrectly",
@@ -267,7 +262,6 @@ def test_applications_list_by_name(self):
267262
"params": {
268263
"display_name": "Application display name",
269264
},
270-
"verify": True,
271265
},
272266
),
273267
msg="GET method called incorrectly",
@@ -295,7 +289,6 @@ def test_applications_regenerate(self):
295289
"authorization": "Bearer authauthauth",
296290
},
297291
"json": None,
298-
"verify": True,
299292
},
300293
),
301294
msg="POST method called incorrectly",

unittests/testarchivist.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,6 @@ def test_patch(self):
269269
"headers": {
270270
"authorization": "Bearer authauthauth",
271271
},
272-
"verify": True,
273272
},
274273
msg="POST method kwargs called incorrectly",
275274
)
@@ -312,7 +311,6 @@ def test_patch_with_headers(self):
312311
"authorization": "Bearer authauthauth",
313312
"headerfield1": "headervalue1",
314313
},
315-
"verify": True,
316314
},
317315
msg="PATCH method kwargs called incorrectly",
318316
)
@@ -389,7 +387,6 @@ def test_patch_with_429_retry_and_success(self):
389387
"headers": {
390388
"authorization": "Bearer authauthauth",
391389
},
392-
"verify": True,
393390
},
394391
msg="PATCH method kwargs called incorrectly",
395392
)

unittests/testarchivistdelete.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ def test_delete(self):
5050
"headers": {
5151
"authorization": "Bearer authauthauth",
5252
},
53-
"verify": True,
5453
},
5554
),
5655
msg="DELETE method called incorrectly",
@@ -84,7 +83,6 @@ def test_delete_with_headers(self):
8483
"authorization": "Bearer authauthauth",
8584
"headerfield1": "headervalue1",
8685
},
87-
"verify": True,
8886
},
8987
),
9088
msg="DELETE method called incorrectly",
@@ -147,7 +145,6 @@ def test_delete_with_429_retry_and_success(self):
147145
"headers": {
148146
"authorization": "Bearer authauthauth",
149147
},
150-
"verify": True,
151148
},
152149
),
153150
msg="DELETE method called incorrectly",

0 commit comments

Comments
 (0)