-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathmain.go
144 lines (119 loc) · 3.43 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package main
import (
"fmt"
"io"
"os"
"strconv"
"github.com/safedep/dry/utils"
"github.com/safedep/vet/cmd/cloud"
"github.com/safedep/vet/cmd/code"
"github.com/safedep/vet/cmd/inspect"
"github.com/safedep/vet/internal/ui"
"github.com/safedep/vet/pkg/common/logger"
"github.com/safedep/vet/pkg/exceptions"
"github.com/spf13/cobra"
)
var (
verbose bool
debug bool
noBanner bool
logFile string
globalExceptionsFile string
globalExceptionsExtra []string
)
const (
vetName = "vet"
vetInformationURI = "https://github.com/safedep/vet"
vetVendorName = "Safedep"
vetVendorInformationURI = "https://safedep.io"
)
var vetPurl = "pkg:golang/safedep/vet@" + version
const banner string = `
Yb dP 888888 888888
Yb dP 88__ 88
YbdP 88"" 88
YP 888888 88
`
func main() {
cmd := &cobra.Command{
Use: "vet [OPTIONS] COMMAND [ARG...]",
Short: "[ Establish trust in open source software supply chain ]",
TraverseChildren: true,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return cmd.Help()
}
return fmt.Errorf("vet: %s is not a valid command", args[0])
},
}
cmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Show verbose logs")
cmd.PersistentFlags().BoolVarP(&debug, "debug", "d", false, "Show debug logs")
cmd.PersistentFlags().BoolVarP(&noBanner, "no-banner", "", false, "Do not display the vet banner")
cmd.PersistentFlags().StringVarP(&logFile, "log", "l", "", "Write command logs to file, use - as for stdout")
cmd.PersistentFlags().StringVarP(&globalExceptionsFile, "exceptions", "e", "", "Load exceptions from file")
cmd.PersistentFlags().StringSliceVarP(&globalExceptionsExtra, "exceptions-extra", "", []string{}, "Load additional exceptions from file")
cmd.AddCommand(newAuthCommand())
cmd.AddCommand(newScanCommand())
cmd.AddCommand(newQueryCommand())
cmd.AddCommand(newVersionCommand())
cmd.AddCommand(newConnectCommand())
cmd.AddCommand(cloud.NewCloudCommand())
cmd.AddCommand(code.NewCodeCommand())
if checkIfPackageInspectCommandEnabled() {
cmd.AddCommand(inspect.NewPackageInspectCommand())
}
cobra.OnInitialize(func() {
printBanner()
loadExceptions()
logger.SetLogLevel(verbose, debug)
})
if err := cmd.Execute(); err != nil {
os.Exit(1)
}
}
func loadExceptions() {
loadExceptionsFromFile(globalExceptionsFile)
for _, extra := range globalExceptionsExtra {
loadExceptionsFromFile(extra)
}
}
func loadExceptionsFromFile(file string) {
if file == "" {
return
}
loader, err := exceptions.NewExceptionsFileLoader(file)
if err != nil {
logger.Fatalf("Failed to create Exceptions loader: %v", err)
}
err = exceptions.Load(loader)
if err != nil {
logger.Fatalf("Failed to load exceptions: %v", err)
}
}
func printBanner() {
if noBanner {
return
}
bRet, err := strconv.ParseBool(os.Getenv("VET_DISABLE_BANNER"))
if (err == nil) && (bRet) {
return
}
ui.PrintBanner(banner)
}
func checkIfPackageInspectCommandEnabled() bool {
// Enabled by default now that we have tested this for a while
return true
}
// Redirect to file or discard log if empty
func redirectLogToFile(path string) {
logger.Debugf("Redirecting logger output to: %s", path)
if !utils.IsEmptyString(path) {
if path == "-" {
logger.MigrateTo(os.Stdout)
} else {
logger.LogToFile(path)
}
} else {
logger.MigrateTo(io.Discard)
}
}