Skip to content

Commit

Permalink
Merge pull request #128 from intezer/fix/small-fixes
Browse files Browse the repository at this point in the history
Fix/small fixes
  • Loading branch information
davidt99 authored Jan 15, 2024
2 parents 57f79f5 + d229c76 commit 4810456
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
5 changes: 5 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
1.19.10
_______
- Add timeout support to IntezerApiClient
- Set pip-system-certs requirement correctly

1.19.9
------
- Fix certificate issue by adding pip-system-certs to requirements
Expand Down
24 changes: 16 additions & 8 deletions intezer_sdk/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ def __init__(self,
on_premise_version: OnPremiseVersion = None,
user_agent: str = None,
renew_token_window=20,
max_retry=3):
max_retry=3,
timeout_in_seconds: Optional[int] = None):
self.full_url = base_url + api_version
self.base_url = base_url
self._proxies = proxies
Expand All @@ -97,6 +98,7 @@ def __init__(self,
self.verify_ssl = verify_ssl
self.on_premise_version = on_premise_version
self.max_retry = max_retry
self.timeout_in_seconds = timeout_in_seconds
if user_agent:
user_agent = f'{consts.USER_AGENT}/{user_agent}'
else:
Expand All @@ -110,7 +112,8 @@ def _request(self,
headers: dict = None,
files: dict = None,
stream: bool = None,
base_url: str = None) -> Response:
base_url: str = None,
timeout_in_seconds: Optional[int] = None) -> Response:
if not self._session:
self._set_session()

Expand All @@ -123,7 +126,8 @@ def _request(self,
files=files,
data=data or {},
headers=headers or {},
stream=stream
stream=stream,
timeout=timeout_in_seconds or self.timeout_in_seconds
)
elif isinstance(data, bytes):
response = self._session.request(
Expand All @@ -132,15 +136,17 @@ def _request(self,
files=files,
data=data,
headers=headers or {},
stream=stream
stream=stream,
timeout=timeout_in_seconds or self.timeout_in_seconds
)
else:
response = self._session.request(
method,
url,
json=data or {},
headers=headers,
stream=stream
stream=stream,
timeout=timeout_in_seconds or self.timeout_in_seconds
)

return response
Expand All @@ -158,15 +164,16 @@ def request_with_refresh_expired_access_token(self,
headers: dict = None,
files: dict = None,
stream: bool = None,
base_url: str = None) -> Response:
base_url: str = None,
timeout_in_seconds: Optional[int] = None) -> Response:
for retry_count in range(self.max_retry):
try:
self._refresh_token_if_needed()
response = self._request(method, path, data, headers, files, stream, base_url=base_url)
response = self._request(method, path, data, headers, files, stream, base_url, timeout_in_seconds)

if response.status_code == HTTPStatus.UNAUTHORIZED and not self._token_expiration:
self._set_access_token()
response = self._request(method, path, data, headers, files, stream, base_url)
response = self._request(method, path, data, headers, files, stream, base_url, timeout_in_seconds)

return response
except ConnectionError:
Expand Down Expand Up @@ -733,6 +740,7 @@ def set_global_api(api_key: str = None,
proxies=proxies)
return _global_api


def set_global_api_custom_instance(api: IntezerApiClient) -> IntezerApiClient:
"""
Configure the global api with a custom instance
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# This is not used by the project, but is used by the CI/CD pipeline to install dependencies, update setup.py for package dependencies.
requests>=2.29.0,<3
pip-system-certs==4.0
responses==0.23.3
responses==0.24.1
pytest==7.4.4
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ def rel(*xs):
long_description = f.read()

install_requires = [
'requests >= 2.29.0,<3'
'requests >= 2.29.0,<3',
'pip-system-certs == 4.0'
]
setup(
name='intezer_sdk',
Expand All @@ -37,7 +38,7 @@ def rel(*xs):
install_requires=install_requires,
keywords='intezer',
tests_requires=[
'responses == 0.23.3',
'responses == 0.24.1',
'pytest == 7.4.4'
],
python_requires='!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,!=3.7.*',
Expand Down

0 comments on commit 4810456

Please sign in to comment.