-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
106 lines (91 loc) · 2.86 KB
/
config.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package server
import (
"net"
"strconv"
"time"
"github.com/gin-gonic/gin"
)
// Config is a structure used to configure a GenericAPIServer.
// Its members are sorted roughly in order of importance for composers.
type Config struct {
SecureServing *SecureServingInfo
InsecureServing *InsecureServingInfo
Jwt *JwtInfo
Mode string
Middlewares []string
Healthz bool
EnableProfiling bool
EnableMetrics bool
}
// CertKey contains configuration items related to certificate.
type CertKey struct {
// CertFile is a file containing a PEM-encoded certificate, and possibly the complete certificate chain
CertFile string
// KeyFile is a file containing a PEM-encoded private key for the certificate specified by CertFile
KeyFile string
}
// SecureServingInfo holds configuration of the TLS server.
type SecureServingInfo struct {
BindAddress string
BindPort int
CertKey CertKey
}
// Address join host IP address and host port number into a address string, like: 0.0.0.0:8443.
func (s *SecureServingInfo) Address() string {
return net.JoinHostPort(s.BindAddress, strconv.Itoa(s.BindPort))
}
// InsecureServingInfo holds configuration of the insecure http server.
type InsecureServingInfo struct {
Address string
}
// JwtInfo defines jwt fields used to create jwt authentication middleware.
type JwtInfo struct {
// defaults to "iam jwt"
Realm string
// defaults to empty
Key string
// defaults to one hour
Timeout time.Duration
// defaults to zero
MaxRefresh time.Duration
}
// NewConfig returns a Config struct with the default values.
func NewConfig() *Config {
return &Config{
Healthz: true,
Mode: gin.ReleaseMode,
Middlewares: []string{},
EnableProfiling: true,
EnableMetrics: true,
Jwt: &JwtInfo{
Realm: "bolo jwt",
Timeout: 1 * time.Hour,
MaxRefresh: 1 * time.Hour,
},
}
}
// CompletedConfig is the completed configuration for GenericAPIServer.
type CompletedConfig struct {
*Config
}
// Complete fills in any fields not set that are required to have valid data and can be derived
// from other fields. If you're going to `ApplyOptions`, do that first. It's mutating the receiver.
func (c *Config) Complete() CompletedConfig {
return CompletedConfig{c}
}
// New returns a new instance of GenericAPIServer from the given config.
func (c CompletedConfig) New() (*GenericAPIServer, error) {
// setMode before gin.New()
gin.SetMode(c.Mode)
s := &GenericAPIServer{
// SecureServingInfo: c.SecureServing,
InsecureServingInfo: c.InsecureServing,
healthz: c.Healthz,
enableMetrics: c.EnableMetrics,
enableProfiling: c.EnableProfiling,
middlewares: c.Middlewares,
Engine: gin.New(),
}
initGenericAPIServer(s)
return s, nil
}