|
|
|
@ -17,12 +17,16 @@ limitations under the License.
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"bufio"
|
|
|
|
|
"fmt"
|
|
|
|
|
"log"
|
|
|
|
|
"os"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
"strings"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
"golang.org/x/term"
|
|
|
|
|
corev1 "k8s.io/api/core/v1"
|
|
|
|
|
_ "k8s.io/client-go/plugin/pkg/client/auth"
|
|
|
|
|
|
|
|
|
@ -167,3 +171,25 @@ func homeDir() string {
|
|
|
|
|
}
|
|
|
|
|
return os.Getenv("USERPROFILE") // windows
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// readPasswordFromStdin reads a password from stdin and returns the input
|
|
|
|
|
// with trailing newline and/or carriage return removed. It also makes sure that terminal
|
|
|
|
|
// echoing is turned off if stdin is a terminal.
|
|
|
|
|
func readPasswordFromStdin(prompt string) (string, error) {
|
|
|
|
|
var out string
|
|
|
|
|
var err error
|
|
|
|
|
fmt.Fprint(os.Stdout, prompt)
|
|
|
|
|
stdinFD := int(os.Stdin.Fd())
|
|
|
|
|
if term.IsTerminal(stdinFD) {
|
|
|
|
|
var inBytes []byte
|
|
|
|
|
inBytes, err = term.ReadPassword(int(os.Stdin.Fd()))
|
|
|
|
|
out = string(inBytes)
|
|
|
|
|
} else {
|
|
|
|
|
out, err = bufio.NewReader(os.Stdin).ReadString('\n')
|
|
|
|
|
}
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", fmt.Errorf("could not read from stdin: %w", err)
|
|
|
|
|
}
|
|
|
|
|
fmt.Println()
|
|
|
|
|
return strings.TrimRight(out, "\r\n"), nil
|
|
|
|
|
}
|
|
|
|
|