|
1 | 1 | package lockfile |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "fmt" |
5 | | - "os" |
6 | | - |
7 | | - "github.com/BurntSushi/toml" |
| 4 | + "github.com/google/osv-scalibr/extractor/filesystem/language/python/pylock" |
8 | 5 | ) |
9 | 6 |
|
10 | | -type pylockVCS struct { |
11 | | - Type string `toml:"type"` |
12 | | - Commit string `toml:"commit-id"` |
13 | | -} |
14 | | - |
15 | | -type pylockDirectory struct { |
16 | | - Path string `toml:"path"` |
17 | | -} |
18 | | - |
19 | | -type PylockPackage struct { |
20 | | - Name string `toml:"name"` |
21 | | - Version string `toml:"version"` |
22 | | - VCS pylockVCS `toml:"vcs"` |
23 | | - Directory pylockDirectory `toml:"directory"` |
24 | | -} |
25 | | - |
26 | | -type PylockLockfile struct { |
27 | | - Version string `toml:"lock-version"` |
28 | | - Packages []PylockPackage `toml:"packages"` |
29 | | -} |
30 | | - |
31 | 7 | const PylockEcosystem = PipEcosystem |
32 | 8 |
|
33 | 9 | func ParsePylock(pathToLockfile string) ([]PackageDetails, error) { |
34 | | - var parsedLockfile *PylockLockfile |
35 | | - |
36 | | - lockfileContents, err := os.ReadFile(pathToLockfile) |
37 | | - |
38 | | - if err != nil { |
39 | | - return []PackageDetails{}, fmt.Errorf("could not read %s: %w", pathToLockfile, err) |
40 | | - } |
41 | | - |
42 | | - err = toml.Unmarshal(lockfileContents, &parsedLockfile) |
43 | | - |
44 | | - if err != nil { |
45 | | - return []PackageDetails{}, fmt.Errorf("could not parse %s: %w", pathToLockfile, err) |
46 | | - } |
47 | | - |
48 | | - packages := make([]PackageDetails, 0, len(parsedLockfile.Packages)) |
49 | | - |
50 | | - for _, pkg := range parsedLockfile.Packages { |
51 | | - // this is likely the root package, which is sometimes included in the lockfile |
52 | | - if pkg.Version == "" && pkg.Directory.Path == "." { |
53 | | - continue |
54 | | - } |
55 | | - |
56 | | - pkgDetails := PackageDetails{ |
57 | | - Name: pkg.Name, |
58 | | - Version: pkg.Version, |
59 | | - Ecosystem: PylockEcosystem, |
60 | | - CompareAs: PylockEcosystem, |
61 | | - } |
62 | | - |
63 | | - if pkg.VCS.Commit != "" { |
64 | | - pkgDetails.Commit = pkg.VCS.Commit |
65 | | - } |
66 | | - |
67 | | - packages = append(packages, pkgDetails) |
68 | | - } |
69 | | - |
70 | | - return packages, nil |
| 10 | + return extract(pathToLockfile, pylock.New(), PylockEcosystem) |
71 | 11 | } |
0 commit comments