github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/elb/v3/listeners/requests.go (about) 1 package listeners 2 3 import ( 4 "github.com/chnsz/golangsdk" 5 ) 6 7 // Type Protocol represents a listener protocol. 8 type Protocol string 9 10 // Supported attributes for create/update operations. 11 const ( 12 ProtocolTCP Protocol = "TCP" 13 ProtocolUDP Protocol = "UDP" 14 ProtocolHTTP Protocol = "HTTP" 15 ProtocolHTTPS Protocol = "HTTPS" 16 ) 17 18 // CreateOptsBuilder allows extensions to add additional parameters to the 19 // Create request. 20 type CreateOptsBuilder interface { 21 ToListenerCreateMap() (map[string]interface{}, error) 22 } 23 24 // CreateOpts represents options for creating a listener. 25 type CreateOpts struct { 26 // The administrative state of the Listener. A valid value is true (UP) 27 // or false (DOWN). 28 AdminStateUp *bool `json:"admin_state_up,omitempty"` 29 30 // the ID of the CA certificate used by the listener. 31 CAContainerRef string `json:"client_ca_tls_container_ref,omitempty"` 32 33 // The ID of the default pool with which the Listener is associated. 34 DefaultPoolID string `json:"default_pool_id,omitempty"` 35 36 // A reference to a Barbican container of TLS secrets. 37 DefaultTlsContainerRef string `json:"default_tls_container_ref,omitempty"` 38 39 // Human-readable description for the Listener. 40 Description string `json:"description,omitempty"` 41 42 // whether to use HTTP2. 43 Http2Enable *bool `json:"http2_enable,omitempty"` 44 45 // The load balancer on which to provision this listener. 46 LoadbalancerID string `json:"loadbalancer_id" required:"true"` 47 48 // Human-readable name for the Listener. Does not have to be unique. 49 Name string `json:"name,omitempty"` 50 51 // ProjectID is only required if the caller has an admin role and wants 52 // to create a pool for another project. 53 ProjectID string `json:"project_id,omitempty"` 54 55 // The protocol - can either be TCP, HTTP or HTTPS. 56 Protocol Protocol `json:"protocol" required:"true"` 57 58 // The port on which to listen for client traffic. 59 ProtocolPort int `json:"protocol_port,omitempty"` 60 61 // A list of references to TLS secrets. 62 SniContainerRefs []string `json:"sni_container_refs,omitempty"` 63 64 // Specifies the security policy used by the listener. 65 TlsCiphersPolicy string `json:"tls_ciphers_policy,omitempty"` 66 67 // Whether enable member retry 68 EnableMemberRetry *bool `json:"enable_member_retry,omitempty"` 69 70 // Whether enable proxy protocol 71 ProxyProtocolEnable *bool `json:"proxy_protocol_enable,omitempty"` 72 73 // Whether enable ssl early data 74 SslEarlyDataEnable *bool `json:"ssl_early_data_enable,omitempty"` 75 76 // The keepalive timeout of the Listener. 77 KeepaliveTimeout *int `json:"keepalive_timeout,omitempty"` 78 79 // The client timeout of the Listener. 80 ClientTimeout *int `json:"client_timeout,omitempty"` 81 82 // The member timeout of the Listener. 83 MemberTimeout *int `json:"member_timeout,omitempty"` 84 85 // The ipgroup of the Listener. 86 IpGroup *IpGroup `json:"ipgroup,omitempty"` 87 88 // The http insert headers of the Listener. 89 InsertHeaders *InsertHeaders `json:"insert_headers,omitempty"` 90 91 // Transparent client ip enable 92 TransparentClientIP *bool `json:"transparent_client_ip_enable,omitempty"` 93 94 // Enhance L7policy enable 95 EnhanceL7policy *bool `json:"enhance_l7policy_enable,omitempty"` 96 97 // The port range of the current listener 98 PortRanges []PortRange `json:"port_ranges,omitempty"` 99 100 // ELB gzip enable 101 GzipEnable *bool `json:"gzip_enable,omitempty"` 102 103 // The QUIC configuration for the current listener 104 QuicConfig *QuicConfig `json:"quic_config,omitempty"` 105 106 // Security Policy ID 107 SecurityPolicyId string `json:"security_policy_id,omitempty"` 108 109 // The SNI certificates used by the listener. 110 SniMatchAlgo string `json:"sni_match_algo,omitempty"` 111 112 // Protection status 113 ProtectionStatus string `json:"protection_status,omitempty"` 114 115 // Protection reason 116 ProtectionReason string `json:"protection_reason,omitempty"` 117 } 118 119 type IpGroup struct { 120 IpGroupId string `json:"ipgroup_id" required:"true"` 121 Enable bool `json:"enable_ipgroup" required:"true"` 122 Type string `json:"type" required:"true"` 123 } 124 125 type PortRange struct { 126 StartPort int `json:"start_port,omitempty"` 127 EndPort int `json:"end_port,omitempty"` 128 } 129 130 type QuicConfig struct { 131 QuicListenerId string `json:"quic_listener_id" required:"true"` 132 EnableQuicUpgrade bool `json:"enable_quic_upgrade,omitempty"` 133 } 134 135 type InsertHeaders struct { 136 ForwardedELBIP *bool `json:"X-Forwarded-ELB-IP,omitempty"` 137 ForwardedPort *bool `json:"X-Forwarded-Port,omitempty"` 138 ForwardedForPort *bool `json:"X-Forwarded-For-Port,omitempty"` 139 ForwardedHost *bool `json:"X-Forwarded-Host,omitempty"` 140 ForwardedProto *bool `json:"X-Forwarded-Proto,omitempty"` 141 RealIP *bool `json:"X-Real-IP,omitempty"` 142 ForwardedELBID *bool `json:"X-Forwarded-ELB-ID,omitempty"` 143 ForwardedTLSCertificateID *bool `json:"X-Forwarded-TLS-Certificate-ID,omitempty"` 144 ForwardedTLSCipher *bool `json:"X-Forwarded-TLS-Cipher,omitempty"` 145 ForwardedTLSProtocol *bool `json:"X-Forwarded-TLS-Protocol,omitempty"` 146 } 147 148 // ToListenerCreateMap builds a request body from CreateOpts. 149 func (opts CreateOpts) ToListenerCreateMap() (map[string]interface{}, error) { 150 return golangsdk.BuildRequestBody(opts, "listener") 151 } 152 153 // Create is an operation which provisions a new Listeners based on the 154 // configuration defined in the CreateOpts struct. Once the request is 155 // validated and progress has started on the provisioning process, a 156 // CreateResult will be returned. 157 // 158 // Users with an admin role can create Listeners on behalf of other tenants by 159 // specifying a TenantID attribute different than their own. 160 func Create(c *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { 161 b, err := opts.ToListenerCreateMap() 162 if err != nil { 163 r.Err = err 164 return 165 } 166 _, r.Err = c.Post(rootURL(c), b, &r.Body, nil) 167 return 168 } 169 170 // Get retrieves a particular Listeners based on its unique ID. 171 func Get(c *golangsdk.ServiceClient, id string) (r GetResult) { 172 _, r.Err = c.Get(resourceURL(c, id), &r.Body, nil) 173 return 174 } 175 176 // UpdateOptsBuilder allows extensions to add additional parameters to the 177 // Update request. 178 type UpdateOptsBuilder interface { 179 ToListenerUpdateMap() (map[string]interface{}, error) 180 } 181 182 type IpGroupUpdate struct { 183 IpGroupId string `json:"ipgroup_id,omitempty"` 184 Type string `json:"type,omitempty"` 185 } 186 187 // UpdateOpts represents options for updating a Listener. 188 type UpdateOpts struct { 189 // Human-readable name for the Listener. Does not have to be unique. 190 Name string `json:"name,omitempty"` 191 192 // Human-readable description for the Listener. 193 Description *string `json:"description,omitempty"` 194 195 // The administrative state of the Listener. A valid value is true (UP) 196 // or false (DOWN). 197 AdminStateUp *bool `json:"admin_state_up,omitempty"` 198 199 // the ID of the CA certificate used by the listener. 200 CAContainerRef *string `json:"client_ca_tls_container_ref,omitempty"` 201 202 // The ID of the default pool with which the Listener is associated. 203 DefaultPoolID string `json:"default_pool_id,omitempty"` 204 205 // A reference to a container of TLS secrets. 206 DefaultTlsContainerRef *string `json:"default_tls_container_ref,omitempty"` 207 208 // whether to use HTTP2. 209 Http2Enable *bool `json:"http2_enable,omitempty"` 210 211 // A list of references to TLS secrets. 212 SniContainerRefs *[]string `json:"sni_container_refs,omitempty"` 213 214 // Specifies the security policy used by the listener. 215 TlsCiphersPolicy *string `json:"tls_ciphers_policy,omitempty"` 216 217 // Whether enable member retry 218 EnableMemberRetry *bool `json:"enable_member_retry,omitempty"` 219 220 // Whether enable proxy protocol 221 ProxyProtocolEnable *bool `json:"proxy_protocol_enable,omitempty"` 222 223 // Whether enable ssl early data 224 SslEarlyDataEnable *bool `json:"ssl_early_data_enable,omitempty"` 225 226 // The keepalive timeout of the Listener. 227 KeepaliveTimeout *int `json:"keepalive_timeout,omitempty"` 228 229 // The client timeout of the Listener. 230 ClientTimeout *int `json:"client_timeout,omitempty"` 231 232 // The member timeout of the Listener. 233 MemberTimeout *int `json:"member_timeout,omitempty"` 234 235 // The ipgroup of the Listener. 236 IpGroup *IpGroupUpdate `json:"ipgroup,omitempty"` 237 238 // The http insert headers of the Listener. 239 InsertHeaders *InsertHeaders `json:"insert_headers,omitempty"` 240 241 // Transparent client ip enable 242 TransparentClientIP *bool `json:"transparent_client_ip_enable,omitempty"` 243 244 // Enhance L7policy enable 245 EnhanceL7policy *bool `json:"enhance_l7policy_enable,omitempty"` 246 247 // ELB gzip enable 248 GzipEnable *bool `json:"gzip_enable,omitempty"` 249 250 // The QUIC configuration for the current listener 251 QuicConfig *QuicConfig `json:"quic_config"` 252 253 // Security Policy ID 254 SecurityPolicyId *string `json:"security_policy_id"` 255 256 // The SNI certificates used by the listener. 257 SniMatchAlgo string `json:"sni_match_algo,omitempty"` 258 259 // Update protection status 260 ProtectionStatus string `json:"protection_status,omitempty"` 261 262 // Update protection reason 263 ProtectionReason *string `json:"protection_reason,omitempty"` 264 } 265 266 // ToListenerUpdateMap builds a request body from UpdateOpts. 267 func (opts UpdateOpts) ToListenerUpdateMap() (map[string]interface{}, error) { 268 return golangsdk.BuildRequestBody(opts, "listener") 269 } 270 271 // Update is an operation which modifies the attributes of the specified 272 // Listener. 273 func Update(c *golangsdk.ServiceClient, id string, opts UpdateOpts) (r UpdateResult) { 274 b, err := opts.ToListenerUpdateMap() 275 if err != nil { 276 r.Err = err 277 return 278 } 279 _, r.Err = c.Put(resourceURL(c, id), b, &r.Body, &golangsdk.RequestOpts{ 280 OkCodes: []int{200, 202}, 281 }) 282 return 283 } 284 285 // Delete will permanently delete a particular Listeners based on its unique ID. 286 func Delete(c *golangsdk.ServiceClient, id string) (r DeleteResult) { 287 _, r.Err = c.Delete(resourceURL(c, id), nil) 288 return 289 } 290 291 // ForceDelete will delete the listener and the sub resource(listener and l7 policies, unbind associated pools) 292 func ForceDelete(c *golangsdk.ServiceClient, id string) (r DeleteResult) { 293 _, r.Err = c.Delete(resourceForceDeleteURL(c, id), nil) 294 return 295 }