53 lines
1.2 KiB
Go
53 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func main() {
|
|
var rootCmd = &cobra.Command{
|
|
Use: "traefik-certs-dumper",
|
|
Short: "Dump Let's Encrypt certificates from Traefik",
|
|
Long: `Dump the content of the "acme.json" file from Traefik to certificates.`,
|
|
Version: version,
|
|
}
|
|
|
|
var dumpCmd = &cobra.Command{
|
|
Use: "dump",
|
|
Short: "Dump Let's Encrypt certificates from Traefik",
|
|
Long: `Dump the content of the "acme.json" file from Traefik to certificates.`,
|
|
Run: func(cmd *cobra.Command, _ []string) {
|
|
acmeFile := cmd.Flag("source").Value.String()
|
|
dumpPath := cmd.Flag("dest").Value.String()
|
|
|
|
err := dump(acmeFile, dumpPath)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
},
|
|
}
|
|
|
|
dumpCmd.Flags().String("source", "./acme.json", "Path to 'acme.json' file.")
|
|
dumpCmd.Flags().String("dest", "./dump", "Path to store the dump content.")
|
|
rootCmd.AddCommand(dumpCmd)
|
|
|
|
var versionCmd = &cobra.Command{
|
|
Use: "version",
|
|
Short: "Display version",
|
|
Run: func(_ *cobra.Command, _ []string) {
|
|
displayVersion(rootCmd.Name())
|
|
},
|
|
}
|
|
|
|
rootCmd.AddCommand(versionCmd)
|
|
|
|
if err := rootCmd.Execute(); err != nil {
|
|
fmt.Println(err)
|
|
os.Exit(1)
|
|
}
|
|
}
|