github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/elb/v2/listeners/requests.go (about) 1 package listeners 2 3 import ( 4 "github.com/chnsz/golangsdk" 5 "github.com/chnsz/golangsdk/pagination" 6 ) 7 8 // Type Protocol represents a listener protocol. 9 type Protocol string 10 11 // Supported attributes for create/update operations. 12 const ( 13 ProtocolTCP Protocol = "TCP" 14 ProtocolHTTP Protocol = "HTTP" 15 ProtocolHTTPS Protocol = "HTTPS" 16 ) 17 18 // ListOptsBuilder allows extensions to add additional parameters to the 19 // List request. 20 type ListOptsBuilder interface { 21 ToListenerListQuery() (string, error) 22 } 23 24 // ListOpts allows the filtering and sorting of paginated collections through 25 // the API. Filtering is achieved by passing in struct field values that map to 26 // the floating IP attributes you want to see returned. SortKey allows you to 27 // sort by a particular listener attribute. SortDir sets the direction, and is 28 // either `asc' or `desc'. Marker and Limit are used for pagination. 29 type ListOpts struct { 30 ID string `q:"id"` 31 Name string `q:"name"` 32 Description string `q:"description"` 33 AdminStateUp *bool `q:"admin_state_up"` 34 TenantID string `q:"tenant_id"` 35 ProjectID string `q:"project_id"` 36 LoadbalancerID string `q:"loadbalancer_id"` 37 DefaultPoolID string `q:"default_pool_id"` 38 Protocol string `q:"protocol"` 39 ProtocolPort int `q:"protocol_port"` 40 ConnectionLimit int `q:"connection_limit"` 41 Http2Enable *bool `q:"http2_enable"` 42 DefaultTlsContainerRef string `q:"default_tls_container_ref"` 43 DefaultCaTlsContainerRef string `q:"default_ca_tls_container_ref"` 44 TlsCiphersPolicy string `q:"tls_ciphers_policy"` 45 EnterpriseProjectID string `q:"enterprise_project_id"` 46 Limit int `q:"limit"` 47 Marker string `q:"marker"` 48 PageReverse *bool `q:"page_reverse"` 49 SortKey string `q:"sort_key"` 50 SortDir string `q:"sort_dir"` 51 } 52 53 // ToListenerListQuery formats a ListOpts into a query string. 54 func (opts ListOpts) ToListenerListQuery() (string, error) { 55 q, err := golangsdk.BuildQueryString(opts) 56 return q.String(), err 57 } 58 59 // List returns a Pager which allows you to iterate over a collection of 60 // listeners. It accepts a ListOpts struct, which allows you to filter and sort 61 // the returned collection for greater efficiency. 62 // 63 // Default policy settings return only those listeners that are owned by the 64 // tenant who submits the request, unless an admin user submits the request. 65 func List(c *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager { 66 url := rootURL(c) 67 if opts != nil { 68 query, err := opts.ToListenerListQuery() 69 if err != nil { 70 return pagination.Pager{Err: err} 71 } 72 url += query 73 } 74 return pagination.NewPager(c, url, func(r pagination.PageResult) pagination.Page { 75 return ListenerPage{pagination.LinkedPageBase{PageResult: r}} 76 }) 77 } 78 79 // CreateOptsBuilder allows extensions to add additional parameters to the 80 // Create request. 81 type CreateOptsBuilder interface { 82 ToListenerCreateMap() (map[string]interface{}, error) 83 } 84 85 // CreateOpts represents options for creating a listener. 86 type CreateOpts struct { 87 // TenantID is only required if the caller has an admin role and wants 88 // to create a pool for another project. 89 TenantID string `json:"tenant_id,omitempty"` 90 91 // ProjectID is only required if the caller has an admin role and wants 92 // to create a pool for another project. 93 ProjectID string `json:"project_id,omitempty"` 94 95 // Human-readable name for the Listener. Does not have to be unique. 96 Name string `json:"name,omitempty"` 97 98 // Human-readable description for the Listener. 99 Description string `json:"description,omitempty"` 100 101 // The protocol - can either be TCP, HTTP or HTTPS. 102 Protocol Protocol `json:"protocol" required:"true"` 103 104 // The port on which to listen for client traffic. 105 ProtocolPort int `json:"protocol_port" required:"true"` 106 107 // The load balancer on which to provision this listener. 108 LoadbalancerID string `json:"loadbalancer_id" required:"true"` 109 110 // The maximum number of connections allowed for the Listener. 111 ConnLimit *int `json:"connection_limit,omitempty"` 112 113 // The administrative state of the Listener. A valid value is true (UP) 114 // or false (DOWN). 115 AdminStateUp *bool `json:"admin_state_up,omitempty"` 116 117 // whether to use HTTP2. 118 Http2Enable *bool `json:"http2_enable,omitempty"` 119 120 // The ID of the default pool with which the Listener is associated. 121 DefaultPoolID string `json:"default_pool_id,omitempty"` 122 123 // A reference to a Barbican container of TLS secrets. 124 DefaultTlsContainerRef string `json:"default_tls_container_ref,omitempty"` 125 126 // the ID of the CA certificate used by the listener. 127 CAContainerRef string `json:"client_ca_tls_container_ref,omitempty"` 128 129 // A list of references to TLS secrets. 130 SniContainerRefs []string `json:"sni_container_refs,omitempty"` 131 132 // Specifies the security policy used by the listener. 133 TlsCiphersPolicy string `json:"tls_ciphers_policy,omitempty"` 134 } 135 136 // ToListenerCreateMap builds a request body from CreateOpts. 137 func (opts CreateOpts) ToListenerCreateMap() (map[string]interface{}, error) { 138 return golangsdk.BuildRequestBody(opts, "listener") 139 } 140 141 // Create is an operation which provisions a new Listeners based on the 142 // configuration defined in the CreateOpts struct. Once the request is 143 // validated and progress has started on the provisioning process, a 144 // CreateResult will be returned. 145 // 146 // Users with an admin role can create Listeners on behalf of other tenants by 147 // specifying a TenantID attribute different than their own. 148 func Create(c *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { 149 b, err := opts.ToListenerCreateMap() 150 if err != nil { 151 r.Err = err 152 return 153 } 154 _, r.Err = c.Post(rootURL(c), b, &r.Body, nil) 155 return 156 } 157 158 // Get retrieves a particular Listeners based on its unique ID. 159 func Get(c *golangsdk.ServiceClient, id string) (r GetResult) { 160 _, r.Err = c.Get(resourceURL(c, id), &r.Body, nil) 161 return 162 } 163 164 // UpdateOptsBuilder allows extensions to add additional parameters to the 165 // Update request. 166 type UpdateOptsBuilder interface { 167 ToListenerUpdateMap() (map[string]interface{}, error) 168 } 169 170 // UpdateOpts represents options for updating a Listener. 171 type UpdateOpts struct { 172 // Human-readable name for the Listener. Does not have to be unique. 173 Name string `json:"name,omitempty"` 174 175 // Human-readable description for the Listener. 176 Description *string `json:"description,omitempty"` 177 178 // The maximum number of connections allowed for the Listener. 179 ConnLimit *int `json:"connection_limit,omitempty"` 180 181 // whether to use HTTP2. 182 Http2Enable *bool `json:"http2_enable,omitempty"` 183 184 // Specifies the ID of the associated backend server group. 185 DefaultPoolID string `json:"default_pool_id,omitempty"` 186 187 // A reference to a Barbican container of TLS secrets. 188 DefaultTlsContainerRef string `json:"default_tls_container_ref,omitempty"` 189 190 // A list of references to TLS secrets. 191 SniContainerRefs []string `json:"sni_container_refs,omitempty"` 192 193 // the ID of the CA certificate used by the listener. 194 CAContainerRef string `json:"client_ca_tls_container_ref,omitempty"` 195 196 // Specifies the security policy used by the listener. 197 TlsCiphersPolicy string `json:"tls_ciphers_policy,omitempty"` 198 199 // The administrative state of the Listener. A valid value is true (UP) 200 // or false (DOWN). 201 AdminStateUp *bool `json:"admin_state_up,omitempty"` 202 } 203 204 // ToListenerUpdateMap builds a request body from UpdateOpts. 205 func (opts UpdateOpts) ToListenerUpdateMap() (map[string]interface{}, error) { 206 return golangsdk.BuildRequestBody(opts, "listener") 207 } 208 209 // Update is an operation which modifies the attributes of the specified 210 // Listener. 211 func Update(c *golangsdk.ServiceClient, id string, opts UpdateOpts) (r UpdateResult) { 212 b, err := opts.ToListenerUpdateMap() 213 if err != nil { 214 r.Err = err 215 return 216 } 217 _, r.Err = c.Put(resourceURL(c, id), b, &r.Body, &golangsdk.RequestOpts{ 218 OkCodes: []int{200, 202}, 219 }) 220 return 221 } 222 223 // Delete will permanently delete a particular Listeners based on its unique ID. 224 func Delete(c *golangsdk.ServiceClient, id string) (r DeleteResult) { 225 _, r.Err = c.Delete(resourceURL(c, id), nil) 226 return 227 }