diff options
author | Amine Hilaly <hilalyamine@gmail.com> | 2019-06-05 01:42:36 +0200 |
---|---|---|
committer | Amine Hilaly <hilalyamine@gmail.com> | 2019-06-07 01:17:59 +0200 |
commit | a6c8b6b78dcf9b31c73fe35545e3fb754e06851a (patch) | |
tree | b9b86262f478be9a0d4c65fbb4a17f7f0bb75e05 | |
parent | c52a467302608012c4fd7d496a7cd60ad153b5cd (diff) | |
download | git-bug-a6c8b6b78dcf9b31c73fe35545e3fb754e06851a.tar.gz |
make token visible in configuration process
validate token
global fixes
-rw-r--r-- | bridge/github/config.go | 28 | ||||
-rw-r--r-- | commands/bridge_configure.go | 19 |
2 files changed, 28 insertions, 19 deletions
diff --git a/bridge/github/config.go b/bridge/github/config.go index b5468846..707b3e2f 100644 --- a/bridge/github/config.go +++ b/bridge/github/config.go @@ -197,8 +197,8 @@ func randomFingerprint() string { func promptTokenOptions(owner, project string) (string, error) { for { fmt.Println() - fmt.Println("[0]: user provided token") - fmt.Println("[1]: interactive token creation") + fmt.Println("[1]: user provided token") + fmt.Println("[2]: interactive token creation") fmt.Print("Select option: ") line, err := bufio.NewReader(os.Stdin).ReadString('\n') @@ -210,12 +210,12 @@ func promptTokenOptions(owner, project string) (string, error) { line = strings.TrimRight(line, "\n") index, err := strconv.Atoi(line) - if err != nil || (index != 0 && index != 1) { + if err != nil || (index != 1 && index != 2) { fmt.Println("invalid input") continue } - if index == 0 { + if index == 1 { return promptToken() } @@ -234,21 +234,25 @@ func promptToken() (string, error) { fmt.Println(" - 'repo' : to be able to read private repositories") fmt.Println() + re, err := regexp.Compile(`^[a-zA-Z0-9]{40}`) + if err != nil { + panic("regexp compile:" + err.Error()) + } + for { fmt.Print("Enter token: ") - byteToken, err := terminal.ReadPassword(int(syscall.Stdin)) - fmt.Println() - + line, err := bufio.NewReader(os.Stdin).ReadString('\n') if err != nil { return "", err } - if len(byteToken) > 0 { - return string(byteToken), nil + token := strings.TrimRight(line, "\n") + if re.MatchString(token) { + return token, nil } - fmt.Println("token is empty") + fmt.Println("token is invalid") } } @@ -534,8 +538,8 @@ func prompt2FA() (string, error) { func promptProjectVisibility() (bool, error) { for { - fmt.Println("[0]: public") - fmt.Println("[1]: private") + fmt.Println("[1]: public") + fmt.Println("[2]: private") fmt.Print("repository visibility: ") line, err := bufio.NewReader(os.Stdin).ReadString('\n') diff --git a/commands/bridge_configure.go b/commands/bridge_configure.go index 169919f6..cecfe139 100644 --- a/commands/bridge_configure.go +++ b/commands/bridge_configure.go @@ -6,13 +6,15 @@ import ( "os" "strconv" "strings" + "syscall" - "github.com/MichaelMure/git-bug/bridge/core" + "github.com/spf13/cobra" + "golang.org/x/crypto/ssh/terminal" "github.com/MichaelMure/git-bug/bridge" + "github.com/MichaelMure/git-bug/bridge/core" "github.com/MichaelMure/git-bug/cache" "github.com/MichaelMure/git-bug/util/interrupt" - "github.com/spf13/cobra" ) const ( @@ -37,9 +39,11 @@ func runBridgeConfigure(cmd *cobra.Command, args []string) error { if err != nil { return err } + interrupt.RegisterCleaner(func() error { return terminal.Restore(int(syscall.Stdin), termState) }) + if bridgeConfigureTarget == "" { bridgeConfigureTarget, err = promptTarget() if err != nil { @@ -78,8 +82,9 @@ func promptTarget() (string, error) { fmt.Printf("target: ") line, err := bufio.NewReader(os.Stdin).ReadString('\n') + if err != nil { - return "", err + return "", fmt.Errorf("got err: '%v' '%v'", line, err) } line = strings.TrimRight(line, "\n") @@ -131,9 +136,9 @@ Detected projects: Select option: 1 -[0]: user provided token -[1]: interactive token creation -Select option: 0 +[1]: user provided token +[2]: interactive token creation +Select option: 1 You can generate a new token by visiting https://github.com/settings/tokens. Choose 'Generate new token' and set the necessary access scope for your repository. @@ -144,7 +149,7 @@ Public: Private: - 'repo' : to be able to read private repositories -Enter token: +Enter token: 87cf5c03b64029f18ea5f9ca5679daa08ccbd700 Successfully configured bridge: default # For Github |