-
Notifications
You must be signed in to change notification settings - Fork 0
/
read.go
49 lines (40 loc) · 1.02 KB
/
read.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
/*
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
*/
package cmd
import (
"context"
"fmt"
"github.com/spf13/cobra"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// readCmd represents the read command
var readCmd = &cobra.Command{
Use: "read",
Aliases: []string{"r"},
Short: "Retrieve secret data in human-readable format",
Long: `Retrieve secret data in human-readable format
To retrieve "db-pass" secret data, located in "core" namespace, command will be:
ksec read db-pass -n core
`,
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
RunE: func(cmd *cobra.Command, args []string) error {
clientSet, err := getKubernetesClient()
if err != nil {
return err
}
secretName := args[0]
secretsClient := clientSet.CoreV1().Secrets(namespace)
secret, err := secretsClient.Get(context.TODO(), secretName, metav1.GetOptions{})
if err != nil {
return err
}
for k, v := range secret.Data {
fmt.Printf("%s: %s\n", k, string(v))
}
return nil
},
}
func init() {
rootCmd.AddCommand(readCmd)
}