Skip to content

Commit 93a8281

Browse files
committed
[client] Introduce endpoint upsert
1 parent bda7463 commit 93a8281

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,6 @@ dmypy.json
133133

134134
# Cython debug symbols
135135
cython_debug/
136+
137+
# testing
138+
test.py

pyobas/apis/endpoint.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from pyobas import exceptions as exc
44
from pyobas.base import RESTManager, RESTObject
5-
5+
from pyobas.utils import RequiredOptional
66

77
class Endpoint(RESTObject):
88
_id_attr = "asset_id"
@@ -11,9 +11,24 @@ class Endpoint(RESTObject):
1111
class EndpointManager(RESTManager):
1212
_path = "/endpoints"
1313
_obj_cls = Endpoint
14+
_create_attrs = RequiredOptional(
15+
required=("endpoint_hostname", "endpoint_ips", "endpoint_platform", "endpoint_arch"),
16+
optional=(
17+
"endpoint_mac_addresses",
18+
"asset_external_reference",
19+
),
20+
)
1421

1522
@exc.on_http_error(exc.OpenBASUpdateError)
1623
def get(self, asset_id: str, **kwargs: Any) -> Dict[str, Any]:
1724
path = f"{self.path}/" + asset_id
1825
result = self.openbas.http_get(path, **kwargs)
1926
return result
27+
28+
@exc.on_http_error(exc.OpenBASUpdateError)
29+
def upsert(
30+
self, endpoint: Dict[str, Any], **kwargs: Any
31+
) -> Dict[str, Any]:
32+
path = f"{self.path}/agentless/upsert"
33+
result = self.openbas.http_post(path, post_data=endpoint, **kwargs)
34+
return result

0 commit comments

Comments
 (0)