Skip to content
This repository has been archived by the owner on Nov 23, 2021. It is now read-only.

Commit

Permalink
gpkg: add basic support (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcoops authored Nov 17, 2021
1 parent e81f145 commit 4bed126
Show file tree
Hide file tree
Showing 22 changed files with 3,990 additions and 1 deletion.
20 changes: 19 additions & 1 deletion deplist.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func GetDeps(fullPath string) ([]Dependency, Bitmask, error) {

pomPath := filepath.Join(fullPath, "pom.xml")
goPath := filepath.Join(fullPath, "go.mod")
goPkgPath := filepath.Join(fullPath, "Gopkg.lock")
rubyPath := filepath.Join(fullPath, "Gemfile.lock")
pythonPath := filepath.Join(fullPath, "requirements.txt")

Expand Down Expand Up @@ -165,7 +166,6 @@ func GetDeps(fullPath string) ([]Dependency, Bitmask, error) {
}

for path, goPkg := range pkgs {

d := Dependency{
DepType: LangGolang,
Path: path,
Expand All @@ -174,6 +174,24 @@ func GetDeps(fullPath string) ([]Dependency, Bitmask, error) {
}
deps = append(deps, d)
}
case goPkgPath:
pkgs, err := scan.GetGoPkgDeps(path)
if err != nil {
return err
}

if len(pkgs) > 0 {
foundTypes.DepFoundAddFlag(LangGolang)
}
for _, goPkg := range pkgs {
d := Dependency{
DepType: LangGolang,
Path: goPkg.Name,
Files: goPkg.Gofiles,
Version: goPkg.Version,
}
deps = append(deps, d)
}
case pomPath:
pkgs, err := scan.GetMvnDeps(path)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/mcoops/deplist
go 1.16

require (
github.com/BurntSushi/toml v0.4.1
github.com/mcoops/jargo v1.0.1
github.com/mcoops/packageurl-go v0.2.0
github.com/sirupsen/logrus v1.8.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/BurntSushi/toml v0.4.1 h1:GaI7EiDXDRfa8VshkTj7Fym7ha+y8/XxIgD2okUIjLw=
github.com/BurntSushi/toml v0.4.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
57 changes: 57 additions & 0 deletions internal/scan/gopkg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package scan

import (
"github.com/BurntSushi/toml"
log "github.com/sirupsen/logrus"
)

type GoPkgLockDeps struct {
Name string
Version string
Gofiles []string
}

type goPkg struct {
Name string `toml:"name"`
Packages []string `toml:"packages"`
Revision string `toml:"revision"`
Version string `toml:"version"`
}

type goPkgDeps struct {
Deps []goPkg `toml:"projects"`
}

func GetGoPkgDeps(path string) ([]GoPkgLockDeps, error) {
log.Debugf("GetGoPkgDeps %s", path)

var deps goPkgDeps
var gathered []GoPkgLockDeps

_, err := toml.DecodeFile(path, &deps)
if err != nil {
return nil, err
}

for _, d := range deps.Deps {
ver := d.Version
if ver == "" {
ver = d.Revision
}

var files []string
if len(d.Packages) > 1 {
files = append(files, d.Packages...)
}

gathered = append(gathered,
GoPkgLockDeps{
Name: d.Name,
Version: ver,
Gofiles: files,
},
)
}

return gathered, nil
}
2 changes: 2 additions & 0 deletions vendor/github.com/BurntSushi/toml/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/github.com/BurntSushi/toml/COMPATIBLE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions vendor/github.com/BurntSushi/toml/COPYING

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

220 changes: 220 additions & 0 deletions vendor/github.com/BurntSushi/toml/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4bed126

Please sign in to comment.