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

     1  package listeners
     2  
     3  import (
     4  	"github.com/huaweicloud/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" required:"true"`
    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  	// The keepalive timeout of the Listener.
    71  	KeepaliveTimeout *int `json:"keepalive_timeout,omitempty"`
    72  
    73  	// The client timeout of the Listener.
    74  	ClientTimeout *int `json:"client_timeout,omitempty"`
    75  
    76  	// The member timeout of the Listener.
    77  	MemberTimeout *int `json:"member_timeout,omitempty"`
    78  
    79  	// The ipgroup of the Listener.
    80  	IpGroup *IpGroup `json:"ipgroup,omitempty"`
    81  
    82  	// The http insert headers of the Listener.
    83  	InsertHeaders *InsertHeaders `json:"insert_headers,omitempty"`
    84  
    85  	// Transparent client ip enable
    86  	TransparentClientIP *bool `json:"transparent_client_ip_enable,omitempty"`
    87  
    88  	// Enhance L7policy enable
    89  	EnhanceL7policy *bool `json:"enhance_l7policy_enable,omitempty"`
    90  }
    91  
    92  type IpGroup struct {
    93  	IpGroupId string `json:"ipgroup_id" required:"true"`
    94  	Enable    bool   `json:"enable_ipgroup" required:"true"`
    95  	Type      string `json:"type" required:"true"`
    96  }
    97  
    98  type InsertHeaders struct {
    99  	ForwardedELBIP   *bool `json:"X-Forwarded-ELB-IP,omitempty"`
   100  	ForwardedPort    *bool `json:"X-Forwarded-Port,omitempty"`
   101  	ForwardedForPort *bool `json:"X-Forwarded-For-Port,omitempty"`
   102  	ForwardedHost    *bool `json:"X-Forwarded-Host" required:"true"`
   103  }
   104  
   105  // ToListenerCreateMap builds a request body from CreateOpts.
   106  func (opts CreateOpts) ToListenerCreateMap() (map[string]interface{}, error) {
   107  	return golangsdk.BuildRequestBody(opts, "listener")
   108  }
   109  
   110  // Create is an operation which provisions a new Listeners based on the
   111  // configuration defined in the CreateOpts struct. Once the request is
   112  // validated and progress has started on the provisioning process, a
   113  // CreateResult will be returned.
   114  //
   115  // Users with an admin role can create Listeners on behalf of other tenants by
   116  // specifying a TenantID attribute different than their own.
   117  func Create(c *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
   118  	b, err := opts.ToListenerCreateMap()
   119  	if err != nil {
   120  		r.Err = err
   121  		return
   122  	}
   123  	_, r.Err = c.Post(rootURL(c), b, &r.Body, nil)
   124  	return
   125  }
   126  
   127  // Get retrieves a particular Listeners based on its unique ID.
   128  func Get(c *golangsdk.ServiceClient, id string) (r GetResult) {
   129  	_, r.Err = c.Get(resourceURL(c, id), &r.Body, nil)
   130  	return
   131  }
   132  
   133  // UpdateOptsBuilder allows extensions to add additional parameters to the
   134  // Update request.
   135  type UpdateOptsBuilder interface {
   136  	ToListenerUpdateMap() (map[string]interface{}, error)
   137  }
   138  
   139  type IpGroupUpdate struct {
   140  	IpGroupId string `json:"ipgroup_id,omitempty"`
   141  	Type      string `json:"type,omitempty"`
   142  }
   143  
   144  // UpdateOpts represents options for updating a Listener.
   145  type UpdateOpts struct {
   146  	// The administrative state of the Listener. A valid value is true (UP)
   147  	// or false (DOWN).
   148  	AdminStateUp *bool `json:"admin_state_up,omitempty"`
   149  
   150  	// the ID of the CA certificate used by the listener.
   151  	CAContainerRef *string `json:"client_ca_tls_container_ref,omitempty"`
   152  
   153  	// The ID of the default pool with which the Listener is associated.
   154  	DefaultPoolID string `json:"default_pool_id,omitempty"`
   155  
   156  	// A reference to a container of TLS secrets.
   157  	DefaultTlsContainerRef *string `json:"default_tls_container_ref,omitempty"`
   158  
   159  	// Human-readable description for the Listener.
   160  	Description string `json:"description,omitempty"`
   161  
   162  	// whether to use HTTP2.
   163  	Http2Enable *bool `json:"http2_enable,omitempty"`
   164  
   165  	// Human-readable name for the Listener. Does not have to be unique.
   166  	Name string `json:"name,omitempty"`
   167  
   168  	// A list of references to TLS secrets.
   169  	SniContainerRefs *[]string `json:"sni_container_refs,omitempty"`
   170  
   171  	// Specifies the security policy used by the listener.
   172  	TlsCiphersPolicy *string `json:"tls_ciphers_policy,omitempty"`
   173  
   174  	// Whether enable member retry
   175  	EnableMemberRetry *bool `json:"enable_member_retry,omitempty"`
   176  
   177  	// The keepalive timeout of the Listener.
   178  	KeepaliveTimeout *int `json:"keepalive_timeout,omitempty"`
   179  
   180  	// The client timeout of the Listener.
   181  	ClientTimeout *int `json:"client_timeout,omitempty"`
   182  
   183  	// The member timeout of the Listener.
   184  	MemberTimeout *int `json:"member_timeout,omitempty"`
   185  
   186  	// The ipgroup of the Listener.
   187  	IpGroup *IpGroupUpdate `json:"ipgroup,omitempty"`
   188  
   189  	// The http insert headers of the Listener.
   190  	InsertHeaders *InsertHeaders `json:"insert_headers,omitempty"`
   191  
   192  	// Transparent client ip enable
   193  	TransparentClientIP *bool `json:"transparent_client_ip_enable,omitempty"`
   194  
   195  	// Enhance L7policy enable
   196  	EnhanceL7policy *bool `json:"enhance_l7policy_enable,omitempty"`
   197  }
   198  
   199  // ToListenerUpdateMap builds a request body from UpdateOpts.
   200  func (opts UpdateOpts) ToListenerUpdateMap() (map[string]interface{}, error) {
   201  	return golangsdk.BuildRequestBody(opts, "listener")
   202  }
   203  
   204  // Update is an operation which modifies the attributes of the specified
   205  // Listener.
   206  func Update(c *golangsdk.ServiceClient, id string, opts UpdateOpts) (r UpdateResult) {
   207  	b, err := opts.ToListenerUpdateMap()
   208  	if err != nil {
   209  		r.Err = err
   210  		return
   211  	}
   212  	_, r.Err = c.Put(resourceURL(c, id), b, &r.Body, &golangsdk.RequestOpts{
   213  		OkCodes: []int{200, 202},
   214  	})
   215  	return
   216  }
   217  
   218  // Delete will permanently delete a particular Listeners based on its unique ID.
   219  func Delete(c *golangsdk.ServiceClient, id string) (r DeleteResult) {
   220  	_, r.Err = c.Delete(resourceURL(c, id), nil)
   221  	return
   222  }