Skip to content

Commit 0fcf014

Browse files
authored
Allow trusting custom integration fingerprints (#42)
This adds three new `ImportAsset` attributes to allow custom integrations to specify that their fingerprint data should be trusted, even if the data cannot be normalized by runZero's fingerprint engine: * `trust_os` - Trusts the `os` attribute and use it to set Asset OS * `trust_os_version` - Trusts the `os_version` attribute and use it to set Asset OS * `trust_device_type` - Trusts the `device_type` attribute and use to to set Asset Type Without these options set, `os`, `os_version` and `device_type` will only be used to set the runZero asset fingerprint if they can be normalized via runZero's fingerprint engine. `os`, `os_version` and `device_type` are always available under the custom integrations attributes, even when the corresponding `trust_*` options are not set. ## Example: ```py asset = ImportAsset( id=f"test-asset-{i}", hostnames=[f"test-asset-{i}"], device_type="Custom Type", os="Custom OS", os_version="0.1.2", trust_device_type=True, trust_os=True, trust_os_version=True, ) ```
1 parent 218466c commit 0fcf014

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "runzero-sdk"
3-
version = "0.8.6"
3+
version = "0.8.7"
44
description = "The runZero platform sdk"
55
license = "BSD-2-Clause"
66
authors = ["runZero <[email protected]>"]

runzero/types/_data_models_gen.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,3 +1097,15 @@ class Config:
10971097
"""
10981098
Flat map of arbitrary string key/value pairs representing custom attribute data not described in properties above. Note the maximum number of keys and length of values. Additionally, property names may only be 256 characters long.
10991099
"""
1100+
trust_os: Optional[bool] = Field(False, alias="trustOS", example=False)
1101+
"""
1102+
If true, the provided OS value will be used even if it cannot be normalized using runZero's fingerprint engine.
1103+
"""
1104+
trust_os_version: Optional[bool] = Field(False, alias="trustOSVersion", example=False)
1105+
"""
1106+
If true, the provided OS version value will be used even if it cannot be normalized using runZero's fingerprint engine.
1107+
"""
1108+
trust_device_type: Optional[bool] = Field(False, alias="trustDeviceType", example=False)
1109+
"""
1110+
If true, the provided device type value will be used even if it cannot be normalized using runZero's fingerprint engine.
1111+
"""

tests/runzero/test_orgs.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,22 @@ def test_client_org_create_and_delete(account_client, integration_config, reques
4141
assert created_org.name == org_name
4242

4343
org = org_mgr.get(org_id=created_org.id)
44-
assert org == created_org
44+
if (
45+
equal_ignore_fields(
46+
org,
47+
created_org,
48+
[
49+
"export_token",
50+
"export_token_created_at",
51+
"export_token_last_used_at",
52+
"export_token_last_used_by",
53+
"export_token_counter",
54+
],
55+
)
56+
!= True
57+
):
58+
# asserting here instead of equal_ignore_fields gives better error messages
59+
assert org == created_org
4560

4661
org_mgr.delete(org_id=org.id)
4762
with pytest.raises(ClientError):
@@ -82,3 +97,22 @@ def test_client_org_create_twice_is_error(account_client, integration_config, re
8297
org_mgr.delete(created_org.id)
8398
with pytest.raises(ClientError):
8499
org_mgr.get(org_id=created_org.id)
100+
101+
102+
def equal_ignore_fields(obj1, obj2, ignore_fields=None):
103+
if ignore_fields is None:
104+
ignore_fields = []
105+
106+
if type(obj1) != type(obj2):
107+
return False
108+
109+
for field in obj1.__dict__: # Assuming objects have __dict__ for attributes
110+
if field in ignore_fields:
111+
continue
112+
value1 = getattr(obj1, field)
113+
value2 = getattr(obj2, field)
114+
115+
# For other fields or if the special condition wasn't met
116+
if value1 != value2:
117+
return False
118+
return True

0 commit comments

Comments
 (0)