github.com/kubernetes-incubator/kube-aws@v0.16.4/cmd/show.go (about)

     1  package cmd
     2  
     3  import (
     4  	"github.com/kubernetes-incubator/kube-aws/core/root"
     5  	"github.com/kubernetes-incubator/kube-aws/logger"
     6  	"github.com/kubernetes-incubator/kube-aws/pki"
     7  	"github.com/spf13/cobra"
     8  	"sort"
     9  )
    10  
    11  var (
    12  	cmdShow = &cobra.Command{
    13  		Use:          "show",
    14  		Short:        "Show info about certificates in credentials directory",
    15  		Long:         ``,
    16  		SilenceUsage: true,
    17  	}
    18  
    19  	cmdShowCertificates = &cobra.Command{
    20  		Use:   "certificates",
    21  		Short: "Show info about certificates",
    22  		Long: `Loads all certificates from credentials directory and prints certificate
    23  Issuer, Validity, Subject and DNS Names fields`,
    24  		RunE:         runCmdShowCertificates,
    25  		SilenceUsage: true,
    26  	}
    27  )
    28  
    29  func init() {
    30  	RootCmd.AddCommand(cmdShow)
    31  	cmdShow.AddCommand(cmdShowCertificates)
    32  }
    33  
    34  func runCmdShowCertificates(_ *cobra.Command, _ []string) error {
    35  	certs, err := root.LoadCertificates()
    36  	if err != nil {
    37  		return err
    38  	}
    39  
    40  	keys := sortedKeys(certs)
    41  	for _, k := range keys {
    42  		cert := certs[k]
    43  		logger.Headingf("--- %s ---\n", k)
    44  		for _, v := range cert {
    45  			logger.Info(v)
    46  		}
    47  		logger.Info("")
    48  	}
    49  	return nil
    50  }
    51  
    52  func sortedKeys(m map[string]pki.Certificates) []string {
    53  
    54  	var keys []string
    55  	for k := range m {
    56  		keys = append(keys, k)
    57  	}
    58  
    59  	sort.Sort(sort.StringSlice(keys))
    60  	return keys
    61  }