-
Notifications
You must be signed in to change notification settings - Fork 10
/
nat_rule.go
160 lines (121 loc) · 4.03 KB
/
nat_rule.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
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"context"
"github.com/go-openapi/errors"
"github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
"github.com/go-openapi/validate"
)
// NatRule NAT Rule
//
// swagger:model NatRule
type NatRule struct {
// Description of the NAT rule.
Description string `json:"description,omitempty"`
// The external IP address of the outbound or routed network
// Example: any, 10.20.156.101
// Read Only: true
DestinationAddress string `json:"destinationAddress,omitempty"`
// The edge gateway port. Default is `any`
// Example: any, 80, 5000-5100
DestinationPorts string `json:"destinationPorts,omitempty"`
// Index in which the rule must be applied
// Required: true
Index *int32 `json:"index"`
// Kind of NAT: NAT44/NAT64/NAT66. Only NAT44 is supported currently and it is the default value
// Example: NAT44
Kind string `json:"kind,omitempty"`
// The protocol of the incoming requests. Default is TCP.
// Example: TCP, UDP
Protocol string `json:"protocol,omitempty"`
// Unique ID of the NAT Rule
// Read Only: true
RuleID string `json:"ruleId,omitempty"`
// The IP of the external source. Default is `any`
// Example: any, 10.20.156.101
SourceIPs string `json:"sourceIPs,omitempty"`
// Ports from where the request is originating. Default is `any`
// Example: any, 80, 5000-5100
SourcePorts string `json:"sourcePorts,omitempty"`
// A links to target load balancer or a machine's network interface where the request will be forwarded.
// Example: /iaas/api/load-balancers/try6-45ef, /iaas/api/machines/ht54-a472/network-interfaces/dyd6-d67e
// Required: true
TargetLink *string `json:"targetLink"`
// The machine port where the request will be forwarded. Default is `any`
// Example: any, 80, 5000-5100
TranslatedPorts string `json:"translatedPorts,omitempty"`
// Type of the NAT rule. Only DNAT is supported currently.
// Example: DNAT
Type string `json:"type,omitempty"`
}
// Validate validates this nat rule
func (m *NatRule) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateIndex(formats); err != nil {
res = append(res, err)
}
if err := m.validateTargetLink(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *NatRule) validateIndex(formats strfmt.Registry) error {
if err := validate.Required("index", "body", m.Index); err != nil {
return err
}
return nil
}
func (m *NatRule) validateTargetLink(formats strfmt.Registry) error {
if err := validate.Required("targetLink", "body", m.TargetLink); err != nil {
return err
}
return nil
}
// ContextValidate validate this nat rule based on the context it is used
func (m *NatRule) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
var res []error
if err := m.contextValidateDestinationAddress(ctx, formats); err != nil {
res = append(res, err)
}
if err := m.contextValidateRuleID(ctx, formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *NatRule) contextValidateDestinationAddress(ctx context.Context, formats strfmt.Registry) error {
if err := validate.ReadOnly(ctx, "destinationAddress", "body", string(m.DestinationAddress)); err != nil {
return err
}
return nil
}
func (m *NatRule) contextValidateRuleID(ctx context.Context, formats strfmt.Registry) error {
if err := validate.ReadOnly(ctx, "ruleId", "body", string(m.RuleID)); err != nil {
return err
}
return nil
}
// MarshalBinary interface implementation
func (m *NatRule) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *NatRule) UnmarshalBinary(b []byte) error {
var res NatRule
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}