traefik-certs-dumper/cmd/file.go
Fernandez Ludovic 627b5423bc consul: WIP
2019-04-20 15:32:24 +02:00

50 lines
1.1 KiB
Go

package cmd
import (
"strconv"
"github.com/ldez/traefik-certs-dumper/dumper"
"github.com/ldez/traefik-certs-dumper/dumper/file"
"github.com/spf13/cobra"
)
// fileCmd represents the file command
var fileCmd = &cobra.Command{
Use: "file",
Short: `Dump the content of the "acme.json" file.`,
Long: `Dump the content of the "acme.json" file from Traefik to certificates.`,
RunE: func(cmd *cobra.Command, _ []string) error {
// FIXME shared with KV
dumpPath := cmd.Flag("dest").Value.String()
crtInfo := dumper.FileInfo{
Name: cmd.Flag("crt-name").Value.String(),
Ext: cmd.Flag("crt-ext").Value.String(),
}
keyInfo := dumper.FileInfo{
Name: cmd.Flag("key-name").Value.String(),
Ext: cmd.Flag("key-ext").Value.String(),
}
subDir, _ := strconv.ParseBool(cmd.Flag("domain-subdir").Value.String())
// ---
acmeFile := cmd.Flag("source").Value.String()
err := file.Dump(acmeFile, dumpPath, crtInfo, keyInfo, subDir)
if err != nil {
return err
}
return dumper.Tree(dumpPath, "")
},
}
func init() {
rootCmd.AddCommand(fileCmd)
fileCmd.Flags().String("source", "./acme.json", "Path to 'acme.json' file.")
}