-
Notifications
You must be signed in to change notification settings - Fork 26
/
certs.go
80 lines (66 loc) · 1.64 KB
/
certs.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
package certs
import (
"fmt"
"path/filepath"
)
type CertsCmd struct {
List ListCertsCmd `cmd:"" help:"list dev certs"`
Generate GenerateCertsCmd `cmd:"" help:"generate dev certs"`
Trust TrustCertsCmd `cmd:"" help:"trust/untrust dev certs"`
Remove RemoveCertFileCmd `cmd:"" help:"remove dev certs"`
}
const (
gatewayFileName = "gateway"
grpcFileName = "grpc"
certCommonName = "topaz"
)
type fileListArgs struct {
inclCACerts bool
inclCerts bool
inclKeys bool
}
type fileListOption func(*fileListArgs)
func withAll() fileListOption {
return func(arg *fileListArgs) {
arg.inclCACerts = true
arg.inclCerts = true
arg.inclKeys = true
}
}
func withCerts() fileListOption {
return func(arg *fileListArgs) {
arg.inclCerts = true
arg.inclCACerts = true
}
}
func withCACerts() fileListOption {
return func(arg *fileListArgs) {
arg.inclCACerts = true
}
}
func getFileList(certsDir string, opts ...fileListOption) []string {
args := &fileListArgs{}
for _, opt := range opts {
opt(args)
}
filePaths := []string{}
if args.inclCACerts {
filePaths = append(filePaths,
filepath.Join(certsDir, fmt.Sprintf("%s-ca.crt", grpcFileName)),
filepath.Join(certsDir, fmt.Sprintf("%s-ca.crt", gatewayFileName)),
)
}
if args.inclCerts {
filePaths = append(filePaths,
filepath.Join(certsDir, fmt.Sprintf("%s.crt", grpcFileName)),
filepath.Join(certsDir, fmt.Sprintf("%s.crt", gatewayFileName)),
)
}
if args.inclKeys {
filePaths = append(filePaths,
filepath.Join(certsDir, fmt.Sprintf("%s.key", grpcFileName)),
filepath.Join(certsDir, fmt.Sprintf("%s.key", gatewayFileName)),
)
}
return filePaths
}