MCPcopy
hub / github.com/git-lfs/git-lfs / getFromProgram

Method getFromProgram

creds/creds.go:263–300  ·  view source on GitHub ↗
(valueType credValueType, u *url.URL)

Source from the content-addressed store, hash-verified

261}
262
263func (a *AskPassCredentialHelper) getFromProgram(valueType credValueType, u *url.URL) (string, error) {
264 var (
265 value bytes.Buffer
266 err bytes.Buffer
267
268 valueString string
269 )
270
271 switch valueType {
272 case credValueTypeUsername:
273 valueString = "Username"
274 case credValueTypePassword:
275 valueString = "Password"
276 default:
277 return "", errors.New(tr.Tr.Get("Invalid Credential type queried from AskPass"))
278 }
279
280 // 'cmd' will run the GIT_ASKPASS (or core.askpass) command prompting
281 // for the desired valueType (`Username` or `Password`)
282 cmd, errVal := subprocess.ExecCommand(a.Program, a.args(fmt.Sprintf("%s for %q", valueString, u))...)
283 if errVal != nil {
284 tracerx.Printf("creds: failed to find GIT_ASKPASS command: %s", a.Program)
285 return "", errVal
286 }
287 cmd.Stderr = &err
288 cmd.Stdout = &value
289
290 tracerx.Printf("creds: filling with GIT_ASKPASS: %s", strings.Join(cmd.Args, " "))
291 if err := cmd.Run(); err != nil {
292 return "", err
293 }
294
295 if err.Len() > 0 {
296 return "", errors.New(err.String())
297 }
298
299 return strings.TrimSpace(value.String()), nil
300}
301
302// Approve implements CredentialHelper.Approve, and returns nil. The ASKPASS
303// credential helper does not implement credential approval.

Callers 1

getValueMethod · 0.95

Calls 7

argsMethod · 0.95
NewFunction · 0.92
ExecCommandFunction · 0.92
GetMethod · 0.65
RunMethod · 0.65
StringMethod · 0.65
LenMethod · 0.45

Tested by

no test coverage detected