-
Notifications
You must be signed in to change notification settings - Fork 7
/
requests.go
110 lines (94 loc) · 3.33 KB
/
requests.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
package securities
import "github.com/huaweicloud/terraform-provider-hcs/huaweicloudstack/sdk/huaweicloud"
// SSLOpts is a struct which will be used to config the SSL (Secure Sockets Layer).
type SSLOpts struct {
// Specifies whether to enable SSL.
// true: SSL is enabled.
// false: SSL is disabled.
SSLEnable *bool `json:"ssl_option" required:"true"`
}
// SSLOptsBuilder is an interface which to support request body build of
// the ssl configuration of the specifies database.
type SSLOptsBuilder interface {
ToSSLOptsMap() (map[string]interface{}, error)
}
// ToSSLOptsMap is a method which to build a request body by the SSLOpts.
func (opts SSLOpts) ToSSLOptsMap() (map[string]interface{}, error) {
b, err := golangsdk.BuildRequestBody(opts, "")
if err != nil {
return nil, err
}
return b, nil
}
// UpdateSSL is a method to enable or disable the SSL.
func UpdateSSL(client *golangsdk.ServiceClient, instanceId string, opts SSLOptsBuilder) (r SSLUpdateResult) {
b, err := opts.ToSSLOptsMap()
if err != nil {
r.Err = err
return
}
_, r.Err = client.Put(rootURL(client, instanceId, "ssl"), b, &r.Body, &golangsdk.RequestOpts{
OkCodes: []int{200},
})
return
}
// PortOpts is a struct which will be used to config the secure sockets layer.
type PortOpts struct {
// Specifies the port number.
// The MySQL port number ranges from 1024 to 65535, excluding 12017 and 33071.
Port int `json:"port" required:"true"`
}
// PortOptsBuilder is an interface which to support request body build of
// the port configuration of the specifies database.
type PortOptsBuilder interface {
ToPortOptsMap() (map[string]interface{}, error)
}
// ToPortOptsMap is a method which to build a request body by the DBPortOpts.
func (opts PortOpts) ToPortOptsMap() (map[string]interface{}, error) {
b, err := golangsdk.BuildRequestBody(opts, "")
if err != nil {
return nil, err
}
return b, nil
}
// UpdatePort is a method to update the port of the database.
func UpdatePort(client *golangsdk.ServiceClient, instanceId string, opts PortOptsBuilder) (r commonResult) {
b, err := opts.ToPortOptsMap()
if err != nil {
r.Err = err
return
}
_, r.Err = client.Put(rootURL(client, instanceId, "port"), b, &r.Body, &golangsdk.RequestOpts{
OkCodes: []int{200},
})
return
}
// SecGroupOpts is a struct which will be used to update the specifies security group.
type SecGroupOpts struct {
// Specifies the security group ID.
SecurityGroupId string `json:"security_group_id" required:"true"`
}
// SecGroupOptsBuilder is an interface which to support request body build of the security group updation.
type SecGroupOptsBuilder interface {
ToSecGroupOptsMap() (map[string]interface{}, error)
}
// ToSecGroupOptsMap is a method which to build a request body by the SecGroupOpts.
func (opts SecGroupOpts) ToSecGroupOptsMap() (map[string]interface{}, error) {
b, err := golangsdk.BuildRequestBody(opts, "")
if err != nil {
return nil, err
}
return b, nil
}
// UpdateSecGroup is a method to update the security group which the database belongs.
func UpdateSecGroup(client *golangsdk.ServiceClient, instanceId string, opts SecGroupOptsBuilder) (r commonResult) {
b, err := opts.ToSecGroupOptsMap()
if err != nil {
r.Err = err
return
}
_, r.Err = client.Put(rootURL(client, instanceId, "security-group"), b, &r.Body, &golangsdk.RequestOpts{
OkCodes: []int{200},
})
return
}