Skip to content
This repository has been archived by the owner on Feb 21, 2023. It is now read-only.

Add interactive password input #40

Merged
merged 5 commits into from
Aug 27, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions go/cmd/ccql/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import (
"log"
"os"
"os/user"
"syscall"

"github.com/github/ccql/go/logic"
"github.com/github/ccql/go/sql"
"github.com/github/ccql/go/text"
"golang.org/x/crypto/ssh/terminal"

golib_log "github.com/outbrain/golib/log"
"gopkg.in/gcfg.v1"
Expand All @@ -35,6 +37,7 @@ func main() {
help := flag.Bool("help", false, "Display usage")
user := flag.String("u", osUser, "MySQL username")
password := flag.String("p", "", "MySQL password")
askPassword := flag.Bool("ask-pass", false, "prompt for MySQL password")
credentialsFile := flag.String("C", "", "Credentials file, expecting [client] scope, with 'user', 'password' fields. Overrides -u and -p")
defaultSchema := flag.String("d", "information_schema", "Default schema to use")
hostsList := flag.String("h", "", "Comma or space delimited list of hosts in hostname[:port] format. If not given, hosts read from stdin")
Expand Down Expand Up @@ -105,6 +108,15 @@ func main() {
}
}

if *askPassword {
fmt.Print("Mysql password: ")
passwd, err := terminal.ReadPassword(int(syscall.Stdin))
if err != nil {
log.Fatalf("\nError while get password:", err)
}
*password = string(passwd)
}

if err := logic.QueryHosts(hosts, *user, *password, *defaultSchema, queries, *maxConcurrency, *timeout); err != nil {
os.Exit(1)
}
Expand Down