-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_model.go
More file actions
429 lines (370 loc) · 10.7 KB
/
data_model.go
File metadata and controls
429 lines (370 loc) · 10.7 KB
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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
// Code generated by github.com/atombender/go-jsonschema, DO NOT EDIT.
package spec
import (
"encoding/json"
"fmt"
"reflect"
)
type AnyProtocol struct {
// Necessarily ANY
Protocol AnyProtocolProtocol `json:"protocol"`
}
type AnyProtocolProtocol string
const AnyProtocolProtocolANY AnyProtocolProtocol = "ANY"
var enumValues_AnyProtocolProtocol = []interface{}{
"ANY",
}
// UnmarshalJSON implements json.Unmarshaler.
func (j *AnyProtocolProtocol) UnmarshalJSON(b []byte) error {
var v string
if err := json.Unmarshal(b, &v); err != nil {
return err
}
var ok bool
for _, expected := range enumValues_AnyProtocolProtocol {
if reflect.DeepEqual(v, expected) {
ok = true
break
}
}
if !ok {
return fmt.Errorf("invalid value (expected one of %#v): %#v", enumValues_AnyProtocolProtocol, v)
}
*j = AnyProtocolProtocol(v)
return nil
}
// UnmarshalJSON implements json.Unmarshaler.
func (j *AnyProtocol) UnmarshalJSON(b []byte) error {
var raw map[string]interface{}
if err := json.Unmarshal(b, &raw); err != nil {
return err
}
if _, ok := raw["protocol"]; raw != nil && !ok {
return fmt.Errorf("field protocol in AnyProtocol: required")
}
type Plain AnyProtocol
var plain Plain
if err := json.Unmarshal(b, &plain); err != nil {
return err
}
*j = AnyProtocol(plain)
return nil
}
type Icmp struct {
// ICMP code allowed. If omitted, any code is allowed
Code *int `json:"code,omitempty"`
// Necessarily ICMP
Protocol IcmpProtocol `json:"protocol"`
// ICMP type allowed. If omitted, any type is allowed
Type *int `json:"type,omitempty"`
}
type IcmpProtocol string
const IcmpProtocolICMP IcmpProtocol = "ICMP"
var enumValues_IcmpProtocol = []interface{}{
"ICMP",
}
// UnmarshalJSON implements json.Unmarshaler.
func (j *IcmpProtocol) UnmarshalJSON(b []byte) error {
var v string
if err := json.Unmarshal(b, &v); err != nil {
return err
}
var ok bool
for _, expected := range enumValues_IcmpProtocol {
if reflect.DeepEqual(v, expected) {
ok = true
break
}
}
if !ok {
return fmt.Errorf("invalid value (expected one of %#v): %#v", enumValues_IcmpProtocol, v)
}
*j = IcmpProtocol(v)
return nil
}
// UnmarshalJSON implements json.Unmarshaler.
func (j *Icmp) UnmarshalJSON(b []byte) error {
var raw map[string]interface{}
if err := json.Unmarshal(b, &raw); err != nil {
return err
}
if _, ok := raw["protocol"]; raw != nil && !ok {
return fmt.Errorf("field protocol in Icmp: required")
}
type Plain Icmp
var plain Plain
if err := json.Unmarshal(b, &plain); err != nil {
return err
}
*j = Icmp(plain)
return nil
}
type Protocol interface{}
type ProtocolList []interface{}
type Resource struct {
// Name of resource
Name string `json:"name"`
// Type of resource
Type ResourceType `json:"type"`
}
type ResourceType string
const ResourceTypeCidr ResourceType = "cidr"
const ResourceTypeExternal ResourceType = "external"
const ResourceTypeInstance ResourceType = "instance"
const ResourceTypeNif ResourceType = "nif"
const ResourceTypeSegment ResourceType = "segment"
const ResourceTypeSubnet ResourceType = "subnet"
const ResourceTypeVpe ResourceType = "vpe"
var enumValues_ResourceType = []interface{}{
"external",
"segment",
"subnet",
"instance",
"nif",
"cidr",
"vpe",
}
// UnmarshalJSON implements json.Unmarshaler.
func (j *ResourceType) UnmarshalJSON(b []byte) error {
var v string
if err := json.Unmarshal(b, &v); err != nil {
return err
}
var ok bool
for _, expected := range enumValues_ResourceType {
if reflect.DeepEqual(v, expected) {
ok = true
break
}
}
if !ok {
return fmt.Errorf("invalid value (expected one of %#v): %#v", enumValues_ResourceType, v)
}
*j = ResourceType(v)
return nil
}
// UnmarshalJSON implements json.Unmarshaler.
func (j *Resource) UnmarshalJSON(b []byte) error {
var raw map[string]interface{}
if err := json.Unmarshal(b, &raw); err != nil {
return err
}
if _, ok := raw["name"]; raw != nil && !ok {
return fmt.Errorf("field name in Resource: required")
}
if _, ok := raw["type"]; raw != nil && !ok {
return fmt.Errorf("field type in Resource: required")
}
type Plain Resource
var plain Plain
if err := json.Unmarshal(b, &plain); err != nil {
return err
}
*j = Resource(plain)
return nil
}
// A segment is a named collection of resources of the same type (subnet, cidr,
// instance, or nif)
type Segment struct {
// All items are of the type specified in the type property, identified by name
Items []string `json:"items"`
// The type of the elements inside the segment
Type SegmentType `json:"type"`
}
type SegmentType string
const SegmentTypeCidr SegmentType = "cidr"
const SegmentTypeInstance SegmentType = "instance"
const SegmentTypeNif SegmentType = "nif"
const SegmentTypeSubnet SegmentType = "subnet"
const SegmentTypeVpe SegmentType = "vpe"
var enumValues_SegmentType = []interface{}{
"subnet",
"cidr",
"instance",
"nif",
"vpe",
}
// UnmarshalJSON implements json.Unmarshaler.
func (j *SegmentType) UnmarshalJSON(b []byte) error {
var v string
if err := json.Unmarshal(b, &v); err != nil {
return err
}
var ok bool
for _, expected := range enumValues_SegmentType {
if reflect.DeepEqual(v, expected) {
ok = true
break
}
}
if !ok {
return fmt.Errorf("invalid value (expected one of %#v): %#v", enumValues_SegmentType, v)
}
*j = SegmentType(v)
return nil
}
// UnmarshalJSON implements json.Unmarshaler.
func (j *Segment) UnmarshalJSON(b []byte) error {
var raw map[string]interface{}
if err := json.Unmarshal(b, &raw); err != nil {
return err
}
if _, ok := raw["items"]; raw != nil && !ok {
return fmt.Errorf("field items in Segment: required")
}
if _, ok := raw["type"]; raw != nil && !ok {
return fmt.Errorf("field type in Segment: required")
}
type Plain Segment
var plain Plain
if err := json.Unmarshal(b, &plain); err != nil {
return err
}
*j = Segment(plain)
return nil
}
type Spec struct {
// Externals are a way for users to name CIDRs external to the VPC. These are
// later used in src/dst definitions
Externals SpecExternals `json:"externals,omitempty"`
// Lightweight way to define instance as a list of interfaces.
Instances SpecInstances `json:"instances,omitempty"`
// Lightweight way to define network interfaces.
Nifs SpecNifs `json:"nifs,omitempty"`
// A list of required connections
RequiredConnections []SpecRequiredConnectionsElem `json:"required-connections"`
// Segments are a way for users to create aggregations. These can later be used in
// src/dst fields
Segments SpecSegments `json:"segments,omitempty"`
// Lightweight way to define subnets.
Subnets SpecSubnets `json:"subnets,omitempty"`
}
// Externals are a way for users to name CIDRs external to the VPC. These are later
// used in src/dst definitions
type SpecExternals map[string]string
// Lightweight way to define instance as a list of interfaces.
type SpecInstances map[string][]string
// Lightweight way to define network interfaces.
type SpecNifs map[string]string
type SpecRequiredConnectionsElem struct {
// List of allowed protocols
AllowedProtocols ProtocolList `json:"allowed-protocols,omitempty"`
// If true, allow both connections from src to dst and connections from dst to src
Bidirectional bool `json:"bidirectional,omitempty"`
// In unidirectional connection, this is the ingress resource
Dst Resource `json:"dst"`
// In unidirectional connection, this is the egress resource
Src Resource `json:"src"`
}
// UnmarshalJSON implements json.Unmarshaler.
func (j *SpecRequiredConnectionsElem) UnmarshalJSON(b []byte) error {
var raw map[string]interface{}
if err := json.Unmarshal(b, &raw); err != nil {
return err
}
if _, ok := raw["dst"]; raw != nil && !ok {
return fmt.Errorf("field dst in SpecRequiredConnectionsElem: required")
}
if _, ok := raw["src"]; raw != nil && !ok {
return fmt.Errorf("field src in SpecRequiredConnectionsElem: required")
}
type Plain SpecRequiredConnectionsElem
var plain Plain
if err := json.Unmarshal(b, &plain); err != nil {
return err
}
if v, ok := raw["bidirectional"]; !ok || v == nil {
plain.Bidirectional = false
}
*j = SpecRequiredConnectionsElem(plain)
return nil
}
// Segments are a way for users to create aggregations. These can later be used in
// src/dst fields
type SpecSegments map[string]Segment
// Lightweight way to define subnets.
type SpecSubnets map[string]string
// UnmarshalJSON implements json.Unmarshaler.
func (j *Spec) UnmarshalJSON(b []byte) error {
var raw map[string]interface{}
if err := json.Unmarshal(b, &raw); err != nil {
return err
}
if _, ok := raw["required-connections"]; raw != nil && !ok {
return fmt.Errorf("field required-connections in Spec: required")
}
type Plain Spec
var plain Plain
if err := json.Unmarshal(b, &plain); err != nil {
return err
}
*j = Spec(plain)
return nil
}
type TcpUdp struct {
// Maximal destination port; default is 65535
MaxDestinationPort int `json:"max_destination_port,omitempty"`
// Maximal source port; default is 65535. Unsupported in vpc synthesis
MaxSourcePort int `json:"max_source_port,omitempty"`
// Minimal destination port; default is 1
MinDestinationPort int `json:"min_destination_port,omitempty"`
// Minimal source port; default is 1. Unsupported in vpc synthesis
MinSourcePort int `json:"min_source_port,omitempty"`
// Is it TCP or UDP
Protocol TcpUdpProtocol `json:"protocol"`
}
type TcpUdpProtocol string
const TcpUdpProtocolTCP TcpUdpProtocol = "TCP"
const TcpUdpProtocolUDP TcpUdpProtocol = "UDP"
var enumValues_TcpUdpProtocol = []interface{}{
"TCP",
"UDP",
}
// UnmarshalJSON implements json.Unmarshaler.
func (j *TcpUdpProtocol) UnmarshalJSON(b []byte) error {
var v string
if err := json.Unmarshal(b, &v); err != nil {
return err
}
var ok bool
for _, expected := range enumValues_TcpUdpProtocol {
if reflect.DeepEqual(v, expected) {
ok = true
break
}
}
if !ok {
return fmt.Errorf("invalid value (expected one of %#v): %#v", enumValues_TcpUdpProtocol, v)
}
*j = TcpUdpProtocol(v)
return nil
}
// UnmarshalJSON implements json.Unmarshaler.
func (j *TcpUdp) UnmarshalJSON(b []byte) error {
var raw map[string]interface{}
if err := json.Unmarshal(b, &raw); err != nil {
return err
}
if _, ok := raw["protocol"]; raw != nil && !ok {
return fmt.Errorf("field protocol in TcpUdp: required")
}
type Plain TcpUdp
var plain Plain
if err := json.Unmarshal(b, &plain); err != nil {
return err
}
if v, ok := raw["max_destination_port"]; !ok || v == nil {
plain.MaxDestinationPort = 65535.0
}
if v, ok := raw["max_source_port"]; !ok || v == nil {
plain.MaxSourcePort = 65535.0
}
if v, ok := raw["min_destination_port"]; !ok || v == nil {
plain.MinDestinationPort = 1.0
}
if v, ok := raw["min_source_port"]; !ok || v == nil {
plain.MinSourcePort = 1.0
}
*j = TcpUdp(plain)
return nil
}