-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
60 lines (45 loc) · 1.16 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
// Package main contains the kcm-tool
package main
import (
"context"
"log"
"os"
"time"
"github.com/rs/zerolog"
flag "github.com/spf13/pflag"
)
var (
version = "dev"
)
func main() {
var (
path = flag.StringP("config", "c", "/etc/kcm.yaml", "Path to the config file")
versionFlag = flag.BoolP("version", "v", false, "Print the version")
)
flag.Parse()
if *versionFlag {
log.Println(version)
os.Exit(0)
}
output := zerolog.ConsoleWriter{Out: os.Stdout, TimeFormat: time.RFC3339}
logger := zerolog.New(output).With().Timestamp().Logger()
config, err := newConfigFromFile(*path)
if err != nil {
logger.Err(err).Str("path", *path).Msg("Failed to load config")
os.Exit(1)
}
logger.Info().Int("quantity", len(config.Certificates)).Msgf("Processing certificates")
quantityUpdated := 0
ctx := context.Background()
for _, certificate := range config.Certificates {
updated, err := certificate.Process(ctx, &logger)
if err != nil {
logger.Err(err).Str("url", certificate.URL).Msg("Failed to process certificate")
continue
}
if updated {
quantityUpdated++
}
}
logger.Info().Int("updated", quantityUpdated).Msgf("All done")
}