-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.go
65 lines (53 loc) · 1.64 KB
/
main.go
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"fmt"
"github.com/akamensky/argparse"
"github.com/checkmarx/dustilock/analysis"
"log"
"os"
"path/filepath"
)
var excludedDirectories = map[string]bool{
".git": true,
"node_modules": true,
}
func main() {
parser := argparse.NewParser("DustiLock", "a tool to find which of your dependencies is susceptible to Dependency Confusion attack")
recursive := parser.Flag("r", "recursive", &argparse.Options{Help: "scan all files recursively"})
audit := parser.Flag("a", "audit", &argparse.Options{Help: "audit only mode"})
customDir := parser.String("p", "path", &argparse.Options{Help: "the path to scan. default is cwd"})
err := parser.Parse(os.Args)
if err != nil {
fmt.Print(parser.Usage(err))
}
auditValue := *audit
customDirValue := *customDir
recursiveValue := *recursive
// -------------
fmt.Println("DustiLock started")
scanDir, err := os.Getwd()
if err != nil {
log.Fatal(err)
}
if customDirValue != "" {
scanDir, _ = filepath.Abs(customDirValue)
}
fmt.Printf("scanning directory \"%v\" (recursive=%v) ...\n", scanDir, recursiveValue)
var hasAnyPackageAvailableForRegistration bool
if recursiveValue {
hasAnyPackageAvailableForRegistration, err = analysis.AnalyzeDirectoryRecursive(scanDir, excludedDirectories)
} else {
hasAnyPackageAvailableForRegistration, err = analysis.AnalyzeDirectory(scanDir)
}
if err != nil {
log.Fatal(err)
}
if hasAnyPackageAvailableForRegistration {
_, _ = fmt.Fprintln(os.Stderr, "one or more packages are available for public registration")
if !auditValue {
os.Exit(1)
}
} else {
fmt.Printf("finished scanning directory \"%v\"\n", scanDir)
}
}