forked from infobloxopen/atlas-app-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flag.go
87 lines (71 loc) · 2.04 KB
/
flag.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
package server
import (
"crypto/tls"
"flag"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
)
type GRPCFlags struct {
addr *string
}
type TLSFlags struct {
cert *string
key *string
ca *string
}
type HealthProbesFlags struct {
addr *string
healthPath *string
readyPath *string
}
func NewHealthProbesFlags() *HealthProbesFlags {
addr := flag.String("health-addr", ":8080", "address to use for the health endpoint")
healthPath := flag.String("health-path", "/healthz", "path to use for the health endpoint")
readyPath := flag.String("ready-path", "/ready", "path to use for the readiness endpoint")
return &HealthProbesFlags{
addr: addr,
healthPath: healthPath,
readyPath: readyPath}
}
func (hpf *HealthProbesFlags) Addr() string {
return *hpf.addr
}
func (hpf *HealthProbesFlags) HealthPath() string {
return *hpf.healthPath
}
func (hpf *HealthProbesFlags) ReadyPath() string {
return *hpf.readyPath
}
func MetricsFlags() (*string, *string) {
addr := flag.String("metrics-addr", ":9500", "address to use for the metrics endpoint")
path := flag.String("metrics-path", "/metrics", "path to use for the metrics endpoint")
return addr, path
}
func NewGRPCFlags() *GRPCFlags {
f := &GRPCFlags{}
f.addr = flag.String("addr", ":9000", "address to use for the gRPC endpoint")
return f
}
func (f *GRPCFlags) Addr() string {
return *f.addr
}
func NewTLSFlags() *TLSFlags {
f := &TLSFlags{}
f.cert = flag.String("cert", "", "path to the Server certificate in PEM format")
f.key = flag.String("key", "", "path to the Server private key in PEM format")
f.ca = flag.String("ca", "", "path to the CA PEM for validating the client cert; system CAs will be used if blank")
return f
}
func (f *TLSFlags) TLSConfig() (*tls.Config, error) {
return NewTLSConfig(*f.cert, *f.key, *f.ca)
}
func (f *TLSFlags) WithGRPCTLSCreds() (grpc.ServerOption, error) {
if *f.cert == "" {
return nil, nil
}
tlsConfig, err := f.TLSConfig()
if err != nil {
return nil, err
}
return grpc.Creds(credentials.NewTLS(tlsConfig)), nil
}