forked from esurdam/go-sophos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroute.go
262 lines (213 loc) · 9.01 KB
/
route.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
package objects
import (
"fmt"
"github.com/esurdam/go-sophos"
)
// Route is a generated struct representing the Sophos Route Endpoint
// GET /api/nodes/route
type Route struct {
RouteGroup RouteGroup `json:"route_group"`
RoutePolicy RoutePolicy `json:"route_policy"`
RouteStatic RouteStatic `json:"route_static"`
}
var _ sophos.Endpoint = &Route{}
var defsRoute = map[string]sophos.RestObject{
"RouteGroup": &RouteGroup{},
"RoutePolicy": &RoutePolicy{},
"RouteStatic": &RouteStatic{},
}
// RestObjects implements the sophos.Node interface and returns a map of Route's Objects
func (Route) RestObjects() map[string]sophos.RestObject { return defsRoute }
// GetPath implements sophos.RestGetter
func (*Route) GetPath() string { return "/api/nodes/route" }
// RefRequired implements sophos.RestGetter
func (*Route) RefRequired() (string, bool) { return "", false }
var defRoute = &sophos.Definition{Description: "route", Name: "route", Link: "/api/definitions/route"}
// Definition returns the /api/definitions struct of Route
func (Route) Definition() sophos.Definition { return *defRoute }
// ApiRoutes returns all known Route Paths
func (Route) ApiRoutes() []string {
return []string{
"/api/objects/route/group/",
"/api/objects/route/group/{ref}",
"/api/objects/route/group/{ref}/usedby",
"/api/objects/route/policy/",
"/api/objects/route/policy/{ref}",
"/api/objects/route/policy/{ref}/usedby",
"/api/objects/route/static/",
"/api/objects/route/static/{ref}",
"/api/objects/route/static/{ref}/usedby",
}
}
// References returns the Route's references. These strings serve no purpose other than to demonstrate which
// Reference keys are used for this Endpoint
func (Route) References() []string {
return []string{
"REF_RouteGroup",
"REF_RoutePolicy",
"REF_RouteStatic",
}
}
// RouteGroups is an Sophos Endpoint subType and implements sophos.RestObject
type RouteGroups []RouteGroup
// RouteGroup represents a UTM group
type RouteGroup struct {
Locked string `json:"_locked"`
ObjectType string `json:"_type"`
Reference string `json:"_ref"`
Comment string `json:"comment"`
Name string `json:"name"`
}
var _ sophos.RestGetter = &RouteGroup{}
// GetPath implements sophos.RestObject and returns the RouteGroups GET path
// Returns all available route/group objects
func (*RouteGroups) GetPath() string { return "/api/objects/route/group/" }
// RefRequired implements sophos.RestObject
func (*RouteGroups) RefRequired() (string, bool) { return "", false }
// GetPath implements sophos.RestObject and returns the RouteGroups GET path
// Returns all available group types
func (r *RouteGroup) GetPath() string { return fmt.Sprintf("/api/objects/route/group/%s", r.Reference) }
// RefRequired implements sophos.RestObject
func (r *RouteGroup) RefRequired() (string, bool) { return r.Reference, true }
// DeletePath implements sophos.RestObject and returns the RouteGroup DELETE path
// Creates or updates the complete object group
func (*RouteGroup) DeletePath(ref string) string {
return fmt.Sprintf("/api/objects/route/group/%s", ref)
}
// PatchPath implements sophos.RestObject and returns the RouteGroup PATCH path
// Changes to parts of the object group types
func (*RouteGroup) PatchPath(ref string) string {
return fmt.Sprintf("/api/objects/route/group/%s", ref)
}
// PostPath implements sophos.RestObject and returns the RouteGroup POST path
// Create a new route/group object
func (*RouteGroup) PostPath() string {
return "/api/objects/route/group/"
}
// PutPath implements sophos.RestObject and returns the RouteGroup PUT path
// Creates or updates the complete object group
func (*RouteGroup) PutPath(ref string) string {
return fmt.Sprintf("/api/objects/route/group/%s", ref)
}
// UsedByPath implements sophos.RestObject
// Returns the objects and the nodes that use the object with the given ref
func (*RouteGroup) UsedByPath(ref string) string {
return fmt.Sprintf("/api/objects/route/group/%s/usedby", ref)
}
// RoutePolicys is an Sophos Endpoint subType and implements sophos.RestObject
type RoutePolicys []RoutePolicy
// RoutePolicy represents a UTM policy route
type RoutePolicy struct {
Locked string `json:"_locked"`
ObjectType string `json:"_type"`
Reference string `json:"_ref"`
Comment string `json:"comment"`
// Destination description: REF(network/*)
Destination string `json:"destination"`
// Interface description: REF(interface/*)
Interface string `json:"interface"`
// Status default value is false
Status bool `json:"status"`
Name string `json:"name"`
// Service description: REF(service/*)
Service string `json:"service"`
// Source description: REF(network/*)
Source string `json:"source"`
// Target description: REF(/*)
Target string `json:"target"`
// Type can be one of: []string{"itf", "host"}
Type string `json:"type"`
}
var _ sophos.RestGetter = &RoutePolicy{}
// GetPath implements sophos.RestObject and returns the RoutePolicys GET path
// Returns all available route/policy objects
func (*RoutePolicys) GetPath() string { return "/api/objects/route/policy/" }
// RefRequired implements sophos.RestObject
func (*RoutePolicys) RefRequired() (string, bool) { return "", false }
// GetPath implements sophos.RestObject and returns the RoutePolicys GET path
// Returns all available policy types
func (r *RoutePolicy) GetPath() string {
return fmt.Sprintf("/api/objects/route/policy/%s", r.Reference)
}
// RefRequired implements sophos.RestObject
func (r *RoutePolicy) RefRequired() (string, bool) { return r.Reference, true }
// DeletePath implements sophos.RestObject and returns the RoutePolicy DELETE path
// Creates or updates the complete object policy
func (*RoutePolicy) DeletePath(ref string) string {
return fmt.Sprintf("/api/objects/route/policy/%s", ref)
}
// PatchPath implements sophos.RestObject and returns the RoutePolicy PATCH path
// Changes to parts of the object policy types
func (*RoutePolicy) PatchPath(ref string) string {
return fmt.Sprintf("/api/objects/route/policy/%s", ref)
}
// PostPath implements sophos.RestObject and returns the RoutePolicy POST path
// Create a new route/policy object
func (*RoutePolicy) PostPath() string {
return "/api/objects/route/policy/"
}
// PutPath implements sophos.RestObject and returns the RoutePolicy PUT path
// Creates or updates the complete object policy
func (*RoutePolicy) PutPath(ref string) string {
return fmt.Sprintf("/api/objects/route/policy/%s", ref)
}
// UsedByPath implements sophos.RestObject
// Returns the objects and the nodes that use the object with the given ref
func (*RoutePolicy) UsedByPath(ref string) string {
return fmt.Sprintf("/api/objects/route/policy/%s/usedby", ref)
}
// RouteStatics is an Sophos Endpoint subType and implements sophos.RestObject
type RouteStatics []RouteStatic
// RouteStatic is a generated Sophos object
type RouteStatic struct {
Locked string `json:"_locked"`
Reference string `json:"_ref"`
ObjectType string `json:"_type"`
Comment string `json:"comment"`
Metric int64 `json:"metric"`
Name string `json:"name"`
Network string `json:"network"`
Status bool `json:"status"`
Target string `json:"target"`
Type string `json:"type"`
}
var _ sophos.RestGetter = &RouteStatic{}
// GetPath implements sophos.RestObject and returns the RouteStatics GET path
// Returns all available route/static objects
func (*RouteStatics) GetPath() string { return "/api/objects/route/static/" }
// RefRequired implements sophos.RestObject
func (*RouteStatics) RefRequired() (string, bool) { return "", false }
// GetPath implements sophos.RestObject and returns the RouteStatics GET path
// Returns all available static types
func (r *RouteStatic) GetPath() string {
return fmt.Sprintf("/api/objects/route/static/%s", r.Reference)
}
// RefRequired implements sophos.RestObject
func (r *RouteStatic) RefRequired() (string, bool) { return r.Reference, true }
// DeletePath implements sophos.RestObject and returns the RouteStatic DELETE path
// Creates or updates the complete object static
func (*RouteStatic) DeletePath(ref string) string {
return fmt.Sprintf("/api/objects/route/static/%s", ref)
}
// PatchPath implements sophos.RestObject and returns the RouteStatic PATCH path
// Changes to parts of the object static types
func (*RouteStatic) PatchPath(ref string) string {
return fmt.Sprintf("/api/objects/route/static/%s", ref)
}
// PostPath implements sophos.RestObject and returns the RouteStatic POST path
// Create a new route/static object
func (*RouteStatic) PostPath() string {
return "/api/objects/route/static/"
}
// PutPath implements sophos.RestObject and returns the RouteStatic PUT path
// Creates or updates the complete object static
func (*RouteStatic) PutPath(ref string) string {
return fmt.Sprintf("/api/objects/route/static/%s", ref)
}
// UsedByPath implements sophos.RestObject
// Returns the objects and the nodes that use the object with the given ref
func (*RouteStatic) UsedByPath(ref string) string {
return fmt.Sprintf("/api/objects/route/static/%s/usedby", ref)
}
// GetType implements sophos.Object
func (r *RouteStatic) GetType() string { return r.ObjectType }