Skip to content

Commit f5d832c

Browse files
committed
fix(manager): build_payload accepts extra by expectation_type (#206)
1 parent 08988f8 commit f5d832c

4 files changed

Lines changed: 52 additions & 15 deletions

File tree

pyoaev/signatures/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111
build_network_configs,
1212
)
1313
from pyoaev.signatures.signature_manager import SignatureManager
14-
from pyoaev.signatures.types import MatchTypes, SignatureTypes
14+
from pyoaev.signatures.types import ExpectationType, MatchTypes, SignatureTypes
1515

1616
__all__ = [
1717
"CloudInjectorConfig",
1818
"ExpectationSignatureGroup",
1919
"ExternalInjectorConfig",
20+
"ExpectationType",
2021
"InjectorConfig",
2122
"MatchTypes",
2223
"NetworkInjectorConfig",

pyoaev/signatures/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import ipaddress
44
from typing import Any
55

6-
from pydantic import BaseModel, ConfigDict
6+
from pydantic import BaseModel, ConfigDict, JsonValue
77

88

99
class SignatureValue(BaseModel):
@@ -12,7 +12,7 @@ class SignatureValue(BaseModel):
1212
model_config = ConfigDict(extra="allow")
1313

1414
signature_type: str
15-
signature_value: str
15+
signature_value: JsonValue
1616

1717

1818
class ExpectationSignatureGroup(BaseModel):

pyoaev/signatures/signature_manager.py

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
TargetSignatures,
2424
ToolOutput,
2525
)
26+
from pyoaev.signatures.types import ExpectationType
2627

2728
if TYPE_CHECKING:
2829
from pyoaev.client import OpenAEV
@@ -172,10 +173,11 @@ def _merge_post(
172173

173174
return merged
174175

176+
@staticmethod
175177
def build_payload(
176-
self,
177178
post_signatures: dict[str, Any] | list[dict[str, Any]],
178179
expectation_types: list[str],
180+
extra_signature: dict | None = None,
179181
) -> dict[str, Any]:
180182
"""Build the nested wire payload from flat post-execution signatures.
181183
@@ -185,26 +187,54 @@ def build_payload(
185187
Args:
186188
post_signatures: A single post-execution dict or a list (multi-targets).
187189
expectation_types: The 1+ expectation type labels (e.g. ['DETECTION', 'PREVENTION']).
190+
extra_signature: Optional mapping of expectation types to additional signature fields that will be merged
191+
into the base post_signatures.
188192
189193
Returns:
190194
A payload dict ready for send_signatures.
191195
"""
192196
if isinstance(post_signatures, dict):
193197
post_signatures = [post_signatures]
194198

199+
# Validate expectation types
200+
expectation_types_valid = [
201+
ExpectationType(expectation_type.upper())
202+
for expectation_type in expectation_types
203+
]
204+
# Normalize and validate extra_signatures keys
205+
extra_signatures = {
206+
ExpectationType(key.upper()): value
207+
for key, value in (extra_signature or {}).items()
208+
}
209+
195210
targets = []
196-
for sig in post_signatures:
197-
values = [
198-
SignatureValue(signature_type=k, signature_value=str(v))
199-
for k, v in sig.items()
200-
]
201-
signature_values = [
202-
ExpectationSignatureGroup(
203-
expectation_type=expectation_type, values=values
211+
for signature in post_signatures:
212+
signature_values = []
213+
214+
for expectation_type in expectation_types_valid:
215+
signature_data = signature.copy()
216+
if expectation_type in extra_signatures:
217+
signature_data.update(extra_signatures[expectation_type])
218+
219+
values = [
220+
SignatureValue(
221+
signature_type=key,
222+
signature_value=value,
223+
)
224+
for key, value in signature_data.items()
225+
]
226+
227+
signature_values.append(
228+
ExpectationSignatureGroup(
229+
expectation_type=expectation_type.value,
230+
values=values,
231+
)
204232
)
205-
for expectation_type in expectation_types
206-
]
207-
targets.append(TargetSignatures(signature_values=signature_values))
233+
targets.append(
234+
TargetSignatures(
235+
signature_values=signature_values,
236+
)
237+
)
208238

209239
return SignaturePayload(targets=targets).model_dump()
210240

pyoaev/signatures/types.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
from enum import Enum
22

33

4+
class ExpectationType(str, Enum):
5+
DETECTION = "DETECTION"
6+
PREVENTION = "PREVENTION"
7+
VULNERABILITY = "VULNERABILITY"
8+
9+
410
class MatchTypes(str, Enum):
511
MATCH_TYPE_FUZZY = "fuzzy"
612
MATCH_TYPE_SIMPLE = "simple"

0 commit comments

Comments
 (0)