github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/networking/v2/extensions/lbaas_v2/certificates/requests.go (about)

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