1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
package poetry
import (
"io"
"github.com/BurntSushi/toml"
"github.com/aquasecurity/go-dep-parser/pkg/types"
"golang.org/x/xerrors"
)
type Lockfile struct {
Packages []struct {
Category string `toml:"category"`
Description string `toml:"description"`
Marker string `toml:"marker,omitempty"`
Name string `toml:"name"`
Optional bool `toml:"optional"`
PythonVersions string `toml:"python-versions"`
Version string `toml:"version"`
Dependencies interface{}
Metadata interface{}
} `toml:"package"`
}
func Parse(r io.Reader) ([]types.Library, error) {
var lockfile Lockfile
if _, err := toml.DecodeReader(r, &lockfile); err != nil {
return nil, xerrors.Errorf("decode error: %w", err)
}
var libs []types.Library
for _, pkg := range lockfile.Packages {
libs = append(libs, types.Library{
Name: pkg.Name,
Version: pkg.Version,
})
}
return libs, nil
}
|