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