github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/waf/v1/domains/requests.go (about) 1 package domains 2 3 import ( 4 "github.com/huaweicloud/golangsdk" 5 ) 6 7 var RequestOpts golangsdk.RequestOpts = golangsdk.RequestOpts{ 8 MoreHeaders: map[string]string{"Content-Type": "application/json", "X-Language": "en-us"}, 9 } 10 11 // CreateOptsBuilder allows extensions to add additional parameters to the 12 // Create request. 13 type CreateOptsBuilder interface { 14 ToDomainCreateMap() (map[string]interface{}, error) 15 } 16 17 // CreateOpts contains all the values needed to create a new backup. 18 type CreateOpts struct { 19 // Domain name 20 HostName string `json:"hostname" required:"true"` 21 // The original server information 22 Servers []ServerOpts `json:"server" required:"true"` 23 // Whether proxy is configured 24 Proxy *bool `json:"proxy" required:"true"` 25 // Certificate ID 26 CertificateId string `json:"certificate_id,omitempty"` 27 // The type of the source IP header 28 SipHeaderName string `json:"sip_header_name,omitempty"` 29 // The HTTP request header for identifying the real source IP. 30 SipHeaderList []string `json:"sip_header_list,omitempty"` 31 } 32 33 // ServerOpts contains the origin server information. 34 type ServerOpts struct { 35 // Protocol type of the client 36 ClientProtocol string `json:"client_protocol" required:"true"` 37 // Protocol used by WAF to forward client requests to the server 38 ServerProtocol string `json:"server_protocol" required:"true"` 39 // IP address or domain name of the web server that the client accesses. 40 Address string `json:"address" required:"true"` 41 // Port number used by the web server, the value ranges from 0 to 65535. 42 Port string `json:"port" required:"true"` 43 } 44 45 // ToDomainCreateMap builds a create request body from CreateOpts. 46 func (opts CreateOpts) ToDomainCreateMap() (map[string]interface{}, error) { 47 return golangsdk.BuildRequestBody(opts, "") 48 } 49 50 // Create will create a new Domain based on the values in CreateOpts. 51 func Create(c *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { 52 b, err := opts.ToDomainCreateMap() 53 if err != nil { 54 r.Err = err 55 return 56 } 57 reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}} 58 _, r.Err = c.Post(rootURL(c), b, &r.Body, reqOpt) 59 return 60 } 61 62 // UpdateOptsBuilder allows extensions to add additional parameters to the 63 // Update request. 64 type UpdateOptsBuilder interface { 65 ToDomainUpdateMap() (map[string]interface{}, error) 66 } 67 68 // UpdateOpts contains all the values needed to update a Domain. 69 type UpdateOpts struct { 70 // Certificate ID 71 CertificateId string `json:"certificate_id,omitempty"` 72 // The original server information 73 Servers []ServerOpts `json:"server,omitempty"` 74 // Whether proxy is configured 75 Proxy *bool `json:"proxy,omitempty"` 76 // The type of the source IP header 77 SipHeaderName string `json:"sip_header_name,omitempty"` 78 // The HTTP request header for identifying the real source IP. 79 SipHeaderList []string `json:"sip_header_list,omitempty"` 80 } 81 82 // ToDomainUpdateMap builds a update request body from UpdateOpts. 83 func (opts UpdateOpts) ToDomainUpdateMap() (map[string]interface{}, error) { 84 return golangsdk.BuildRequestBody(opts, "") 85 } 86 87 // Update accepts a UpdateOpts struct and uses the values to update a Domain.The response code from api is 200 88 func Update(c *golangsdk.ServiceClient, domainID string, opts UpdateOptsBuilder) (r UpdateResult) { 89 b, err := opts.ToDomainUpdateMap() 90 if err != nil { 91 r.Err = err 92 return 93 } 94 reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}} 95 _, r.Err = c.Put(resourceURL(c, domainID), b, nil, reqOpt) 96 return 97 } 98 99 // Get retrieves a particular Domain based on its unique ID. 100 func Get(c *golangsdk.ServiceClient, id string) (r GetResult) { 101 reqOpt := &golangsdk.RequestOpts{ 102 OkCodes: []int{200}, 103 MoreHeaders: RequestOpts.MoreHeaders, 104 } 105 _, r.Err = c.Get(resourceURL(c, id), &r.Body, reqOpt) 106 return 107 } 108 109 // DeleteOptsBuilder allows extensions to add additional parameters to the 110 // delete request. 111 type DeleteOptsBuilder interface { 112 ToDeleteQuery() (string, error) 113 } 114 115 // DeleteOpts contains all the values needed to delete a domain. 116 type DeleteOpts struct { 117 // KeepPolicy specifies whether to retain the policy when deleting a domain name 118 // the default value is false 119 KeepPolicy bool `q:"keepPolicy"` 120 } 121 122 // ToDeleteQuery builds a delete request body from DeleteOpts. 123 func (opts DeleteOpts) ToDeleteQuery() (string, error) { 124 q, err := golangsdk.BuildQueryString(opts) 125 return q.String(), err 126 } 127 128 // Delete will permanently delete a particular Domain based on its unique ID. 129 func Delete(c *golangsdk.ServiceClient, id string, opts DeleteOptsBuilder) (r DeleteResult) { 130 url := resourceURL(c, id) 131 if opts != nil { 132 var query string 133 query, r.Err = opts.ToDeleteQuery() 134 if r.Err != nil { 135 return 136 } 137 url += query 138 } 139 140 reqOpt := &golangsdk.RequestOpts{ 141 OkCodes: []int{204}, 142 MoreHeaders: RequestOpts.MoreHeaders, 143 } 144 _, r.Err = c.Delete(url, reqOpt) 145 return 146 }