forked from moby/swarmkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinspect.go
54 lines (45 loc) · 1.22 KB
/
inspect.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
53
54
package secret
import (
"errors"
"fmt"
"os"
"text/tabwriter"
gogotypes "github.com/gogo/protobuf/types"
"github.com/moby/swarmkit/swarmd/cmd/swarmctl/common"
"github.com/moby/swarmkit/v2/api"
"github.com/spf13/cobra"
)
func printSecretSummary(secret *api.Secret) {
w := tabwriter.NewWriter(os.Stdout, 8, 8, 8, ' ', 0)
defer w.Flush()
common.FprintfIfNotEmpty(w, "ID\t: %s\n", secret.ID)
common.FprintfIfNotEmpty(w, "Name\t: %s\n", secret.Spec.Annotations.Name)
if len(secret.Spec.Annotations.Labels) > 0 {
fmt.Fprintln(w, "Labels\t")
for k, v := range secret.Spec.Annotations.Labels {
fmt.Fprintf(w, " %s\t: %s\n", k, v)
}
}
common.FprintfIfNotEmpty(w, "Created\t: %s\n", gogotypes.TimestampString(secret.Meta.CreatedAt))
}
var (
inspectCmd = &cobra.Command{
Use: "inspect <secret ID or name>",
Short: "Inspect a secret",
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
return errors.New("inspect command takes a single secret ID or name")
}
client, err := common.Dial(cmd)
if err != nil {
return err
}
secret, err := getSecret(common.Context(cmd), client, args[0])
if err != nil {
return err
}
printSecretSummary(secret)
return nil
},
}
)