Skip to content

Commit 315dc09

Browse files
bsoroushianpeterhaochen47
authored andcommitted
Replaced the dependency github.com/howeyc/gopass
In case of tests golang.org/x/term failing because stdin is not terminal as such in the case the input is not a terminal then a bufio.NewReader is used to read a line
1 parent 67eb1d8 commit 315dc09

File tree

15 files changed

+17
-740
lines changed

15 files changed

+17
-740
lines changed

commands/login.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package commands
22

33
import (
4+
"bufio"
45
"fmt"
56

67
"os"
@@ -11,7 +12,7 @@ import (
1112
"code.cloudfoundry.org/credhub-cli/credhub/auth/uaa"
1213
"code.cloudfoundry.org/credhub-cli/errors"
1314
"code.cloudfoundry.org/credhub-cli/util"
14-
"github.com/howeyc/gopass"
15+
"golang.org/x/term"
1516
)
1617

1718
type LoginCommand struct {
@@ -209,7 +210,7 @@ func promptForMissingCredentials(cmd *LoginCommand, uaa *uaa.Client) error {
209210
return err
210211
}
211212
fmt.Printf("%s : ", md.PasscodePrompt())
212-
code, err := gopass.GetPasswdMasked()
213+
code, err := getPasswordMasked()
213214
if err != nil {
214215
return err
215216
}
@@ -223,8 +224,18 @@ func promptForMissingCredentials(cmd *LoginCommand, uaa *uaa.Client) error {
223224
}
224225
if cmd.Password == "" {
225226
fmt.Printf("password: ")
226-
pass, _ := gopass.GetPasswdMasked()
227+
pass, _ := getPasswordMasked()
227228
cmd.Password = string(pass)
228229
}
229230
return nil
230231
}
232+
233+
func getPasswordMasked() ([]byte, error) {
234+
stdin := os.Stdin
235+
if term.IsTerminal(int(stdin.Fd())) {
236+
return term.ReadPassword(int(stdin.Fd()))
237+
}
238+
r := bufio.NewReader(stdin)
239+
line, _, err := r.ReadLine()
240+
return line, err
241+
}

commands/login_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ var _ = Describe("Login", func() {
159159
setConfigAuthUrl(uaaServer.URL())
160160
session := runCommandWithStdin(strings.NewReader("user\npass\n"), "login")
161161
Eventually(session.Out).Should(Say("username:"))
162-
Eventually(session.Out).Should(Say(`password: \*\*\*\*`))
163162
Eventually(session.Wait("10s").Out).Should(Say("Login Successful"))
164163
Eventually(session).Should(Exit(0))
165164
})

commands/set.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"code.cloudfoundry.org/credhub-cli/credhub/credentials/values"
1414
"code.cloudfoundry.org/credhub-cli/errors"
1515
"code.cloudfoundry.org/credhub-cli/util"
16-
"github.com/howeyc/gopass"
1716
)
1817

1918
type SetCommand struct {
@@ -63,7 +62,7 @@ func (c *SetCommand) setFieldsFromInteractiveUserInput() {
6362

6463
if c.Password == "" && (c.Type == "password" || c.Type == "user") {
6564
fmt.Printf("password: ")
66-
pass, _ := gopass.GetPasswdMasked()
65+
pass, _ := getPasswordMasked()
6766
c.Password = string(pass)
6867
}
6968
}

commands/set_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ metadata:
369369

370370
session := runCommandWithStdin(strings.NewReader("potatoes\n"), "set", "-n", "my-password", "-t", "password")
371371

372-
Eventually(string(session.Out.Contents())).Should(ContainSubstring("password: ********"))
372+
Eventually(string(session.Out.Contents())).Should(ContainSubstring("password: "))
373373
Eventually(session).Should(Exit(0))
374374
Eventually(string(session.Out.Contents())).Should(ContainSubstring("name: my-password"))
375375
Eventually(string(session.Out.Contents())).Should(ContainSubstring("type: password"))

go.mod

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ require (
1111
github.com/cloudfoundry/socks5-proxy v0.2.150
1212
github.com/fatih/color v1.18.0
1313
github.com/hashicorp/go-version v1.7.0
14-
github.com/howeyc/gopass v0.0.0-20210920133722-c8aef6fb66ef
1514
github.com/jessevdk/go-flags v1.6.1
1615
github.com/onsi/ginkgo/v2 v2.23.4
1716
github.com/onsi/gomega v1.37.0
1817
golang.org/x/net v0.39.0
18+
golang.org/x/term v0.31.0
1919
gopkg.in/yaml.v3 v3.0.1
2020
)
2121

@@ -35,7 +35,6 @@ require (
3535
go.uber.org/automaxprocs v1.6.0 // indirect
3636
golang.org/x/crypto v0.37.0 // indirect
3737
golang.org/x/sys v0.32.0 // indirect
38-
golang.org/x/term v0.31.0 // indirect
3938
golang.org/x/text v0.24.0 // indirect
4039
golang.org/x/tools v0.32.0 // indirect
4140
google.golang.org/protobuf v1.36.6 // indirect

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ github.com/google/pprof v0.0.0-20250423184734-337e5dd93bb4 h1:gD0vax+4I+mAj+jECh
2929
github.com/google/pprof v0.0.0-20250423184734-337e5dd93bb4/go.mod h1:5hDyRhoBCxViHszMt12TnOpEI4VVi+U8Gm9iphldiMA=
3030
github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKeRZfjY=
3131
github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
32-
github.com/howeyc/gopass v0.0.0-20210920133722-c8aef6fb66ef h1:A9HsByNhogrvm9cWb28sjiS3i7tcKCkflWFEkHfuAgM=
33-
github.com/howeyc/gopass v0.0.0-20210920133722-c8aef6fb66ef/go.mod h1:lADxMC39cJJqL93Duh1xhAs4I2Zs8mKS89XWXFGp9cs=
3432
github.com/jessevdk/go-flags v1.6.1 h1:Cvu5U8UGrLay1rZfv/zP7iLpSHGUZ/Ou68T0iX1bBK4=
3533
github.com/jessevdk/go-flags v1.6.1/go.mod h1:Mk8T1hIAWpOiJiHa9rJASDK2UGWji0EuPGBnNLMooyc=
3634
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=

vendor/github.com/howeyc/gopass/.travis.yml

Lines changed: 0 additions & 11 deletions
This file was deleted.

vendor/github.com/howeyc/gopass/LICENSE.txt

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)