Skip to content

Commit 6d08a6e

Browse files
Fix formatting and improve parsing of risk factor's parquet file (#48)
1 parent 19be2bd commit 6d08a6e

9 files changed

Lines changed: 38 additions & 30 deletions

File tree

armis_sdk/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
from armis_sdk.core.armis_sdk import ArmisSdk
2-
from armis_sdk.core.client_credentials import ClientCredentials
1+
from armis_sdk.core.armis_sdk import ArmisSdk # noqa: F401
2+
from armis_sdk.core.client_credentials import ClientCredentials # noqa: F401

armis_sdk/clients/sites_client.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from typing import AsyncIterator
2-
from typing import List
32

43
import universalasync
54

@@ -129,7 +128,7 @@ async def main():
129128
data = response_utils.get_data_dict(response)
130129
return Site.model_validate(data)
131130

132-
async def hierarchy(self) -> List[Site]:
131+
async def hierarchy(self) -> list[Site]:
133132
"""Create a hierarchy of the tenant's sites, taking into account the parent-child relationships.
134133
135134
Returns:

armis_sdk/core/armis_error.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"""
55

66
import json
7-
from typing import List
87
from typing import Optional
98
from typing import Union
109

@@ -26,7 +25,7 @@ def __str__(self):
2625

2726

2827
class ErrorBody(BaseModel):
29-
detail: Union[str, List[DetailItem]]
28+
detail: Union[str, list[DetailItem]]
3029

3130

3231
class ArmisError(Exception):
@@ -63,7 +62,7 @@ class ResponseError(ArmisError):
6362
def __init__(
6463
self,
6564
error_body: ErrorBody,
66-
response_errors: Optional[List[HTTPStatusError]] = None,
65+
response_errors: Optional[list[HTTPStatusError]] = None,
6766
):
6867
super().__init__(self._get_message(error_body))
6968
self.response_errors = response_errors

armis_sdk/entities/asq_rule.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from typing import List
21
from typing import Optional
32
from typing import Union
43

@@ -41,10 +40,10 @@ class AsqRule(BaseEntity):
4140
```
4241
"""
4342

44-
and_: Optional[List[Union[str, "AsqRule"]]] = Field(alias="and", default=None)
43+
and_: Optional[list[Union[str, "AsqRule"]]] = Field(alias="and", default=None)
4544
"""Rules that all must match."""
4645

47-
or_: Optional[List[Union[str, "AsqRule"]]] = Field(alias="or", default=None)
46+
or_: Optional[list[Union[str, "AsqRule"]]] = Field(alias="or", default=None)
4847
"""Rules that at least one of them must match."""
4948

5049
@classmethod

armis_sdk/entities/data_export/risk_factor.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class RiskFactor(BaseExportedEntity):
6868
**Example**: `Device Supports SMBv1`
6969
"""
7070

71-
score: int
71+
score: Optional[int]
7272
"""The score of the risk factor"""
7373

7474
group: str
@@ -78,14 +78,14 @@ class RiskFactor(BaseExportedEntity):
7878
**Example**: `INSECURE_TRAFFIC_AND_BEHAVIOR`
7979
"""
8080

81-
remediation_type: str
81+
remediation_type: Optional[str]
8282
"""
8383
The type of the remediation
8484
8585
**Example**: `Disable SMBv1 Protocol`
8686
"""
8787

88-
remediation_description: str
88+
remediation_description: Optional[str]
8989
"""
9090
The description of the remediation
9191
@@ -130,15 +130,27 @@ def series_to_model(cls, series: pandas.Series) -> "RiskFactor":
130130
category=series.loc["category"],
131131
type=series.loc["type"],
132132
description=series.loc["description"],
133-
score=series.loc["score"],
133+
score=(
134+
int(score)
135+
if (score := cls._value_or_none(series.loc["score"]))
136+
else None
137+
),
134138
status=series.loc["status"],
135139
group=series.loc["group"],
136-
remediation_type=series.loc["remediation"],
137-
remediation_description=series.loc["remediation_description"],
138-
remediation_recommended_actions=[
139-
RiskFactorRecommendedAction(**item)
140-
for item in json.loads(series.loc["remediation_recommended_actions"])
141-
],
140+
remediation_type=cls._value_or_none(series.loc["remediation"]),
141+
remediation_description=cls._value_or_none(
142+
series.loc["remediation_description"]
143+
),
144+
remediation_recommended_actions=(
145+
[
146+
RiskFactorRecommendedAction(**item)
147+
for item in json.loads(
148+
series.loc["remediation_recommended_actions"]
149+
)
150+
]
151+
if series.loc["remediation_recommended_actions"]
152+
else []
153+
),
142154
first_seen=series.loc["first_seen"].to_pydatetime(),
143155
last_seen=series.loc["last_seen"].to_pydatetime(),
144156
status_update_time=cls._value_or_none(series.loc["status_update_time"]),

armis_sdk/entities/site.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import json
22
from typing import Annotated
33
from typing import Any
4-
from typing import List
54
from typing import Optional
65

76
from pydantic import BeforeValidator
@@ -71,16 +70,16 @@ class Site(BaseEntity):
7170
"""The ASQ rule of the site."""
7271

7372
network_equipment_device_ids: Annotated[
74-
Optional[List[int]], BeforeValidator(ensure_list_of_ints)
73+
Optional[list[int]], BeforeValidator(ensure_list_of_ints)
7574
] = None
7675
"""The ids of network equipment devices associated with the site."""
7776

7877
integration_ids: Annotated[
79-
Optional[List[int]], BeforeValidator(ensure_list_of_ints)
78+
Optional[list[int]], BeforeValidator(ensure_list_of_ints)
8079
] = None
8180
"""The ids of the integration associated with the site."""
8281

83-
children: List["Site"] = Field(default_factory=list)
82+
children: list["Site"] = Field(default_factory=list)
8483
"""The sub-sites that are directly under this site
8584
(their `parent_id` will match this site's `id`)."""
8685

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "armis_sdk"
3-
version = "1.1.1"
3+
version = "1.1.2"
44
description = "The Armis SDK is a package that encapsulates common use-cases for interacting with the Armis platform."
55
authors = [
66
{ name = "Shai Lachmanovich", email = "[email protected]" },

tests/armis_sdk/clients/assets_client_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -374,10 +374,10 @@ async def test_update_with_failed_requests(httpx_mock: pytest_httpx.HTTPXMock):
374374
with pytest.raises(
375375
BulkUpdateError,
376376
match=(
377-
"Failed to update item at index 2. "
378-
'Request: {"asset_id": 2, "key": "custom.MyField1", '
379-
'"operation": "SET", "value": "value3"}, '
380-
'Response: {"status": 400, "error": "Bad Request"}'
377+
r"Failed to update item at index 2\. "
378+
r'Request: \{"asset_id": 2, "key": "custom\.MyField1", '
379+
r'"operation": "SET", "value": "value3"\}, '
380+
r'Response: \{"status": 400, "error": "Bad Request"\}'
381381
),
382382
):
383383
await assets_client.update(assets, fields)

tests/plugins/auto_setup_plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55

66
@pytest.fixture(autouse=True)
77
def auto_setup(setup_env_variables, authorized): # pylint: disable=unused-argument
8-
yield
8+
return

0 commit comments

Comments
 (0)