Skip to content

Commit 61e4421

Browse files
committed
[client] Enhance inject expectation APIs
1 parent 7f55486 commit 61e4421

File tree

5 files changed

+36
-2
lines changed

5 files changed

+36
-2
lines changed

pyobas/apis/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from .attack_pattern import * # noqa: F401,F403
22
from .collector import * # noqa: F401,F403
33
from .document import * # noqa: F401,F403
4+
from .endpoint import * # noqa: F401,F403
45
from .inject import * # noqa: F401,F403
56
from .inject_expectation import * # noqa: F401,F403
67
from .injector import * # noqa: F401,F403

pyobas/apis/endpoint.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from typing import Any, Dict, List
2+
3+
from pyobas import exceptions as exc
4+
from pyobas.base import RESTManager, RESTObject
5+
6+
7+
class Endpoint(RESTObject):
8+
_id_attr = "asset_id"
9+
10+
11+
class EndpointManager(RESTManager):
12+
_path = "/endpoints"
13+
_obj_cls = Endpoint
14+
15+
@exc.on_http_error(exc.OpenBASUpdateError)
16+
def get(self, asset_id: str, **kwargs: Any) -> Dict[str, Any]:
17+
path = f"{self.path}/" + asset_id
18+
result = self.openbas.http_get(path, **kwargs)
19+
return result

pyobas/apis/inject_expectation.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,31 @@
33
from pyobas import exceptions as exc
44
from pyobas.base import RESTManager, RESTObject
55
from pyobas.mixins import ListMixin, UpdateMixin
6+
from pyobas.utils import RequiredOptional
67

78

89
class InjectExpectation(RESTObject):
9-
pass
10+
_id_attr = "inject_expectation_id"
1011

1112

1213
class InjectExpectationManager(ListMixin, UpdateMixin, RESTManager):
1314
_path = "/injects/expectations"
1415
_obj_cls = InjectExpectation
16+
_update_attrs = RequiredOptional(required=("collector_id", "result", "is_success"))
1517

1618
@exc.on_http_error(exc.OpenBASUpdateError)
1719
def expectations_for_source(self, source_id: str, **kwargs: Any) -> Dict[str, Any]:
1820
path = f"{self.path}/" + source_id
1921
result = self.openbas.http_get(path, **kwargs)
2022
return result
23+
24+
@exc.on_http_error(exc.OpenBASUpdateError)
25+
def update(
26+
self,
27+
inject_expectation_id: str,
28+
inject_expectation: Dict[str, Any],
29+
**kwargs: Any,
30+
) -> Dict[str, Any]:
31+
path = f"{self.path}/{inject_expectation_id}"
32+
result = self.openbas.http_put(path, post_data=inject_expectation, **kwargs)
33+
return result

pyobas/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def __init__(
6464
self.kill_chain_phase = apis.KillChainPhaseManager(self)
6565
self.attack_pattern = apis.AttackPatternManager(self)
6666
self.team = apis.TeamManager(self)
67+
self.endpoint = apis.EndpointManager(self)
6768
self.user = apis.UserManager(self)
6869
self.inject_expectation = apis.InjectExpectationManager(self)
6970

@@ -294,7 +295,6 @@ def http_put(
294295
) -> Union[Dict[str, Any], requests.Response]:
295296
query_data = query_data or {}
296297
post_data = post_data or {}
297-
298298
result = self.http_request(
299299
"put",
300300
path,

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
PyYAML~=6.0
22
requests~=2.32.2
3+
datefinder~=0.7.3
34
requests-toolbelt~=1.0.0
45
dataclasses-json~=0.6.4
56
pika~=1.3.0

0 commit comments

Comments
 (0)