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

     1  package certificates
     2  
     3  import (
     4  	golangsdk "github.com/opentelekomcloud/gophertelekomcloud"
     5  	"github.com/opentelekomcloud/gophertelekomcloud/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  
    21  	Limit       int    `q:"limit"`
    22  	Marker      string `q:"marker"`
    23  	PageReverse bool   `q:"page_reverse"`
    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(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager {
    33  	url := rootURL(client)
    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(client, 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, "certificate")
    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 from their own.
    77  func Create(client *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 = client.Post(rootURL(client), 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(client *golangsdk.ServiceClient, id string) (r GetResult) {
    91  	_, r.Err = client.Get(resourceURL(client, 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, "certificate")
   116  }
   117  
   118  // Update is an operation which modifies the attributes of the specified Certificate.
   119  func Update(client *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 = client.Put(resourceURL(client, 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(client *golangsdk.ServiceClient, id string) (r DeleteResult) {
   133  	_, r.Err = client.Delete(resourceURL(client, id), nil)
   134  	return
   135  }