| 56 | } |
| 57 | |
| 58 | func helperRun(opts *CredentialOptions) error { |
| 59 | if opts.Operation == "store" { |
| 60 | // We pretend to implement the "store" operation, but do nothing since we already have a cached token. |
| 61 | return nil |
| 62 | } |
| 63 | |
| 64 | if opts.Operation == "erase" { |
| 65 | // We pretend to implement the "erase" operation, but do nothing since we don't want git to cause user to be logged out. |
| 66 | return nil |
| 67 | } |
| 68 | |
| 69 | if opts.Operation != "get" { |
| 70 | return fmt.Errorf("gh auth git-credential: %q operation not supported", opts.Operation) |
| 71 | } |
| 72 | |
| 73 | wants := map[string]string{} |
| 74 | |
| 75 | s := bufio.NewScanner(opts.IO.In) |
| 76 | for s.Scan() { |
| 77 | line := s.Text() |
| 78 | if line == "" { |
| 79 | break |
| 80 | } |
| 81 | parts := strings.SplitN(line, "=", 2) |
| 82 | if len(parts) < 2 { |
| 83 | continue |
| 84 | } |
| 85 | key, value := parts[0], parts[1] |
| 86 | if key == "url" { |
| 87 | u, err := url.Parse(value) |
| 88 | if err != nil { |
| 89 | return err |
| 90 | } |
| 91 | wants["protocol"] = u.Scheme |
| 92 | wants["host"] = u.Host |
| 93 | wants["path"] = u.Path |
| 94 | wants["username"] = u.User.Username() |
| 95 | wants["password"], _ = u.User.Password() |
| 96 | } else { |
| 97 | wants[key] = value |
| 98 | } |
| 99 | } |
| 100 | if err := s.Err(); err != nil { |
| 101 | return err |
| 102 | } |
| 103 | |
| 104 | if wants["protocol"] != "https" { |
| 105 | return cmdutil.SilentError |
| 106 | } |
| 107 | |
| 108 | cfg, err := opts.Config() |
| 109 | if err != nil { |
| 110 | return err |
| 111 | } |
| 112 | |
| 113 | lookupHost := wants["host"] |
| 114 | var gotUser string |
| 115 | gotToken, source := cfg.ActiveToken(lookupHost) |