diff --git a/openstack/cce/v3/clusters/requests.go b/openstack/cce/v3/clusters/requests.go index 9d89a53cd..b2881b518 100644 --- a/openstack/cce/v3/clusters/requests.go +++ b/openstack/cce/v3/clusters/requests.go @@ -148,6 +148,15 @@ func Get(c *golangsdk.ServiceClient, id string) (r GetResult) { return } +// GetCert retrieves a particular cluster certificate based on its unique ID. +func GetCert(c *golangsdk.ServiceClient, id string) (r GetCertResult) { + _, r.Err = c.Get(certificateURL(c, id), &r.Body, &golangsdk.RequestOpts{ + OkCodes: []int{200}, + MoreHeaders: RequestOpts.MoreHeaders, JSONBody: nil, + }) + return +} + // UpdateOpts contains all the values needed to update a new cluster type UpdateOpts struct { Spec UpdateSpec `json:"spec" required:"true"` diff --git a/openstack/cce/v3/clusters/results.go b/openstack/cce/v3/clusters/results.go index 530dc4cbd..5f7ef05d9 100644 --- a/openstack/cce/v3/clusters/results.go +++ b/openstack/cce/v3/clusters/results.go @@ -123,6 +123,63 @@ type Endpoints struct { ExternalOTC string `json:"external_otc"` } +type Certificate struct { + //API type, fixed value Config + Kind string `json:"kind"` + //API version, fixed value v1 + ApiVersion string `json:"apiVersion"` + //Cluster list + Clusters []CertClusters `json:"clusters"` + //User list + Users []CertUsers `json:"users"` + //Context list + Contexts []CertContexts `json:"contexts"` + //The current context + CurrentContext string `json:"current-context"` +} + +type CertClusters struct { + //Cluster name + Name string `json:"name"` + //Cluster information + Cluster CertCluster `json:"cluster"` +} + +type CertCluster struct { + //Server IP address + Server string `json:"server"` + //Certificate data + CertAuthorityData string `json:"certificate-authority-data"` +} + +type CertUsers struct { + //User name + Name string `json:"name"` + //Cluster information + User CertUser `json:"user"` +} + +type CertUser struct { + //Client certificate + ClientCertData string `json:"client-certificate-data"` + //Client key data + ClientKeyData string `json:"client-key-data"` +} + +type CertContexts struct { + //Context name + Name string `json:"name"` + //Context information + Context CertContext `json:"context"` +} + +type CertContext struct { + //Cluster name + Cluster string `json:"cluster"` + //User name + User string `json:"user"` +} + // UnmarshalJSON helps to unmarshal Status fields into needed values. //OTC and Huawei have different data types and child fields for `endpoints` field in Cluster Status. //This function handles the unmarshal for both @@ -215,3 +272,14 @@ type DeleteResult struct { type ListResult struct { commonResult } + +type GetCertResult struct { + golangsdk.Result +} + +// Extract is a function that accepts a result and extracts a cluster. +func (r GetCertResult) Extract() (*Certificate, error) { + var s Certificate + err := r.ExtractInto(&s) + return &s, err +} diff --git a/openstack/cce/v3/clusters/urls.go b/openstack/cce/v3/clusters/urls.go index 3d483e90e..af2c00c43 100644 --- a/openstack/cce/v3/clusters/urls.go +++ b/openstack/cce/v3/clusters/urls.go @@ -4,6 +4,7 @@ import "github.com/huaweicloud/golangsdk" const ( rootPath = "clusters" + certPath = "clustercert" ) func rootURL(client *golangsdk.ServiceClient) string { @@ -13,3 +14,7 @@ func rootURL(client *golangsdk.ServiceClient) string { func resourceURL(c *golangsdk.ServiceClient, id string) string { return c.ServiceURL(rootPath, id) } + +func certificateURL(c *golangsdk.ServiceClient, id string) string { + return c.ServiceURL(rootPath, id, certPath) +}