forked from scottdware/go-bigip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sys.go
359 lines (305 loc) · 11.4 KB
/
sys.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
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
package bigip
import "encoding/json"
const (
uriSys = "sys"
uriFolder = "folder"
uriSyslog = "syslog"
uriSoftware = "software"
uriVolume = "volume"
uriHardware = "hardware"
uriGlobalSettings = "global-settings"
uriManagementIp = "management-ip"
uriFile = "file"
uriSslCert = "ssl-cert"
uriSslKey = "ssl-key"
//uriPlatform = "?$select=platform"
)
type Volumes struct {
Volumes []Volume `json:"items,omitempty"`
}
type Volume struct {
Name string `json:"items,omitempty"`
FullPath string `json:"fullPath,omitempty"`
Generation int `json:"generation,omitempty"`
SelfLink string `json:"selfLink,omitempty"`
Active bool `json:"active,omitempty"`
BaseBuild string `json:"basebuild,omitempty"`
Build string `json:"build,omitempty"`
Product string `json:"product,omitempty"`
Status string `json:"status,omitempty"`
Version string `json:"version,omitempty"`
}
// Volumes returns a list of Software Volumes.
func (b *BigIP) Volumes() (*Volumes, error) {
var volumes Volumes
err, _ := b.getForEntity(&volumes, uriSys, uriSoftware, uriVolume)
if err != nil {
return nil, err
}
return &volumes, nil
}
type ManagementIP struct {
Addresses []ManagementIPAddress
}
type ManagementIPAddress struct {
Name string `json:"items,omitempty"`
FullPath string `json:"fullPath,omitempty"`
Generation int `json:"generation,omitempty"`
SelfLink string `json:"selfLink,omitempty"`
}
func (b *BigIP) ManagementIPs() (*ManagementIP, error) {
var managementIP ManagementIP
err, _ := b.getForEntity(&managementIP, uriSys, uriManagementIp)
if err != nil {
return nil, err
}
return &managementIP, nil
}
type SyslogRemoteServer struct {
Name string `json:"name,omitempty"`
Host string `json:"host,omitempty"`
LocalIP string `json:"localIp,omitempty"`
RemotePort int `json:"remotePort,omitempty"`
}
type Syslog struct {
SelfLink string `json:"selfLink,omitempty"`
RemoteServers []SyslogRemoteServer `json:"remoteServers,omitempty"`
}
func (b *BigIP) Syslog() (*Syslog, error) {
var syslog Syslog
err, _ := b.getForEntity(&syslog, uriSys, uriSyslog)
if err != nil {
return nil, err
}
return &syslog, nil
}
func (b *BigIP) SetSyslog(config Syslog) error {
return b.put(config, uriSys, uriSyslog)
}
// Folders contains a list of every folder on the BIG-IP system.
type Folders struct {
Folders []Folder `json:"items"`
}
type folderDTO struct {
Name string `json:"name,omitempty"`
Partition string `json:"partition,omitempty"`
SubPath string `json:"subPath,omitempty"`
FullPath string `json:"fullPath,omitempty"`
AppService string `json:"appService,omitempty"`
Description string `json:"description,omitempty"`
// Set to "default" to inherit or a device group name to control. You can also set it to "non-default" to pin its device group to its current setting and turn off inheritance.
DeviceGroup string `json:"deviceGroup,omitempty"`
Hidden string `json:"hidden,omitempty" bool:"true"`
NoRefCheck string `json:"noRefCheck,omitempty" bool:"true"`
// Set to "default" to inherit or a traffic group name to control. You can also set it to "non-default" to pin its traffic group to its current setting and turn off inheritance.
TrafficGroup string `json:"trafficGroup,omitempty"`
// Read-only property. Set DeviceGroup to control.
InheritedDeviceGroup string `json:"inheritedDevicegroup,omitempty" bool:"true"`
// Read-only property. Set TrafficGroup to control.
InheritedTrafficGroup string `json:"inheritedTrafficGroup,omitempty" bool:"true"`
}
type Folder struct {
Name string `json:"name,omitempty"`
Partition string `json:"partition,omitempty"`
SubPath string `json:"subPath,omitempty"`
FullPath string `json:"fullPath,omitempty"`
AppService string `json:"appService,omitempty"`
Description string `json:"description,omitempty"`
DeviceGroup string `json:"deviceGroup,omitempty"`
Hidden *bool `json:"hidden,omitempty"`
NoRefCheck *bool `json:"noRefCheck,omitempty"`
TrafficGroup string `json:"trafficGroup,omitempty"`
// Read-only property. Set DeviceGroup to "default" or "non-default" to control.
InheritedDeviceGroup *bool `json:"inheritedDevicegroup,omitempty"`
// Read-only property. Set TrafficGroup to "default" or "non-default" to control.
InheritedTrafficGroup *bool `json:"inheritedTrafficGroup,omitempty"`
}
func (f *Folder) MarshalJSON() ([]byte, error) {
var dto folderDTO
marshal(&dto, f)
return json.Marshal(dto)
}
func (f *Folder) UnmarshalJSON(b []byte) error {
var dto folderDTO
err := json.Unmarshal(b, &dto)
if err != nil {
return err
}
return marshal(f, &dto)
}
// Folders returns a list of folders.
func (b *BigIP) Folders() (*Folders, error) {
var folders Folders
err, _ := b.getForEntity(&folders, uriSys, uriFolder)
if err != nil {
return nil, err
}
return &folders, nil
}
// CreateFolder adds a new folder to the BIG-IP system.
func (b *BigIP) CreateFolder(name string) error {
config := &Folder{
Name: name,
}
return b.post(config, uriSys, uriFolder)
}
// AddFolder adds a new folder by config to the BIG-IP system.
func (b *BigIP) AddFolder(config *Folder) error {
return b.post(config, uriSys, uriFolder)
}
// GetFolder retrieves a Folder by name. Returns nil if the folder does not exist
func (b *BigIP) GetFolder(name string) (*Folder, error) {
var folder Folder
err, ok := b.getForEntity(&folder, uriSys, uriFolder, name)
if err != nil {
return nil, err
}
if !ok {
return nil, nil
}
return &folder, nil
}
// DeleteFolder removes a folder.
func (b *BigIP) DeleteFolder(name string) error {
return b.delete(uriSys, uriFolder, name)
}
// ModifyFolder allows you to change any attribute of a folder. Fields that can
// be modified are referenced in the Folder struct. This replaces the existing
// configuration, so use PatchFolder if you want to change only particular
// attributes.
func (b *BigIP) ModifyFolder(name string, config *Folder) error {
return b.put(config, uriSys, uriFolder, name)
}
// PatchFolder allows you to change any attribute of a folder. Fields that can
// be modified are referenced in the Folder struct. This changes only the
// attributes provided, so use ModifyFolder if you want to replace the existing
// configuration.
func (b *BigIP) PatchFolder(name string, config *Folder) error {
return b.patch(config, uriSys, uriFolder, name)
}
// Certificates represents a list of installed SSL certificates.
type Certificates struct {
Certificates []Certificate `json:"items,omitempty"`
}
// Certificate represents an SSL Certificate.
type Certificate struct {
AppService string `json:"appService,omitempty"`
CachePath string `json:"cachePath,omitempty"`
CertificateKeyCurveName string `json:"certificateKeyCurveName,omitempty"`
CertificateKeySize int `json:"certificateKeySize,omitempty"`
CertValidationOptions string `json:"certValidationOptions,omitempty"`
Checksum string `json:"checksum,omitempty"`
CreatedBy string `json:"createdBy,omitempty"`
CreateTime string `json:"createTime,omitempty"`
Email string `json:"email,omitempty"`
ExpirationDate int `json:"expirationDate,omitempty"`
ExpirationString string `json:"expirationString,omitempty"`
Fingerprint string `json:"fingerprint,omitempty"`
FullPath string `json:"fullPath,omitempty"`
Generation int `json:"generation,omitempty"`
IsBundle string `json:"isBundle,omitempty"`
IsDynamic string `json:"isDynamic,omitempty"`
Issuer string `json:"issuer,omitempty"`
IssuerCert string `json:"issuerCert,omitempty"`
KeyType string `json:"keyType,omitempty"`
LastUpdateTime string `json:"lastUpdateTime,omitempty"`
Mode int `json:"mode,omitempty"`
Name string `json:"name,omitempty"`
Partition string `json:"partition,omitempty"`
Revision int `json:"revision,omitempty"`
SerialNumber string `json:"serialNumber,omitempty"`
Size uint64 `json:"size,omitempty"`
SourcePath string `json:"sourcePath,omitempty"`
Subject string `json:"subject,omitempty"`
SubjectAlternativeName string `json:"subjectAlternativeName,omitempty"`
SystemPath string `json:"systemPath,omitempty"`
UpdatedBy string `json:"updatedBy,omitempty"`
Version int `json:"version,omitempty"`
}
// Certificates returns a list of certificates.
func (b *BigIP) Certificates() (*Certificates, error) {
var certs Certificates
err, _ := b.getForEntity(&certs, uriSys, uriFile, uriSslCert)
if err != nil {
return nil, err
}
return &certs, nil
}
// AddCertificate installs a certificate.
func (b *BigIP) AddCertificate(cert *Certificate) error {
return b.post(cert, uriSys, uriFile, uriSslCert)
}
// GetCertificate retrieves a Certificate by name. Returns nil if the certificate does not exist
func (b *BigIP) GetCertificate(name string) (*Certificate, error) {
var cert Certificate
err, ok := b.getForEntity(&cert, uriSys, uriFile, uriSslCert, name)
if err != nil {
return nil, err
}
if !ok {
return nil, nil
}
return &cert, nil
}
// DeleteCertificate removes a certificate.
func (b *BigIP) DeleteCertificate(name string) error {
return b.delete(uriSys, uriFile, uriSslCert, name)
}
// Keys represents a list of installed keys.
type Keys struct {
Keys []Key `json:"items,omitempty"`
}
// Key represents a private key associated with a certificate.
type Key struct {
AppService string `json:"appService,omitempty"`
CachePath string `json:"cachePath,omitempty"`
Checksum string `json:"checksum,omitempty"`
CreatedBy string `json:"createdBy,omitempty"`
CreateTime string `json:"createTime,omitempty"`
CurveName string `json:"curveName,omitempty"`
FullPath string `json:"fullPath,omitempty"`
Generation int `json:"generation,omitempty"`
IsDynamic string `json:"isDynamic,omitempty"`
KeySize int `json:"keySize,omitempty"`
KeyType string `json:"keyType,omitempty"`
LastUpdateTime string `json:"lastUpdateTime,omitempty"`
Mode int `json:"mode,omitempty"`
Name string `json:"name,omitempty"`
Partition string `json:"partition,omitempty"`
Passphrase string `json:"passphrase,omitempty"`
Revision int `json:"revision,omitempty"`
SecurityType string `json:"securityType,omitempty"`
Size uint64 `json:"size,omitempty"`
SourcePath string `json:"sourcePath,omitempty"`
SystemPath string `json:"systemPath,omitempty"`
UpdatedBy string `json:"updatedBy,omitempty"`
}
// Keys returns a list of keys.
func (b *BigIP) Keys() (*Keys, error) {
var keys Keys
err, _ := b.getForEntity(&keys, uriSys, uriFile, uriSslKey)
if err != nil {
return nil, err
}
return &keys, nil
}
// AddKey installs a key.
func (b *BigIP) AddKey(config *Key) error {
return b.post(config, uriSys, uriFile, uriSslKey)
}
// GetKey retrieves a key by name. Returns nil if the key does not exist.
func (b *BigIP) GetKey(name string) (*Key, error) {
var key Key
err, ok := b.getForEntity(&key, uriSys, uriFile, uriSslKey, name)
if err != nil {
return nil, err
}
if !ok {
return nil, nil
}
return &key, nil
}
// DeleteKey removes a key.
func (b *BigIP) DeleteKey(name string) error {
return b.delete(uriSys, uriFile, uriSslKey, name)
}