Skip to content

Commit

Permalink
[#45] (internal/gitlab) fix token asked for wrong domain + display is…
Browse files Browse the repository at this point in the history
…sues

Use the user-defined GitLab host when printing the token key

fix the cursor to prompt on the "Enter...token" line

dont echo the token when its being entered
  • Loading branch information
zaquestion committed Nov 18, 2017
1 parent 67c66f0 commit 5ff07c2
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions internal/gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import (
"os"
"path/filepath"
"strings"
"syscall"

"golang.org/x/crypto/ssh/terminal"

"github.com/davecgh/go-spew/spew"
"github.com/pkg/errors"
Expand Down Expand Up @@ -41,7 +44,7 @@ func Init() {
if err != nil {
fmt.Printf("Enter default GitLab host (default: %s): ", defaultGitLabHost)
host, err = reader.ReadString('\n')
host = host[:len(host)-1]
host = strings.TrimSpace(host)
if err != nil {
log.Fatal(err)
}
Expand All @@ -61,7 +64,7 @@ func Init() {
if err != nil {
fmt.Print("Enter default GitLab user: ")
User, err = reader.ReadString('\n')
User = User[:len(User)-1]
User = strings.TrimSpace(User)
if err != nil {
log.Fatal(err)
}
Expand All @@ -74,15 +77,23 @@ func Init() {
log.Fatal(err)
}

var tokenURL string
if strings.HasSuffix(host, "/") {
tokenURL = host + "profile/personal_access_tokens"
} else {
tokenURL = host + "/profile/personal_access_tokens"
}

// If the default user is being set this is the first time lab
// is being run.
if errt != nil {
fmt.Print("Enter default GitLab token (scope: api ): \nCreate here: https://gitlab.com/profile/personal_access_tokens")
token, err = reader.ReadString('\n')
token = token[:len(token)-1]
fmt.Printf("Create a token here: %s\nEnter default GitLab token (scope: api): ", tokenURL)
byteToken, err := terminal.ReadPassword(int(syscall.Stdin))
if err != nil {
log.Fatal(err)
}
token := strings.TrimSpace(string(byteToken))

// Its okay for the key to be empty, since you can still call public repos
if token != "" {
cmd := git.New("config", "--global", "gitlab.token", token)
Expand Down

0 comments on commit 5ff07c2

Please sign in to comment.