Merge pull request #250 from digitalocean/k8s-get-cluster-user
Add Kubernetes GetUser
This commit is contained in:
commit
a7662efeda
|
@ -1,5 +1,9 @@
|
||||||
# Change Log
|
# Change Log
|
||||||
|
|
||||||
|
## Unreleased
|
||||||
|
|
||||||
|
- #250 Add Kubernetes GetUser method - @snormore
|
||||||
|
|
||||||
## [v1.19.0] - 2019-07-19
|
## [v1.19.0] - 2019-07-19
|
||||||
|
|
||||||
- #244 dbaas: add private-network-uuid field to create request
|
- #244 dbaas: add private-network-uuid field to create request
|
||||||
|
|
|
@ -24,6 +24,7 @@ const (
|
||||||
type KubernetesService interface {
|
type KubernetesService interface {
|
||||||
Create(context.Context, *KubernetesClusterCreateRequest) (*KubernetesCluster, *Response, error)
|
Create(context.Context, *KubernetesClusterCreateRequest) (*KubernetesCluster, *Response, error)
|
||||||
Get(context.Context, string) (*KubernetesCluster, *Response, error)
|
Get(context.Context, string) (*KubernetesCluster, *Response, error)
|
||||||
|
GetUser(context.Context, string) (*KubernetesClusterUser, *Response, error)
|
||||||
GetUpgrades(context.Context, string) ([]*KubernetesVersion, *Response, error)
|
GetUpgrades(context.Context, string) ([]*KubernetesVersion, *Response, error)
|
||||||
GetKubeConfig(context.Context, string) (*KubernetesClusterConfig, *Response, error)
|
GetKubeConfig(context.Context, string) (*KubernetesClusterConfig, *Response, error)
|
||||||
List(context.Context, *ListOptions) ([]*KubernetesCluster, *Response, error)
|
List(context.Context, *ListOptions) ([]*KubernetesCluster, *Response, error)
|
||||||
|
@ -133,6 +134,12 @@ type KubernetesCluster struct {
|
||||||
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// KubernetesClusterUser represents a Kubernetes cluster user.
|
||||||
|
type KubernetesClusterUser struct {
|
||||||
|
Username string `json:"username,omitempty"`
|
||||||
|
Groups []string `json:"groups,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
// KubernetesMaintenancePolicy is a configuration to set the maintenance window
|
// KubernetesMaintenancePolicy is a configuration to set the maintenance window
|
||||||
// of a cluster
|
// of a cluster
|
||||||
type KubernetesMaintenancePolicy struct {
|
type KubernetesMaintenancePolicy struct {
|
||||||
|
@ -326,6 +333,10 @@ type kubernetesClusterRoot struct {
|
||||||
Cluster *KubernetesCluster `json:"kubernetes_cluster,omitempty"`
|
Cluster *KubernetesCluster `json:"kubernetes_cluster,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type kubernetesClusterUserRoot struct {
|
||||||
|
User *KubernetesClusterUser `json:"kubernetes_cluster_user,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
type kubernetesNodePoolRoot struct {
|
type kubernetesNodePoolRoot struct {
|
||||||
NodePool *KubernetesNodePool `json:"node_pool,omitempty"`
|
NodePool *KubernetesNodePool `json:"node_pool,omitempty"`
|
||||||
}
|
}
|
||||||
|
@ -354,6 +365,21 @@ func (svc *KubernetesServiceOp) Get(ctx context.Context, clusterID string) (*Kub
|
||||||
return root.Cluster, resp, nil
|
return root.Cluster, resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetUser retrieves the details of a Kubernetes cluster user.
|
||||||
|
func (svc *KubernetesServiceOp) GetUser(ctx context.Context, clusterID string) (*KubernetesClusterUser, *Response, error) {
|
||||||
|
path := fmt.Sprintf("%s/%s/user", kubernetesClustersPath, clusterID)
|
||||||
|
req, err := svc.client.NewRequest(ctx, http.MethodGet, path, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
root := new(kubernetesClusterUserRoot)
|
||||||
|
resp, err := svc.client.Do(ctx, req, root)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
return root.User, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
// GetUpgrades retrieves versions a Kubernetes cluster can be upgraded to. An
|
// GetUpgrades retrieves versions a Kubernetes cluster can be upgraded to. An
|
||||||
// upgrade can be requested using `Upgrade`.
|
// upgrade can be requested using `Upgrade`.
|
||||||
func (svc *KubernetesServiceOp) GetUpgrades(ctx context.Context, clusterID string) ([]*KubernetesVersion, *Response, error) {
|
func (svc *KubernetesServiceOp) GetUpgrades(ctx context.Context, clusterID string) ([]*KubernetesVersion, *Response, error) {
|
||||||
|
|
|
@ -316,6 +316,34 @@ func TestKubernetesClusters_Get(t *testing.T) {
|
||||||
require.Equal(t, want, got)
|
require.Equal(t, want, got)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestKubernetesClusters_GetUser(t *testing.T) {
|
||||||
|
setup()
|
||||||
|
defer teardown()
|
||||||
|
|
||||||
|
kubeSvc := client.Kubernetes
|
||||||
|
want := &KubernetesClusterUser{
|
||||||
|
Username: "foo@example.com",
|
||||||
|
Groups: []string{
|
||||||
|
"foo:bar",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
jBlob := `
|
||||||
|
{
|
||||||
|
"kubernetes_cluster_user": {
|
||||||
|
"username": "foo@example.com",
|
||||||
|
"groups": ["foo:bar"]
|
||||||
|
}
|
||||||
|
}`
|
||||||
|
|
||||||
|
mux.HandleFunc("/v2/kubernetes/clusters/deadbeef-dead-4aa5-beef-deadbeef347d/user", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
testMethod(t, r, http.MethodGet)
|
||||||
|
fmt.Fprint(w, jBlob)
|
||||||
|
})
|
||||||
|
got, _, err := kubeSvc.GetUser(ctx, "deadbeef-dead-4aa5-beef-deadbeef347d")
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, want, got)
|
||||||
|
}
|
||||||
|
|
||||||
func TestKubernetesClusters_GetKubeConfig(t *testing.T) {
|
func TestKubernetesClusters_GetKubeConfig(t *testing.T) {
|
||||||
setup()
|
setup()
|
||||||
defer teardown()
|
defer teardown()
|
||||||
|
|
Loading…
Reference in New Issue