github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/elb/v3/listeners/requests.go (about)

     1  package listeners
     2  
     3  import (
     4  	golangsdk "github.com/opentelekomcloud/gophertelekomcloud"
     5  	"github.com/opentelekomcloud/gophertelekomcloud/openstack/common/tags"
     6  	"github.com/opentelekomcloud/gophertelekomcloud/pagination"
     7  )
     8  
     9  // Protocol represents a listener protocol.
    10  type Protocol string
    11  
    12  // Supported attributes for create/update operations.
    13  const (
    14  	ProtocolTCP   Protocol = "TCP"
    15  	ProtocolUDP   Protocol = "UDP"
    16  	ProtocolHTTP  Protocol = "HTTP"
    17  	ProtocolHTTPS Protocol = "HTTPS"
    18  )
    19  
    20  // CreateOptsBuilder allows extensions to add additional parameters to the
    21  // Create request.
    22  type CreateOptsBuilder interface {
    23  	ToListenerCreateMap() (map[string]interface{}, error)
    24  }
    25  
    26  // CreateOpts represents options for creating a listener.
    27  type CreateOpts struct {
    28  	// The administrative state of the Listener. A valid value is true (UP)
    29  	// or false (DOWN).
    30  	AdminStateUp *bool `json:"admin_state_up,omitempty"`
    31  
    32  	// the ID of the CA certificate used by the listener.
    33  	CAContainerRef string `json:"client_ca_tls_container_ref,omitempty"`
    34  
    35  	// The ID of the default pool with which the Listener is associated.
    36  	DefaultPoolID string `json:"default_pool_id,omitempty"`
    37  
    38  	// A reference to a Barbican container of TLS secrets.
    39  	DefaultTlsContainerRef string `json:"default_tls_container_ref,omitempty"`
    40  
    41  	// Provides supplementary information about the Listener.
    42  	Description string `json:"description,omitempty"`
    43  
    44  	// whether to use HTTP2.
    45  	Http2Enable *bool `json:"http2_enable,omitempty"`
    46  
    47  	// The load balancer on which to provision this listener.
    48  	LoadbalancerID string `json:"loadbalancer_id" required:"true"`
    49  
    50  	// Specifies the Listener name.
    51  	Name string `json:"name,omitempty"`
    52  
    53  	// ProjectID is only required if the caller has an admin role and wants
    54  	// to create a pool for another project.
    55  	ProjectID string `json:"project_id,omitempty"`
    56  
    57  	// The protocol - can either be TCP, HTTP or HTTPS.
    58  	Protocol Protocol `json:"protocol" required:"true"`
    59  
    60  	// The port on which to listen for client traffic.
    61  	ProtocolPort int `json:"protocol_port" required:"true"`
    62  
    63  	// A list of references to TLS secrets.
    64  	SniContainerRefs []string `json:"sni_container_refs,omitempty"`
    65  
    66  	// Specifies how wildcard domain name matches with the SNI certificates used by the listener.
    67  	// longest_suffix indicates longest suffix match. wildcard indicates wildcard match.
    68  	// The default value is wildcard.
    69  	SniMatchAlgo string `json:"sni_match_algo,omitempty"`
    70  
    71  	// A list of Tags.
    72  	Tags []tags.ResourceTag `json:"tags,omitempty"`
    73  
    74  	// Specifies the security policy used by the listener.
    75  	TlsCiphersPolicy string `json:"tls_ciphers_policy,omitempty"`
    76  
    77  	// Specifies the ID of the custom security policy.
    78  	// Note:
    79  	// This parameter is available only for HTTPS listeners added to a dedicated load balancer.
    80  	// If both security_policy_id and tls_ciphers_policy are specified, only security_policy_id will take effect.
    81  	// The priority of the encryption suite from high to low is: ecc suite: ecc suite, rsa suite, tls 1.3 suite (supporting both ecc and rsa).
    82  	SecurityPolicy string `json:"security_policy_id,omitempty"`
    83  
    84  	// Whether enable member retry
    85  	EnableMemberRetry *bool `json:"enable_member_retry,omitempty"`
    86  
    87  	// The keepalive timeout of the Listener.
    88  	KeepAliveTimeout int `json:"keepalive_timeout,omitempty"`
    89  
    90  	// The client timeout of the Listener.
    91  	ClientTimeout int `json:"client_timeout,omitempty"`
    92  
    93  	// The member timeout of the Listener.
    94  	MemberTimeout int `json:"member_timeout,omitempty"`
    95  
    96  	// The IpGroup of the Listener.
    97  	IpGroup *IpGroup `json:"ipgroup,omitempty"`
    98  
    99  	// The http insert headers of the Listener.
   100  	InsertHeaders *InsertHeaders `json:"insert_headers,omitempty"`
   101  
   102  	// Transparent client ip enable
   103  	TransparentClientIP *bool `json:"transparent_client_ip_enable,omitempty"`
   104  
   105  	// Enhance L7policy enable
   106  	EnhanceL7policy *bool `json:"enhance_l7policy_enable,omitempty"`
   107  }
   108  
   109  type IpGroup struct {
   110  	IpGroupID string `json:"ipgroup_id" required:"true"`
   111  	Enable    *bool  `json:"enable_ipgroup,omitempty"`
   112  	Type      string `json:"type,omitempty"`
   113  }
   114  
   115  type InsertHeaders struct {
   116  	ForwardedELBIP   *bool `json:"X-Forwarded-ELB-IP,omitempty"`
   117  	ForwardedPort    *bool `json:"X-Forwarded-Port,omitempty"`
   118  	ForwardedForPort *bool `json:"X-Forwarded-For-Port,omitempty"`
   119  	ForwardedHost    *bool `json:"X-Forwarded-Host" required:"true"`
   120  }
   121  
   122  // ToListenerCreateMap builds a request body from CreateOpts.
   123  func (opts CreateOpts) ToListenerCreateMap() (map[string]interface{}, error) {
   124  	return golangsdk.BuildRequestBody(opts, "listener")
   125  }
   126  
   127  // Create is an operation which provisions a new Listeners based on the
   128  // configuration defined in the CreateOpts struct. Once the request is
   129  // validated and progress has started on the provisioning process, a
   130  // CreateResult will be returned.
   131  //
   132  // Users with an admin role can create Listeners on behalf of other tenants by
   133  // specifying a TenantID attribute different from their own.
   134  func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
   135  	b, err := opts.ToListenerCreateMap()
   136  	if err != nil {
   137  		r.Err = err
   138  		return
   139  	}
   140  	_, r.Err = client.Post(rootURL(client), b, &r.Body, nil)
   141  	return
   142  }
   143  
   144  // Get retrieves a particular Listeners based on its unique ID.
   145  func Get(client *golangsdk.ServiceClient, id string) (r GetResult) {
   146  	_, r.Err = client.Get(resourceURL(client, id), &r.Body, nil)
   147  	return
   148  }
   149  
   150  // UpdateOptsBuilder allows extensions to add additional parameters to the
   151  // Update request.
   152  type UpdateOptsBuilder interface {
   153  	ToListenerUpdateMap() (map[string]interface{}, error)
   154  }
   155  
   156  type IpGroupUpdate struct {
   157  	IpGroupId string `json:"ipgroup_id,omitempty"`
   158  	Enable    *bool  `json:"enable_ipgroup,omitempty"`
   159  	Type      string `json:"type,omitempty"`
   160  }
   161  
   162  // UpdateOpts represents options for updating a Listener.
   163  type UpdateOpts struct {
   164  	// The administrative state of the Listener. A valid value is true (UP)
   165  	// or false (DOWN).
   166  	AdminStateUp *bool `json:"admin_state_up,omitempty"`
   167  
   168  	// the ID of the CA certificate used by the listener.
   169  	CAContainerRef *string `json:"client_ca_tls_container_ref,omitempty"`
   170  
   171  	// The ID of the default pool with which the Listener is associated.
   172  	DefaultPoolID string `json:"default_pool_id,omitempty"`
   173  
   174  	// A reference to a container of TLS secrets.
   175  	DefaultTlsContainerRef *string `json:"default_tls_container_ref,omitempty"`
   176  
   177  	// Provides supplementary information about the Listener.
   178  	Description *string `json:"description,omitempty"`
   179  
   180  	// whether to use HTTP2.
   181  	Http2Enable *bool `json:"http2_enable,omitempty"`
   182  
   183  	// Specifies the Listener name.
   184  	Name *string `json:"name,omitempty"`
   185  
   186  	// A list of references to TLS secrets.
   187  	SniContainerRefs *[]string `json:"sni_container_refs,omitempty"`
   188  
   189  	// Specifies how wildcard domain name matches with the SNI certificates used by the listener.
   190  	// longest_suffix indicates longest suffix match. wildcard indicates wildcard match.
   191  	// The default value is wildcard.
   192  	SniMatchAlgo string `json:"sni_match_algo,omitempty"`
   193  
   194  	// Specifies the security policy used by the listener.
   195  	TlsCiphersPolicy *string `json:"tls_ciphers_policy,omitempty"`
   196  
   197  	// Specifies the ID of the custom security policy.
   198  	// Note:
   199  	// This parameter is available only for HTTPS listeners added to a dedicated load balancer.
   200  	// If both security_policy_id and tls_ciphers_policy are specified, only security_policy_id will take effect.
   201  	// The priority of the encryption suite from high to low is: ecc suite: ecc suite, rsa suite, tls 1.3 suite (supporting both ecc and rsa).
   202  	SecurityPolicy string `json:"security_policy_id,omitempty"`
   203  
   204  	// Whether enable member retry
   205  	EnableMemberRetry *bool `json:"enable_member_retry,omitempty"`
   206  
   207  	// The keepalive timeout of the Listener.
   208  	KeepAliveTimeout int `json:"keepalive_timeout,omitempty"`
   209  
   210  	// The client timeout of the Listener.
   211  	ClientTimeout int `json:"client_timeout,omitempty"`
   212  
   213  	// The member timeout of the Listener.
   214  	MemberTimeout int `json:"member_timeout,omitempty"`
   215  
   216  	// The IpGroup of the Listener.
   217  	IpGroup *IpGroupUpdate `json:"ipgroup,omitempty"`
   218  
   219  	// The http insert headers of the Listener.
   220  	InsertHeaders *InsertHeaders `json:"insert_headers,omitempty"`
   221  
   222  	// Transparent client ip enable
   223  	TransparentClientIP *bool `json:"transparent_client_ip_enable,omitempty"`
   224  
   225  	// Enhance L7policy enable
   226  	EnhanceL7policy *bool `json:"enhance_l7policy_enable,omitempty"`
   227  }
   228  
   229  // ToListenerUpdateMap builds a request body from UpdateOpts.
   230  func (opts UpdateOpts) ToListenerUpdateMap() (map[string]interface{}, error) {
   231  	return golangsdk.BuildRequestBody(opts, "listener")
   232  }
   233  
   234  // Update is an operation which modifies the attributes of the specified
   235  // Listener.
   236  func Update(client *golangsdk.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) {
   237  	b, err := opts.ToListenerUpdateMap()
   238  	if err != nil {
   239  		r.Err = err
   240  		return
   241  	}
   242  	_, r.Err = client.Put(resourceURL(client, id), b, &r.Body, &golangsdk.RequestOpts{
   243  		OkCodes: []int{200, 202},
   244  	})
   245  	return
   246  }
   247  
   248  // Delete will permanently delete a particular Listeners based on its unique ID.
   249  func Delete(client *golangsdk.ServiceClient, id string) (r DeleteResult) {
   250  	_, r.Err = client.Delete(resourceURL(client, id), nil)
   251  	return
   252  }
   253  
   254  type ListOptsBuilder interface {
   255  	ToListenerListQuery() (string, error)
   256  }
   257  
   258  type ListOpts struct {
   259  	Limit       int    `q:"limit"`
   260  	Marker      string `q:"marker"`
   261  	PageReverse bool   `q:"page_reverse"`
   262  
   263  	ProtocolPort            []int      `q:"protocol_port"`
   264  	Protocol                []Protocol `q:"protocol"`
   265  	Description             []string   `q:"description"`
   266  	DefaultTLSContainerRef  []string   `q:"default_tls_container_ref"`
   267  	ClientCATLSContainerRef []string   `q:"client_ca_tls_container_ref"`
   268  	DefaultPoolID           []string   `q:"default_pool_id"`
   269  	ID                      []string   `q:"id"`
   270  	Name                    []string   `q:"name"`
   271  	LoadBalancerID          []string   `q:"loadbalancer_id"`
   272  	TLSCiphersPolicy        []string   `q:"tls_ciphers_policy"`
   273  	MemberAddress           []string   `q:"member_address"`
   274  	MemberDeviceID          []string   `q:"member_device_id"`
   275  	MemberTimeout           []int      `q:"member_timeout"`
   276  	ClientTimeout           []int      `q:"client_timeout"`
   277  	KeepAliveTimeout        []int      `q:"keepalive_timeout"`
   278  }
   279  
   280  func (opts ListOpts) ToListenerListQuery() (string, error) {
   281  	q, err := golangsdk.BuildQueryString(opts)
   282  	if err != nil {
   283  		return "", err
   284  	}
   285  	return q.String(), nil
   286  }
   287  
   288  func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager {
   289  	url := rootURL(client)
   290  	if opts != nil {
   291  		q, err := opts.ToListenerListQuery()
   292  		if err != nil {
   293  			return pagination.Pager{Err: err}
   294  		}
   295  		url += q
   296  	}
   297  	return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
   298  		return ListenerPage{PageWithInfo: pagination.NewPageWithInfo(r)}
   299  	})
   300  }