github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/elb/v3/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 EnterpriseProjectID string `json:"enterprise_project_id,omitempty"` 64 } 65 66 // ToCertificateCreateMap casts a CreateOpts struct to a map. 67 func (opts CreateOpts) ToCertificateCreateMap() (map[string]interface{}, error) { 68 return golangsdk.BuildRequestBody(opts, "certificate") 69 } 70 71 // Create is an operation which provisions a new loadbalancer based on the 72 // configuration defined in the CreateOpts struct. Once the request is 73 // validated and progress has started on the provisioning process, a 74 // CreateResult will be returned. 75 // 76 // Users with an admin role can create loadbalancers on behalf of other tenants by 77 // specifying a TenantID attribute different than their own. 78 func Create(c *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { 79 b, err := opts.ToCertificateCreateMap() 80 if err != nil { 81 r.Err = err 82 return 83 } 84 _, r.Err = c.Post(rootURL(c), b, &r.Body, &golangsdk.RequestOpts{ 85 OkCodes: []int{200, 201}, 86 }) 87 return 88 } 89 90 // Get retrieves a particular Loadbalancer based on its unique ID. 91 func Get(c *golangsdk.ServiceClient, id string) (r GetResult) { 92 _, r.Err = c.Get(resourceURL(c, id), &r.Body, nil) 93 return 94 } 95 96 // UpdateOptsBuilder is the interface options structs have to satisfy in order 97 // to be used in the main Update operation in this package. Since many 98 // extensions decorate or modify the common logic, it is useful for them to 99 // satisfy a basic interface in order for them to be used. 100 type UpdateOptsBuilder interface { 101 ToCertificateUpdateMap() (map[string]interface{}, error) 102 } 103 104 // UpdateOpts is the common options struct used in this package's Update 105 // operation. 106 type UpdateOpts struct { 107 Name string `json:"name,omitempty"` 108 Description *string `json:"description,omitempty"` 109 Domain string `json:"domain,omitempty"` 110 PrivateKey string `json:"private_key,omitempty"` 111 Certificate string `json:"certificate,omitempty"` 112 } 113 114 // ToCertificateUpdateMap casts a UpdateOpts struct to a map. 115 func (opts UpdateOpts) ToCertificateUpdateMap() (map[string]interface{}, error) { 116 return golangsdk.BuildRequestBody(opts, "certificate") 117 } 118 119 // Update is an operation which modifies the attributes of the specified Certificate. 120 func Update(c *golangsdk.ServiceClient, id string, opts UpdateOpts) (r UpdateResult) { 121 b, err := opts.ToCertificateUpdateMap() 122 if err != nil { 123 r.Err = err 124 return 125 } 126 _, r.Err = c.Put(resourceURL(c, id), b, &r.Body, &golangsdk.RequestOpts{ 127 OkCodes: []int{200}, 128 }) 129 return 130 } 131 132 // Delete will permanently delete a particular Certificate based on its unique ID. 133 func Delete(c *golangsdk.ServiceClient, id string) (r DeleteResult) { 134 _, r.Err = c.Delete(resourceURL(c, id), nil) 135 return 136 }