github.com/gophercloud/gophercloud@v1.11.0/openstack/containerinfra/v1/certificates/requests.go (about) 1 package certificates 2 3 import ( 4 "github.com/gophercloud/gophercloud" 5 ) 6 7 // CreateOptsBuilder allows extensions to add additional parameters 8 // to the Create request. 9 type CreateOptsBuilder interface { 10 ToCertificateCreateMap() (map[string]interface{}, error) 11 } 12 13 // CreateOpts represents options used to create a certificate. 14 type CreateOpts struct { 15 ClusterUUID string `json:"cluster_uuid,omitempty" xor:"BayUUID"` 16 BayUUID string `json:"bay_uuid,omitempty" xor:"ClusterUUID"` 17 CSR string `json:"csr" required:"true"` 18 } 19 20 // ToCertificateCreateMap constructs a request body from CreateOpts. 21 func (opts CreateOpts) ToCertificateCreateMap() (map[string]interface{}, error) { 22 return gophercloud.BuildRequestBody(opts, "") 23 } 24 25 // Get makes a request against the API to get details for a certificate. 26 func Get(client *gophercloud.ServiceClient, clusterID string) (r GetResult) { 27 url := getURL(client, clusterID) 28 resp, err := client.Get(url, &r.Body, &gophercloud.RequestOpts{ 29 OkCodes: []int{200}, 30 }) 31 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 32 return 33 } 34 35 // Create requests the creation of a new certificate. 36 func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { 37 b, err := opts.ToCertificateCreateMap() 38 if err != nil { 39 r.Err = err 40 return 41 } 42 resp, err := client.Post(createURL(client), b, &r.Body, &gophercloud.RequestOpts{ 43 OkCodes: []int{201}, 44 }) 45 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 46 return 47 } 48 49 // Update will rotate the CA certificate for a cluster 50 func Update(client *gophercloud.ServiceClient, clusterID string) (r UpdateResult) { 51 resp, err := client.Patch(updateURL(client, clusterID), nil, &r.Body, &gophercloud.RequestOpts{ 52 OkCodes: []int{202}, 53 }) 54 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 55 return 56 }