Skip to content

Commit 60ea081

Browse files
committed
Specify SSC in rule_schema_v2.atd
test plan: see related semgrep PR
1 parent dd89d3c commit 60ea081

File tree

2 files changed

+57
-8
lines changed

2 files changed

+57
-8
lines changed

rule_schema_v2.atd

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,13 @@ type rule = {
7474
?match_ <json name="match">: formula option;
7575
?taint: taint option;
7676
?extract: extract option;
77-
(* TODO: steps, secrets, sca *)
77+
(* TODO: steps, secrets *)
7878
(* TODO? product: product; *)
7979

80+
(* can work with match/taint/..., maybe not extract *)
81+
?project_depends_on <json name="r2c-internal-project-depends-on">:
82+
project_depends_on option;
83+
8084
(* alt: later: could be replaced by a pattern-filename: *)
8185
?paths: paths option;
8286

@@ -400,9 +404,43 @@ type propagator = {
400404
<json adapter.ocaml="Rule_schema_v2_adapter.Formula">
401405

402406
(*****************************************************************************)
403-
(* TODO: SSC *)
407+
(* Supply chain *)
404408
(*****************************************************************************)
405409

410+
(* need an adapter there too *)
411+
type project_depends_on = [
412+
| DependsBasic <json name="B"> of project_depends_on_basic
413+
| DependsEither <json name="E"> of project_depends_on_either
414+
]
415+
<json adapter.ocaml="Rule_schema_v2_adapter.ProjectDependsOn">
416+
417+
type project_depends_on_basic = {
418+
namespace: namespace;
419+
package: string;
420+
version: semver_range;
421+
}
422+
423+
type project_depends_on_either = {
424+
depends_on_either <json name="depends-on-either">:
425+
project_depends_on_basic list;
426+
}
427+
428+
(* coupling: semgrep_output_v1.ecosystem (better name than namespace) *)
429+
type namespace = [
430+
| Npm <json name="npm">
431+
| Pypi <json name="pypi">
432+
| Gem <json name="gem">
433+
| Gomod <json name="gomod">
434+
| Cargo <json name="cargo">
435+
| Maven <json name="maven">
436+
| Composer <json name="composer">
437+
| Nuget <json name="nuget">
438+
| Pub <json name="pub">
439+
]
440+
441+
(* ex: < 0.0.8 *)
442+
type semver_range = string
443+
406444
(*****************************************************************************)
407445
(* TODO: Extract mode *)
408446
(*****************************************************************************)

rule_schema_v2_adapter.ml

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ end
2020

2121
module Condition = struct
2222

23-
(** Convert from original json to ATD-compatible json *)
2423
let normalize (orig : Yojson.Safe.t ) : Yojson.Safe.t =
2524
match orig with
2625
| `Assoc (("comparison", cmp)::rest) ->
@@ -30,6 +29,7 @@ module Condition = struct
3029
(* TODO: check at least one of type/types/... is specified *)
3130
`List [`String "M";
3231
`Assoc (("metavariable", mvar)::rest)]
32+
(* alt: we could do the String vs List in a separate adapter *)
3333
| `Assoc [("focus", `String x)] ->
3434
`List [`String "F";
3535
`Assoc [("focus", `List [`String x])]]
@@ -38,23 +38,34 @@ module Condition = struct
3838
`Assoc [("focus", `List x)]]
3939
| x -> x
4040

41-
(** Convert from ATD-compatible json to original json *)
4241
let restore (_atd : Yojson.Safe.t) : Yojson.Safe.t =
43-
(* not needed for now; we care just about parsing *)
4442
failwith "Rule_schema_v2_adapter.Condition.restore not implemented"
4543
end
4644

4745
module BySideEffect = struct
4846

49-
(** Convert from original json to ATD-compatible json *)
5047
let normalize (orig : Yojson.Safe.t ) : Yojson.Safe.t =
5148
match orig with
5249
| `Bool true -> `String "true"
5350
| `Bool false -> `String "false"
5451
| x -> x
5552

56-
(** Convert from ATD-compatible json to original json *)
5753
let restore (_atd : Yojson.Safe.t) : Yojson.Safe.t =
58-
(* not needed for now; we care just about parsing *)
5954
failwith "Rule_schema_v2_adapter.BySideEffect.restore not implemented"
6055
end
56+
57+
module ProjectDependsOn = struct
58+
59+
let normalize (orig : Yojson.Safe.t ) : Yojson.Safe.t =
60+
match orig with
61+
| `Assoc [("depends-on-either", arr)] ->
62+
`List [`String "E";
63+
`Assoc [("depends-on-either", arr)]]
64+
| `Assoc (xs) ->
65+
`List [`String "B";
66+
`Assoc xs]
67+
| x -> x
68+
69+
let restore (_atd : Yojson.Safe.t) : Yojson.Safe.t =
70+
failwith "Rule_schema_v2_adapter.ProjectDependsOn.restore not implemented"
71+
end

0 commit comments

Comments
 (0)