Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cmd): read password from file #1653

Merged
merged 8 commits into from
Dec 30, 2024
10 changes: 10 additions & 0 deletions cmd/daemon/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import (
"os"
"path/filepath"
"strings"

"github.com/gofrs/flock"
"github.com/pactus-project/pactus/cmd"
"github.com/pactus-project/pactus/util"
"github.com/pactus-project/pactus/wallet"
"github.com/spf13/cobra"
)
Expand All @@ -24,6 +26,9 @@
passwordOpt := startCmd.Flags().StringP("password", "p", "",
"the wallet password")

passwordFromFileOpt := startCmd.Flags().String("password-from-file", "",
"the file containing the wallet password")

Check warning on line 31 in cmd/daemon/start.go

View check run for this annotation

Codecov / codecov/patch

cmd/daemon/start.go#L29-L31

Added lines #L29 - L31 were not covered by tests
startCmd.Run = func(_ *cobra.Command, _ []string) {
workingDir, _ := filepath.Abs(*workingDirOpt)
// change working directory
Expand All @@ -49,8 +54,13 @@
}

var password string

Check warning on line 57 in cmd/daemon/start.go

View check run for this annotation

Codecov / codecov/patch

cmd/daemon/start.go#L57

Added line #L57 was not covered by tests
if *passwordOpt != "" {
password = *passwordOpt
} else if *passwordFromFileOpt != "" {
b, err := util.ReadFile(*passwordFromFileOpt)
cmd.FatalErrorCheck(err)
password = strings.TrimSpace(string(b))

Check warning on line 63 in cmd/daemon/start.go

View check run for this annotation

Codecov / codecov/patch

cmd/daemon/start.go#L60-L63

Added lines #L60 - L63 were not covered by tests
b00f marked this conversation as resolved.
Show resolved Hide resolved
} else {
password = cmd.PromptPassword("Wallet password", false)
}
Expand Down
Loading