Skip to content

Commit

Permalink
Merge pull request #108 from loophole/fix-change_deprecated_terminal_…
Browse files Browse the repository at this point in the history
…package

Switch deprecated terminal package
  • Loading branch information
Morishiri authored Mar 31, 2021
2 parents 6c5b783 + a0d846a commit 8513d05
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
4 changes: 2 additions & 2 deletions cmd/virtual-serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/loophole/cli/internal/pkg/inpututil"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"golang.org/x/crypto/ssh/terminal"
"golang.org/x/term"
)

var remoteEndpointSpecs lm.RemoteEndpointSpecs
Expand Down Expand Up @@ -64,7 +64,7 @@ func parseBasicAuthFlags(flagset *pflag.FlagSet) error {
if !inpututil.IsUsingPipe() { //only ask for password in terminal if not using pipe
fmt.Print("Enter basic auth password: ")
var err error
passwordBytes, err := terminal.ReadPassword(int(os.Stdin.Fd()))
passwordBytes, err := term.ReadPassword(int(os.Stdin.Fd()))
password = string(passwordBytes)
if err != nil {
return err
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ require (
github.com/zserge/lorca v0.1.9
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073
golang.org/x/net v0.0.0-20200301022130-244492dfa37a
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae // indirect
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c // indirect
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf
golang.org/x/text v0.3.2 // indirect
)
8 changes: 6 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,12 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae h1:Ih9Yo4hSPImZOpfGuA4bR/ORKTAbhZo2AbWNRCnevdo=
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c h1:VwygUrnw9jn88c4u8GD3rZQbqrP/tgas88tPUbBxQrk=
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf h1:MZ2shdL+ZM/XzY3ZGOnh4Nlpnxz5GSOhOmtHo3iPU6M=
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
Expand Down
10 changes: 5 additions & 5 deletions internal/pkg/closehandler/closehandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ import (

"github.com/loophole/cli/internal/pkg/communication"
"github.com/loophole/cli/internal/pkg/inpututil"
"golang.org/x/crypto/ssh/terminal"
"golang.org/x/term"
)

var successfulConnectionOccured bool = false
var terminalState *terminal.State = &terminal.State{}
var terminalState *term.State = &term.State{}

// SetupCloseHandler ensures that CTRL+C inputs are properly processed, restoring the terminal state from not displaying entered characters where necessary
func SetupCloseHandler(feedbackFormURL string) {
var terminalState *terminal.State
var terminalState *term.State
c := make(chan os.Signal)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)

if !inpututil.IsUsingPipe() { //don't try to get terminal state if using a pipe
var err error
terminalState, err = terminal.GetState(int(os.Stdin.Fd()))
terminalState, err = term.GetState(int(os.Stdin.Fd()))
if err != nil {
communication.Warn("Error saving terminal state")
communication.Fatal(err.Error())
Expand All @@ -30,7 +30,7 @@ func SetupCloseHandler(feedbackFormURL string) {
go func() {
<-c
if terminalState != nil {
terminal.Restore(int(os.Stdin.Fd()), terminalState)
term.Restore(int(os.Stdin.Fd()), terminalState)
}
communication.ApplicationStop()
os.Exit(0)
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/keys/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

"golang.org/x/crypto/ssh"
"golang.org/x/crypto/ssh/agent"
"golang.org/x/crypto/ssh/terminal"
"golang.org/x/term"
)

//ParsePublicKey retrieves an ssh.AuthMethod and the related PublicKey
Expand Down Expand Up @@ -57,7 +57,7 @@ func ParsePublicKey(file string) (ssh.AuthMethod, ssh.PublicKey, error) {
if err != nil {
fmt.Print("Enter SSH password: ")

password, _ := terminal.ReadPassword(int(os.Stdin.Fd()))
password, _ := term.ReadPassword(int(os.Stdin.Fd()))
fmt.Println()
signer, err = ssh.ParsePrivateKeyWithPassphrase(privateKey, []byte(password))
if err != nil {
Expand Down

0 comments on commit 8513d05

Please sign in to comment.