@@ -41,28 +41,29 @@ var credentialHelper = &cobra.Command{
41
41
return
42
42
}
43
43
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
+
44
51
var user , token string
45
52
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
- }
52
53
// Server could return only the token and not the username, so we fallback to hardcoded `oauth2` username.
53
54
// See https://github.com/gitpod-io/gitpod/pull/7889#discussion_r801670957
54
- if user == "" {
55
+ if token != "" && user == "" {
55
56
user = "oauth2"
56
57
}
57
- fmt .Printf ("username=%s\n password=%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
+ }
58
65
}()
59
66
60
- host , err := parseHostFromStdin ()
61
- if err != nil {
62
- log .WithError (err ).Print ("error parsing 'host' from stdin" )
63
- return
64
- }
65
-
66
67
ctx , cancel := context .WithTimeout (context .Background (), 1 * time .Minute )
67
68
defer cancel ()
68
69
@@ -146,27 +147,22 @@ var credentialHelper = &cobra.Command{
146
147
},
147
148
}
148
149
149
- func parseHostFromStdin () (host string , err error ) {
150
+ func parseFromStdin () (map [string ]string , error ) {
151
+ result := make (map [string ]string )
150
152
scanner := bufio .NewScanner (os .Stdin )
151
153
for scanner .Scan () {
152
154
line := strings .TrimSpace (scanner .Text ())
153
155
if len (line ) > 0 {
154
156
tuple := strings .Split (line , "=" )
155
157
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 ])
159
159
}
160
160
}
161
161
}
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
168
164
}
169
- return
165
+ return result , nil
170
166
}
171
167
172
168
type gitCommandInfo struct {
0 commit comments