Skip to content

Commit

Permalink
Update verify parameter
Browse files Browse the repository at this point in the history
- Instead of passing in a verify parameter for every request, set it on startup
- update unit tests to reflect this
- black formatting
  • Loading branch information
Serhiy1 committed May 21, 2024
1 parent f7f3af9 commit 2bfaf97
Show file tree
Hide file tree
Showing 35 changed files with 34 additions and 169 deletions.
46 changes: 21 additions & 25 deletions archivist/archivist.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
# -*- coding: utf-8 -*-
"""Archivist connection interface
This module contains the base Archivist class which manages
the connection parameters to a DataTrails instance and
the basic REST verbs to GET, POST, PATCH and DELETE entities..
This module contains the base Archivist class which manages
the connection parameters to a DataTrails instance and
the basic REST verbs to GET, POST, PATCH and DELETE entities..
The REST methods in this class should only be used directly when
a CRUD endpoint for the specific type of entity is unavailable.
Current CRUD endpoints are assets, events, locations, attachments.
IAM subjects and IAM access policies.
The REST methods in this class should only be used directly when
a CRUD endpoint for the specific type of entity is unavailable.
Current CRUD endpoints are assets, events, locations, attachments.
IAM subjects and IAM access policies.
Instantiation of this class encapsulates the URL and authentication
parameters (the max_time parameter is optional):
Instantiation of this class encapsulates the URL and authentication
parameters (the max_time parameter is optional):
.. code-block:: python
.. code-block:: python
with open(".auth_token", mode="r", encoding="utf-8") as tokenfile:
authtoken = tokenfile.read().strip()
with open(".auth_token", mode="r", encoding="utf-8") as tokenfile:
authtoken = tokenfile.read().strip()
# Initialize connection to Archivist
arch = Archivist(
"https://app.datatrails.ai",
authtoken,
max_time=300.0,
)
# Initialize connection to Archivist
arch = Archivist(
"https://app.datatrails.ai",
authtoken,
max_time=300.0,
)
The arch variable now has additional endpoints assets,events,locations,
attachments, IAM subjects and IAM access policies documented elsewhere.
The arch variable now has additional endpoints assets,events,locations,
attachments, IAM subjects and IAM access policies documented elsewhere.
"""

from copy import deepcopy
from logging import getLogger
from time import time
Expand Down Expand Up @@ -253,14 +254,12 @@ def post(
response = self.session.post(
url,
data=request,
verify=self.verify,
)
else:
response = self.session.post(
url,
json=request,
headers=self._add_headers(headers),
verify=self.verify,
)

error = _parse_response(response)
Expand Down Expand Up @@ -305,7 +304,6 @@ def post_file(
url,
data=multipart, # pyright: ignore https://github.com/requests/toolbelt/issues/312
headers=self._add_headers(headers),
verify=self.verify,
params=_dotdict(params),
)

Expand Down Expand Up @@ -335,7 +333,6 @@ def delete(
response = self.session.delete(
url,
headers=self._add_headers(headers),
verify=self.verify,
)

self._response_ring_buffer.appendleft(response)
Expand Down Expand Up @@ -371,7 +368,6 @@ def patch(
url,
json=request,
headers=self._add_headers(headers),
verify=self.verify,
)

self._response_ring_buffer.appendleft(response)
Expand Down
4 changes: 1 addition & 3 deletions archivist/archivistpublic.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def session(self) -> requests.Session:
"""creates and returns session"""
if self._session is None:
self._session = requests.Session()
self._session.verify = self.verify
return self._session

def close(self):
Expand Down Expand Up @@ -197,7 +198,6 @@ def get(
response = self.session.get(
url,
headers=self._add_headers(headers),
verify=self.verify,
params=_dotdict(params),
)

Expand Down Expand Up @@ -237,7 +237,6 @@ def get_file(
response = self.session.get(
url,
headers=self._add_headers(headers),
verify=self.verify,
stream=True,
params=_dotdict(params),
)
Expand Down Expand Up @@ -272,7 +271,6 @@ def __list(
response = self.session.get(
url,
headers=self._add_headers(headers),
verify=self.verify,
params=_dotdict(params),
)

Expand Down
12 changes: 4 additions & 8 deletions archivist/confirmer.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,32 +52,28 @@ def __on_giveup_confirmation(details: "Details"):
def _wait_for_confirmation(
self: "_AssetsRestricted",
identity: str,
) -> "Asset":
... # pragma: no cover
) -> "Asset": ... # pragma: no cover


@overload
def _wait_for_confirmation(
self: "_AssetsPublic",
identity: str,
) -> "Asset":
... # pragma: no cover
) -> "Asset": ... # pragma: no cover


@overload
def _wait_for_confirmation(
self: "_EventsRestricted",
identity: str,
) -> "Event":
... # pragma: no cover
) -> "Event": ... # pragma: no cover


@overload
def _wait_for_confirmation(
self: "_EventsPublic",
identity: str,
) -> "Event":
... # pragma: no cover
) -> "Event": ... # pragma: no cover


@backoff.on_predicate(
Expand Down
6 changes: 3 additions & 3 deletions functests/execassets.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ def setUp(self):
self.traffic_light = deepcopy(ATTRS)
self.traffic_light["arc_display_type"] = "Traffic light with violation camera"
self.traffic_light_merkle_log = deepcopy(ATTRS)
self.traffic_light_merkle_log[
"arc_display_type"
] = "Traffic light with violation camera (merkle_log)"
self.traffic_light_merkle_log["arc_display_type"] = (
"Traffic light with violation camera (merkle_log)"
)

def tearDown(self):
self.arch.close()
Expand Down
10 changes: 0 additions & 10 deletions unittests/testaccess_policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ def test_access_policies_create(self):
"headers": {
"authorization": "Bearer authauthauth",
},
"verify": True,
},
msg="CREATE method called incorrectly",
)
Expand Down Expand Up @@ -159,7 +158,6 @@ def test_access_policies_read(self):
"authorization": "Bearer authauthauth",
},
"params": None,
"verify": True,
},
),
msg="GET method called incorrectly",
Expand All @@ -181,7 +179,6 @@ def test_access_policies_delete(self):
"headers": {
"authorization": "Bearer authauthauth",
},
"verify": True,
},
),
msg="DELETE method called incorrectly",
Expand Down Expand Up @@ -211,7 +208,6 @@ def test_access_policies_update(self):
"headers": {
"authorization": "Bearer authauthauth",
},
"verify": True,
},
msg="PATCH method kwargs called incorrectly",
)
Expand Down Expand Up @@ -249,7 +245,6 @@ def test_access_policies_count(self):
HEADERS_REQUEST_TOTAL_COUNT: "true",
},
"params": {"page_size": 1},
"verify": True,
},
),
msg="GET method called incorrectly",
Expand Down Expand Up @@ -289,7 +284,6 @@ def test_access_policies_count_by_name(self):
"page_size": 1,
"display_name": "Policy display name",
},
"verify": True,
},
),
msg="GET method called incorrectly",
Expand Down Expand Up @@ -330,7 +324,6 @@ def test_access_policies_list(self):
"authorization": "Bearer authauthauth",
},
"params": None,
"verify": True,
},
),
msg="GET method called incorrectly",
Expand Down Expand Up @@ -375,7 +368,6 @@ def test_access_policies_list_by_name(self):
"authorization": "Bearer authauthauth",
},
"params": {"display_name": "Policy display name"},
"verify": True,
},
),
msg="GET method called incorrectly",
Expand Down Expand Up @@ -421,7 +413,6 @@ def test_access_policies_list_matching_access_policies(self):
"authorization": "Bearer authauthauth",
},
"params": None,
"verify": True,
},
),
msg="GET method called incorrectly",
Expand Down Expand Up @@ -464,7 +455,6 @@ def test_access_policies_list_matching_assets(self):
"authorization": "Bearer authauthauth",
},
"params": None,
"verify": True,
},
),
msg="GET method called incorrectly",
Expand Down
1 change: 0 additions & 1 deletion unittests/testappidp.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ def test_appidp_token_create(self):
kwargs,
{
"data": REQUEST,
"verify": True,
},
msg="CREATE method kwargs called incorrectly",
)
Expand Down
7 changes: 0 additions & 7 deletions unittests/testapplications.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ def test_applications_create(self):
"headers": {
"authorization": "Bearer authauthauth",
},
"verify": True,
},
msg="CREATE method kwargs called incorrectly",
)
Expand All @@ -122,7 +121,6 @@ def test_applications_read(self):
"authorization": "Bearer authauthauth",
},
"params": None,
"verify": True,
},
),
msg="GET method called incorrectly",
Expand All @@ -144,7 +142,6 @@ def test_applications_delete(self):
"headers": {
"authorization": "Bearer authauthauth",
},
"verify": True,
},
),
msg="DELETE method called incorrectly",
Expand All @@ -170,7 +167,6 @@ def test_applications_update(self):
"headers": {
"authorization": "Bearer authauthauth",
},
"verify": True,
},
),
msg="PATCH method called incorrectly",
Expand Down Expand Up @@ -220,7 +216,6 @@ def test_applications_list(self):
"authorization": "Bearer authauthauth",
},
"params": {},
"verify": True,
},
),
msg="GET method called incorrectly",
Expand Down Expand Up @@ -267,7 +262,6 @@ def test_applications_list_by_name(self):
"params": {
"display_name": "Application display name",
},
"verify": True,
},
),
msg="GET method called incorrectly",
Expand Down Expand Up @@ -295,7 +289,6 @@ def test_applications_regenerate(self):
"authorization": "Bearer authauthauth",
},
"json": None,
"verify": True,
},
),
msg="POST method called incorrectly",
Expand Down
3 changes: 0 additions & 3 deletions unittests/testarchivist.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ def test_patch(self):
"headers": {
"authorization": "Bearer authauthauth",
},
"verify": True,
},
msg="POST method kwargs called incorrectly",
)
Expand Down Expand Up @@ -312,7 +311,6 @@ def test_patch_with_headers(self):
"authorization": "Bearer authauthauth",
"headerfield1": "headervalue1",
},
"verify": True,
},
msg="PATCH method kwargs called incorrectly",
)
Expand Down Expand Up @@ -389,7 +387,6 @@ def test_patch_with_429_retry_and_success(self):
"headers": {
"authorization": "Bearer authauthauth",
},
"verify": True,
},
msg="PATCH method kwargs called incorrectly",
)
Expand Down
3 changes: 0 additions & 3 deletions unittests/testarchivistdelete.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ def test_delete(self):
"headers": {
"authorization": "Bearer authauthauth",
},
"verify": True,
},
),
msg="DELETE method called incorrectly",
Expand Down Expand Up @@ -84,7 +83,6 @@ def test_delete_with_headers(self):
"authorization": "Bearer authauthauth",
"headerfield1": "headervalue1",
},
"verify": True,
},
),
msg="DELETE method called incorrectly",
Expand Down Expand Up @@ -147,7 +145,6 @@ def test_delete_with_429_retry_and_success(self):
"headers": {
"authorization": "Bearer authauthauth",
},
"verify": True,
},
),
msg="DELETE method called incorrectly",
Expand Down
Loading

0 comments on commit 2bfaf97

Please sign in to comment.