feat: custom file extensions.
This commit is contained in:
parent
33b732cd4e
commit
14112a73cc
@ -40,7 +40,7 @@ type Account struct {
|
|||||||
KeyType certcrypto.KeyType
|
KeyType certcrypto.KeyType
|
||||||
}
|
}
|
||||||
|
|
||||||
func dump(acmeFile, dumpPath string) error {
|
func dump(acmeFile, dumpPath string, crtExt, keyExt string) error {
|
||||||
f, err := os.Open(acmeFile)
|
f, err := os.Open(acmeFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -66,18 +66,18 @@ func dump(acmeFile, dumpPath string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
privateKeyPem := extractPEMPrivateKey(data.Account)
|
privateKeyPem := extractPEMPrivateKey(data.Account)
|
||||||
err = ioutil.WriteFile(filepath.Join(dumpPath, "private", "letsencrypt.key"), privateKeyPem, 0666)
|
err = ioutil.WriteFile(filepath.Join(dumpPath, "private", "letsencrypt"+keyExt), privateKeyPem, 0666)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, cert := range data.Certificates {
|
for _, cert := range data.Certificates {
|
||||||
err = ioutil.WriteFile(filepath.Join(dumpPath, "private", cert.Domain.Main+".key"), cert.Key, 0666)
|
err = ioutil.WriteFile(filepath.Join(dumpPath, "private", cert.Domain.Main+keyExt), cert.Key, 0666)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = ioutil.WriteFile(filepath.Join(dumpPath, "certs", cert.Domain.Main+".crt"), cert.Certificate, 0666)
|
err = ioutil.WriteFile(filepath.Join(dumpPath, "certs", cert.Domain.Main+crtExt), cert.Certificate, 0666)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
6
main.go
6
main.go
@ -23,8 +23,10 @@ func main() {
|
|||||||
Run: func(cmd *cobra.Command, _ []string) {
|
Run: func(cmd *cobra.Command, _ []string) {
|
||||||
acmeFile := cmd.Flag("source").Value.String()
|
acmeFile := cmd.Flag("source").Value.String()
|
||||||
dumpPath := cmd.Flag("dest").Value.String()
|
dumpPath := cmd.Flag("dest").Value.String()
|
||||||
|
crtExt := cmd.Flag("crt-ext").Value.String()
|
||||||
|
keyExt := cmd.Flag("key-ext").Value.String()
|
||||||
|
|
||||||
err := dump(acmeFile, dumpPath)
|
err := dump(acmeFile, dumpPath, crtExt, keyExt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -33,6 +35,8 @@ func main() {
|
|||||||
|
|
||||||
dumpCmd.Flags().String("source", "./acme.json", "Path to 'acme.json' file.")
|
dumpCmd.Flags().String("source", "./acme.json", "Path to 'acme.json' file.")
|
||||||
dumpCmd.Flags().String("dest", "./dump", "Path to store the dump content.")
|
dumpCmd.Flags().String("dest", "./dump", "Path to store the dump content.")
|
||||||
|
dumpCmd.Flags().String("crt-ext", ".crt", "The file extension of the generated certificates")
|
||||||
|
dumpCmd.Flags().String("key-ext", ".key", "The file extension of the generated privates keys")
|
||||||
rootCmd.AddCommand(dumpCmd)
|
rootCmd.AddCommand(dumpCmd)
|
||||||
|
|
||||||
var versionCmd = &cobra.Command{
|
var versionCmd = &cobra.Command{
|
||||||
|
|||||||
12
readme.md
12
readme.md
@ -29,8 +29,10 @@ Usage:
|
|||||||
traefik-certs-dumper dump [flags]
|
traefik-certs-dumper dump [flags]
|
||||||
|
|
||||||
Flags:
|
Flags:
|
||||||
|
--crt-ext string The file extension of the generated certificates (default ".crt")
|
||||||
--dest string Path to store the dump content. (default "./dump")
|
--dest string Path to store the dump content. (default "./dump")
|
||||||
-h, --help help for dump
|
-h, --help help for dump
|
||||||
|
--key-ext string The file extension of the generated privates keys (default ".key")
|
||||||
--source string Path to 'acme.json' file. (default "./acme.json")
|
--source string Path to 'acme.json' file. (default "./acme.json")
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -43,3 +45,13 @@ traefik-certs-dumper dump
|
|||||||
```bash
|
```bash
|
||||||
traefik-certs-dumper dump --source ./acme.json --dest ./dump
|
traefik-certs-dumper dump --source ./acme.json --dest ./dump
|
||||||
```
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
traefik-certs-dumper dump --crt-ext=.pem --key-ext=.pem
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
- https://github.com/containous/traefik/issues/4381
|
||||||
|
- https://github.com/containous/traefik/issues/2418
|
||||||
|
- https://github.com/containous/traefik/issues/3847
|
||||||
|
- https://github.com/SvenDowideit/traefik-certdumper
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user