/
show_init_password.go
52 lines (44 loc) · 1.13 KB
/
show_init_password.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"context"
"fmt"
"github.com/flux-subsystem-argo/cli/pkg/utils"
"github.com/spf13/cobra"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
)
var showInitPasswordCmd = &cobra.Command{
Use: "show-init-password",
Aliases: []string{"show-init-pass", "show-init-pwd"},
Short: "Show the init password",
Long: `
# Show the init password
flamingo show-init-password
`,
RunE: runShowInitPassword,
}
func init() {
rootCmd.AddCommand(showInitPasswordCmd)
}
func runShowInitPassword(cmd *cobra.Command, args []string) error {
return showInitPassword()
}
// showInitPassword shows the init password
func showInitPassword() error {
cli, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions)
if err != nil {
return err
}
secret := corev1.Secret{
ObjectMeta: v1.ObjectMeta{
Name: "argocd-initial-admin-secret",
Namespace: rootArgs.applicationNamespace,
},
}
if err := cli.Get(context.Background(), client.ObjectKeyFromObject(&secret), &secret); err != nil {
return err
}
fmt.Println(string(secret.Data["password"]))
return nil
}