-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
60 lines (51 loc) · 1.84 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
import (
// . "github.com/ahmetb/go-linq" // From
"github.com/jondot/lightscreen/pkg/admission"
"go.uber.org/zap"
"gopkg.in/alecthomas/kingpin.v2"
)
var (
version = "dev"
commit = "none"
date = "unknown"
)
var (
config = kingpin.Flag("config", "Action mapping configuration file").Default("lightscreen.yaml").OverrideDefaultFromEnvar("LS_CONFIG").Short('c').String()
input = kingpin.Flag("check", "Check input file for admission").String()
host = kingpin.Flag("host", "HTTP host").OverrideDefaultFromEnvar("LS_HOST").Default("0.0.0.0").String()
port = kingpin.Flag("port", "HTTP port").OverrideDefaultFromEnvar("LS_PORT").Default("443").Int()
metrics = kingpin.Flag("metrics", "Metrics HTTP port").OverrideDefaultFromEnvar("LS_METRICSPORT").Default(":8080").String()
production = kingpin.Flag("production", "Run in production mode").OverrideDefaultFromEnvar("LS_PROD").Short('p').Bool()
certs = kingpin.Flag("certs", "Certs dir").OverrideDefaultFromEnvar("LS_CERTS").Default("self-certs").String()
)
func main() {
kingpin.Parse()
development := !(*production)
log_, _ := zap.NewProduction()
if development {
log_, _ = zap.NewDevelopment()
}
logger := log_.Sugar()
server := admission.NewServer(admission.ServerOptions{
CertDir: *certs,
Config: *config,
Development: development,
Port: *port,
Host: *host,
MetricsAddress: *metrics,
}, logger)
//server.Actions.
logger.Infof("mutations=%v validations=%v", server.Actions.MutationMap, server.Actions.ValidationMap)
logger.Infow("running", "port", *port, "host", *host, "config", *config, "development", development)
if *input != "" {
resp, err := server.Check(*input)
if err != nil {
logger.Errorf("error %v", err)
} else {
logger.Infow("", "response", resp)
}
} else {
server.Serve()
}
}