feat: display dump tree.
This commit is contained in:
parent
cd622112a8
commit
f7141a44aa
49
main.go
49
main.go
@ -2,8 +2,9 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
@ -30,7 +31,7 @@ func main() {
|
||||
}
|
||||
return nil
|
||||
},
|
||||
Run: func(cmd *cobra.Command, _ []string) {
|
||||
RunE: func(cmd *cobra.Command, _ []string) error {
|
||||
acmeFile := cmd.Flag("source").Value.String()
|
||||
dumpPath := cmd.Flag("dest").Value.String()
|
||||
crtExt := cmd.Flag("crt-ext").Value.String()
|
||||
@ -39,8 +40,10 @@ func main() {
|
||||
|
||||
err := dump(acmeFile, dumpPath, crtExt, keyExt, subDir)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
|
||||
return tree(dumpPath, "")
|
||||
},
|
||||
}
|
||||
|
||||
@ -66,3 +69,43 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func tree(root, indent string) error {
|
||||
fi, err := os.Stat(root)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not stat %s: %v", root, err)
|
||||
}
|
||||
|
||||
fmt.Println(fi.Name())
|
||||
if !fi.IsDir() {
|
||||
return nil
|
||||
}
|
||||
|
||||
fis, err := ioutil.ReadDir(root)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not read dir %s: %v", root, err)
|
||||
}
|
||||
|
||||
var names []string
|
||||
for _, fi := range fis {
|
||||
if fi.Name()[0] != '.' {
|
||||
names = append(names, fi.Name())
|
||||
}
|
||||
}
|
||||
|
||||
for i, name := range names {
|
||||
add := "│ "
|
||||
if i == len(names)-1 {
|
||||
fmt.Printf(indent + "└──")
|
||||
add = " "
|
||||
} else {
|
||||
fmt.Printf(indent + "├──")
|
||||
}
|
||||
|
||||
if err := tree(filepath.Join(root, name), indent+add); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
56
readme.md
56
readme.md
@ -4,8 +4,7 @@
|
||||
[](https://travis-ci.org/ldez/traefik-certs-dumper)
|
||||
[](https://goreportcard.com/report/github.com/ldez/traefik-certs-dumper)
|
||||
|
||||
|
||||
```yml
|
||||
```yaml
|
||||
Dump the content of the "acme.json" file from Traefik to certificates.
|
||||
|
||||
Usage:
|
||||
@ -23,7 +22,7 @@ Flags:
|
||||
Use "traefik-certs-dumper [command] --help" for more information about a command.
|
||||
```
|
||||
|
||||
```yml
|
||||
```yaml
|
||||
Dump the content of the "acme.json" file from Traefik to certificates.
|
||||
|
||||
Usage:
|
||||
@ -40,27 +39,44 @@ Flags:
|
||||
|
||||
## Examples
|
||||
|
||||
```bash
|
||||
traefik-certs-dumper dump
|
||||
```console
|
||||
$ traefik-certs-dumper dump
|
||||
dump
|
||||
├──certs
|
||||
│ └──my.domain.com.key
|
||||
└──private
|
||||
├──my.domain.com.crt
|
||||
└──letsencrypt.key
|
||||
|
||||
```
|
||||
|
||||
```bash
|
||||
traefik-certs-dumper dump --source ./acme.json --dest ./dump
|
||||
```console
|
||||
$ traefik-certs-dumper dump --domain-subdir=true
|
||||
dump
|
||||
├──my.domain.com
|
||||
│ ├──certificate.crt
|
||||
│ └──privatekey.key
|
||||
└──private
|
||||
└──letsencrypt.key
|
||||
```
|
||||
|
||||
```bash
|
||||
traefik-certs-dumper dump --crt-ext=.pem --key-ext=.pem
|
||||
```console
|
||||
$ traefik-certs-dumper dump --domain-subdir=true --crt-ext=.pem --key-ext=.pem
|
||||
dump
|
||||
├──my.domain.com
|
||||
│ ├──certificate.pem
|
||||
│ └──privatekey.pem
|
||||
└──private
|
||||
└──letsencrypt.key
|
||||
```
|
||||
|
||||
```bash
|
||||
traefik-certs-dumper dump --domain-subdir=true
|
||||
```console
|
||||
$ traefik-certs-dumper dump --source ./acme.json --dest ./dump/test
|
||||
test
|
||||
├──certs
|
||||
│ └──my.domain.com.key
|
||||
└──private
|
||||
├──my.domain.com.crt
|
||||
└──letsencrypt.key
|
||||
|
||||
```
|
||||
|
||||
- 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
|
||||
|
||||
```bash
|
||||
traefik-certs-dumper dump --use-subdir=false --crt-ext=.pem --key-ext=.pem --dest="/home/your_user/.homeassistant/"
|
||||
```
|
||||
Loading…
Reference in New Issue
Block a user