-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
53 lines (46 loc) · 1.38 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
package main
import (
"fmt"
"github.com/yashvardhan-kukreja/kube-bench-exporter/pkg/apis/aws"
"github.com/yashvardhan-kukreja/kube-bench-exporter/pkg/global"
"sync"
)
var targetDeserializers map[string]func(map[string]interface{}) (global.Target, error)
var wg sync.WaitGroup
func init() {
targetDeserializers = map[string](func(map[string]interface{}) (global.Target, error)){
"s3": aws.DeserializeInputJsonToS3Config,
}
}
func main() {
path := "/etc/config/target-config.json"
inputConfigs, err := global.DecodeConfigFile(path)
if err != nil {
fmt.Println(err)
return
}
var targets []global.Target
for _, input := range inputConfigs {
destinationType := input["type"].(string)
destinationConfig := input["config"].(map[string]interface{})
destinationDeserializer := targetDeserializers[destinationType]
currentTargetConfig, err := destinationDeserializer(destinationConfig)
if err != nil {
fmt.Println(err)
return
}
targets = append(targets, currentTargetConfig)
}
wg.Add(len(targets))
for _, target := range targets {
go func(target global.Target, wg *sync.WaitGroup) {
defer wg.Done()
if err := target.Export(); err != nil {
fmt.Printf("\nerror occurred while exporting to the target (%+v) : %+v", target, err)
return
}
fmt.Printf("\nSuccessfully exported the kube-bench report to the target %+v", target)
}(target, &wg)
}
wg.Wait()
}