github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/waf/v1/domains/requests.go (about) 1 package domains 2 3 import ( 4 "github.com/opentelekomcloud/gophertelekomcloud" 5 "github.com/opentelekomcloud/gophertelekomcloud/openstack" 6 ) 7 8 // CreateOptsBuilder allows extensions to add additional parameters to the 9 // Create request. 10 type CreateOptsBuilder interface { 11 ToDomainCreateMap() (map[string]interface{}, error) 12 } 13 14 // CreateOpts contains all the values needed to create a new backup. 15 type CreateOpts struct { 16 // Domain name 17 HostName string `json:"hostname" required:"true"` 18 // Certificate ID 19 CertificateId string `json:"certificate_id,omitempty"` 20 // The original server information 21 Server []ServerOpts `json:"server" required:"true"` 22 // Whether proxy is configured 23 Proxy *bool `json:"proxy" required:"true"` 24 // TLS version 25 TLS string `json:"tls,omitempty"` 26 // Cipher suite version 27 Cipher string `json:"cipher,omitempty"` 28 // The type of the source IP header 29 SipHeaderName string `json:"sip_header_name,omitempty"` 30 // The HTTP request header for identifying the real source IP. 31 SipHeaderList []string `json:"sip_header_list,omitempty"` 32 } 33 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 42 Port int `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 Server []ServerOpts `json:"server,omitempty"` 74 // Whether proxy is configured 75 Proxy *bool `json:"proxy,omitempty"` 76 // TLS version 77 TLS string `json:"tls,omitempty"` 78 // Cipher suite version 79 Cipher string `json:"cipher,omitempty"` 80 // The type of the source IP header 81 SipHeaderName string `json:"sip_header_name,omitempty"` 82 // The HTTP request header for identifying the real source IP. 83 SipHeaderList []string `json:"sip_header_list,omitempty"` 84 // Alarm page configuration 85 BlockPage *BlockPage `json:"block_page,omitempty"` 86 } 87 88 type BlockPage struct { 89 Template string `json:"template" required:"true"` 90 CustomPage *CustomPage `json:"custom_page,omitempty"` 91 RedirectUrl string `json:"redirect_url,omitempty"` 92 } 93 94 type CustomPage struct { 95 StatusCode string `json:"status_code" required:"true"` 96 ContentType string `json:"content_type" required:"true"` 97 Content string `json:"content" required:"true"` 98 } 99 100 // ToDomainUpdateMap builds a update request body from UpdateOpts. 101 func (opts UpdateOpts) ToDomainUpdateMap() (map[string]interface{}, error) { 102 return golangsdk.BuildRequestBody(opts, "") 103 } 104 105 // Update accepts a UpdateOpts struct and uses the values to update a Domain.The response code from api is 200 106 func Update(c *golangsdk.ServiceClient, domainID string, opts UpdateOptsBuilder) (r UpdateResult) { 107 b, err := opts.ToDomainUpdateMap() 108 if err != nil { 109 r.Err = err 110 return 111 } 112 _, r.Err = c.Put(resourceURL(c, domainID), b, &r.Body, &golangsdk.RequestOpts{ 113 OkCodes: []int{200}, 114 }) 115 return 116 } 117 118 // Get retrieves a particular Domain based on its unique ID. 119 func Get(c *golangsdk.ServiceClient, id string) (r GetResult) { 120 _, r.Err = c.Get(resourceURL(c, id), &r.Body, openstack.StdRequestOpts()) 121 return 122 } 123 124 // Delete will permanently delete a particular Domain based on its unique ID. 125 func Delete(c *golangsdk.ServiceClient, id string) (r DeleteResult) { 126 reqOpt := &golangsdk.RequestOpts{OkCodes: []int{204}, 127 MoreHeaders: openstack.StdRequestOpts().MoreHeaders} 128 _, r.Err = c.Delete(resourceURL(c, id), reqOpt) 129 return 130 }