github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/vpcep/v1/services/requests.go (about)

     1  package services
     2  
     3  import (
     4  	"github.com/huaweicloud/golangsdk"
     5  	"github.com/huaweicloud/golangsdk/openstack/common/tags"
     6  )
     7  
     8  // PostOptsBuilder allows extensions to add parameters to the
     9  // Post request.
    10  type PostOptsBuilder interface {
    11  	ToServicePostMap() (map[string]interface{}, error)
    12  }
    13  
    14  // CreateOpts contains the options for create a VPC endpoint service.
    15  // This object is passed to Create().
    16  type CreateOpts struct {
    17  	// Specifies the ID of the VPC to which the backend resource of the VPC endpoint service belongs.
    18  	VpcID string `json:"vpc_id" required:"true"`
    19  	// Specifies the ID for identifying the backend resource of the VPC endpoint service.
    20  	PortID string `json:"port_id" required:"true"`
    21  	// Specifies the resource type.
    22  	ServerType string `json:"server_type" required:"true"`
    23  	// Lists the port mappings opened to the VPC endpoint service.
    24  	Ports []PortOpts `json:"ports" required:"true"`
    25  
    26  	// Specifies the name of the VPC endpoint service.
    27  	// The value contains a maximum of 16 characters, including letters, digits, underscores (_), and hyphens (-).
    28  	ServiceName string `json:"service_name,omitempty"`
    29  	// Specifies the type of the VPC endpoint service, only interface is valid.
    30  	ServiceType string `json:"service_type,omitempty"`
    31  	// Specifies whether connection approval is required.
    32  	Approval *bool `json:"approval_enabled,omitempty"`
    33  	// Specifies the ID of the virtual NIC to which the virtual IP address is bound.
    34  	VipPortID string `json:"vip_port_id,omitempty"`
    35  	// Specifies whether the client IP address and port number or marker_id information is transmitted to the server.
    36  	TCPProxy string `json:"tcp_proxy,omitempty"`
    37  	// Specifies the resource tags in key/value format
    38  	Tags []tags.ResourceTag `json:"tags,omitempty"`
    39  }
    40  
    41  // PortOpts contains the port mappings opened to the VPC endpoint service.
    42  type PortOpts struct {
    43  	// Specifies the protocol used in port mappings. The value can be TCP or UDP. The default value is TCP.
    44  	Protocol string `json:"protocol,omitempty"`
    45  	// Specifies the port for accessing the VPC endpoint.
    46  	ClientPort int `json:"client_port,omitempty"`
    47  	// Specifies the port for accessing the VPC endpoint service.
    48  	ServerPort int `json:"server_port,omitempty"`
    49  }
    50  
    51  // ToServicePostMap assembles a request body based on the contents of a CreateOpts.
    52  func (opts CreateOpts) ToServicePostMap() (map[string]interface{}, error) {
    53  	return golangsdk.BuildRequestBody(opts, "")
    54  }
    55  
    56  // Create accepts a CreateOpts struct and uses the values to create a new
    57  // VPC endpoint service.
    58  func Create(c *golangsdk.ServiceClient, opts PostOptsBuilder) (r CreateResult) {
    59  	b, err := opts.ToServicePostMap()
    60  	if err != nil {
    61  		r.Err = err
    62  		return
    63  	}
    64  	reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}}
    65  	_, r.Err = c.Post(rootURL(c), b, &r.Body, reqOpt)
    66  	return
    67  }
    68  
    69  // Get retrieves a particular nodes based on its unique ID and cluster ID.
    70  func Get(c *golangsdk.ServiceClient, serviceID string) (r GetResult) {
    71  	_, r.Err = c.Get(resourceURL(c, serviceID), &r.Body, nil)
    72  	return
    73  }
    74  
    75  // UpdateOptsBuilder allows extensions to add parameters to the
    76  // Update request.
    77  type UpdateOptsBuilder interface {
    78  	ToServiceUpdateMap() (map[string]interface{}, error)
    79  }
    80  
    81  // UpdateOpts contains all the values needed to update a VPC endpoint service
    82  type UpdateOpts struct {
    83  	// Specifies the name of the VPC endpoint service.
    84  	ServiceName string `json:"service_name,omitempty"`
    85  	// Specifies whether connection approval is required.
    86  	Approval *bool `json:"approval_enabled,omitempty"`
    87  	// Specifies the ID for identifying the backend resource of the VPC endpoint service.
    88  	PortID string `json:"port_id,omitempty"`
    89  	// Lists the port mappings opened to the VPC endpoint service.
    90  	Ports []PortOpts `json:"ports,omitempty"`
    91  	// Specifies the ID of the virtual NIC to which the virtual IP address is bound.
    92  	VipPortID string `json:"vip_port_id,omitempty"`
    93  }
    94  
    95  // ToServiceUpdateMap builds an update body based on UpdateOpts.
    96  func (opts UpdateOpts) ToServiceUpdateMap() (map[string]interface{}, error) {
    97  	return golangsdk.BuildRequestBody(opts, "")
    98  }
    99  
   100  // Update allows a VPC endpoint service to be updated.
   101  func Update(c *golangsdk.ServiceClient, serviceID string, opts UpdateOptsBuilder) (r UpdateResult) {
   102  	b, err := opts.ToServiceUpdateMap()
   103  	if err != nil {
   104  		r.Err = err
   105  		return
   106  	}
   107  	_, r.Err = c.Put(resourceURL(c, serviceID), b, &r.Body, &golangsdk.RequestOpts{
   108  		OkCodes: []int{200},
   109  	})
   110  	return
   111  }
   112  
   113  // Delete will permanently delete a particular node based on its unique ID and cluster ID.
   114  func Delete(c *golangsdk.ServiceClient, serviceID string) (r DeleteResult) {
   115  	_, r.Err = c.Delete(resourceURL(c, serviceID), nil)
   116  	return
   117  }
   118  
   119  // ListOptsBuilder allows extensions to add parameters to the
   120  // List request.
   121  type ListOptsBuilder interface {
   122  	ToListQuery() (string, error)
   123  }
   124  
   125  // ListOpts allows the filtering of list data using given parameters.
   126  type ListOpts struct {
   127  	ServiceName string `q:"endpoint_service_name"`
   128  	ID          string `q:"id"`
   129  	// Status is not supported for ListPublic
   130  	Status string `q:"status"`
   131  }
   132  
   133  // ToListQuery formats a ListOpts into a query string.
   134  func (opts ListOpts) ToListQuery() (string, error) {
   135  	q, err := golangsdk.BuildQueryString(opts)
   136  	return q.String(), err
   137  }
   138  
   139  // List makes a request against the API to list VPC endpoint services.
   140  func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) ([]Service, error) {
   141  	var r ListResult
   142  	url := rootURL(client)
   143  	if opts != nil {
   144  		query, err := opts.ToListQuery()
   145  		if err != nil {
   146  			return nil, err
   147  		}
   148  		url += query
   149  	}
   150  	_, r.Err = client.Get(url, &r.Body, nil)
   151  	if r.Err != nil {
   152  		return nil, r.Err
   153  	}
   154  
   155  	allNodes, err := r.ExtractServices()
   156  	if err != nil {
   157  		return nil, err
   158  	}
   159  
   160  	return allNodes, nil
   161  }
   162  
   163  // ListPublic makes a request against the API to list public VPC endpoint services.
   164  func ListPublic(client *golangsdk.ServiceClient, opts ListOptsBuilder) ([]PublicService, error) {
   165  	var r ListPublicResult
   166  	url := publicResourceURL(client)
   167  	if opts != nil {
   168  		query, err := opts.ToListQuery()
   169  		if err != nil {
   170  			return nil, err
   171  		}
   172  		url += query
   173  	}
   174  	_, r.Err = client.Get(url, &r.Body, nil)
   175  	if r.Err != nil {
   176  		return nil, r.Err
   177  	}
   178  
   179  	allNodes, err := r.ExtractServices()
   180  	if err != nil {
   181  		return nil, err
   182  	}
   183  
   184  	return allNodes, nil
   185  }
   186  
   187  // ConnActionOpts used to receive or reject a VPC endpoint for a VPC endpoint service.
   188  type ConnActionOpts struct {
   189  	// Specifies whether to receive or reject a VPC endpoint for a VPC endpoint service.
   190  	Action string `json:"action" required:"true"`
   191  	// Lists the VPC endpoints.
   192  	Endpoints []string `json:"endpoints" required:"true"`
   193  }
   194  
   195  // ToServicePostMap assembles a request body based on the contents of a ConnActionOpts.
   196  func (opts ConnActionOpts) ToServicePostMap() (map[string]interface{}, error) {
   197  	return golangsdk.BuildRequestBody(opts, "")
   198  }
   199  
   200  // ConnAction accepts a ConnActionOpts struct and uses the values to receive or reject
   201  // a VPC endpoint for a VPC endpoint service.
   202  func ConnAction(c *golangsdk.ServiceClient, serviceID string, opts PostOptsBuilder) (r ConnectionResult) {
   203  	b, err := opts.ToServicePostMap()
   204  	if err != nil {
   205  		r.Err = err
   206  		return
   207  	}
   208  	reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}}
   209  	_, r.Err = c.Post(connectionsActionURL(c, serviceID), b, &r.Body, reqOpt)
   210  	return
   211  }
   212  
   213  // ListConnOpts used to query connections of a VPC endpoint service.
   214  type ListConnOpts struct {
   215  	// Specifies the unique ID of the VPC endpoint
   216  	EndpointID string `q:"id"`
   217  	// Specifies the packet ID of the VPC endpoint
   218  	MarkerID string `q:"marker_id"`
   219  }
   220  
   221  // ToListQuery formats a ListConnOpts into a query string.
   222  func (opts ListConnOpts) ToListQuery() (string, error) {
   223  	q, err := golangsdk.BuildQueryString(opts)
   224  	return q.String(), err
   225  }
   226  
   227  // ListConnections makes a request against the API to list connections of a VPC endpoint service.
   228  func ListConnections(client *golangsdk.ServiceClient, serviceID string, opts ListOptsBuilder) ([]Connection, error) {
   229  	var r ConnectionResult
   230  	url := connectionsURL(client, serviceID)
   231  	if opts != nil {
   232  		query, err := opts.ToListQuery()
   233  		if err != nil {
   234  			return nil, err
   235  		}
   236  		url += query
   237  	}
   238  	_, r.Err = client.Get(url, &r.Body, nil)
   239  	if r.Err != nil {
   240  		return nil, r.Err
   241  	}
   242  
   243  	allConnections, err := r.ExtractConnections()
   244  	if err != nil {
   245  		return nil, err
   246  	}
   247  
   248  	return allConnections, nil
   249  }
   250  
   251  // PermActionOpts used to add to or delete whitelist records from a VPC endpoint service.
   252  type PermActionOpts struct {
   253  	// Specifies the operation to be performed: dd or remove.
   254  	Action string `json:"action" required:"true"`
   255  	// Lists the whitelist records. The record is in the iam:domain::domain_id format.
   256  	Permissions []string `json:"permissions" required:"true"`
   257  }
   258  
   259  // ToServicePostMap assembles a request body based on the contents of a PermActionOpts.
   260  func (opts PermActionOpts) ToServicePostMap() (map[string]interface{}, error) {
   261  	return golangsdk.BuildRequestBody(opts, "")
   262  }
   263  
   264  // PermAction accepts a PermActionOpts struct and uses the values toadd to or delete
   265  // whitelist records from a VPC endpoint service.
   266  func PermAction(c *golangsdk.ServiceClient, serviceID string, opts PostOptsBuilder) (r PermActionResult) {
   267  	b, err := opts.ToServicePostMap()
   268  	if err != nil {
   269  		r.Err = err
   270  		return
   271  	}
   272  	reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}}
   273  	_, r.Err = c.Post(permissionsActionURL(c, serviceID), b, &r.Body, reqOpt)
   274  	return
   275  }
   276  
   277  // ListPermissions makes a request against the API to query the whitelist records of
   278  // a VPC endpoint service.
   279  func ListPermissions(client *golangsdk.ServiceClient, serviceID string) ([]Permission, error) {
   280  	var r ListPermResult
   281  	url := permissionsURL(client, serviceID)
   282  
   283  	_, r.Err = client.Get(url, &r.Body, nil)
   284  	if r.Err != nil {
   285  		return nil, r.Err
   286  	}
   287  
   288  	allPermissions, err := r.ExtractPermissions()
   289  	if err != nil {
   290  		return nil, err
   291  	}
   292  
   293  	return allPermissions, nil
   294  }