-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathpaas.go
716 lines (583 loc) · 24.6 KB
/
paas.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
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
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
package gsclient
import (
"context"
"errors"
"net/http"
"path"
)
// PaaSOperator provides an interface for operations on PaaS-service-related resource.
type PaaSOperator interface {
GetPaaSServiceList(ctx context.Context) ([]PaaSService, error)
GetPaaSService(ctx context.Context, id string) (PaaSService, error)
CreatePaaSService(ctx context.Context, body PaaSServiceCreateRequest) (PaaSServiceCreateResponse, error)
UpdatePaaSService(ctx context.Context, id string, body PaaSServiceUpdateRequest) error
DeletePaaSService(ctx context.Context, id string) error
GetPaaSServiceMetrics(ctx context.Context, id string) ([]PaaSServiceMetric, error)
GetPaaSTemplateList(ctx context.Context) ([]PaaSTemplate, error)
GetDeletedPaaSServices(ctx context.Context) ([]PaaSService, error)
RenewK8sCredentials(ctx context.Context, id string) error
GetPaaSSecurityZoneList(ctx context.Context) ([]PaaSSecurityZone, error)
GetPaaSSecurityZone(ctx context.Context, id string) (PaaSSecurityZone, error)
CreatePaaSSecurityZone(ctx context.Context, body PaaSSecurityZoneCreateRequest) (PaaSSecurityZoneCreateResponse, error)
UpdatePaaSSecurityZone(ctx context.Context, id string, body PaaSSecurityZoneUpdateRequest) error
DeletePaaSSecurityZone(ctx context.Context, id string) error
}
// PaaSServices holds a list of available PaaS services.
type PaaSServices struct {
// Array of PaaS services
List map[string]PaaSServiceProperties `json:"paas_services"`
}
// DeletedPaaSServices provides a list of deleted PaaS services.
type DeletedPaaSServices struct {
// Array of deleted PaaS services.
List map[string]PaaSServiceProperties `json:"deleted_paas_services"`
}
// PaaSService represents a single PaaS service.
type PaaSService struct {
// Properties of a PaaS service.
Properties PaaSServiceProperties `json:"paas_service"`
}
// PaaSServiceProperties holds properties of a single PaaS service.
type PaaSServiceProperties struct {
// The UUID of an object is always unique, and refers to a specific object.
ObjectUUID string `json:"object_uuid"`
// List of labels.
Labels []string `json:"labels"`
// Contains the initial setup credentials for Service.
Credentials []Credential `json:"credentials"`
// Defines the date and time the object was initially created.
CreateTime GSTime `json:"create_time"`
// Contains the IPv6/IPv4 address and port that the Service will listen to,
// you can use these details to connect internally to a service.
ListenPorts map[string]map[string]int `json:"listen_ports"`
// The UUID of the security zone that the service is attached to.
SecurityZoneUUID string `json:"security_zone_uuid"`
// The UUID of the network that the service is attached to.
NetworkUUID string `json:"network_uuid"`
// The template used to create the service, you can find an available list at the /service_templates endpoint.
ServiceTemplateUUID string `json:"service_template_uuid"`
// The template category used to create the service.
ServiceTemplateCategory string `json:"service_template_category"`
// Total minutes the object has been running.
UsageInMinutes int `json:"usage_in_minutes"`
// **DEPRECATED** The price for the current period since the last bill.
CurrentPrice float64 `json:"current_price"`
// Defines the date and time of the last object change.
ChangeTime GSTime `json:"change_time"`
// Status indicates the status of the object.
Status string `json:"status"`
// The human-readable name of the object. It supports the full UTF-8 character set, with a maximum of 64 characters.
Name string `json:"name"`
// A list of service resource limits.
ResourceLimits []ResourceLimit `json:"resource_limits"`
// Contains the service parameters for the service.
Parameters map[string]interface{} `json:"parameters"`
}
// Credential represents credential used to access a PaaS service.
type Credential struct {
// The initial username to authenticate the Service.
Username string `json:"username"`
// The initial password to authenticate the Service.
Password string `json:"password"`
// The type of Service.
Type string `json:"type"`
// If the PaaS service is a k8s cluster, this field will be set.
KubeConfig string `json:"kubeconfig"`
// Expiration time of k8s credential.
ExpirationTime GSTime `json:"expiration_time"`
}
// PaaSServiceCreateRequest represents a request for creating a PaaS service.
type PaaSServiceCreateRequest struct {
// The human-readable name of the object. It supports the full UTF-8 character set, with a maximum of 64 characters.
Name string `json:"name"`
// The template used to create the service, you can find an available list at the /service_templates endpoint.
PaaSServiceTemplateUUID string `json:"paas_service_template_uuid"`
// The list of labels.
Labels []string `json:"labels,omitempty"`
// The UUID of the security zone that the service is attached to.
PaaSSecurityZoneUUID string `json:"paas_security_zone_uuid,omitempty"`
// The UUID of the network that the service is attached to.
NetworkUUID string `json:"network_uuid,omitempty"`
// A list of service resource limits.
ResourceLimits []ResourceLimit `json:"resource_limits,omitempty"`
// Contains the service parameters for the service.
Parameters map[string]interface{} `json:"parameters,omitempty"`
}
// ResourceLimit represents a resource limit.
// It is used to limit a specific computational resource in a PaaS service.
// e.g. it can be used to limit cpu count.
type ResourceLimit struct {
// The name of the resource you would like to cap.
Resource string `json:"resource"`
// The maximum number of the specific resource your service can use.
Limit int `json:"limit"`
}
// PaaSServiceCreateResponse represents a response for creating a PaaS service.
type PaaSServiceCreateResponse struct {
// UUID of the request.
RequestUUID string `json:"request_uuid"`
// Contains the IPv6 address and port that the Service will listen to, you can use these details to connect internally to a service.
ListenPorts map[string]map[string]int `json:"listen_ports"`
// The template used to create the service, you can find an available list at the /service_templates endpoint.
PaaSServiceUUID string `json:"paas_service_uuid"`
// Contains the initial setup credentials for Service.
Credentials []Credential `json:"credentials"`
// The UUID of an object is always unique, and refers to a specific object.
ObjectUUID string `json:"object_uuid"`
// A list of service resource limits.
ResourceLimits []ResourceLimit `json:"resource_limits"`
// Contains the service parameters for the service.
Parameters map[string]interface{} `json:"parameters"`
}
// PaaSTemplates holds a list of PaaS Templates.
type PaaSTemplates struct {
// Array of PaaS templates.
List map[string]PaaSTemplateProperties `json:"paas_service_templates"`
}
// PaaSTemplate represents a single PaaS Template.
type PaaSTemplate struct {
// Properties of a PaaS template.
Properties PaaSTemplateProperties `json:"paas_service_template"`
}
// PaaSTemplateProperties holds properties of a PaaS template.
// A PaaS template can be retrieved and used to create a new PaaS service via the PaaS template UUID.
type PaaSTemplateProperties struct {
// The human-readable name of the object. It supports the full UTF-8 character set, with a maximum of 64 characters.
Name string `json:"name"`
// The UUID of an object is always unique, and refers to a specific object.
ObjectUUID string `json:"object_uuid"`
// Describes the category of the service.
Category string `json:"category"`
// Product No.
ProductNo int `json:"product_no"`
// Discounted product number related to the service template.
DiscountProductNo int `json:"discount_product_no"`
// Time period (seconds) for which the discounted product number is valid.
DiscountPeriod int64 `json:"discount_period"`
// List of labels.
Labels []string `json:"labels"`
// The amount of concurrent connections for the service.
Resources Resource `json:"resources"`
// Status indicates the status of the object.
Status string `json:"status"`
// A definition of possible service template parameters (python-cerberus compatible).
ParametersSchema map[string]Parameter `json:"parameters_schema"`
// Describes the flavour of the service. E.g. kubernetes, redis-store, postgres, etc.
Flavour string `json:"flavour"`
// Describes the version of the service.
Version string `json:"version"`
// Describes the release of the service.
Release string `json:"release"`
// Describes the performance class of the service.
PerformanceClass string `json:"performance_class"`
// List of service template uuids to which a performance class update is allowed.
PerformanceClassUpdates []string `json:"performance_class_updates"`
// List of service template uuids to which an upgrade is allowed.
VersionUpgrades []string `json:"version_upgrades"`
// List of service template uuids to which a patch update is allowed.
PatchUpdates []string `json:"patch_updates"`
// Values of the autoscaling resources.
Autoscaling AutoscalingProperties `json:"autoscaling"`
// Is the service template active.
Active bool `json:"active"`
}
// AutoscalingProperties holds properties of resource autoscalings.
type AutoscalingProperties struct {
// Limit values of CPU core autoscaling.
Cores AutoscalingResourceProperties `json:"cores"`
// Limit values of storage autoscaling.
Storage AutoscalingResourceProperties `json:"storage"`
}
// AutoscalingResourceProperties holds properties (Min/Max values)
// of a resource autoscaling.
type AutoscalingResourceProperties struct {
// Min value of a resource autoscaling.
Min int `json:"min"`
// Max value of a resource autoscaling.
Max int `json:"max"`
}
// Parameter represents a parameter used in PaaS template.
// Each type of PaaS service has diffrent set of parameters.
// Use method `GetPaaSTemplateList` to get infomation about
// parameters of a PaaS template.
type Parameter struct {
// Is required.
Required bool `json:"required"`
// Is empty.
Empty bool `json:"empty"`
// Description of parameter.
Description string `json:"description"`
// Maximum.
Max int `json:"max"`
// Minimum.
Min int `json:"min"`
// Default value.
Default interface{} `json:"default"`
// Type of parameter.
Type string `json:"type"`
// Allowed values.
Allowed []string `json:"allowed"`
// Regex.
Regex string `json:"regex"`
// Immutable.
Immutable bool `json:"immutable"`
// Nested schema
Schema Schema `json:"schema"`
}
// Schema represents the structure of a nested parameter.
type Schema struct {
// Type of the schema.
Type string `json:"type"`
// If the type is "dict", this defines the schema of the dictionary fields.
Schema map[string]Parameter `json:"schema"`
}
// Resource represents the amount of concurrent connections for the service.
type Resource struct {
// The amount of memory required by the service, either RAM(MB) or SSD Storage(GB).
Memory int `json:"memory"`
// The amount of concurrent connections for the service.
Connections int `json:"connections"`
// Storage type (one of storage, storage_high, storage_insane).
StorageType string `json:"storage_type"`
}
// PaaSServiceUpdateRequest represetns a request for updating a PaaS service.
type PaaSServiceUpdateRequest struct {
// The human-readable name of the object. It supports the full UTF-8 character set, with a maximum of 64 characters.
// Leave it if you do not want to update the name.
Name string `json:"name,omitempty"`
// List of labels. Leave it if you do not want to update the list of labels.
Labels *[]string `json:"labels,omitempty"`
// Contains the service parameters for the service. Leave it if you do not want to update the parameters.
Parameters map[string]interface{} `json:"parameters,omitempty"`
// A list of service resource limits. Leave it if you do not want to update the resource limits.
ResourceLimits []ResourceLimit `json:"resource_limits,omitempty"`
// The template that you want to use in the service, you can find an available list at the /service_templates endpoint.
PaaSServiceTemplateUUID string `json:"service_template_uuid,omitempty"`
// The UUID of the network that the service is attached to.
NetworkUUID string `json:"network_uuid,omitempty"`
}
// PaaSServiceMetrics represents a list of metrics of a PaaS service.
type PaaSServiceMetrics struct {
// Array of a PaaS service's metrics.
List []PaaSMetricProperties `json:"paas_service_metrics"`
}
// PaaSServiceMetric represents a single metric of a PaaS service.
type PaaSServiceMetric struct {
// Properties of a PaaS service metric.
Properties PaaSMetricProperties `json:"paas_service_metric"`
}
// PaaSMetricProperties holds properties of a PaaS service metric.
type PaaSMetricProperties struct {
// Defines the begin of the time range.
BeginTime GSTime `json:"begin_time"`
// Defines the end of the time range.
EndTime GSTime `json:"end_time"`
// The UUID of an object is always unique, and refers to a specific object.
PaaSServiceUUID string `json:"paas_service_uuid"`
// CPU core usage.
CoreUsage PaaSMetricValue `json:"core_usage"`
// Storage usage.
StorageSize PaaSMetricValue `json:"storage_size"`
}
// PaaSMetricValue represents a PaaS metric value.
type PaaSMetricValue struct {
// Value.
Value float64 `json:"value"`
// Unit of the value.
Unit string `json:"unit"`
}
// PaaSSecurityZones holds a list of PaaS security zones.
type PaaSSecurityZones struct {
// Array of security zones.
List map[string]PaaSSecurityZoneProperties `json:"paas_security_zones"`
}
// PaaSSecurityZone represents a single PaaS security zone.
type PaaSSecurityZone struct {
// Properties of a security zone.
Properties PaaSSecurityZoneProperties `json:"paas_security_zone"`
}
// PaaSSecurityZoneProperties holds properties of a PaaS security zone.
// PaaS security zone can be retrieved and attached to PaaS services via security zone UUID,
// or attached to servers via the security zone's network UUID. To get the security zone's network UUID,
// check out methods `GetNetwork` and `GetNetworkList`, and retrieve the network relations.
type PaaSSecurityZoneProperties struct {
// The human-readable name of the location. It supports the full UTF-8 character set, with a maximum of 64 characters.
LocationCountry string `json:"location_country"`
// Defines the date and time the object was initially created.
CreateTime GSTime `json:"create_time"`
// Uses IATA airport code, which works as a location identifier.
LocationIata string `json:"location_iata"`
// The UUID of an object is always unique, and refers to a specific object.
ObjectUUID string `json:"object_uuid"`
// List of labels.
Labels []string `json:"labels"`
// The human-readable name of the location. It supports the full UTF-8 character set, with a maximum of 64 characters.
LocationName string `json:"location_name"`
// Status indicates the status of the object.
Status string `json:"status"`
// Helps to identify which data center an object belongs to.
LocationUUID string `json:"location_uuid"`
// Defines the date and time of the last object change.
ChangeTime GSTime `json:"change_time"`
// The human-readable name of the object. It supports the full UTF-8 character set, with a maximum of 64 characters.
Name string `json:"name"`
// object (PaaSRelationService).
Relation PaaSRelationService `json:"relations"`
}
// PaaSRelationService represents a relation between a PaaS security zone and PaaS services.
type PaaSRelationService struct {
// Array of object (ServiceObject).
Services []ServiceObject `json:"services"`
}
// ServiceObject represents the UUID of a PaaS service relating to a PaaS security zone.
type ServiceObject struct {
// The UUID of an object is always unique, and refers to a specific object.
ObjectUUID string `json:"object_uuid"`
}
// PaaSSecurityZoneCreateRequest represents a request for creating a PaaS security zone.
type PaaSSecurityZoneCreateRequest struct {
// The human-readable name of the object. It supports the full UTF-8 character set, with a maximum of 64 characters.
Name string `json:"name"`
}
// PaaSSecurityZoneCreateResponse represents a response for creating a PaaS security zone.
type PaaSSecurityZoneCreateResponse struct {
// UUID of the request.
RequestUUID string `json:"request_uuid"`
// UUID of the security zone being created.
PaaSSecurityZoneUUID string `json:"paas_security_zone_uuid"`
// The UUID of an object is always unique, and refers to a specific object.
ObjectUUID string `json:"object_uuid"`
}
// PaaSSecurityZoneUpdateRequest represents a request for updating a PaaS security zone.
type PaaSSecurityZoneUpdateRequest struct {
// The new name you give to the security zone. Leave it if you do not want to update the name.
Name string `json:"name,omitempty"`
// The UUID for the security zone you would like to update. Leave it if you do not want to update the security zone.
PaaSSecurityZoneUUID string `json:"paas_security_zone_uuid,omitempty"`
}
// GetPaaSServiceList returns a list of available PaaS Services.
//
// See: https://gridscale.io/en//api-documentation/index.html#operation/getPaasServices
func (c *Client) GetPaaSServiceList(ctx context.Context) ([]PaaSService, error) {
r := gsRequest{
uri: path.Join(apiPaaSBase, "services"),
method: http.MethodGet,
skipCheckingRequest: true,
}
var response PaaSServices
var paasServices []PaaSService
err := r.execute(ctx, *c, &response)
for _, properties := range response.List {
paasServices = append(paasServices, PaaSService{
Properties: properties,
})
}
return paasServices, err
}
// CreatePaaSService creates a new PaaS service.
//
// See: https://gridscale.io/en//api-documentation/index.html#operation/createPaasService
func (c *Client) CreatePaaSService(ctx context.Context, body PaaSServiceCreateRequest) (PaaSServiceCreateResponse, error) {
r := gsRequest{
uri: path.Join(apiPaaSBase, "services"),
method: http.MethodPost,
body: body,
}
var response PaaSServiceCreateResponse
err := r.execute(ctx, *c, &response)
return response, err
}
// GetPaaSService returns a specific PaaS Service based on given id.
//
// See: https://gridscale.io/en//api-documentation/index.html#operation/getPaasService
func (c *Client) GetPaaSService(ctx context.Context, id string) (PaaSService, error) {
if !isValidUUID(id) {
return PaaSService{}, errors.New("'id' is invalid")
}
r := gsRequest{
uri: path.Join(apiPaaSBase, "services", id),
method: http.MethodGet,
skipCheckingRequest: true,
}
var response PaaSService
err := r.execute(ctx, *c, &response)
return response, err
}
// UpdatePaaSService updates a specific PaaS Service based on a given id.
//
// See: https://gridscale.io/en//api-documentation/index.html#operation/updatePaasService
func (c *Client) UpdatePaaSService(ctx context.Context, id string, body PaaSServiceUpdateRequest) error {
if !isValidUUID(id) {
return errors.New("'id' is invalid")
}
r := gsRequest{
uri: path.Join(apiPaaSBase, "services", id),
method: http.MethodPatch,
body: body,
}
return r.execute(ctx, *c, nil)
}
// DeletePaaSService removes a PaaS service.
//
// See: https://gridscale.io/en//api-documentation/index.html#operation/deletePaasService
func (c *Client) DeletePaaSService(ctx context.Context, id string) error {
if !isValidUUID(id) {
return errors.New("'id' is invalid")
}
r := gsRequest{
uri: path.Join(apiPaaSBase, "services", id),
method: http.MethodDelete,
}
return r.execute(ctx, *c, nil)
}
// GetPaaSServiceMetrics get a specific PaaS Service's metrics based on a given id.
//
// See: https://gridscale.io/en//api-documentation/index.html#operation/getPaasServiceMetrics
func (c *Client) GetPaaSServiceMetrics(ctx context.Context, id string) ([]PaaSServiceMetric, error) {
if !isValidUUID(id) {
return nil, errors.New("'id' is invalid")
}
r := gsRequest{
uri: path.Join(apiPaaSBase, "services", id, "metrics"),
method: http.MethodGet,
skipCheckingRequest: true,
}
var response PaaSServiceMetrics
var metrics []PaaSServiceMetric
err := r.execute(ctx, *c, &response)
for _, properties := range response.List {
metrics = append(metrics, PaaSServiceMetric{
Properties: properties,
})
}
return metrics, err
}
// RenewK8sCredentials renews credentials for gridscale Kubernetes PaaS service templates.
// The credentials of a PaaS service will be renewed (if supported by service template).
//
// See:https://gridscale.io/en/api-documentation/index.html#operation/renewPaasServiceCredentials
func (c *Client) RenewK8sCredentials(ctx context.Context, id string) error {
if !isValidUUID(id) {
return errors.New("'id' is invalid")
}
r := gsRequest{
uri: path.Join(apiPaaSBase, "services", id, "renew_credentials"),
method: http.MethodPatch,
body: emptyStruct{},
}
return r.execute(ctx, *c, nil)
}
// GetPaaSTemplateList returns a list of PaaS service templates.
//
// See: https://gridscale.io/en//api-documentation/index.html#operation/getPaasServiceTemplates
func (c *Client) GetPaaSTemplateList(ctx context.Context) ([]PaaSTemplate, error) {
r := gsRequest{
uri: path.Join(apiPaaSBase, "service_templates"),
method: http.MethodGet,
skipCheckingRequest: true,
}
var response PaaSTemplates
var paasTemplates []PaaSTemplate
err := r.execute(ctx, *c, &response)
for _, properties := range response.List {
paasTemplate := PaaSTemplate{
Properties: properties,
}
paasTemplates = append(paasTemplates, paasTemplate)
}
return paasTemplates, err
}
// GetPaaSSecurityZoneList gets available security zones.
//
// See: https://gridscale.io/en//api-documentation/index.html#operation/getPaasSecurityZones
func (c *Client) GetPaaSSecurityZoneList(ctx context.Context) ([]PaaSSecurityZone, error) {
r := gsRequest{
uri: path.Join(apiPaaSBase, "security_zones"),
method: http.MethodGet,
skipCheckingRequest: true,
}
var response PaaSSecurityZones
var securityZones []PaaSSecurityZone
err := r.execute(ctx, *c, &response)
for _, properties := range response.List {
securityZones = append(securityZones, PaaSSecurityZone{
Properties: properties,
})
}
return securityZones, err
}
// CreatePaaSSecurityZone creates a new PaaS security zone.
//
// See: https://gridscale.io/en//api-documentation/index.html#operation/createPaasSecurityZone
func (c *Client) CreatePaaSSecurityZone(ctx context.Context, body PaaSSecurityZoneCreateRequest) (PaaSSecurityZoneCreateResponse, error) {
r := gsRequest{
uri: path.Join(apiPaaSBase, "security_zones"),
method: http.MethodPost,
body: body,
}
var response PaaSSecurityZoneCreateResponse
err := r.execute(ctx, *c, &response)
return response, err
}
// GetPaaSSecurityZone gets a specific PaaS Security Zone based on given id.
//
// See: https://gridscale.io/en//api-documentation/index.html#operation/getPaasSecurityZone
func (c *Client) GetPaaSSecurityZone(ctx context.Context, id string) (PaaSSecurityZone, error) {
if !isValidUUID(id) {
return PaaSSecurityZone{}, errors.New("'id' is invalid")
}
r := gsRequest{
uri: path.Join(apiPaaSBase, "security_zones", id),
method: http.MethodGet,
skipCheckingRequest: true,
}
var response PaaSSecurityZone
err := r.execute(ctx, *c, &response)
return response, err
}
// UpdatePaaSSecurityZone updates a specific PaaS security zone based on given id.
//
// See: https://gridscale.io/en//api-documentation/index.html#operation/updatePaasSecurityZone
func (c *Client) UpdatePaaSSecurityZone(ctx context.Context, id string, body PaaSSecurityZoneUpdateRequest) error {
if !isValidUUID(id) {
return errors.New("'id' is invalid")
}
r := gsRequest{
uri: path.Join(apiPaaSBase, "security_zones", id),
method: http.MethodPatch,
body: body,
}
return r.execute(ctx, *c, nil)
}
// DeletePaaSSecurityZone removes a specific PaaS Security Zone based on given id.
//
// See: https://gridscale.io/en//api-documentation/index.html#operation/deletePaasSecurityZone
func (c *Client) DeletePaaSSecurityZone(ctx context.Context, id string) error {
if !isValidUUID(id) {
return errors.New("'id' is invalid")
}
r := gsRequest{
uri: path.Join(apiPaaSBase, "security_zones", id),
method: http.MethodDelete,
}
return r.execute(ctx, *c, nil)
}
// GetDeletedPaaSServices returns a list of deleted PaaS Services.
//
// See: https://gridscale.io/en//api-documentation/index.html#operation/getDeletedPaasServices
func (c *Client) GetDeletedPaaSServices(ctx context.Context) ([]PaaSService, error) {
r := gsRequest{
uri: path.Join(apiDeletedBase, "paas_services"),
method: http.MethodGet,
skipCheckingRequest: true,
}
var response DeletedPaaSServices
var paasServices []PaaSService
err := r.execute(ctx, *c, &response)
for _, properties := range response.List {
paasServices = append(paasServices, PaaSService{
Properties: properties,
})
}
return paasServices, err
}