Skip to content

Commit 1cda73e

Browse files
Added support for the bulk create traces endpoint (#2873)
1 parent d3f6da5 commit 1cda73e

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

pyobas/apis/inject_expectation/inject_expectation.py

+11
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,14 @@ def update(
105105
path = f"{self.path}/{inject_expectation_id}"
106106
result = self.openbas.http_put(path, post_data=inject_expectation, **kwargs)
107107
return result
108+
109+
@exc.on_http_error(exc.OpenBASUpdateError)
110+
def bulk_update(
111+
self,
112+
inject_expectation_input_by_id: Dict[str, Dict[str, Any]],
113+
**kwargs: Any,
114+
) -> None:
115+
path = f"{self.path}/bulk"
116+
self.openbas.http_put(
117+
path, post_data={"inputs": inject_expectation_input_by_id}, **kwargs
118+
)

pyobas/apis/inject_expectation_trace.py

+15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from typing import Any, Dict, List
2+
3+
from pyobas import exceptions as exc
14
from pyobas.base import RESTManager, RESTObject
25
from pyobas.mixins import CreateMixin
36
from pyobas.utils import RequiredOptional
@@ -19,3 +22,15 @@ class InjectExpectationTraceManager(CreateMixin, RESTManager):
1922
"inject_expectation_trace_date",
2023
),
2124
)
25+
26+
@exc.on_http_error(exc.OpenBASUpdateError)
27+
def bulk_create(
28+
self, payload: Dict[str, List[Dict[str, str]]], **kwargs: Any
29+
) -> dict[str, Any]:
30+
path = f"{self.path}/bulk"
31+
result = self.openbas.http_post(
32+
path,
33+
post_data=payload,
34+
**kwargs,
35+
)
36+
return result

pyobas/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def add_fields(self, log_record, record, message_dict):
121121
super(CustomJsonFormatter, self).add_fields(log_record, record, message_dict)
122122
if not log_record.get("timestamp"):
123123
# This doesn't use record.created, so it is slightly off
124-
now = datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S.%fZ")
124+
now = datetime.datetime.now(datetime.UTC).strftime("%Y-%m-%dT%H:%M:%S.%fZ")
125125
log_record["timestamp"] = now
126126
if log_record.get("level"):
127127
log_record["level"] = log_record["level"].upper()

0 commit comments

Comments
 (0)