-
Notifications
You must be signed in to change notification settings - Fork 15
/
ca_get.go
52 lines (43 loc) · 945 Bytes
/
ca_get.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 cmd
import (
"context"
"errors"
"os"
"github.com/cybozu-go/well"
"github.com/spf13/cobra"
)
// caGetCmd represents the "ca get" command
var caGetCmd = &cobra.Command{
Use: "get NAME",
Short: "dump stored CA certificate to stdout",
Long: `Dump stored CA certificate to stdout.
NAME is one of:
server
etcd-peer
etcd-client
kubernetes`,
Args: func(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
return errors.New("wrong number of arguments")
}
if !isValidCAName(args[0]) {
return errors.New("wrong CA name: " + args[0])
}
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
well.Go(func(ctx context.Context) error {
pem, err := storage.GetCACertificate(ctx, args[0])
if err != nil {
return err
}
_, err = os.Stdout.WriteString(pem)
return err
})
well.Stop()
return well.Wait()
},
}
func init() {
caCmd.AddCommand(caGetCmd)
}