From b1f7b29dceb5dbce8a290a7919f828c6e8f9d8e3 Mon Sep 17 00:00:00 2001 From: Sal Olivares Date: Fri, 22 Nov 2024 11:08:34 -0800 Subject: [PATCH] feat(sca): add types for new potential lockfile/manifest types (#315) This PR adds types for the Python UV & Conan C++ manifests and lockfiles. - [x] I ran `make setup && make` to update the generated code after editing a `.atd` file (TODO: have a CI check) - [x] I made sure we're still backward compatible with old versions of the CLI. For example, the Semgrep backend need to still be able to *consume* data generated by Semgrep 1.17.0. See https://atd.readthedocs.io/en/latest/atdgen-tutorial.html#smooth-protocol-upgrades --- semgrep_output_v1.atd | 4 ++ semgrep_output_v1.jsonschema | 8 +++- semgrep_output_v1.proto | 2 +- semgrep_output_v1.py | 80 +++++++++++++++++++++++++++++++++++- semgrep_output_v1.ts | 20 +++++++++ semgrep_output_v1_j.ml | 37 +++++++++++++++-- semgrep_output_v1_j.mli | 9 ++-- 7 files changed, 147 insertions(+), 13 deletions(-) diff --git a/semgrep_output_v1.atd b/semgrep_output_v1.atd index d861fb6d..26365abc 100644 --- a/semgrep_output_v1.atd +++ b/semgrep_output_v1.atd @@ -1914,6 +1914,7 @@ type lockfile_kind | PipRequirementsTxt | PoetryLock | PipfileLock + | UvLock | NpmPackageLockJson | YarnLock | PnpmLock @@ -1927,6 +1928,7 @@ type lockfile_kind | PubspecLock | SwiftPackageResolved (* not a real lockfile *) | MixLock + | ConanLock ] type manifest_kind @@ -1959,6 +1961,8 @@ type manifest_kind | Pipfile (* Pipfile - https://pipenv.pypa.io/en/latest/pipfile.html *) | PyprojectToml (* pyproject.toml - https://packaging.python.org/en/latest/guides/writing-pyproject-toml/ *) + | ConanFileTxt (* conanfile.txt - https://docs.conan.io/2.9/reference/conanfile_txt.html#conanfile-txt *) + | ConanFilePy (* conanfile.py - https://docs.conan.io/2.9/reference/conanfile.html *) ] type manifest diff --git a/semgrep_output_v1.jsonschema b/semgrep_output_v1.jsonschema index fd3ee340..8add2576 100644 --- a/semgrep_output_v1.jsonschema +++ b/semgrep_output_v1.jsonschema @@ -1616,6 +1616,7 @@ { "const": "PipRequirementsTxt" }, { "const": "PoetryLock" }, { "const": "PipfileLock" }, + { "const": "UvLock" }, { "const": "NpmPackageLockJson" }, { "const": "YarnLock" }, { "const": "PnpmLock" }, @@ -1628,7 +1629,8 @@ { "const": "NugetPackagesLockJson" }, { "const": "PubspecLock" }, { "const": "SwiftPackageResolved" }, - { "const": "MixLock" } + { "const": "MixLock" }, + { "const": "ConanLock" } ] }, "manifest_kind": { @@ -1647,7 +1649,9 @@ { "const": "PackageSwift" }, { "const": "MixExs" }, { "const": "Pipfile" }, - { "const": "PyprojectToml" } + { "const": "PyprojectToml" }, + { "const": "ConanFileTxt" }, + { "const": "ConanFilePy" } ] }, "manifest": { diff --git a/semgrep_output_v1.proto b/semgrep_output_v1.proto index dfac9684..e3aae7b2 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: 9e7f28fdb812d97483514411de60911c80496fbccf1a0fb88c770873a8818de1 +// Source file sha256 digest: 1e60b2e61e38c4ee07ad36c0b7baaaebc23a95923552937fec5bcd70d0a4105d syntax = "proto3"; diff --git a/semgrep_output_v1.py b/semgrep_output_v1.py index 67718827..8b52323f 100644 --- a/semgrep_output_v1.py +++ b/semgrep_output_v1.py @@ -2838,11 +2838,45 @@ def to_json_string(self, **kw: Any) -> str: return json.dumps(self.to_json(), **kw) +@dataclass(frozen=True) +class ConanFileTxt: + """Original type: manifest_kind = [ ... | ConanFileTxt | ... ]""" + + @property + def kind(self) -> str: + """Name of the class representing this variant.""" + return 'ConanFileTxt' + + @staticmethod + def to_json() -> Any: + return 'ConanFileTxt' + + def to_json_string(self, **kw: Any) -> str: + return json.dumps(self.to_json(), **kw) + + +@dataclass(frozen=True) +class ConanFilePy: + """Original type: manifest_kind = [ ... | ConanFilePy | ... ]""" + + @property + def kind(self) -> str: + """Name of the class representing this variant.""" + return 'ConanFilePy' + + @staticmethod + def to_json() -> Any: + return 'ConanFilePy' + + def to_json_string(self, **kw: Any) -> str: + return json.dumps(self.to_json(), **kw) + + @dataclass(frozen=True) class ManifestKind: """Original type: manifest_kind = [ ... ]""" - value: Union[RequirementsIn, PackageJson, Gemfile, GoMod, CargoToml, PomXml, BuildGradle, SettingsGradle, ComposerJson, NugetManifestJson, PubspecYaml, PackageSwift, MixExs, Pipfile, PyprojectToml] + value: Union[RequirementsIn, PackageJson, Gemfile, GoMod, CargoToml, PomXml, BuildGradle, SettingsGradle, ComposerJson, NugetManifestJson, PubspecYaml, PackageSwift, MixExs, Pipfile, PyprojectToml, ConanFileTxt, ConanFilePy] @property def kind(self) -> str: @@ -2882,6 +2916,10 @@ def from_json(cls, x: Any) -> 'ManifestKind': return cls(Pipfile()) if x == 'PyprojectToml': return cls(PyprojectToml()) + if x == 'ConanFileTxt': + return cls(ConanFileTxt()) + if x == 'ConanFilePy': + return cls(ConanFilePy()) _atd_bad_json('ManifestKind', x) _atd_bad_json('ManifestKind', x) @@ -2947,6 +2985,23 @@ def to_json_string(self, **kw: Any) -> str: return json.dumps(self.to_json(), **kw) +@dataclass(frozen=True) +class UvLock: + """Original type: lockfile_kind = [ ... | UvLock | ... ]""" + + @property + def kind(self) -> str: + """Name of the class representing this variant.""" + return 'UvLock' + + @staticmethod + def to_json() -> Any: + return 'UvLock' + + def to_json_string(self, **kw: Any) -> str: + return json.dumps(self.to_json(), **kw) + + @dataclass(frozen=True) class NpmPackageLockJson: """Original type: lockfile_kind = [ ... | NpmPackageLockJson | ... ]""" @@ -3168,11 +3223,28 @@ def to_json_string(self, **kw: Any) -> str: return json.dumps(self.to_json(), **kw) +@dataclass(frozen=True) +class ConanLock: + """Original type: lockfile_kind = [ ... | ConanLock | ... ]""" + + @property + def kind(self) -> str: + """Name of the class representing this variant.""" + return 'ConanLock' + + @staticmethod + def to_json() -> Any: + return 'ConanLock' + + def to_json_string(self, **kw: Any) -> str: + return json.dumps(self.to_json(), **kw) + + @dataclass(frozen=True) class LockfileKind: """Original type: lockfile_kind = [ ... ]""" - value: Union[PipRequirementsTxt, PoetryLock, PipfileLock, NpmPackageLockJson, YarnLock, PnpmLock, GemfileLock, GoMod_, CargoLock, MavenDepTree, GradleLockfile, ComposerLock, NugetPackagesLockJson, PubspecLock, SwiftPackageResolved, MixLock] + value: Union[PipRequirementsTxt, PoetryLock, PipfileLock, UvLock, NpmPackageLockJson, YarnLock, PnpmLock, GemfileLock, GoMod_, CargoLock, MavenDepTree, GradleLockfile, ComposerLock, NugetPackagesLockJson, PubspecLock, SwiftPackageResolved, MixLock, ConanLock] @property def kind(self) -> str: @@ -3188,6 +3260,8 @@ def from_json(cls, x: Any) -> 'LockfileKind': return cls(PoetryLock()) if x == 'PipfileLock': return cls(PipfileLock()) + if x == 'UvLock': + return cls(UvLock()) if x == 'NpmPackageLockJson': return cls(NpmPackageLockJson()) if x == 'YarnLock': @@ -3214,6 +3288,8 @@ def from_json(cls, x: Any) -> 'LockfileKind': return cls(SwiftPackageResolved()) if x == 'MixLock': return cls(MixLock()) + if x == 'ConanLock': + return cls(ConanLock()) _atd_bad_json('LockfileKind', x) _atd_bad_json('LockfileKind', x) diff --git a/semgrep_output_v1.ts b/semgrep_output_v1.ts index 02773dc2..d92e82f0 100644 --- a/semgrep_output_v1.ts +++ b/semgrep_output_v1.ts @@ -885,6 +885,7 @@ export type LockfileKind = | { kind: 'PipRequirementsTxt' } | { kind: 'PoetryLock' } | { kind: 'PipfileLock' } +| { kind: 'UvLock' } | { kind: 'NpmPackageLockJson' } | { kind: 'YarnLock' } | { kind: 'PnpmLock' } @@ -898,6 +899,7 @@ export type LockfileKind = | { kind: 'PubspecLock' } | { kind: 'SwiftPackageResolved' } | { kind: 'MixLock' } +| { kind: 'ConanLock' } export type ManifestKind = | { kind: 'RequirementsIn' } @@ -915,6 +917,8 @@ export type ManifestKind = | { kind: 'MixExs' } | { kind: 'Pipfile' } | { kind: 'PyprojectToml' } +| { kind: 'ConanFileTxt' } +| { kind: 'ConanFilePy' } export type Manifest = { kind: ManifestKind; @@ -3645,6 +3649,8 @@ export function writeLockfileKind(x: LockfileKind, context: any = x): any { return 'PoetryLock' case 'PipfileLock': return 'PipfileLock' + case 'UvLock': + return 'UvLock' case 'NpmPackageLockJson': return 'NpmPackageLockJson' case 'YarnLock': @@ -3671,6 +3677,8 @@ export function writeLockfileKind(x: LockfileKind, context: any = x): any { return 'SwiftPackageResolved' case 'MixLock': return 'MixLock' + case 'ConanLock': + return 'ConanLock' } } @@ -3682,6 +3690,8 @@ export function readLockfileKind(x: any, context: any = x): LockfileKind { return { kind: 'PoetryLock' } case 'PipfileLock': return { kind: 'PipfileLock' } + case 'UvLock': + return { kind: 'UvLock' } case 'NpmPackageLockJson': return { kind: 'NpmPackageLockJson' } case 'YarnLock': @@ -3708,6 +3718,8 @@ export function readLockfileKind(x: any, context: any = x): LockfileKind { return { kind: 'SwiftPackageResolved' } case 'MixLock': return { kind: 'MixLock' } + case 'ConanLock': + return { kind: 'ConanLock' } default: _atd_bad_json('LockfileKind', x, context) throw new Error('impossible') @@ -3746,6 +3758,10 @@ export function writeManifestKind(x: ManifestKind, context: any = x): any { return 'Pipfile' case 'PyprojectToml': return 'PyprojectToml' + case 'ConanFileTxt': + return 'ConanFileTxt' + case 'ConanFilePy': + return 'ConanFilePy' } } @@ -3781,6 +3797,10 @@ export function readManifestKind(x: any, context: any = x): ManifestKind { return { kind: 'Pipfile' } case 'PyprojectToml': return { kind: 'PyprojectToml' } + case 'ConanFileTxt': + return { kind: 'ConanFileTxt' } + case 'ConanFilePy': + return { kind: 'ConanFilePy' } 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 d8cf6724..149b8aad 100644 --- a/semgrep_output_v1_j.ml +++ b/semgrep_output_v1_j.ml @@ -233,10 +233,11 @@ type manifest_kind = Semgrep_output_v1_t.manifest_kind [@@deriving show, eq, yojson] type lockfile_kind = Semgrep_output_v1_t.lockfile_kind = - PipRequirementsTxt | PoetryLock | PipfileLock | NpmPackageLockJson - | YarnLock | PnpmLock | GemfileLock | GoMod | CargoLock | MavenDepTree - | GradleLockfile | ComposerLock | NugetPackagesLockJson | PubspecLock - | SwiftPackageResolved | MixLock + PipRequirementsTxt | PoetryLock | PipfileLock | UvLock + | NpmPackageLockJson | YarnLock | PnpmLock | GemfileLock | GoMod + | CargoLock | MavenDepTree | GradleLockfile | ComposerLock + | NugetPackagesLockJson | PubspecLock | SwiftPackageResolved | MixLock + | ConanLock [@@deriving show, eq, yojson] @@ -8637,6 +8638,8 @@ let write_manifest_kind = ( | `MixExs -> Buffer.add_string ob "\"MixExs\"" | `Pipfile -> Buffer.add_string ob "\"Pipfile\"" | `PyprojectToml -> Buffer.add_string ob "\"PyprojectToml\"" + | `ConanFileTxt -> Buffer.add_string ob "\"ConanFileTxt\"" + | `ConanFilePy -> Buffer.add_string ob "\"ConanFilePy\"" ) let string_of_manifest_kind ?(len = 1024) x = let ob = Buffer.create len in @@ -8708,6 +8711,14 @@ let read_manifest_kind = ( Yojson.Safe.read_space p lb; Yojson.Safe.read_gt p lb; `PyprojectToml + | "ConanFileTxt" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + `ConanFileTxt + | "ConanFilePy" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + `ConanFilePy | x -> Atdgen_runtime.Oj_run.invalid_variant_tag p x ) @@ -8743,6 +8754,10 @@ let read_manifest_kind = ( `Pipfile | "PyprojectToml" -> `PyprojectToml + | "ConanFileTxt" -> + `ConanFileTxt + | "ConanFilePy" -> + `ConanFilePy | x -> Atdgen_runtime.Oj_run.invalid_variant_tag p x ) @@ -8760,6 +8775,7 @@ let write_lockfile_kind : _ -> lockfile_kind -> _ = ( | PipRequirementsTxt -> Buffer.add_string ob "\"PipRequirementsTxt\"" | PoetryLock -> Buffer.add_string ob "\"PoetryLock\"" | PipfileLock -> Buffer.add_string ob "\"PipfileLock\"" + | UvLock -> Buffer.add_string ob "\"UvLock\"" | NpmPackageLockJson -> Buffer.add_string ob "\"NpmPackageLockJson\"" | YarnLock -> Buffer.add_string ob "\"YarnLock\"" | PnpmLock -> Buffer.add_string ob "\"PnpmLock\"" @@ -8773,6 +8789,7 @@ let write_lockfile_kind : _ -> lockfile_kind -> _ = ( | PubspecLock -> Buffer.add_string ob "\"PubspecLock\"" | SwiftPackageResolved -> Buffer.add_string ob "\"SwiftPackageResolved\"" | MixLock -> Buffer.add_string ob "\"MixLock\"" + | ConanLock -> Buffer.add_string ob "\"ConanLock\"" ) let string_of_lockfile_kind ?(len = 1024) x = let ob = Buffer.create len in @@ -8796,6 +8813,10 @@ let read_lockfile_kind = ( Yojson.Safe.read_space p lb; Yojson.Safe.read_gt p lb; (PipfileLock : lockfile_kind) + | "UvLock" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (UvLock : lockfile_kind) | "NpmPackageLockJson" -> Yojson.Safe.read_space p lb; Yojson.Safe.read_gt p lb; @@ -8848,6 +8869,10 @@ let read_lockfile_kind = ( Yojson.Safe.read_space p lb; Yojson.Safe.read_gt p lb; (MixLock : lockfile_kind) + | "ConanLock" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (ConanLock : lockfile_kind) | x -> Atdgen_runtime.Oj_run.invalid_variant_tag p x ) @@ -8859,6 +8884,8 @@ let read_lockfile_kind = ( (PoetryLock : lockfile_kind) | "PipfileLock" -> (PipfileLock : lockfile_kind) + | "UvLock" -> + (UvLock : lockfile_kind) | "NpmPackageLockJson" -> (NpmPackageLockJson : lockfile_kind) | "YarnLock" -> @@ -8885,6 +8912,8 @@ let read_lockfile_kind = ( (SwiftPackageResolved : lockfile_kind) | "MixLock" -> (MixLock : lockfile_kind) + | "ConanLock" -> + (ConanLock : lockfile_kind) | x -> Atdgen_runtime.Oj_run.invalid_variant_tag p x ) diff --git a/semgrep_output_v1_j.mli b/semgrep_output_v1_j.mli index 3adda602..7effeeb1 100644 --- a/semgrep_output_v1_j.mli +++ b/semgrep_output_v1_j.mli @@ -233,10 +233,11 @@ type manifest_kind = Semgrep_output_v1_t.manifest_kind [@@deriving show, eq, yojson] type lockfile_kind = Semgrep_output_v1_t.lockfile_kind = - PipRequirementsTxt | PoetryLock | PipfileLock | NpmPackageLockJson - | YarnLock | PnpmLock | GemfileLock | GoMod | CargoLock | MavenDepTree - | GradleLockfile | ComposerLock | NugetPackagesLockJson | PubspecLock - | SwiftPackageResolved | MixLock + PipRequirementsTxt | PoetryLock | PipfileLock | UvLock + | NpmPackageLockJson | YarnLock | PnpmLock | GemfileLock | GoMod + | CargoLock | MavenDepTree | GradleLockfile | ComposerLock + | NugetPackagesLockJson | PubspecLock | SwiftPackageResolved | MixLock + | ConanLock [@@deriving show, eq, yojson]