Skip to content

Commit

Permalink
Replace the deprecated gopass lib with x/term (#4200)
Browse files Browse the repository at this point in the history
  • Loading branch information
nono authored Oct 30, 2023
2 parents 4fd2b97 + 6b670d3 commit 411d62c
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 13 deletions.
16 changes: 11 additions & 5 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
"github.com/cozy/cozy-stack/pkg/crypto"
"github.com/cozy/cozy-stack/pkg/keyring"
"github.com/cozy/cozy-stack/pkg/utils"
"github.com/howeyc/gopass"
"github.com/spf13/cobra"
"golang.org/x/term"
)

var configCmdGroup = &cobra.Command{
Expand All @@ -30,9 +30,13 @@ var adminPasswdCmd = &cobra.Command{
Aliases: []string{"password", "passphrase", "pass"},
Short: "Generate an admin passphrase",
Long: `
cozy-stack instances passphrase generate a passphrase hash and save it to the specified file. If no file is specified, it is directly printed in standard output. This passphrase is the one used to authenticate accesses to the administration API.
cozy-stack config passwd generates a passphrase hash and save it to the
specified file. If no file is specified, it is directly printed in standard
output. This passphrase is the one used to authenticate accesses to the
administration API.
The environment variable 'COZY_ADMIN_PASSPHRASE' can be used to pass the passphrase if needed.
The environment variable 'COZY_ADMIN_PASSPHRASE' can be used to pass the
passphrase if needed.
`,
Example: "$ cozy-stack config passwd ~/.cozy/cozy-admin-passphrase",
RunE: func(cmd *cobra.Command, args []string) error {
Expand All @@ -55,13 +59,15 @@ The environment variable 'COZY_ADMIN_PASSPHRASE' can be used to pass the passphr
passphrase := []byte(os.Getenv("COZY_ADMIN_PASSPHRASE"))
if len(passphrase) == 0 {
errPrintf("Passphrase: ")
pass1, err := gopass.GetPasswdPrompt("", false, os.Stdin, os.Stderr)
pass1, err := term.ReadPassword(int(os.Stdin.Fd()))
errPrintfln("")
if err != nil {
return err
}

errPrintf("Confirmation: ")
pass2, err := gopass.GetPasswdPrompt("", false, os.Stdin, os.Stderr)
pass2, err := term.ReadPassword(int(os.Stdin.Fd()))
errPrintfln("")
if err != nil {
return err
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (
"github.com/cozy/cozy-stack/pkg/config/config"
"github.com/cozy/cozy-stack/pkg/consts"
"github.com/cozy/cozy-stack/pkg/tlsclient"
"github.com/howeyc/gopass"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"golang.org/x/term"
)

// DefaultStorageDir is the default directory name in which data
Expand Down Expand Up @@ -101,7 +101,8 @@ func newAdminClient() *client.AdminClient {
if len(pass) == 0 {
var err error
fmt.Fprintf(os.Stdout, "Password:")
pass, err = gopass.GetPasswdMasked()
pass, err = term.ReadPassword(int(os.Stdin.Fd()))
fmt.Fprintln(os.Stdout, "")
if err != nil {
errFatalf("Could not get password from standard input: %s\n", err)
}
Expand Down
8 changes: 6 additions & 2 deletions docs/cli/cozy-stack_config_passwd.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ Generate an admin passphrase
### Synopsis


cozy-stack instances passphrase generate a passphrase hash and save it to the specified file. If no file is specified, it is directly printed in standard output. This passphrase is the one used to authenticate accesses to the administration API.
cozy-stack config passwd generates a passphrase hash and save it to the
specified file. If no file is specified, it is directly printed in standard
output. This passphrase is the one used to authenticate accesses to the
administration API.

The environment variable 'COZY_ADMIN_PASSPHRASE' can be used to pass the passphrase if needed.
The environment variable 'COZY_ADMIN_PASSPHRASE' can be used to pass the
passphrase if needed.


```
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ require (
github.com/h2non/filetype v1.1.3
github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/golang-lru/v2 v2.0.7
github.com/howeyc/gopass v0.0.0-20210920133722-c8aef6fb66ef
github.com/justincampbell/bigduration v0.0.0-20160531141349-e45bf03c0666
github.com/labstack/echo/v4 v4.11.2
github.com/leonelquinteros/gotext v1.5.2
Expand All @@ -51,6 +50,7 @@ require (
golang.org/x/net v0.17.0
golang.org/x/oauth2 v0.13.0
golang.org/x/sync v0.4.0
golang.org/x/term v0.13.0
golang.org/x/text v0.13.0
)

Expand Down Expand Up @@ -109,7 +109,6 @@ require (
github.com/yudai/gojsondiff v1.0.0 // indirect
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/term v0.13.0 // indirect
golang.org/x/time v0.3.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.31.0 // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,6 @@ github.com/hashicorp/hcl v0.0.0-20170914154624-68e816d1c783/go.mod h1:oZtUIOe8dh
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/hokaccha/go-prettyjson v0.0.0-20211117102719-0474bc63780f h1:7LYC+Yfkj3CTRcShK0KOL/w6iTiKyqqBA9a41Wnggw8=
github.com/howeyc/gopass v0.0.0-20210920133722-c8aef6fb66ef h1:A9HsByNhogrvm9cWb28sjiS3i7tcKCkflWFEkHfuAgM=
github.com/howeyc/gopass v0.0.0-20210920133722-c8aef6fb66ef/go.mod h1:lADxMC39cJJqL93Duh1xhAs4I2Zs8mKS89XWXFGp9cs=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
Expand Down

0 comments on commit 411d62c

Please sign in to comment.