-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
54 lines (46 loc) · 1.47 KB
/
config.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
package main
import (
"log"
"os"
"github.com/spf13/viper"
)
type config struct {
Verbose bool `json:"verbose" yaml:"verbose"`
}
var (
exporterConfig config
flagPort string
flagResultsPath string
flagVerbose bool
)
func init() {
cwd, _ := os.Getwd()
vulsExporter.PersistentFlags().StringVarP(&flagPort, "port", "p", "41337", "Port for vuls_exporter to bind to and expose openmetrics")
vulsExporter.PersistentFlags().BoolVarP(&flagVerbose, "verbose", "v", false, "Enable Verbose mode for log output")
vulsExporter.PersistentFlags().StringVarP(&flagResultsPath, "results", "r", cwd, "Path to Results directory generated by Vuls")
vulsExporter.AddCommand(exporterServerCmd)
vulsExporter.AddCommand(exporterParseCommand)
}
func initializeConfig() {
//registerCVEMetrics()
//registerResultsMetrics()
// configure viper to look into the following directories for
// a 'config.yaml' configuration file.
// 1. $HOME/.kafkactl, 2. /etc/kafkactl, 3. $PWD
viper.SetConfigType("yaml")
viper.AddConfigPath("$HOME/.vuls_exporter")
viper.AddConfigPath("/opt/vuls_exporter")
viper.AddConfigPath(".")
viper.SetConfigName("config")
err := viper.ReadInConfig() // Find and read the config file
if err != nil {
log.Printf("[DEBUG] Unable to find configuration file. (message: %s)", err)
} else {
err = viper.Unmarshal(&exporterConfig)
if err != nil {
if flagVerbose {
log.Fatalf("[FATAL] Configuration file found but unable to parse (err :%s)", err)
}
}
}
}