github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/rds/v3/securities/requests.go (about)

     1  package securities
     2  
     3  import "github.com/huaweicloud/golangsdk"
     4  
     5  // SSLOpts is a struct which will be used to config the SSL (Secure Sockets Layer).
     6  type SSLOpts struct {
     7  	// Specifies whether to enable SSL.
     8  	//   true: SSL is enabled.
     9  	//   false: SSL is disabled.
    10  	SSLEnable *bool `json:"ssl_option" required:"true"`
    11  }
    12  
    13  // SSLOptsBuilder is an interface which to support request body build of
    14  // the ssl configuration of the specifies database.
    15  type SSLOptsBuilder interface {
    16  	ToSSLOptsMap() (map[string]interface{}, error)
    17  }
    18  
    19  // ToSSLOptsMap is a method which to build a request body by the SSLOpts.
    20  func (opts SSLOpts) ToSSLOptsMap() (map[string]interface{}, error) {
    21  	b, err := golangsdk.BuildRequestBody(opts, "")
    22  	if err != nil {
    23  		return nil, err
    24  	}
    25  	return b, nil
    26  }
    27  
    28  // UpdateSSL is a method to enable or disable the SSL.
    29  func UpdateSSL(client *golangsdk.ServiceClient, instanceId string, opts SSLOptsBuilder) (r SSLUpdateResult) {
    30  	b, err := opts.ToSSLOptsMap()
    31  	if err != nil {
    32  		r.Err = err
    33  		return
    34  	}
    35  	_, r.Err = client.Put(rootURL(client, instanceId, "ssl"), b, &r.Body, &golangsdk.RequestOpts{
    36  		OkCodes: []int{200},
    37  	})
    38  
    39  	return
    40  }
    41  
    42  // PortOpts is a struct which will be used to config the secure sockets layer.
    43  type PortOpts struct {
    44  	// Specifies the port number.
    45  	// The MySQL port number ranges from 1024 to 65535, excluding 12017 and 33071.
    46  	Port int `json:"port" required:"true"`
    47  }
    48  
    49  // PortOptsBuilder is an interface which to support request body build of
    50  // the port configuration of the specifies database.
    51  type PortOptsBuilder interface {
    52  	ToPortOptsMap() (map[string]interface{}, error)
    53  }
    54  
    55  // ToPortOptsMap is a method which to build a request body by the DBPortOpts.
    56  func (opts PortOpts) ToPortOptsMap() (map[string]interface{}, error) {
    57  	b, err := golangsdk.BuildRequestBody(opts, "")
    58  	if err != nil {
    59  		return nil, err
    60  	}
    61  	return b, nil
    62  }
    63  
    64  // UpdatePort is a method to update the port of the database.
    65  func UpdatePort(client *golangsdk.ServiceClient, instanceId string, opts PortOptsBuilder) (r commonResult) {
    66  	b, err := opts.ToPortOptsMap()
    67  	if err != nil {
    68  		r.Err = err
    69  		return
    70  	}
    71  	_, r.Err = client.Put(rootURL(client, instanceId, "port"), b, &r.Body, &golangsdk.RequestOpts{
    72  		OkCodes: []int{200},
    73  	})
    74  
    75  	return
    76  }
    77  
    78  // SecGroupOpts is a struct which will be used to update the specifies security group.
    79  type SecGroupOpts struct {
    80  	// Specifies the security group ID.
    81  	SecurityGroupId string `json:"security_group_id" required:"true"`
    82  }
    83  
    84  // SecGroupOptsBuilder is an interface which to support request body build of the security group updation.
    85  type SecGroupOptsBuilder interface {
    86  	ToSecGroupOptsMap() (map[string]interface{}, error)
    87  }
    88  
    89  // ToSecGroupOptsMap is a method which to build a request body by the SecGroupOpts.
    90  func (opts SecGroupOpts) ToSecGroupOptsMap() (map[string]interface{}, error) {
    91  	b, err := golangsdk.BuildRequestBody(opts, "")
    92  	if err != nil {
    93  		return nil, err
    94  	}
    95  	return b, nil
    96  }
    97  
    98  // UpdateSecGroup is a method to update the security group which the database belongs.
    99  func UpdateSecGroup(client *golangsdk.ServiceClient, instanceId string, opts SecGroupOptsBuilder) (r commonResult) {
   100  	b, err := opts.ToSecGroupOptsMap()
   101  	if err != nil {
   102  		r.Err = err
   103  		return
   104  	}
   105  	_, r.Err = client.Put(rootURL(client, instanceId, "security-group"), b, &r.Body, &golangsdk.RequestOpts{
   106  		OkCodes: []int{200},
   107  	})
   108  
   109  	return
   110  }