Skip to content

Commit b0960d2

Browse files
authored
Merge pull request #54 from returntocorp/brandon/label-pro-matches
chore: label pro matches with engine kind
2 parents 1effd3f + 394d8ac commit b0960d2

6 files changed

+340
-50
lines changed

semgrep_output_v1.atd

+11
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,13 @@ type rule_id
102102
(*****************************************************************************)
103103
(* EXPERIMENTAL: Do not rely on those internal types, they might disappear *)
104104

105+
type engine_kind
106+
<ocaml attr="deriving show">
107+
<python decorator="dataclass(frozen=True)"> = [
108+
| OSSMatch
109+
| ProMatch
110+
]
111+
105112
type core_match
106113
<ocaml attr="deriving show">
107114
<python decorator="dataclass(frozen=True)"> = {
@@ -120,6 +127,8 @@ type core_match_extra
120127
* inserted in place of the text in the matched range in order to fix the
121128
* finding. *)
122129
?rendered_fix: string option;
130+
131+
engine_kind: engine_kind;
123132
}
124133

125134
type core_match_call_trace
@@ -590,6 +599,8 @@ type cli_match_extra <ocaml attr="deriving show"> = {
590599
(* EXPERIMENTAL: For now, present only for taint findings. May be extended to others
591600
* later on. *)
592601
?dataflow_trace: cli_match_dataflow_trace option;
602+
603+
engine_kind: engine_kind;
593604
}
594605

595606
type fix_regex <ocaml attr="deriving show"> = {

semgrep_output_v1.jsonschema

+10-4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343
}
4444
},
4545
"rule_id": { "type": "string" },
46+
"engine_kind": {
47+
"oneOf": [ { "const": "OSSMatch" }, { "const": "ProMatch" } ]
48+
},
4649
"core_match": {
4750
"type": "object",
4851
"required": [ "rule_id", "location", "extra" ],
@@ -54,14 +57,15 @@
5457
},
5558
"core_match_extra": {
5659
"type": "object",
57-
"required": [ "metavars" ],
60+
"required": [ "metavars", "engine_kind" ],
5861
"properties": {
5962
"message": { "type": "string" },
6063
"metavars": { "$ref": "#/definitions/metavars" },
6164
"dataflow_trace": {
6265
"$ref": "#/definitions/core_match_dataflow_trace"
6366
},
64-
"rendered_fix": { "type": "string" }
67+
"rendered_fix": { "type": "string" },
68+
"engine_kind": { "$ref": "#/definitions/engine_kind" }
6569
}
6670
},
6771
"core_match_call_trace": {
@@ -491,7 +495,8 @@
491495
"cli_match_extra": {
492496
"type": "object",
493497
"required": [
494-
"fingerprint", "lines", "message", "metadata", "severity"
498+
"fingerprint", "lines", "message", "metadata", "severity",
499+
"engine_kind"
495500
],
496501
"properties": {
497502
"metavars": { "$ref": "#/definitions/metavars" },
@@ -507,7 +512,8 @@
507512
"fixed_lines": { "type": "array", "items": { "type": "string" } },
508513
"dataflow_trace": {
509514
"$ref": "#/definitions/cli_match_dataflow_trace"
510-
}
515+
},
516+
"engine_kind": { "$ref": "#/definitions/engine_kind" }
511517
}
512518
},
513519
"fix_regex": {

semgrep_output_v1.py

+72
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,72 @@ def write_nullable(x: Any) -> Any:
237237
############################################################################
238238

239239

240+
@dataclass(frozen=True)
241+
class OSSMatch:
242+
"""Original type: engine_kind = [ ... | OSSMatch | ... ]"""
243+
244+
@property
245+
def kind(self) -> str:
246+
"""Name of the class representing this variant."""
247+
return 'OSSMatch'
248+
249+
@staticmethod
250+
def to_json() -> Any:
251+
return 'OSSMatch'
252+
253+
def to_json_string(self, **kw: Any) -> str:
254+
return json.dumps(self.to_json(), **kw)
255+
256+
257+
@dataclass(frozen=True)
258+
class ProMatch:
259+
"""Original type: engine_kind = [ ... | ProMatch | ... ]"""
260+
261+
@property
262+
def kind(self) -> str:
263+
"""Name of the class representing this variant."""
264+
return 'ProMatch'
265+
266+
@staticmethod
267+
def to_json() -> Any:
268+
return 'ProMatch'
269+
270+
def to_json_string(self, **kw: Any) -> str:
271+
return json.dumps(self.to_json(), **kw)
272+
273+
274+
@dataclass(frozen=True)
275+
class EngineKind:
276+
"""Original type: engine_kind = [ ... ]"""
277+
278+
value: Union[OSSMatch, ProMatch]
279+
280+
@property
281+
def kind(self) -> str:
282+
"""Name of the class representing this variant."""
283+
return self.value.kind
284+
285+
@classmethod
286+
def from_json(cls, x: Any) -> 'EngineKind':
287+
if isinstance(x, str):
288+
if x == 'OSSMatch':
289+
return cls(OSSMatch())
290+
if x == 'ProMatch':
291+
return cls(ProMatch())
292+
_atd_bad_json('EngineKind', x)
293+
_atd_bad_json('EngineKind', x)
294+
295+
def to_json(self) -> Any:
296+
return self.value.to_json()
297+
298+
@classmethod
299+
def from_json_string(cls, x: str) -> 'EngineKind':
300+
return cls.from_json(json.loads(x))
301+
302+
def to_json_string(self, **kw: Any) -> str:
303+
return json.dumps(self.to_json(), **kw)
304+
305+
240306
@dataclass(frozen=True)
241307
class And:
242308
"""Original type: matching_operation = [ ... | And | ... ]"""
@@ -852,6 +918,7 @@ class CoreMatchExtra:
852918
"""Original type: core_match_extra = { ... }"""
853919

854920
metavars: Metavars
921+
engine_kind: EngineKind
855922
message: Optional[str] = None
856923
dataflow_trace: Optional[CoreMatchDataflowTrace] = None
857924
rendered_fix: Optional[str] = None
@@ -861,6 +928,7 @@ def from_json(cls, x: Any) -> 'CoreMatchExtra':
861928
if isinstance(x, dict):
862929
return cls(
863930
metavars=Metavars.from_json(x['metavars']) if 'metavars' in x else _atd_missing_json_field('CoreMatchExtra', 'metavars'),
931+
engine_kind=EngineKind.from_json(x['engine_kind']) if 'engine_kind' in x else _atd_missing_json_field('CoreMatchExtra', 'engine_kind'),
864932
message=_atd_read_string(x['message']) if 'message' in x else None,
865933
dataflow_trace=CoreMatchDataflowTrace.from_json(x['dataflow_trace']) if 'dataflow_trace' in x else None,
866934
rendered_fix=_atd_read_string(x['rendered_fix']) if 'rendered_fix' in x else None,
@@ -871,6 +939,7 @@ def from_json(cls, x: Any) -> 'CoreMatchExtra':
871939
def to_json(self) -> Any:
872940
res: Dict[str, Any] = {}
873941
res['metavars'] = (lambda x: x.to_json())(self.metavars)
942+
res['engine_kind'] = (lambda x: x.to_json())(self.engine_kind)
874943
if self.message is not None:
875944
res['message'] = _atd_write_string(self.message)
876945
if self.dataflow_trace is not None:
@@ -2837,6 +2906,7 @@ class CliMatchExtra:
28372906
message: str
28382907
metadata: RawJson
28392908
severity: str
2909+
engine_kind: EngineKind
28402910
metavars: Optional[Metavars] = None
28412911
fix: Optional[str] = None
28422912
fix_regex: Optional[FixRegex] = None
@@ -2854,6 +2924,7 @@ def from_json(cls, x: Any) -> 'CliMatchExtra':
28542924
message=_atd_read_string(x['message']) if 'message' in x else _atd_missing_json_field('CliMatchExtra', 'message'),
28552925
metadata=RawJson.from_json(x['metadata']) if 'metadata' in x else _atd_missing_json_field('CliMatchExtra', 'metadata'),
28562926
severity=_atd_read_string(x['severity']) if 'severity' in x else _atd_missing_json_field('CliMatchExtra', 'severity'),
2927+
engine_kind=EngineKind.from_json(x['engine_kind']) if 'engine_kind' in x else _atd_missing_json_field('CliMatchExtra', 'engine_kind'),
28572928
metavars=Metavars.from_json(x['metavars']) if 'metavars' in x else None,
28582929
fix=_atd_read_string(x['fix']) if 'fix' in x else None,
28592930
fix_regex=FixRegex.from_json(x['fix_regex']) if 'fix_regex' in x else None,
@@ -2872,6 +2943,7 @@ def to_json(self) -> Any:
28722943
res['message'] = _atd_write_string(self.message)
28732944
res['metadata'] = (lambda x: x.to_json())(self.metadata)
28742945
res['severity'] = _atd_write_string(self.severity)
2946+
res['engine_kind'] = (lambda x: x.to_json())(self.engine_kind)
28752947
if self.metavars is not None:
28762948
res['metavars'] = (lambda x: x.to_json())(self.metavars)
28772949
if self.fix is not None:

semgrep_output_v1.ts

+31
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ export type Location = {
3030

3131
export type RuleId = string
3232

33+
export type EngineKind =
34+
| { kind: 'OSSMatch' }
35+
| { kind: 'ProMatch' }
36+
3337
export type CoreMatch = {
3438
rule_id: RuleId;
3539
location: Location;
@@ -41,6 +45,7 @@ export type CoreMatchExtra = {
4145
metavars: Metavars;
4246
dataflow_trace?: CoreMatchDataflowTrace;
4347
rendered_fix?: string;
48+
engine_kind: EngineKind;
4449
}
4550

4651
export type CoreMatchCallTrace =
@@ -259,6 +264,7 @@ export type CliMatchExtra = {
259264
sca_info?: ScaInfo;
260265
fixed_lines?: string[];
261266
dataflow_trace?: CliMatchDataflowTrace;
267+
engine_kind: EngineKind;
262268
}
263269

264270
export type FixRegex = {
@@ -441,6 +447,27 @@ export function readRuleId(x: any, context: any = x): RuleId {
441447
return _atd_read_string(x, context);
442448
}
443449

450+
export function writeEngineKind(x: EngineKind, context: any = x): any {
451+
switch (x.kind) {
452+
case 'OSSMatch':
453+
return 'OSSMatch'
454+
case 'ProMatch':
455+
return 'ProMatch'
456+
}
457+
}
458+
459+
export function readEngineKind(x: any, context: any = x): EngineKind {
460+
switch (x) {
461+
case 'OSSMatch':
462+
return { kind: 'OSSMatch' }
463+
case 'ProMatch':
464+
return { kind: 'ProMatch' }
465+
default:
466+
_atd_bad_json('EngineKind', x, context)
467+
throw new Error('impossible')
468+
}
469+
}
470+
444471
export function writeCoreMatch(x: CoreMatch, context: any = x): any {
445472
return {
446473
'rule_id': _atd_write_required_field('CoreMatch', 'rule_id', writeRuleId, x.rule_id, x),
@@ -463,6 +490,7 @@ export function writeCoreMatchExtra(x: CoreMatchExtra, context: any = x): any {
463490
'metavars': _atd_write_required_field('CoreMatchExtra', 'metavars', writeMetavars, x.metavars, x),
464491
'dataflow_trace': _atd_write_optional_field(writeCoreMatchDataflowTrace, x.dataflow_trace, x),
465492
'rendered_fix': _atd_write_optional_field(_atd_write_string, x.rendered_fix, x),
493+
'engine_kind': _atd_write_required_field('CoreMatchExtra', 'engine_kind', writeEngineKind, x.engine_kind, x),
466494
};
467495
}
468496

@@ -472,6 +500,7 @@ export function readCoreMatchExtra(x: any, context: any = x): CoreMatchExtra {
472500
metavars: _atd_read_required_field('CoreMatchExtra', 'metavars', readMetavars, x['metavars'], x),
473501
dataflow_trace: _atd_read_optional_field(readCoreMatchDataflowTrace, x['dataflow_trace'], x),
474502
rendered_fix: _atd_read_optional_field(_atd_read_string, x['rendered_fix'], x),
503+
engine_kind: _atd_read_required_field('CoreMatchExtra', 'engine_kind', readEngineKind, x['engine_kind'], x),
475504
};
476505
}
477506

@@ -1145,6 +1174,7 @@ export function writeCliMatchExtra(x: CliMatchExtra, context: any = x): any {
11451174
'sca_info': _atd_write_optional_field(writeScaInfo, x.sca_info, x),
11461175
'fixed_lines': _atd_write_optional_field(_atd_write_array(_atd_write_string), x.fixed_lines, x),
11471176
'dataflow_trace': _atd_write_optional_field(writeCliMatchDataflowTrace, x.dataflow_trace, x),
1177+
'engine_kind': _atd_write_required_field('CliMatchExtra', 'engine_kind', writeEngineKind, x.engine_kind, x),
11481178
};
11491179
}
11501180

@@ -1162,6 +1192,7 @@ export function readCliMatchExtra(x: any, context: any = x): CliMatchExtra {
11621192
sca_info: _atd_read_optional_field(readScaInfo, x['sca_info'], x),
11631193
fixed_lines: _atd_read_optional_field(_atd_read_array(_atd_read_string), x['fixed_lines'], x),
11641194
dataflow_trace: _atd_read_optional_field(readCliMatchDataflowTrace, x['dataflow_trace'], x),
1195+
engine_kind: _atd_read_required_field('CliMatchExtra', 'engine_kind', readEngineKind, x['engine_kind'], x),
11651196
};
11661197
}
11671198

0 commit comments

Comments
 (0)