Skip to content

Commit 343ae26

Browse files
iQQBotroboquat
authored andcommitted
fix 'gp credential-helper' told us to quit
1 parent 9951954 commit 343ae26

File tree

1 file changed

+21
-25
lines changed

1 file changed

+21
-25
lines changed

components/gitpod-cli/cmd/credential-helper.go

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -41,28 +41,29 @@ var credentialHelper = &cobra.Command{
4141
return
4242
}
4343

44+
result, err := parseFromStdin()
45+
host := result["host"]
46+
if err != nil || host == "" {
47+
log.WithError(err).Print("error parsing 'host' from stdin")
48+
return
49+
}
50+
4451
var user, token string
4552
defer func() {
46-
// Credentials not found, return `quit=true` so no further helpers will be consulted, nor will the user be prompted.
47-
// From https://git-scm.com/docs/gitcredentials#_custom_helpers
48-
if token == "" {
49-
fmt.Print("quit=true\n")
50-
return
51-
}
5253
// Server could return only the token and not the username, so we fallback to hardcoded `oauth2` username.
5354
// See https://github.com/gitpod-io/gitpod/pull/7889#discussion_r801670957
54-
if user == "" {
55+
if token != "" && user == "" {
5556
user = "oauth2"
5657
}
57-
fmt.Printf("username=%s\npassword=%s\n", user, token)
58+
if token != "" {
59+
result["username"] = user
60+
result["password"] = token
61+
}
62+
for k, v := range result {
63+
fmt.Printf("%s=%s\n", k, v)
64+
}
5865
}()
5966

60-
host, err := parseHostFromStdin()
61-
if err != nil {
62-
log.WithError(err).Print("error parsing 'host' from stdin")
63-
return
64-
}
65-
6667
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute)
6768
defer cancel()
6869

@@ -146,27 +147,22 @@ var credentialHelper = &cobra.Command{
146147
},
147148
}
148149

149-
func parseHostFromStdin() (host string, err error) {
150+
func parseFromStdin() (map[string]string, error) {
151+
result := make(map[string]string)
150152
scanner := bufio.NewScanner(os.Stdin)
151153
for scanner.Scan() {
152154
line := strings.TrimSpace(scanner.Text())
153155
if len(line) > 0 {
154156
tuple := strings.Split(line, "=")
155157
if len(tuple) == 2 {
156-
if strings.TrimSpace(tuple[0]) == "host" {
157-
host = strings.TrimSpace(tuple[1])
158-
}
158+
result[tuple[0]] = strings.TrimSpace(tuple[1])
159159
}
160160
}
161161
}
162-
163-
err = scanner.Err()
164-
if err != nil {
165-
err = fmt.Errorf("parseHostFromStdin error: %v", err)
166-
} else if host == "" {
167-
err = fmt.Errorf("parseHostFromStdin error 'host' is missing")
162+
if err := scanner.Err(); err != nil {
163+
return nil, err
168164
}
169-
return
165+
return result, nil
170166
}
171167

172168
type gitCommandInfo struct {

0 commit comments

Comments
 (0)