Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
1.25.1
-------
- Make request method kwargs only and add params

1.25.0
-------
- Add support for Python 3.14
Expand Down
2 changes: 1 addition & 1 deletion intezer_sdk/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.25.0'
__version__ = '1.25.1'
8 changes: 4 additions & 4 deletions intezer_sdk/_account_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def __init__(self, api: IntezerApiClient | None):
self.api = api or get_global_api()

def get_my_quota(self, raise_on_no_file_quota=False, raise_on_no_endpoint_quota=False) -> dict:
response = self.api.request_with_refresh_expired_access_token('GET', '/current-quota-usage')
response = self.api.request_with_refresh_expired_access_token(method='GET', path='/current-quota-usage')
raise_for_status(response)
result = response.json()['result']
if raise_on_no_file_quota and result['file_scans']['quota'] - result['file_scans']['usage'] <= 0:
Expand All @@ -21,19 +21,19 @@ def get_my_quota(self, raise_on_no_file_quota=False, raise_on_no_endpoint_quota=
return result

def get_my_account(self) -> dict:
response = self.api.request_with_refresh_expired_access_token('GET', '/accounts/me')
response = self.api.request_with_refresh_expired_access_token(method='GET', path='/accounts/me')
raise_for_status(response)
return response.json()['result']

def get_account(self, account_id: str) -> dict | None:
response = self.api.request_with_refresh_expired_access_token('GET', f'/accounts/{account_id}')
response = self.api.request_with_refresh_expired_access_token(method='GET', path=f'/accounts/{account_id}')
if response.status_code == HTTPStatus.NOT_FOUND:
return None

raise_for_status(response)
return response.json()['result']

def get_organization_accounts(self) -> list[dict]:
response = self.api.request_with_refresh_expired_access_token('GET', f'/accounts')
response = self.api.request_with_refresh_expired_access_token(method='GET', path='/accounts')
raise_for_status(response)
return response.json()['result']
92 changes: 46 additions & 46 deletions intezer_sdk/_api.py

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions intezer_sdk/_endpoint_analysis_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def __init__(self, scan_id: str, api: IntezerApiClient, max_upload_retries: int
self.base_url = f"{api.base_url.replace('/api/', '')}/scans/scans/{scan_id}"
self.max_upload_retries = max_upload_retries

def request_with_refresh_expired_access_token(self, *args, **kwargs):
return self.api.request_with_refresh_expired_access_token(base_url=self.base_url, *args, **kwargs)
def request_with_refresh_expired_access_token(self, **kwargs):
return self.api.request_with_refresh_expired_access_token(base_url=self.base_url, **kwargs)

def send_host_info(self, host_info: dict):
response = self.request_with_refresh_expired_access_token(path='/host-info',
Expand Down
15 changes: 11 additions & 4 deletions intezer_sdk/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,11 @@ def __init__(self,
self.user_agent = user_agent

def _request(self,
*,
method: str,
path: str,
data: dict = None,
params: dict = None,
headers: dict = None,
files: dict = None,
stream: bool = None,
Expand All @@ -115,6 +117,7 @@ def _request(self,
url,
files=files,
data=data or {},
params=params,
headers=headers or {},
stream=stream,
timeout=timeout_in_seconds or self.timeout_in_seconds
Expand All @@ -125,6 +128,7 @@ def _request(self,
url,
files=files,
data=data,
params=params,
headers=headers or {},
stream=stream,
timeout=timeout_in_seconds or self.timeout_in_seconds
Expand All @@ -134,6 +138,7 @@ def _request(self,
method,
url,
json=data or {},
params=params,
headers=headers,
stream=stream,
timeout=timeout_in_seconds or self.timeout_in_seconds
Expand All @@ -148,9 +153,11 @@ def _refresh_token_if_needed(self):
self._set_access_token()

def request_with_refresh_expired_access_token(self,
*,
method: str,
path: str,
data: dict = None,
params: dict = None,
headers: dict = None,
files: dict = None,
stream: bool = None,
Expand All @@ -159,11 +166,11 @@ def request_with_refresh_expired_access_token(self,
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, timeout_in_seconds)
response = self._request(method=method, path=path, data=data, params=params, headers=headers, files=files, stream=stream, base_url=base_url, timeout_in_seconds=timeout_in_seconds)

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

return response
except ConnectionError:
Expand Down Expand Up @@ -427,7 +434,7 @@ def get_dynamic_ttps(self, analyses_id: str) -> dict | None:

@deprecated('IntezerApi is deprecated and will be removed in the future')
def get_family_info(self, family_id: str) -> dict | None:
response = self.request_with_refresh_expired_access_token('GET', '/families/{}/info'.format(family_id))
response = self.request_with_refresh_expired_access_token(method='GET', path='/families/{}/info'.format(family_id))
if response.status_code == HTTPStatus.NOT_FOUND:
return None

Expand All @@ -436,7 +443,7 @@ def get_family_info(self, family_id: str) -> dict | None:

@deprecated('IntezerApi is deprecated and will be removed in the future')
def get_family_by_name(self, family_name: str) -> dict[str, Any] | None:
response = self.request_with_refresh_expired_access_token('GET', '/families', {'family_name': family_name})
response = self.request_with_refresh_expired_access_token(method='GET', path='/families', data={'family_name': family_name})
if response.status_code == HTTPStatus.NOT_FOUND:
return None

Expand Down
8 changes: 4 additions & 4 deletions tests/unit/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test_renew_token(self):
mock.add('POST',
url=f'{self.full_url}/some-route',
status=HTTPStatus.OK)
response = api.request_with_refresh_expired_access_token('POST', '/some-route')
response = api.request_with_refresh_expired_access_token(method='POST', path='/some-route')
response.raise_for_status()
time.sleep(0.2)
mock.reset()
Expand All @@ -55,7 +55,7 @@ def test_renew_token(self):
status=HTTPStatus.OK,
json={'result': 'access-token', 'expire_at': time.time()})

response = api.request_with_refresh_expired_access_token('POST', '/some-route')
response = api.request_with_refresh_expired_access_token(method='POST', path='/some-route')
response.raise_for_status()

def test_api_raise_insufficient_permissions_error_when_insufficient_permissions_received(self):
Expand All @@ -73,7 +73,7 @@ def test_api_raise_insufficient_permissions_error_when_insufficient_permissions_
f'{self.full_url}/some-route',
status=HTTPStatus.FORBIDDEN,
json={'error': 'Insufficient Permissions'})
response = api.request_with_refresh_expired_access_token('GET', '/some-route')
response = api.request_with_refresh_expired_access_token(method='GET', path='/some-route')

with self.assertRaises(errors.InsufficientPermissionsError):
raise_for_status(response)
Expand All @@ -94,7 +94,7 @@ def test_api_raise_invalid_api_key_error_when_unauthorized_received(self):
url=f'{self.full_url}/get-access-token',
status=HTTPStatus.OK,
json={'result': 'access-token', 'expire_at': 2166920067})
response = api.request_with_refresh_expired_access_token('GET', '/some-route')
response = api.request_with_refresh_expired_access_token(method='GET', path='/some-route')

with self.assertRaises(errors.InvalidApiKeyError):
raise_for_status(response)
Expand Down
Loading