refactor: fix fixme.
This commit is contained in:
parent
fc55e9e731
commit
8035547b24
44
cmd/root.go
44
cmd/root.go
@ -2,8 +2,10 @@ package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
|
||||
"github.com/ldez/traefik-certs-dumper/dumper"
|
||||
@ -117,6 +119,46 @@ func runE(apply func(*dumper.BaseConfig, *cobra.Command) error) func(*cobra.Comm
|
||||
return err
|
||||
}
|
||||
|
||||
return dumper.Tree(baseConfig.DumpPath, "")
|
||||
return tree(baseConfig.DumpPath, "")
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package dumper
|
||||
|
||||
// BaseConfig FIXME
|
||||
// BaseConfig Base dump command configuration.
|
||||
type BaseConfig struct {
|
||||
DumpPath string
|
||||
CrtInfo FileInfo
|
||||
|
||||
@ -14,13 +14,13 @@ const (
|
||||
keysSubDir = "private"
|
||||
)
|
||||
|
||||
// FileInfo FIXME
|
||||
// FileInfo File information.
|
||||
type FileInfo struct {
|
||||
Name string
|
||||
Ext string
|
||||
}
|
||||
|
||||
// Dump FIXME
|
||||
// Dump Dumps data to certificates.
|
||||
func Dump(data *StoredData, baseConfig *BaseConfig) error {
|
||||
if err := os.RemoveAll(baseConfig.DumpPath); err != nil {
|
||||
return err
|
||||
|
||||
@ -7,7 +7,7 @@ import (
|
||||
"github.com/ldez/traefik-certs-dumper/dumper"
|
||||
)
|
||||
|
||||
// Dump FIXME
|
||||
// Dump Dumps "acme.json" file to certificates.
|
||||
func Dump(acmeFile string, baseConfig *dumper.BaseConfig) error {
|
||||
data, err := readFile(acmeFile)
|
||||
if err != nil {
|
||||
|
||||
@ -1,11 +1,6 @@
|
||||
package dumper
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/go-acme/lego/certcrypto"
|
||||
"github.com/go-acme/lego/registration"
|
||||
)
|
||||
@ -38,44 +33,3 @@ type Account struct {
|
||||
PrivateKey []byte
|
||||
KeyType certcrypto.KeyType
|
||||
}
|
||||
|
||||
// Tree FIXME move
|
||||
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
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@ package kv
|
||||
|
||||
import "github.com/abronan/valkeyrie/store"
|
||||
|
||||
// Config FIXME
|
||||
// Config KV configuration.
|
||||
type Config struct {
|
||||
Backend store.Backend
|
||||
Prefix string
|
||||
|
||||
@ -14,7 +14,7 @@ import (
|
||||
|
||||
const storeKeySuffix = "/acme/account/object"
|
||||
|
||||
// Dump FIXME
|
||||
// Dump Dumps KV content to certificates.
|
||||
func Dump(config *Config, baseConfig *dumper.BaseConfig) error {
|
||||
kvStore, err := valkeyrie.NewStore(config.Backend, config.Endpoints, config.Options)
|
||||
if err != nil {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user