|
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/poetrylock" |
8 | 5 | ) |
9 | 6 |
|
10 | | -type PoetryLockPackageSource struct { |
11 | | - Type string `toml:"type"` |
12 | | - Commit string `toml:"resolved_reference"` |
13 | | -} |
14 | | - |
15 | | -type PoetryLockPackage struct { |
16 | | - Name string `toml:"name"` |
17 | | - Version string `toml:"version"` |
18 | | - Source PoetryLockPackageSource `toml:"source"` |
19 | | -} |
20 | | - |
21 | | -type PoetryLockFile struct { |
22 | | - Version int `toml:"version"` |
23 | | - Packages []PoetryLockPackage `toml:"package"` |
24 | | -} |
25 | | - |
26 | 7 | const PoetryEcosystem = PipEcosystem |
27 | 8 |
|
28 | 9 | func ParsePoetryLock(pathToLockfile string) ([]PackageDetails, error) { |
29 | | - var parsedLockfile *PoetryLockFile |
30 | | - |
31 | | - lockfileContents, err := os.ReadFile(pathToLockfile) |
32 | | - |
33 | | - if err != nil { |
34 | | - return []PackageDetails{}, fmt.Errorf("could not read %s: %w", pathToLockfile, err) |
35 | | - } |
36 | | - |
37 | | - err = toml.Unmarshal(lockfileContents, &parsedLockfile) |
38 | | - |
39 | | - if err != nil { |
40 | | - return []PackageDetails{}, fmt.Errorf("could not parse %s: %w", pathToLockfile, err) |
41 | | - } |
42 | | - |
43 | | - packages := make([]PackageDetails, 0, len(parsedLockfile.Packages)) |
44 | | - |
45 | | - for _, lockPackage := range parsedLockfile.Packages { |
46 | | - packages = append(packages, PackageDetails{ |
47 | | - Name: lockPackage.Name, |
48 | | - Version: lockPackage.Version, |
49 | | - Commit: lockPackage.Source.Commit, |
50 | | - Ecosystem: PoetryEcosystem, |
51 | | - CompareAs: PoetryEcosystem, |
52 | | - }) |
53 | | - } |
54 | | - |
55 | | - return packages, nil |
| 10 | + return extract(pathToLockfile, poetrylock.New(), PoetryEcosystem) |
56 | 11 | } |
0 commit comments