-
Notifications
You must be signed in to change notification settings - Fork 6
/
service.go
164 lines (149 loc) · 3.59 KB
/
service.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
package audit
// Service represents a KrakenD configuration as a tree of bitsets representing
// which components and flags are enabled at the KrakenD configuration
type Service struct {
Details []int `json:"d"`
Agents []Agent `json:"a"`
Endpoints []Endpoint `json:"e"`
Components Component `json:"c"`
}
// Clone returns a deep copy of the service
func (s Service) Clone() Service {
res := Service{
Details: make([]int, len(s.Details)),
Agents: make([]Agent, len(s.Agents)),
Endpoints: make([]Endpoint, len(s.Endpoints)),
Components: s.Components.Clone(),
}
copy(res.Details, s.Details)
for i, a := range s.Agents {
res.Agents[i] = a.Clone()
}
for i, e := range s.Endpoints {
res.Endpoints[i] = e.Clone()
}
return res
}
// Agent captures details of the AsyncAgents present at the configuration
type Agent struct {
Details []int `json:"d"`
Backends []Backend `json:"b"`
Components Component `json:"c"`
}
// Clone returns a deep copy of the agent
func (a Agent) Clone() Agent {
res := Agent{
Details: make([]int, len(a.Details)),
Backends: make([]Backend, len(a.Backends)),
Components: a.Components.Clone(),
}
copy(res.Details, a.Details)
for i, b := range a.Backends {
res.Backends[i] = b.Clone()
}
return res
}
// Endpoint captures details of the endpoints present at the configuration
type Endpoint struct {
Details []int `json:"d"`
Backends []Backend `json:"b"`
Components Component `json:"c"`
}
// Clone returns a deep copy of the endpoint
func (e Endpoint) Clone() Endpoint {
res := Endpoint{
Details: make([]int, len(e.Details)),
Backends: make([]Backend, len(e.Backends)),
Components: e.Components.Clone(),
}
copy(res.Details, e.Details)
for i, b := range e.Backends {
res.Backends[i] = b.Clone()
}
return res
}
// Backend captures details of the backends present at the configuration
type Backend struct {
Details []int `json:"d"`
Components Component `json:"c"`
}
// Clone returns a deep copy of the backend
func (b Backend) Clone() Backend {
res := Backend{
Details: make([]int, len(b.Details)),
Components: b.Components.Clone(),
}
copy(res.Details, b.Details)
return res
}
// Component captures details of the extra configuration sections
type Component map[string][]int
// Clone returns a deep copy of the set of components
func (c Component) Clone() Component {
res := Component{}
for i, vs := range c {
res[i] = make([]int, len(vs))
copy(res[i], vs)
}
return res
}
const (
ServicePlugin = iota
ServiceSequentialStart
ServiceDebug
ServiceAllowInsecureConnections
ServiceDisableStrictREST
ServiceHasTLS
ServiceTLSEnabled
ServiceTLSEnableMTLS
ServiceTLSDisableSystemCaPool
ServiceTLSCaCerts
ServiceEcho
ServiceUseH2C
ServiceTLSPrivPubKey
)
const (
EncodingNOOP = iota
EncodingJSON
EncodingSAFEJSON
EncodingSTRING
EncodingRSS
EncodingXML
EncodingOther
)
const (
BackendAllow = iota + EncodingOther + 1
BackendDeny
BackendMapping
BackendGroup
BackendTarget
BackendIsCollection
BackendHeadersToPass
BackendQuery
)
const (
RouterErrorBody = iota
RouterDisableHealth
RouterDisableAccessLog
RouterHealthPath
RouterErrorMsg
RouterDisableRedirectTrailingSlash
RouterDisableRedirectFixedPath
RouterExtraSlash
RouterHandleMethodNotAllowed
RouterPathDecoding
RouterAutoOptions
RouterForwardedByClientIp
RouterRemoteIpHeaders
RouterTrustedProxies
RouterAppEngine
RouterMaxMultipartMemory
RouterLoggerSkipPaths
RouterHideVersionHeader
RouterUseH2C
)
const (
BackendComponentHTTPClient = iota
BackendComponentHTTPClientAllowInsecureConnections
BackendComponentHTTPClientCerts
)