Skip to content
This repository has been archived by the owner on Sep 7, 2022. It is now read-only.

Create config dirs when generating account key. #65

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ func readConfig() (*userConfig, error) {
return uc, nil
}

// writeConfig writes uc to a file specified by path, creating paret dirs
func mkConfigDirs() error {
return os.MkdirAll(configDir, 0700)
}

// writeConfig writes uc to a file specified by path, creating parent dirs
// along the way. If file does not exists, it will be created with 0600 mod.
// This function does not store uc.key.
//func writeConfig(path string, uc *userConfig) error {
Expand All @@ -95,7 +99,7 @@ func writeConfig(uc *userConfig) error {
if err != nil {
return err
}
if err := os.MkdirAll(configDir, 0700); err != nil {
if err := mkConfigDirs(); err != nil {
return err
}
return ioutil.WriteFile(filepath.Join(configDir, accountFile), b, 0600)
Expand Down Expand Up @@ -124,7 +128,11 @@ func readKey(path string) (crypto.Signer, error) {

// writeKey writes k to the specified path in PEM format.
// If file does not exists, it will be created with 0600 mod.
// Parent directories will be created along the way.
func writeKey(path string, k *ecdsa.PrivateKey) error {
if err := mkConfigDirs(); err != nil {
return err
}
f, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion reg.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func runReg(args []string) {
func ttyPrompt(tos string) bool {
fmt.Println("CA requires acceptance of their Terms and Services agreement:")
fmt.Println(tos)
fmt.Print("Do you accept? (Y/n) ")
fmt.Print("Do you accept? (y/N) ")
var a string
if _, err := fmt.Scanln(&a); err != nil {
return false
Expand Down