-
Notifications
You must be signed in to change notification settings - Fork 545
/
Copy pathentity.go
315 lines (279 loc) · 11.4 KB
/
entity.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package entity
import (
"reflect"
"time"
"github.com/apisix/manager-api/internal/utils"
)
type BaseInfo struct {
ID interface{} `json:"id"`
CreateTime int64 `json:"create_time,omitempty"`
UpdateTime int64 `json:"update_time,omitempty"`
}
func (info *BaseInfo) GetBaseInfo() *BaseInfo {
return info
}
func (info *BaseInfo) Creating() {
if info.ID == nil {
info.ID = utils.GetFlakeUidStr()
} else {
// convert to string if it's not
if reflect.TypeOf(info.ID).String() != "string" {
info.ID = utils.InterfaceToString(info.ID)
}
}
info.CreateTime = time.Now().Unix()
info.UpdateTime = time.Now().Unix()
}
func (info *BaseInfo) Updating(storedInfo *BaseInfo) {
info.ID = storedInfo.ID
info.CreateTime = storedInfo.CreateTime
info.UpdateTime = time.Now().Unix()
}
func (info *BaseInfo) KeyCompat(key string) {
if info.ID == nil && key != "" {
info.ID = key
}
}
type Status uint8
// swagger:model Route
type Route struct {
BaseInfo
URI string `json:"uri,omitempty"`
Uris []string `json:"uris,omitempty"`
Name string `json:"name" validate:"max=50"`
Desc string `json:"desc,omitempty" validate:"max=256"`
Priority int `json:"priority,omitempty"`
Methods []string `json:"methods,omitempty"`
Host string `json:"host,omitempty"`
Hosts []string `json:"hosts,omitempty"`
RemoteAddr string `json:"remote_addr,omitempty"`
RemoteAddrs []string `json:"remote_addrs,omitempty"`
Vars []interface{} `json:"vars,omitempty"`
FilterFunc string `json:"filter_func,omitempty"`
Script interface{} `json:"script,omitempty"`
ScriptID interface{} `json:"script_id,omitempty"` // For debug and optimization(cache), currently same as Route's ID
Plugins map[string]interface{} `json:"plugins,omitempty"`
PluginConfigID interface{} `json:"plugin_config_id,omitempty"`
Upstream *UpstreamDef `json:"upstream,omitempty"`
ServiceID interface{} `json:"service_id,omitempty"`
UpstreamID interface{} `json:"upstream_id,omitempty"`
ServiceProtocol string `json:"service_protocol,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
EnableWebsocket bool `json:"enable_websocket,omitempty"`
Status Status `json:"status"`
}
// --- structures for upstream start ---
type TimeoutValue float32
type Timeout struct {
Connect TimeoutValue `json:"connect,omitempty"`
Send TimeoutValue `json:"send,omitempty"`
Read TimeoutValue `json:"read,omitempty"`
}
type Node struct {
Host string `json:"host,omitempty"`
Port int `json:"port,omitempty"`
Weight int `json:"weight"`
Metadata interface{} `json:"metadata,omitempty"`
Priority int `json:"priority,omitempty"`
}
type K8sInfo struct {
Namespace string `json:"namespace,omitempty"`
DeployName string `json:"deploy_name,omitempty"`
ServiceName string `json:"service_name,omitempty"`
Port int `json:"port,omitempty"`
BackendType string `json:"backend_type,omitempty"`
}
type Healthy struct {
Interval int `json:"interval,omitempty"`
HttpStatuses []int `json:"http_statuses,omitempty"`
Successes int `json:"successes,omitempty"`
}
type UnHealthy struct {
Interval int `json:"interval,omitempty"`
HTTPStatuses []int `json:"http_statuses,omitempty"`
TCPFailures int `json:"tcp_failures,omitempty"`
Timeouts int `json:"timeouts,omitempty"`
HTTPFailures int `json:"http_failures,omitempty"`
}
type Active struct {
Type string `json:"type,omitempty"`
Timeout TimeoutValue `json:"timeout,omitempty"`
Concurrency int `json:"concurrency,omitempty"`
Host string `json:"host,omitempty"`
Port int `json:"port,omitempty"`
HTTPPath string `json:"http_path,omitempty"`
HTTPSVerifyCertificate bool `json:"https_verify_certificate,omitempty"`
Healthy Healthy `json:"healthy,omitempty"`
UnHealthy UnHealthy `json:"unhealthy,omitempty"`
ReqHeaders []string `json:"req_headers,omitempty"`
}
type Passive struct {
Type string `json:"type,omitempty"`
Healthy Healthy `json:"healthy,omitempty"`
UnHealthy UnHealthy `json:"unhealthy,omitempty"`
}
type HealthChecker struct {
Active Active `json:"active,omitempty"`
Passive Passive `json:"passive,omitempty"`
}
type UpstreamTLS struct {
ClientCert string `json:"client_cert,omitempty"`
ClientKey string `json:"client_key,omitempty"`
}
type UpstreamKeepalivePool struct {
IdleTimeout *TimeoutValue `json:"idle_timeout,omitempty"`
Requests int `json:"requests,omitempty"`
Size int `json:"size"`
}
type UpstreamDef struct {
Nodes interface{} `json:"nodes,omitempty"`
Retries *int `json:"retries,omitempty"`
Timeout *Timeout `json:"timeout,omitempty"`
Type string `json:"type,omitempty"`
Checks interface{} `json:"checks,omitempty"`
HashOn string `json:"hash_on,omitempty"`
Key string `json:"key,omitempty"`
Scheme string `json:"scheme,omitempty"`
DiscoveryType string `json:"discovery_type,omitempty"`
DiscoveryArgs map[string]string `json:"discovery_args,omitempty"`
PassHost string `json:"pass_host,omitempty"`
UpstreamHost string `json:"upstream_host,omitempty"`
Name string `json:"name,omitempty"`
Desc string `json:"desc,omitempty"`
ServiceName string `json:"service_name,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
TLS *UpstreamTLS `json:"tls,omitempty"`
KeepalivePool *UpstreamKeepalivePool `json:"keepalive_pool,omitempty"`
RetryTimeout TimeoutValue `json:"retry_timeout,omitempty"`
}
// swagger:model Upstream
type Upstream struct {
BaseInfo
UpstreamDef
}
type UpstreamNameResponse struct {
ID interface{} `json:"id"`
Name string `json:"name"`
}
func (upstream *Upstream) Parse2NameResponse() (*UpstreamNameResponse, error) {
nameResp := &UpstreamNameResponse{
ID: upstream.ID,
Name: upstream.Name,
}
return nameResp, nil
}
// --- structures for upstream end ---
// swagger:model Consumer
type Consumer struct {
Username string `json:"username"`
Desc string `json:"desc,omitempty"`
Plugins map[string]interface{} `json:"plugins,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
CreateTime int64 `json:"create_time,omitempty"`
UpdateTime int64 `json:"update_time,omitempty"`
}
type SSLClient struct {
CA string `json:"ca,omitempty"`
Depth int `json:"depth,omitempty"`
}
// swagger:model SSL
type SSL struct {
BaseInfo
Cert string `json:"cert,omitempty"`
Key string `json:"key,omitempty"`
Sni string `json:"sni,omitempty"`
Snis []string `json:"snis,omitempty"`
Certs []string `json:"certs,omitempty"`
Keys []string `json:"keys,omitempty"`
ExpTime int64 `json:"exptime,omitempty"`
Status int `json:"status"`
ValidityStart int64 `json:"validity_start,omitempty"`
ValidityEnd int64 `json:"validity_end,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
Client *SSLClient `json:"client,omitempty"`
}
// swagger:model Service
type Service struct {
BaseInfo
Name string `json:"name,omitempty"`
Desc string `json:"desc,omitempty"`
Upstream *UpstreamDef `json:"upstream,omitempty"`
UpstreamID interface{} `json:"upstream_id,omitempty"`
Plugins map[string]interface{} `json:"plugins,omitempty"`
Script string `json:"script,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
EnableWebsocket bool `json:"enable_websocket,omitempty"`
Hosts []string `json:"hosts,omitempty"`
}
type Script struct {
ID string `json:"id"`
Script interface{} `json:"script,omitempty"`
}
type RequestValidation struct {
Type string `json:"type,omitempty"`
Required []string `json:"required,omitempty"`
Properties interface{} `json:"properties,omitempty"`
}
// swagger:model GlobalPlugins
type GlobalPlugins struct {
BaseInfo
Plugins map[string]interface{} `json:"plugins"`
}
type ServerInfo struct {
BaseInfo
LastReportTime int64 `json:"last_report_time,omitempty"`
UpTime int64 `json:"up_time,omitempty"`
BootTime int64 `json:"boot_time,omitempty"`
EtcdVersion string `json:"etcd_version,omitempty"`
Hostname string `json:"hostname,omitempty"`
Version string `json:"version,omitempty"`
}
// swagger:model GlobalPlugins
type PluginConfig struct {
BaseInfo
Desc string `json:"desc,omitempty" validate:"max=256"`
Plugins map[string]interface{} `json:"plugins"`
Labels map[string]string `json:"labels,omitempty"`
}
// swagger:model Proto
type Proto struct {
BaseInfo
Desc string `json:"desc,omitempty"`
Content string `json:"content"`
}
// swagger:model StreamRoute
type StreamRoute struct {
BaseInfo
Desc string `json:"desc,omitempty"`
RemoteAddr string `json:"remote_addr,omitempty"`
ServerAddr string `json:"server_addr,omitempty"`
ServerPort int `json:"server_port,omitempty"`
SNI string `json:"sni,omitempty"`
Upstream *UpstreamDef `json:"upstream,omitempty"`
UpstreamID interface{} `json:"upstream_id,omitempty"`
Plugins map[string]interface{} `json:"plugins,omitempty"`
}
// swagger:model SystemConfig
type SystemConfig struct {
ConfigName string `json:"config_name"`
Desc string `json:"desc,omitempty"`
Payload map[string]interface{} `json:"payload,omitempty"`
CreateTime int64 `json:"create_time,omitempty"`
UpdateTime int64 `json:"update_time,omitempty"`
}