Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- new commands - support for KV Co-authored-by: Stephan Müller <mail@stephanmueller.eu>
- Loading branch information
1 parent
adc8296
commit e2b5cc7
Showing
37 changed files
with
1,528 additions
and
322 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.idea/ | ||
vendor/ | ||
dist/ | ||
dump/ | ||
dumpcerts.sh | ||
acme.json | ||
acme-backup.json | ||
traefik-certs-dumper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/abronan/valkeyrie/store" | ||
"github.com/abronan/valkeyrie/store/boltdb" | ||
"github.com/ldez/traefik-certs-dumper/dumper" | ||
"github.com/ldez/traefik-certs-dumper/dumper/kv" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// boltdbCmd represents the boltdb command | ||
var boltdbCmd = &cobra.Command{ | ||
Use: "boltdb", | ||
Short: "Dump the content of BoltDB.", | ||
Long: `Dump the content of BoltDB.`, | ||
RunE: runE(boltdbRun), | ||
} | ||
|
||
func init() { | ||
kvCmd.AddCommand(boltdbCmd) | ||
|
||
boltdbCmd.Flags().Bool("persist-connection", false, "Persist connection for boltdb.") | ||
boltdbCmd.Flags().String("bucket", "traefik", "Bucket for boltdb.") | ||
} | ||
|
||
func boltdbRun(baseConfig *dumper.BaseConfig, cmd *cobra.Command) error { | ||
config, err := getKvConfig(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
config.Options.Bucket = cmd.Flag("bucket").Value.String() | ||
config.Options.PersistConnection, _ = cmd.Flags().GetBool("persist-connection") | ||
|
||
config.Backend = store.BOLTDB | ||
boltdb.Register() | ||
|
||
return kv.Dump(config, baseConfig) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/abronan/valkeyrie/store" | ||
"github.com/abronan/valkeyrie/store/consul" | ||
"github.com/ldez/traefik-certs-dumper/dumper" | ||
"github.com/ldez/traefik-certs-dumper/dumper/kv" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// consulCmd represents the consul command | ||
var consulCmd = &cobra.Command{ | ||
Use: "consul", | ||
Short: "Dump the content of Consul.", | ||
Long: `Dump the content of Consul.`, | ||
RunE: runE(consulRun), | ||
} | ||
|
||
func init() { | ||
kvCmd.AddCommand(consulCmd) | ||
|
||
consulCmd.Flags().String("token", "", "Token for consul.") | ||
} | ||
|
||
func consulRun(baseConfig *dumper.BaseConfig, cmd *cobra.Command) error { | ||
config, err := getKvConfig(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
config.Options.Token = cmd.Flag("token").Value.String() | ||
|
||
config.Backend = store.CONSUL | ||
consul.Register() | ||
|
||
return kv.Dump(config, baseConfig) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/cobra/doc" | ||
) | ||
|
||
// docCmd represents the doc command | ||
var docCmd = &cobra.Command{ | ||
Use: "doc", | ||
Short: "Generate documentation", | ||
Hidden: true, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return doc.GenMarkdownTree(rootCmd, "./docs") | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(docCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package cmd | ||
|
||
import ( | ||
"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: runE(func(baseConfig *dumper.BaseConfig, cmd *cobra.Command) error { | ||
acmeFile := cmd.Flag("source").Value.String() | ||
|
||
return file.Dump(acmeFile, baseConfig) | ||
}), | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(fileCmd) | ||
|
||
fileCmd.Flags().String("source", "./acme.json", "Path to 'acme.json' file.") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package cmd | ||
|
||
import ( | ||
"strconv" | ||
"time" | ||
|
||
"github.com/abronan/valkeyrie/store" | ||
"github.com/ldez/traefik-certs-dumper/dumper/kv" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// kvCmd represents the kv command | ||
var kvCmd = &cobra.Command{ | ||
Use: "kv", | ||
Short: `Dump the content of a KV store.`, | ||
Long: `Dump the content of a KV store.`, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(kvCmd) | ||
|
||
kvCmd.PersistentFlags().StringSlice("endpoints", []string{"localhost:8500"}, "List of endpoints.") | ||
kvCmd.PersistentFlags().Int("connection-timeout", 0, "Connection timeout in seconds.") | ||
kvCmd.PersistentFlags().String("prefix", "traefik", "Prefix used for KV store.") | ||
kvCmd.PersistentFlags().String("password", "", "Password for connection.") | ||
kvCmd.PersistentFlags().String("username", "", "Username for connection.") | ||
kvCmd.PersistentFlags().Bool("watch", false, "Enable watching changes.") | ||
|
||
// FIXME review TLS parts | ||
// kvCmd.PersistentFlags().Bool("tls.enable", false, "Enable TLS encryption.") | ||
// kvCmd.PersistentFlags().Bool("tls.insecureskipverify", false, "Trust unverified certificates if TLS is enabled.") | ||
// kvCmd.PersistentFlags().String("tls.ca-cert-file", "", "Root CA file for certificate verification if TLS is enabled.") | ||
} | ||
|
||
func getKvConfig(cmd *cobra.Command) (*kv.Config, error) { | ||
endpoints, err := cmd.Flags().GetStringSlice("endpoints") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
connectionTimeout, err := cmd.Flags().GetInt("connection-timeout") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
watch, _ := strconv.ParseBool(cmd.Flag("watch").Value.String()) | ||
|
||
return &kv.Config{ | ||
Endpoints: endpoints, | ||
Prefix: cmd.Flag("prefix").Value.String(), | ||
Options: &store.Config{ | ||
ConnectionTimeout: time.Duration(connectionTimeout) * time.Second, | ||
Username: cmd.Flag("password").Value.String(), | ||
Password: cmd.Flag("username").Value.String(), | ||
}, | ||
Watch: watch, | ||
}, nil | ||
} |
Oops, something went wrong.