HostForAPIHost returns the configured host whose api_host points at apiHost, reporting false when no host claims it. go-gh sends API requests for a host to that host's api_host, which is a hostname gh is not otherwise logged in to. Callers that resolve credentials from a request URL need this to ge
(apiHost string)
| 457 | // A misconfiguration where several hosts share one api_host resolves to the |
| 458 | // first match in lexical Hosts order. |
| 459 | func (c *AuthConfig) HostForAPIHost(apiHost string) (string, bool) { |
| 460 | if apiHost == "" { |
| 461 | return "", false |
| 462 | } |
| 463 | hosts := slices.Clone(c.Hosts()) |
| 464 | slices.Sort(hosts) |
| 465 | for _, host := range hosts { |
| 466 | configured, err := c.cfg.Get([]string{hostsKey, host, apiHostKey}) |
| 467 | if err != nil || configured == "" { |
| 468 | continue |
| 469 | } |
| 470 | if strings.EqualFold(configured, apiHost) { |
| 471 | return host, true |
| 472 | } |
| 473 | } |
| 474 | return "", false |
| 475 | } |
| 476 | |
| 477 | // SetHosts will override any hosts resolution and return the given |
| 478 | // hosts for all calls to Hosts. Use for testing purposes only. |