Create templates path, and remove unnecessary arguments.

This commit is contained in:
Mariano Cano 2019-10-11 11:25:48 -07:00 committed by max furman
parent 3ee0dcec93
commit 505da52279
2 changed files with 22 additions and 20 deletions

View file

@ -162,7 +162,7 @@ func onboardAction(ctx *cli.Context) error {
} }
func onboardPKI(config onboardingConfiguration) (*authority.Config, string, error) { func onboardPKI(config onboardingConfiguration) (*authority.Config, string, error) {
p, err := pki.New(pki.GetPublicPath(), pki.GetSecretsPath(), pki.GetConfigPath()) p, err := pki.New()
if err != nil { if err != nil {
return nil, "", err return nil, "", err
} }

View file

@ -15,8 +15,6 @@ import (
"strconv" "strconv"
"strings" "strings"
"golang.org/x/crypto/ssh"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/smallstep/certificates/authority" "github.com/smallstep/certificates/authority"
"github.com/smallstep/certificates/authority/provisioner" "github.com/smallstep/certificates/authority/provisioner"
@ -31,6 +29,7 @@ import (
"github.com/smallstep/cli/jose" "github.com/smallstep/cli/jose"
"github.com/smallstep/cli/ui" "github.com/smallstep/cli/ui"
"github.com/smallstep/cli/utils" "github.com/smallstep/cli/utils"
"golang.org/x/crypto/ssh"
) )
const ( const (
@ -46,6 +45,8 @@ const (
// DBPath is the directory name under the step path where the private keys // DBPath is the directory name under the step path where the private keys
// will be stored. // will be stored.
dbPath = "db" dbPath = "db"
// templatesPath is the directory to store templates
templatesPath = "templates"
) )
// GetDBPath returns the path where the file-system persistence is stored // GetDBPath returns the path where the file-system persistence is stored
@ -84,6 +85,11 @@ func GetOTTKeyPath() string {
return filepath.Join(config.StepPath(), privatePath, "ott_key") return filepath.Join(config.StepPath(), privatePath, "ott_key")
} }
// GetTemplatesPath returns the path where the templates are stored.
func GetTemplatesPath() string {
return filepath.Join(config.StepPath(), templatesPath)
}
// GetProvisioners returns the map of provisioners on the given CA. // GetProvisioners returns the map of provisioners on the given CA.
func GetProvisioners(caURL, rootFile string) (provisioner.List, error) { func GetProvisioners(caURL, rootFile string) (provisioner.List, error) {
if len(rootFile) == 0 { if len(rootFile) == 0 {
@ -142,21 +148,17 @@ type PKI struct {
} }
// New creates a new PKI configuration. // New creates a new PKI configuration.
func New(public, private, config string) (*PKI, error) { func New() (*PKI, error) {
if _, err := os.Stat(public); os.IsNotExist(err) { public := GetPublicPath()
if err = os.MkdirAll(public, 0700); err != nil { private := GetSecretsPath()
return nil, errs.FileError(err, public) config := GetConfigPath()
}
} // Create directories
if _, err := os.Stat(private); os.IsNotExist(err) { dirs := []string{public, private, config, GetTemplatesPath()}
if err = os.MkdirAll(private, 0700); err != nil { for _, name := range dirs {
return nil, errs.FileError(err, private) if _, err := os.Stat(name); os.IsNotExist(err) {
} if err = os.MkdirAll(name, 0700); err != nil {
} return nil, errs.FileError(err, name)
if len(config) > 0 {
if _, err := os.Stat(config); os.IsNotExist(err) {
if err = os.MkdirAll(config, 0700); err != nil {
return nil, errs.FileError(err, config)
} }
} }
} }
@ -468,7 +470,7 @@ func (p *PKI) Save(opt ...Option) error {
if err != nil { if err != nil {
return errors.Wrapf(err, "error marshaling %s", p.config) return errors.Wrapf(err, "error marshaling %s", p.config)
} }
if err = utils.WriteFile(p.config, b, 0666); err != nil { if err = utils.WriteFile(p.config, b, 0644); err != nil {
return errs.FileError(err, p.config) return errs.FileError(err, p.config)
} }
@ -497,7 +499,7 @@ func (p *PKI) Save(opt ...Option) error {
if err != nil { if err != nil {
return errors.Wrapf(err, "error marshaling %s", p.defaults) return errors.Wrapf(err, "error marshaling %s", p.defaults)
} }
if err = utils.WriteFile(p.defaults, b, 0666); err != nil { if err = utils.WriteFile(p.defaults, b, 0644); err != nil {
return errs.FileError(err, p.defaults) return errs.FileError(err, p.defaults)
} }