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

Commit

Permalink
Add basic debug logging (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfowl authored Sep 30, 2021
1 parent 5055d7e commit 69fcaf1
Show file tree
Hide file tree
Showing 352 changed files with 183,972 additions and 1 deletion.
6 changes: 6 additions & 0 deletions cmd/deplist/deplist.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@ import (
"fmt"

"github.com/mcoops/deplist"
log "github.com/sirupsen/logrus"
)

func main() {
deptypePtr := flag.Int("deptype", -1, "golang, nodejs, python etc")
debugPtr := flag.Bool("debug", false, "debug logging (default false)")

flag.Parse()

if *debugPtr == true {
log.SetLevel(log.DebugLevel)
}

if flag.Args() == nil || len(flag.Args()) == 0 {
fmt.Println("Not path to scan was specified, i.e. deplist /tmp/files/")
return
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.16

require (
github.com/mcoops/jargo v1.0.1
github.com/sirupsen/logrus v1.8.1
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 // indirect
golang.org/x/mod v0.4.2
golang.org/x/tools v0.1.6 // indirect
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/mcoops/jargo v0.0.0-20210410052334-26a02fc9f941 h1:9o1RYcjhgJ7q4oaxHrmOYo3yGpBTUmqEMB21YwK0im0=
github.com/mcoops/jargo v0.0.0-20210410052334-26a02fc9f941/go.mod h1:iSH9HuMFpODf8aG84m6UNrw3tULVYLKWl68rQcYxyiE=
github.com/mcoops/jargo v0.0.0-20210421020551-3a62b19becd9 h1:OMfYen7su1IM7INow4TWbYEKbRT9vnsTn4+BYfttpYI=
Expand All @@ -10,7 +11,10 @@ github.com/mcoops/jargo v1.0.1 h1:CZTY1yUK34QcZWS/ZXPx8eFImqm4GzTuXDVIvJEYOgQ=
github.com/mcoops/jargo v1.0.1/go.mod h1:iSH9HuMFpODf8aG84m6UNrw3tULVYLKWl68rQcYxyiE=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/vifraa/gopom v0.1.0 h1:v897eVxf6lflkEXzPmKbo4YhX2oS/LGjz7cqjWnSmCU=
Expand All @@ -33,9 +37,11 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e h1:WUoyKPm6nCo1BnNUvPGnFG3T5DUVem42yDJZZ4CNxMA=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down
3 changes: 3 additions & 0 deletions internal/scan/golang.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"strings"
"time"

log "github.com/sirupsen/logrus"
"golang.org/x/mod/semver"
)

Expand Down Expand Up @@ -75,6 +76,7 @@ func runCmd(path string, mod bool) ([]byte, error) {
// mod=vendor sometimes still returns results but returns an error. In
// that case ignore the error and return what we can
if err != nil {
log.Debug(string(err.(*exec.ExitError).Stderr))
if !mod {
// assume some retrival error, we have to redo the cmd with mod=vendor
return nil, err
Expand Down Expand Up @@ -108,6 +110,7 @@ func runGoList(path string) ([]byte, error) {
// GetGolangDeps uses `go list` gather a list of dependencies located at `path`
// returning an array of `GoPkg` structs
func GetGolangDeps(path string) (map[string]GoPkg, error) {
log.Debugf("GetGolangDeps %s", path)
// need to use a map as we'll get lots of duplicate entries
gathered := make(map[string]GoPkg)

Expand Down
2 changes: 2 additions & 0 deletions internal/scan/jar.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import (
"strings"

"github.com/mcoops/jargo"
log "github.com/sirupsen/logrus"
)

// GetJarDeps uses github.com/mcoops/jargo retrieve the java dependencies
func GetJarDeps(path string) (map[string]string, error) {
log.Debugf("GetJarDeps %s", path)
gathered := make(map[string]string)

jar, err := jargo.GetJarInfo(path)
Expand Down
3 changes: 3 additions & 0 deletions internal/scan/maven.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ import (
"os/exec"
"path/filepath"
"strings"

log "github.com/sirupsen/logrus"
)

// GetMvnDeps uses the mvn command to attempt to list the dependencies for a
// given project located at `path`
func GetMvnDeps(path string) (map[string]string, error) {
log.Debugf("GetMvnDeps %s", path)
var gathered map[string]string
var found map[string]bool

Expand Down
3 changes: 3 additions & 0 deletions internal/scan/nodejs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"os/exec"
"path/filepath"
"strings"

log "github.com/sirupsen/logrus"
)

type yarnDependencies []yarnDependency
Expand Down Expand Up @@ -91,6 +93,7 @@ func gatherNPMNode(name string, dependency npmDependency) {
// then use the appropriate pkg managers to produce depencies lists of type
// `NodeJSGather`
func GetNodeJSDeps(path string) (map[string]NodeJSGather, error) {
log.Debugf("GetNodeJSDeps %s", path)
switch filepath.Base(path) {
case "yarn.lock":
return getYarnDeps(path)
Expand Down
3 changes: 3 additions & 0 deletions internal/scan/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ import (
"os"
"regexp"
"strings"

log "github.com/sirupsen/logrus"
)

// Account for >, <, >=, <=, ==, !=, ~= and *
var /* const */ re = regexp.MustCompile(`[<>!~*]+`)

// GetPythonDeps scans path for python deps using the `requirements.txt` file
func GetPythonDeps(path string) (map[string]string, error) {
log.Debugf("GetPythonDeps %s", path)
gathered := make(map[string]string)

file, err := os.Open(path)
Expand Down
7 changes: 6 additions & 1 deletion internal/scan/ruby.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ import (
"os/exec"
"path/filepath"
"strings"

log "github.com/sirupsen/logrus"
)

// GetRubyDeps uses `bundle update --bundler` to list ruby dependencies when a
// Gemfile.lock file exists
func GetRubyDeps(path string) (map[string]string, error) {
log.Debugf("GetRubyDeps %s", path)
gathered := make(map[string]string)

dirPath := filepath.Dir(path)
Expand All @@ -29,8 +32,9 @@ func GetRubyDeps(path string) (map[string]string, error) {
cmd.Dir = dirPath
cmd.Env = os.Environ()
cmd.Env = append(cmd.Env, "BUNDLE_PATH="+gemPath)
_, err = cmd.Output()
output, err := cmd.CombinedOutput()
if err != nil {
log.Debug(string(output))
return nil, err
}

Expand All @@ -42,6 +46,7 @@ func GetRubyDeps(path string) (map[string]string, error) {

data, err := cmd.Output()
if err != nil {
log.Debug(string(data))
return nil, errors.New(gemPath + " " + err.Error())
}

Expand Down
4 changes: 4 additions & 0 deletions vendor/github.com/sirupsen/logrus/.gitignore

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

40 changes: 40 additions & 0 deletions vendor/github.com/sirupsen/logrus/.golangci.yml

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

15 changes: 15 additions & 0 deletions vendor/github.com/sirupsen/logrus/.travis.yml

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

Loading

0 comments on commit 69fcaf1

Please sign in to comment.