From b2bcdbba50872d9bf7770a8b1e2d6f0e7ca1b0da Mon Sep 17 00:00:00 2001 From: SayyantR Date: Thu, 24 Oct 2024 15:01:30 -0700 Subject: [PATCH 1/2] Added rest of ManifestKinds --- semgrep_output_v1.atd | 12 ++ semgrep_output_v1.jsonschema | 17 ++- semgrep_output_v1.proto | 2 +- semgrep_output_v1.py | 230 ++++++++++++++++++++++++++++++++++- semgrep_output_v1.ts | 60 +++++++++ semgrep_output_v1_j.ml | 84 +++++++++++++ 6 files changed, 402 insertions(+), 3 deletions(-) diff --git a/semgrep_output_v1.atd b/semgrep_output_v1.atd index 5b9a5226..e2c7f96a 100644 --- a/semgrep_output_v1.atd +++ b/semgrep_output_v1.atd @@ -1815,8 +1815,20 @@ type output_format = [ (* TODO: merge with Manifest_kind.ml *) type manifest_kind = [ + | Requirements + | PackageJson + | Gemfile + | GoMod + | CargoToml | PomXml | BuildGradle + | ComposerJson + | NugetManifestJson + | PubspecYaml + | PackageSwift + | MixExs + | Pipfile + | PyprojectToml ] type manifest = { diff --git a/semgrep_output_v1.jsonschema b/semgrep_output_v1.jsonschema index 355ca226..d72f0f1c 100644 --- a/semgrep_output_v1.jsonschema +++ b/semgrep_output_v1.jsonschema @@ -1511,7 +1511,22 @@ "oneOf": [ { "const": "Vim" }, { "const": "Emacs" } ] }, "manifest_kind": { - "oneOf": [ { "const": "PomXml" }, { "const": "BuildGradle" } ] + "oneOf": [ + { "const": "Requirements" }, + { "const": "PackageJson" }, + { "const": "Gemfile" }, + { "const": "GoMod" }, + { "const": "CargoToml" }, + { "const": "PomXml" }, + { "const": "BuildGradle" }, + { "const": "ComposerJson" }, + { "const": "NugetManifestJson" }, + { "const": "PubspecYaml" }, + { "const": "PackageSwift" }, + { "const": "MixExs" }, + { "const": "Pipfile" }, + { "const": "PyprojectToml" } + ] }, "manifest": { "type": "object", diff --git a/semgrep_output_v1.proto b/semgrep_output_v1.proto index 4ef46d82..bb8aeee4 100644 --- a/semgrep_output_v1.proto +++ b/semgrep_output_v1.proto @@ -1,6 +1,6 @@ // Generated by jsonschema2protobuf. DO NOT EDIT! // Source file: semgrep_output_v1.jsonschema -// Source file sha256 digest: 1dafd6316cd4beb7f32e2081510da5297aebe6a1990dd95e075b59899516a608 +// Source file sha256 digest: 36a3c1aa9fab90804be3d9f2c328d5839ed4bd1eb44e173fea845a75f718edb0 syntax = "proto3"; diff --git a/semgrep_output_v1.py b/semgrep_output_v1.py index bad51331..e2bae86c 100644 --- a/semgrep_output_v1.py +++ b/semgrep_output_v1.py @@ -6548,6 +6548,91 @@ def to_json_string(self, **kw: Any) -> str: return json.dumps(self.to_json(), **kw) +@dataclass +class Requirements_: + """Original type: manifest_kind = [ ... | Requirements | ... ]""" + + @property + def kind(self) -> str: + """Name of the class representing this variant.""" + return 'Requirements_' + + @staticmethod + def to_json() -> Any: + return 'Requirements' + + def to_json_string(self, **kw: Any) -> str: + return json.dumps(self.to_json(), **kw) + + +@dataclass +class PackageJson: + """Original type: manifest_kind = [ ... | PackageJson | ... ]""" + + @property + def kind(self) -> str: + """Name of the class representing this variant.""" + return 'PackageJson' + + @staticmethod + def to_json() -> Any: + return 'PackageJson' + + def to_json_string(self, **kw: Any) -> str: + return json.dumps(self.to_json(), **kw) + + +@dataclass +class Gemfile: + """Original type: manifest_kind = [ ... | Gemfile | ... ]""" + + @property + def kind(self) -> str: + """Name of the class representing this variant.""" + return 'Gemfile' + + @staticmethod + def to_json() -> Any: + return 'Gemfile' + + def to_json_string(self, **kw: Any) -> str: + return json.dumps(self.to_json(), **kw) + + +@dataclass +class GoMod_: + """Original type: manifest_kind = [ ... | GoMod | ... ]""" + + @property + def kind(self) -> str: + """Name of the class representing this variant.""" + return 'GoMod_' + + @staticmethod + def to_json() -> Any: + return 'GoMod' + + def to_json_string(self, **kw: Any) -> str: + return json.dumps(self.to_json(), **kw) + + +@dataclass +class CargoToml: + """Original type: manifest_kind = [ ... | CargoToml | ... ]""" + + @property + def kind(self) -> str: + """Name of the class representing this variant.""" + return 'CargoToml' + + @staticmethod + def to_json() -> Any: + return 'CargoToml' + + def to_json_string(self, **kw: Any) -> str: + return json.dumps(self.to_json(), **kw) + + @dataclass class PomXml: """Original type: manifest_kind = [ ... | PomXml | ... ]""" @@ -6582,11 +6667,130 @@ def to_json_string(self, **kw: Any) -> str: return json.dumps(self.to_json(), **kw) +@dataclass +class ComposerJson: + """Original type: manifest_kind = [ ... | ComposerJson | ... ]""" + + @property + def kind(self) -> str: + """Name of the class representing this variant.""" + return 'ComposerJson' + + @staticmethod + def to_json() -> Any: + return 'ComposerJson' + + def to_json_string(self, **kw: Any) -> str: + return json.dumps(self.to_json(), **kw) + + +@dataclass +class NugetManifestJson: + """Original type: manifest_kind = [ ... | NugetManifestJson | ... ]""" + + @property + def kind(self) -> str: + """Name of the class representing this variant.""" + return 'NugetManifestJson' + + @staticmethod + def to_json() -> Any: + return 'NugetManifestJson' + + def to_json_string(self, **kw: Any) -> str: + return json.dumps(self.to_json(), **kw) + + +@dataclass +class PubspecYaml: + """Original type: manifest_kind = [ ... | PubspecYaml | ... ]""" + + @property + def kind(self) -> str: + """Name of the class representing this variant.""" + return 'PubspecYaml' + + @staticmethod + def to_json() -> Any: + return 'PubspecYaml' + + def to_json_string(self, **kw: Any) -> str: + return json.dumps(self.to_json(), **kw) + + +@dataclass +class PackageSwift_: + """Original type: manifest_kind = [ ... | PackageSwift | ... ]""" + + @property + def kind(self) -> str: + """Name of the class representing this variant.""" + return 'PackageSwift_' + + @staticmethod + def to_json() -> Any: + return 'PackageSwift' + + def to_json_string(self, **kw: Any) -> str: + return json.dumps(self.to_json(), **kw) + + +@dataclass +class MixExs: + """Original type: manifest_kind = [ ... | MixExs | ... ]""" + + @property + def kind(self) -> str: + """Name of the class representing this variant.""" + return 'MixExs' + + @staticmethod + def to_json() -> Any: + return 'MixExs' + + def to_json_string(self, **kw: Any) -> str: + return json.dumps(self.to_json(), **kw) + + +@dataclass +class Pipfile_: + """Original type: manifest_kind = [ ... | Pipfile | ... ]""" + + @property + def kind(self) -> str: + """Name of the class representing this variant.""" + return 'Pipfile_' + + @staticmethod + def to_json() -> Any: + return 'Pipfile' + + def to_json_string(self, **kw: Any) -> str: + return json.dumps(self.to_json(), **kw) + + +@dataclass +class PyprojectToml_: + """Original type: manifest_kind = [ ... | PyprojectToml | ... ]""" + + @property + def kind(self) -> str: + """Name of the class representing this variant.""" + return 'PyprojectToml_' + + @staticmethod + def to_json() -> Any: + return 'PyprojectToml' + + def to_json_string(self, **kw: Any) -> str: + return json.dumps(self.to_json(), **kw) + + @dataclass class ManifestKind: """Original type: manifest_kind = [ ... ]""" - value: Union[PomXml, BuildGradle] + value: Union[Requirements_, PackageJson, Gemfile, GoMod_, CargoToml, PomXml, BuildGradle, ComposerJson, NugetManifestJson, PubspecYaml, PackageSwift_, MixExs, Pipfile_, PyprojectToml_] @property def kind(self) -> str: @@ -6596,10 +6800,34 @@ def kind(self) -> str: @classmethod def from_json(cls, x: Any) -> 'ManifestKind': if isinstance(x, str): + if x == 'Requirements': + return cls(Requirements_()) + if x == 'PackageJson': + return cls(PackageJson()) + if x == 'Gemfile': + return cls(Gemfile()) + if x == 'GoMod': + return cls(GoMod_()) + if x == 'CargoToml': + return cls(CargoToml()) if x == 'PomXml': return cls(PomXml()) if x == 'BuildGradle': return cls(BuildGradle()) + if x == 'ComposerJson': + return cls(ComposerJson()) + if x == 'NugetManifestJson': + return cls(NugetManifestJson()) + if x == 'PubspecYaml': + return cls(PubspecYaml()) + if x == 'PackageSwift': + return cls(PackageSwift_()) + if x == 'MixExs': + return cls(MixExs()) + if x == 'Pipfile': + return cls(Pipfile_()) + if x == 'PyprojectToml': + return cls(PyprojectToml_()) _atd_bad_json('ManifestKind', x) _atd_bad_json('ManifestKind', x) diff --git a/semgrep_output_v1.ts b/semgrep_output_v1.ts index 0da31341..a3443bc6 100644 --- a/semgrep_output_v1.ts +++ b/semgrep_output_v1.ts @@ -834,8 +834,20 @@ export type OutputFormat = | { kind: 'Emacs' } export type ManifestKind = +| { kind: 'Requirements' } +| { kind: 'PackageJson' } +| { kind: 'Gemfile' } +| { kind: 'GoMod' } +| { kind: 'CargoToml' } | { kind: 'PomXml' } | { kind: 'BuildGradle' } +| { kind: 'ComposerJson' } +| { kind: 'NugetManifestJson' } +| { kind: 'PubspecYaml' } +| { kind: 'PackageSwift' } +| { kind: 'MixExs' } +| { kind: 'Pipfile' } +| { kind: 'PyprojectToml' } export type Manifest = { kind: ManifestKind; @@ -3387,19 +3399,67 @@ export function readOutputFormat(x: any, context: any = x): OutputFormat { export function writeManifestKind(x: ManifestKind, context: any = x): any { switch (x.kind) { + case 'Requirements': + return 'Requirements' + case 'PackageJson': + return 'PackageJson' + case 'Gemfile': + return 'Gemfile' + case 'GoMod': + return 'GoMod' + case 'CargoToml': + return 'CargoToml' case 'PomXml': return 'PomXml' case 'BuildGradle': return 'BuildGradle' + case 'ComposerJson': + return 'ComposerJson' + case 'NugetManifestJson': + return 'NugetManifestJson' + case 'PubspecYaml': + return 'PubspecYaml' + case 'PackageSwift': + return 'PackageSwift' + case 'MixExs': + return 'MixExs' + case 'Pipfile': + return 'Pipfile' + case 'PyprojectToml': + return 'PyprojectToml' } } export function readManifestKind(x: any, context: any = x): ManifestKind { switch (x) { + case 'Requirements': + return { kind: 'Requirements' } + case 'PackageJson': + return { kind: 'PackageJson' } + case 'Gemfile': + return { kind: 'Gemfile' } + case 'GoMod': + return { kind: 'GoMod' } + case 'CargoToml': + return { kind: 'CargoToml' } case 'PomXml': return { kind: 'PomXml' } case 'BuildGradle': return { kind: 'BuildGradle' } + case 'ComposerJson': + return { kind: 'ComposerJson' } + case 'NugetManifestJson': + return { kind: 'NugetManifestJson' } + case 'PubspecYaml': + return { kind: 'PubspecYaml' } + case 'PackageSwift': + return { kind: 'PackageSwift' } + case 'MixExs': + return { kind: 'MixExs' } + case 'Pipfile': + return { kind: 'Pipfile' } + case 'PyprojectToml': + return { kind: 'PyprojectToml' } default: _atd_bad_json('ManifestKind', x, context) throw new Error('impossible') diff --git a/semgrep_output_v1_j.ml b/semgrep_output_v1_j.ml index 848e0c82..176e0310 100644 --- a/semgrep_output_v1_j.ml +++ b/semgrep_output_v1_j.ml @@ -26246,8 +26246,20 @@ let output_format_of_string s = let write_manifest_kind = ( fun ob x -> match x with + | `Requirements -> Buffer.add_string ob "\"Requirements\"" + | `PackageJson -> Buffer.add_string ob "\"PackageJson\"" + | `Gemfile -> Buffer.add_string ob "\"Gemfile\"" + | `GoMod -> Buffer.add_string ob "\"GoMod\"" + | `CargoToml -> Buffer.add_string ob "\"CargoToml\"" | `PomXml -> Buffer.add_string ob "\"PomXml\"" | `BuildGradle -> Buffer.add_string ob "\"BuildGradle\"" + | `ComposerJson -> Buffer.add_string ob "\"ComposerJson\"" + | `NugetManifestJson -> Buffer.add_string ob "\"NugetManifestJson\"" + | `PubspecYaml -> Buffer.add_string ob "\"PubspecYaml\"" + | `PackageSwift -> Buffer.add_string ob "\"PackageSwift\"" + | `MixExs -> Buffer.add_string ob "\"MixExs\"" + | `Pipfile -> Buffer.add_string ob "\"Pipfile\"" + | `PyprojectToml -> Buffer.add_string ob "\"PyprojectToml\"" ) let string_of_manifest_kind ?(len = 1024) x = let ob = Buffer.create len in @@ -26259,6 +26271,26 @@ let read_manifest_kind = ( match Yojson.Safe.start_any_variant p lb with | `Edgy_bracket -> ( match Yojson.Safe.read_ident p lb with + | "Requirements" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + `Requirements + | "PackageJson" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + `PackageJson + | "Gemfile" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + `Gemfile + | "GoMod" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + `GoMod + | "CargoToml" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + `CargoToml | "PomXml" -> Yojson.Safe.read_space p lb; Yojson.Safe.read_gt p lb; @@ -26267,15 +26299,67 @@ let read_manifest_kind = ( Yojson.Safe.read_space p lb; Yojson.Safe.read_gt p lb; `BuildGradle + | "ComposerJson" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + `ComposerJson + | "NugetManifestJson" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + `NugetManifestJson + | "PubspecYaml" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + `PubspecYaml + | "PackageSwift" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + `PackageSwift + | "MixExs" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + `MixExs + | "Pipfile" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + `Pipfile + | "PyprojectToml" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + `PyprojectToml | x -> Atdgen_runtime.Oj_run.invalid_variant_tag p x ) | `Double_quote -> ( match Yojson.Safe.finish_string p lb with + | "Requirements" -> + `Requirements + | "PackageJson" -> + `PackageJson + | "Gemfile" -> + `Gemfile + | "GoMod" -> + `GoMod + | "CargoToml" -> + `CargoToml | "PomXml" -> `PomXml | "BuildGradle" -> `BuildGradle + | "ComposerJson" -> + `ComposerJson + | "NugetManifestJson" -> + `NugetManifestJson + | "PubspecYaml" -> + `PubspecYaml + | "PackageSwift" -> + `PackageSwift + | "MixExs" -> + `MixExs + | "Pipfile" -> + `Pipfile + | "PyprojectToml" -> + `PyprojectToml | x -> Atdgen_runtime.Oj_run.invalid_variant_tag p x ) From 5de7dfb3ceb9561338d0f3c93072315e0e3972b8 Mon Sep 17 00:00:00 2001 From: SayyantR Date: Thu, 24 Oct 2024 15:28:39 -0700 Subject: [PATCH 2/2] Switched from requirements to requirementsIn --- semgrep_output_v1.atd | 2 +- semgrep_output_v1.jsonschema | 2 +- semgrep_output_v1.proto | 2 +- semgrep_output_v1.py | 14 +++++++------- semgrep_output_v1.ts | 10 +++++----- semgrep_output_v1_j.ml | 10 +++++----- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/semgrep_output_v1.atd b/semgrep_output_v1.atd index e2c7f96a..5a71aa1b 100644 --- a/semgrep_output_v1.atd +++ b/semgrep_output_v1.atd @@ -1815,7 +1815,7 @@ type output_format = [ (* TODO: merge with Manifest_kind.ml *) type manifest_kind = [ - | Requirements + | RequirementsIn (* Manifest file for pip *) | PackageJson | Gemfile | GoMod diff --git a/semgrep_output_v1.jsonschema b/semgrep_output_v1.jsonschema index d72f0f1c..dab8a15b 100644 --- a/semgrep_output_v1.jsonschema +++ b/semgrep_output_v1.jsonschema @@ -1512,7 +1512,7 @@ }, "manifest_kind": { "oneOf": [ - { "const": "Requirements" }, + { "const": "RequirementsIn" }, { "const": "PackageJson" }, { "const": "Gemfile" }, { "const": "GoMod" }, diff --git a/semgrep_output_v1.proto b/semgrep_output_v1.proto index bb8aeee4..465c0fd8 100644 --- a/semgrep_output_v1.proto +++ b/semgrep_output_v1.proto @@ -1,6 +1,6 @@ // Generated by jsonschema2protobuf. DO NOT EDIT! // Source file: semgrep_output_v1.jsonschema -// Source file sha256 digest: 36a3c1aa9fab90804be3d9f2c328d5839ed4bd1eb44e173fea845a75f718edb0 +// Source file sha256 digest: 820f2f7605e17a8d1da4bdf9477d76d931d40840d0831af416b3cedd16a0d1a6 syntax = "proto3"; diff --git a/semgrep_output_v1.py b/semgrep_output_v1.py index e2bae86c..b38374c7 100644 --- a/semgrep_output_v1.py +++ b/semgrep_output_v1.py @@ -6549,17 +6549,17 @@ def to_json_string(self, **kw: Any) -> str: @dataclass -class Requirements_: - """Original type: manifest_kind = [ ... | Requirements | ... ]""" +class RequirementsIn: + """Original type: manifest_kind = [ ... | RequirementsIn | ... ]""" @property def kind(self) -> str: """Name of the class representing this variant.""" - return 'Requirements_' + return 'RequirementsIn' @staticmethod def to_json() -> Any: - return 'Requirements' + return 'RequirementsIn' def to_json_string(self, **kw: Any) -> str: return json.dumps(self.to_json(), **kw) @@ -6790,7 +6790,7 @@ def to_json_string(self, **kw: Any) -> str: class ManifestKind: """Original type: manifest_kind = [ ... ]""" - value: Union[Requirements_, PackageJson, Gemfile, GoMod_, CargoToml, PomXml, BuildGradle, ComposerJson, NugetManifestJson, PubspecYaml, PackageSwift_, MixExs, Pipfile_, PyprojectToml_] + value: Union[RequirementsIn, PackageJson, Gemfile, GoMod_, CargoToml, PomXml, BuildGradle, ComposerJson, NugetManifestJson, PubspecYaml, PackageSwift_, MixExs, Pipfile_, PyprojectToml_] @property def kind(self) -> str: @@ -6800,8 +6800,8 @@ def kind(self) -> str: @classmethod def from_json(cls, x: Any) -> 'ManifestKind': if isinstance(x, str): - if x == 'Requirements': - return cls(Requirements_()) + if x == 'RequirementsIn': + return cls(RequirementsIn()) if x == 'PackageJson': return cls(PackageJson()) if x == 'Gemfile': diff --git a/semgrep_output_v1.ts b/semgrep_output_v1.ts index a3443bc6..9e45c01d 100644 --- a/semgrep_output_v1.ts +++ b/semgrep_output_v1.ts @@ -834,7 +834,7 @@ export type OutputFormat = | { kind: 'Emacs' } export type ManifestKind = -| { kind: 'Requirements' } +| { kind: 'RequirementsIn' } | { kind: 'PackageJson' } | { kind: 'Gemfile' } | { kind: 'GoMod' } @@ -3399,8 +3399,8 @@ export function readOutputFormat(x: any, context: any = x): OutputFormat { export function writeManifestKind(x: ManifestKind, context: any = x): any { switch (x.kind) { - case 'Requirements': - return 'Requirements' + case 'RequirementsIn': + return 'RequirementsIn' case 'PackageJson': return 'PackageJson' case 'Gemfile': @@ -3432,8 +3432,8 @@ export function writeManifestKind(x: ManifestKind, context: any = x): any { export function readManifestKind(x: any, context: any = x): ManifestKind { switch (x) { - case 'Requirements': - return { kind: 'Requirements' } + case 'RequirementsIn': + return { kind: 'RequirementsIn' } case 'PackageJson': return { kind: 'PackageJson' } case 'Gemfile': diff --git a/semgrep_output_v1_j.ml b/semgrep_output_v1_j.ml index 176e0310..b14959d9 100644 --- a/semgrep_output_v1_j.ml +++ b/semgrep_output_v1_j.ml @@ -26246,7 +26246,7 @@ let output_format_of_string s = let write_manifest_kind = ( fun ob x -> match x with - | `Requirements -> Buffer.add_string ob "\"Requirements\"" + | `RequirementsIn -> Buffer.add_string ob "\"RequirementsIn\"" | `PackageJson -> Buffer.add_string ob "\"PackageJson\"" | `Gemfile -> Buffer.add_string ob "\"Gemfile\"" | `GoMod -> Buffer.add_string ob "\"GoMod\"" @@ -26271,10 +26271,10 @@ let read_manifest_kind = ( match Yojson.Safe.start_any_variant p lb with | `Edgy_bracket -> ( match Yojson.Safe.read_ident p lb with - | "Requirements" -> + | "RequirementsIn" -> Yojson.Safe.read_space p lb; Yojson.Safe.read_gt p lb; - `Requirements + `RequirementsIn | "PackageJson" -> Yojson.Safe.read_space p lb; Yojson.Safe.read_gt p lb; @@ -26332,8 +26332,8 @@ let read_manifest_kind = ( ) | `Double_quote -> ( match Yojson.Safe.finish_string p lb with - | "Requirements" -> - `Requirements + | "RequirementsIn" -> + `RequirementsIn | "PackageJson" -> `PackageJson | "Gemfile" ->