This repository has been archived by the owner on Aug 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
config.go
95 lines (87 loc) · 2.93 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
package main
import (
"os"
"strings"
)
type Config struct {
Regions []string
Roles []string
OutputFile string
ScanInterval string
Tags TagMapping
}
type TagMapping struct {
netbios string
assetType string
baselineConfig string
authenticatedScanPlanned string
lastScanned string
applicationVendor string
applicationNameAndVersion string
applicationPatchLevel string
applicationFunction string
comments string
serialNumber string
sysadmin string
appadmin string
}
func NewConfig() *Config {
config := configDefaults
envMap := map[string]*string{
"OUTPUT_FILE": &config.OutputFile,
"SCAN_INTERVAL": &config.ScanInterval,
"TAG_NETBIOS": &config.Tags.netbios,
"TAG_ASSET_TYPE": &config.Tags.assetType,
"TAG_BASELINE_CONFIG": &config.Tags.baselineConfig,
"TAG_AUTHENTICATED_SCAN_PLANNED": &config.Tags.authenticatedScanPlanned,
"TAG_LAST_SCANNED": &config.Tags.lastScanned,
"TAG_APPLICATION_VENDOR": &config.Tags.applicationVendor,
"TAG_APPLICATION_NAME_VERSION": &config.Tags.applicationNameAndVersion,
"TAG_APPLICATION_PATCH_LEVEL": &config.Tags.applicationPatchLevel,
"TAG_APPLICATION_FUNCTION": &config.Tags.applicationFunction,
"TAG_COMMENTS": &config.Tags.comments,
"TAG_SERIAL_NUMBER": &config.Tags.serialNumber,
"TAG_SYSADMIN": &config.Tags.sysadmin,
"TAG_APPADMIN": &config.Tags.appadmin,
}
if len(os.Getenv("REGIONS")) > 0 {
config.Regions = strings.Split(os.Getenv("REGIONS"), ",")
}
if len(os.Getenv("ROLES")) > 0 {
config.Roles = strings.Split(os.Getenv("ROLES"), ",")
}
for k, v := range envMap {
SetStringFromEnv(k, v)
}
return config
}
func (this *Config) OutputFormat() string {
split := strings.Split(this.OutputFile, ".")
return split[len(split)-1]
}
func SetStringFromEnv(key string, pointer *string) {
if len(os.Getenv(key)) > 0 {
*pointer = os.Getenv(key)
}
}
var configDefaults = &Config{
Regions: []string{"us-gov-west-1"},
Roles: []string{},
OutputFile: "output.csv",
ScanInterval: "24h",
Tags: TagMapping{
netbios: "NetBIOS",
assetType: "AssetType",
baselineConfig: "BaselineConfiguration",
authenticatedScanPlanned: "AuthenticatedScanPlanned",
lastScanned: "LastScanned",
applicationVendor: "ApplicationVendor",
applicationNameAndVersion: "ApplicationNameAndVersion",
applicationPatchLevel: "ApplicationPatchLevel",
applicationFunction: "ApplicationFunction",
comments: "Comments",
serialNumber: "SerialNumber",
sysadmin: "SysAdmin",
appadmin: "AppAdmin",
},
}