feat: display dump tree.

This commit is contained in:
Fernandez Ludovic 2019-02-20 20:23:12 +01:00
parent cd622112a8
commit f7141a44aa
2 changed files with 82 additions and 23 deletions

49
main.go
View File

@ -2,8 +2,9 @@ package main
import ( import (
"fmt" "fmt"
"log" "io/ioutil"
"os" "os"
"path/filepath"
"strconv" "strconv"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -30,7 +31,7 @@ func main() {
} }
return nil return nil
}, },
Run: func(cmd *cobra.Command, _ []string) { RunE: func(cmd *cobra.Command, _ []string) error {
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() crtExt := cmd.Flag("crt-ext").Value.String()
@ -39,8 +40,10 @@ func main() {
err := dump(acmeFile, dumpPath, crtExt, keyExt, subDir) err := dump(acmeFile, dumpPath, crtExt, keyExt, subDir)
if err != nil { if err != nil {
log.Fatal(err) return err
} }
return tree(dumpPath, "")
}, },
} }
@ -66,3 +69,43 @@ func main() {
os.Exit(1) 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
}

View File

@ -4,8 +4,7 @@
[![Build Status](https://travis-ci.org/ldez/traefik-certs-dumper.svg?branch=master)](https://travis-ci.org/ldez/traefik-certs-dumper) [![Build Status](https://travis-ci.org/ldez/traefik-certs-dumper.svg?branch=master)](https://travis-ci.org/ldez/traefik-certs-dumper)
[![Go Report Card](https://goreportcard.com/badge/github.com/ldez/traefik-certs-dumper)](https://goreportcard.com/report/github.com/ldez/traefik-certs-dumper) [![Go Report Card](https://goreportcard.com/badge/github.com/ldez/traefik-certs-dumper)](https://goreportcard.com/report/github.com/ldez/traefik-certs-dumper)
```yaml
```yml
Dump the content of the "acme.json" file from Traefik to certificates. Dump the content of the "acme.json" file from Traefik to certificates.
Usage: Usage:
@ -23,7 +22,7 @@ Flags:
Use "traefik-certs-dumper [command] --help" for more information about a command. 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. Dump the content of the "acme.json" file from Traefik to certificates.
Usage: Usage:
@ -40,27 +39,44 @@ Flags:
## Examples ## Examples
```bash ```console
traefik-certs-dumper dump $ traefik-certs-dumper dump
dump
├──certs
│ └──my.domain.com.key
└──private
├──my.domain.com.crt
└──letsencrypt.key
``` ```
```bash ```console
traefik-certs-dumper dump --source ./acme.json --dest ./dump $ traefik-certs-dumper dump --domain-subdir=true
dump
├──my.domain.com
│ ├──certificate.crt
│ └──privatekey.key
└──private
└──letsencrypt.key
``` ```
```bash ```console
traefik-certs-dumper dump --crt-ext=.pem --key-ext=.pem $ 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 ```console
traefik-certs-dumper dump --domain-subdir=true $ 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/"
```