feat: use viper and cobra to parameterize creation values with viper yaml

This commit is contained in:
2023-02-15 19:30:05 +01:00
parent 0019941054
commit c1680106ab
8 changed files with 722 additions and 2 deletions

View File

@@ -55,7 +55,7 @@ func encodePrivateKey(priv *ecdsa.PrivateKey) ([]byte, error) {
}
// Create a self-signed certificate.
func newRootCA(config ca.CaConfig) ([]byte, []byte, error) {
func newRootCA(config *ca.CaConfig) ([]byte, []byte, error) {
priv, err := newPrivateKey()
if err != nil {
return nil, nil, fmt.Errorf("newPrivateKey: %s", err)
@@ -178,7 +178,7 @@ func (r *rootCA) PEM() []byte {
return r.caPEM
}
func NewRootCA(config ca.CaConfig) (ca.RootCACertificateIface, error) {
func NewRootCA(config *ca.CaConfig) (ca.RootCACertificateIface, error) {
caPEM, keyPEM, err := newRootCA(config)
if err != nil {
return nil, fmt.Errorf("newRootCA: %s", err)

33
internal/io/writer.go Normal file
View File

@@ -0,0 +1,33 @@
package io
import (
"fmt"
"os"
"gitlab.com/urkob/go-cert-gen/pkg/io"
)
type writer struct {
dirPath string
}
func (w writer) WriteFile(filename string, data []byte) (string, error) {
if w.dirPath == "" {
return "", fmt.Errorf("export directory cannot be empty")
}
if err := os.MkdirAll(w.dirPath, 0o755); err != nil {
return "", err
}
outputPath := w.dirPath + "/" + filename
if err := os.WriteFile(outputPath, data, 0o600); err != nil {
return "", err
}
return outputPath, nil
}
func NewWriter(dirPath string) io.WriterIface {
return &writer{
dirPath: dirPath,
}
}