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