generated from LinuxSuRen/.github
-
Notifications
You must be signed in to change notification settings - Fork 16
/
user_cmd.go
31 lines (28 loc) · 853 Bytes
/
user_cmd.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package user
import (
"context"
"fmt"
kstype "github.com/kubesphere-sigs/ks/kubectl-plugin/types"
"github.com/spf13/cobra"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/dynamic"
)
// NewUserCmd returns the command of users
func NewUserCmd(client dynamic.Interface) (cmd *cobra.Command) {
cmd = &cobra.Command{
Use: "user",
Short: "Reset the password of Kubesphere to the default value which is same with its name",
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) (err error) {
name := args[0]
_, err = client.Resource(kstype.GetUserSchema()).Patch(context.TODO(),
name,
types.MergePatchType,
[]byte(fmt.Sprintf(`{"spec":{"password":"%s"},"metadata":{"annotations":null}}`, name)),
metav1.PatchOptions{})
return
},
}
return
}