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