-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
97 lines (78 loc) · 2.19 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
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
package main
import (
"flag"
"io/ioutil"
"log"
"github.com/BurntSushi/toml"
"github.com/brian1917/illumioapi"
)
type config struct {
Illumio illumio `toml:"illumio"`
ServiceNow serviceNow `toml:"serviceNow"`
LabelMapping labelMapping `toml:"labelMapping"`
Logging logging `toml:"logging"`
UnmanagedWorkloads unmanagedWLs `toml:"unmanagedWorkloads"`
}
type illumio struct {
FQDN string `toml:"fqdn"`
Port int `toml:"port"`
Org int `toml:"org"`
User string `toml:"user"`
Key string `toml:"key"`
MatchField string `toml:"match_field"`
}
type serviceNow struct {
TableURL string `toml:"table_url"`
User string `toml:"user"`
Password string `toml:"password"`
MatchField string `toml:"match_field"`
}
type labelMapping struct {
App string `toml:"app"`
Enviornment string `toml:"enviornment"`
Location string `toml:"location"`
Role string `toml:"role"`
}
type logging struct {
LogOnly bool `toml:"log_only"`
LogDirectory string `toml:"log_directory"`
verbose bool
}
type unmanagedWLs struct {
Enable bool `toml:"enable"`
Table string `toml:"table"`
}
var configFile string
var debugLogging bool
func init() {
flag.StringVar(&configFile, "config", "config.toml", "Location of TOML configuration file")
flag.BoolVar(&debugLogging, "v", false, "Set for verbose logging.")
}
func parseConfig() (config, illumioapi.PCE) {
var config config
flag.Parse()
data, err := ioutil.ReadFile(configFile)
if err != nil {
log.Fatal(err)
}
_, err = toml.Decode(string(data), &config)
if err != nil {
log.Fatal(err)
}
// IF A FIELD IS LEFT BLANK WE WANT TO PUT A PLACEHOLDER
fields := []*string{&config.LabelMapping.App, &config.LabelMapping.Enviornment, &config.LabelMapping.Location, &config.LabelMapping.Role}
for _, field := range fields {
if *field == "" {
*field = "csvPlaceHolderIllumio"
}
}
pce := illumioapi.PCE{
FQDN: config.Illumio.FQDN,
Port: config.Illumio.Port,
Org: config.Illumio.Org,
User: config.Illumio.User,
Key: config.Illumio.Key}
// SET THE LOGGING IN THE CONFIG STRUCT
config.Logging.verbose = debugLogging
return config, pce
}