traefik-certs-dumper/cmd/etcd.go
Ludovic Fernandez e2b5cc7e60
KV and commands (#8)
- new commands
- support for KV

Co-authored-by: Stephan Müller <mail@stephanmueller.eu>
2019-04-20 21:56:15 +02:00

44 lines
925 B
Go

package cmd
import (
"time"
"github.com/abronan/valkeyrie/store"
"github.com/abronan/valkeyrie/store/etcd/v2"
"github.com/ldez/traefik-certs-dumper/dumper"
"github.com/ldez/traefik-certs-dumper/dumper/kv"
"github.com/spf13/cobra"
)
// etcdCmd represents the etcd command
var etcdCmd = &cobra.Command{
Use: "etcd",
Short: "Dump the content of etcd.",
Long: `Dump the content of etcd.`,
RunE: runE(etcdRun),
}
func init() {
kvCmd.AddCommand(etcdCmd)
etcdCmd.Flags().Int("sync-period", 0, "Sync period for etcd in seconds.")
}
func etcdRun(baseConfig *dumper.BaseConfig, cmd *cobra.Command) error {
config, err := getKvConfig(cmd)
if err != nil {
return err
}
synPeriod, err := cmd.Flags().GetInt("sync-period")
if err != nil {
return err
}
config.Options.SyncPeriod = time.Duration(synPeriod) * time.Second
config.Backend = store.ETCD
etcd.Register()
return kv.Dump(config, baseConfig)
}