github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/networking/v2/extensions/lbaas_v2/certificates/requests.go (about)

     1  package certificates
     2  
     3  import (
     4  	"github.com/huaweicloud/golangsdk"
     5  	"github.com/huaweicloud/golangsdk/pagination"
     6  )
     7  
     8  // ListOptsBuilder allows extensions to add additional parameters to the
     9  // List request.
    10  type ListOptsBuilder interface {
    11  	ToCertificateListQuery() (string, error)
    12  }
    13  
    14  type ListOpts struct {
    15  	ID          string `q:"id"`
    16  	Name        string `q:"name"`
    17  	Description string `q:"description"`
    18  	Type        string `q:"type"`
    19  	Domain      string `q:"domain"`
    20  	PrivateKey  string `q:"private_key"`
    21  	Certificate string `q:"certificate"`
    22  	Limit       int    `q:"limit"`
    23  	Marker      string `q:"marker"`
    24  }
    25  
    26  // ToCertificateListQuery formats a ListOpts into a query string.
    27  func (opts ListOpts) ToCertificateListQuery() (string, error) {
    28  	q, err := golangsdk.BuildQueryString(opts)
    29  	return q.String(), err
    30  }
    31  
    32  func List(c *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager {
    33  	url := rootURL(c)
    34  	if opts != nil {
    35  		query, err := opts.ToCertificateListQuery()
    36  		if err != nil {
    37  			return pagination.Pager{Err: err}
    38  		}
    39  		url += query
    40  	}
    41  	return pagination.NewPager(c, url, func(r pagination.PageResult) pagination.Page {
    42  		return CertificatePage{pagination.SinglePageBase(r)}
    43  	})
    44  }
    45  
    46  // CreateOptsBuilder is the interface options structs have to satisfy in order
    47  // to be used in the main Create operation in this package. Since many
    48  // extensions decorate or modify the common logic, it is useful for them to
    49  // satisfy a basic interface in order for them to be used.
    50  type CreateOptsBuilder interface {
    51  	ToCertificateCreateMap() (map[string]interface{}, error)
    52  }
    53  
    54  // CreateOpts is the common options struct used in this package's Create
    55  // operation.
    56  type CreateOpts struct {
    57  	Name        string `json:"name,omitempty"`
    58  	Description string `json:"description,omitempty"`
    59  	Type        string `json:"type,omitempty"`
    60  	Domain      string `json:"domain,omitempty"`
    61  	PrivateKey  string `json:"private_key,omitempty"`
    62  	Certificate string `json:"certificate" required:"true"`
    63  }
    64  
    65  // ToCertificateCreateMap casts a CreateOpts struct to a map.
    66  func (opts CreateOpts) ToCertificateCreateMap() (map[string]interface{}, error) {
    67  	return golangsdk.BuildRequestBody(opts, "")
    68  }
    69  
    70  // Create is an operation which provisions a new loadbalancer based on the
    71  // configuration defined in the CreateOpts struct. Once the request is
    72  // validated and progress has started on the provisioning process, a
    73  // CreateResult will be returned.
    74  //
    75  // Users with an admin role can create loadbalancers on behalf of other tenants by
    76  // specifying a TenantID attribute different than their own.
    77  func Create(c *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
    78  	b, err := opts.ToCertificateCreateMap()
    79  	if err != nil {
    80  		r.Err = err
    81  		return
    82  	}
    83  	_, r.Err = c.Post(rootURL(c), b, &r.Body, &golangsdk.RequestOpts{
    84  		OkCodes: []int{200, 201},
    85  	})
    86  	return
    87  }
    88  
    89  // Get retrieves a particular Loadbalancer based on its unique ID.
    90  func Get(c *golangsdk.ServiceClient, id string) (r GetResult) {
    91  	_, r.Err = c.Get(resourceURL(c, id), &r.Body, nil)
    92  	return
    93  }
    94  
    95  // UpdateOptsBuilder is the interface options structs have to satisfy in order
    96  // to be used in the main Update operation in this package. Since many
    97  // extensions decorate or modify the common logic, it is useful for them to
    98  // satisfy a basic interface in order for them to be used.
    99  type UpdateOptsBuilder interface {
   100  	ToCertificateUpdateMap() (map[string]interface{}, error)
   101  }
   102  
   103  // UpdateOpts is the common options struct used in this package's Update
   104  // operation.
   105  type UpdateOpts struct {
   106  	Name        string `json:"name,omitempty"`
   107  	Description string `json:"description,omitempty"`
   108  	Domain      string `json:"domain,omitempty"`
   109  	PrivateKey  string `json:"private_key,omitempty"`
   110  	Certificate string `json:"certificate,omitempty"`
   111  }
   112  
   113  // ToCertificateUpdateMap casts a UpdateOpts struct to a map.
   114  func (opts UpdateOpts) ToCertificateUpdateMap() (map[string]interface{}, error) {
   115  	return golangsdk.BuildRequestBody(opts, "")
   116  }
   117  
   118  // Update is an operation which modifies the attributes of the specified Certificate.
   119  func Update(c *golangsdk.ServiceClient, id string, opts UpdateOpts) (r UpdateResult) {
   120  	b, err := opts.ToCertificateUpdateMap()
   121  	if err != nil {
   122  		r.Err = err
   123  		return
   124  	}
   125  	_, r.Err = c.Put(resourceURL(c, id), b, &r.Body, &golangsdk.RequestOpts{
   126  		OkCodes: []int{200},
   127  	})
   128  	return
   129  }
   130  
   131  // Delete will permanently delete a particular Certificate based on its unique ID.
   132  func Delete(c *golangsdk.ServiceClient, id string) (r DeleteResult) {
   133  	_, r.Err = c.Delete(resourceURL(c, id), nil)
   134  	return
   135  }