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)
| 481 | // A misconfiguration where several hosts share one api_host resolves to the |
| 482 | // first match in lexical Hosts order. |
| 483 | func (c *AuthConfig) HostForAPIHost(apiHost string) (string, bool) { |
| 484 | if apiHost == "" { |
| 485 | return "", false |
| 486 | } |
| 487 | hosts := slices.Clone(c.Hosts()) |
| 488 | slices.Sort(hosts) |
| 489 | for _, host := range hosts { |
| 490 | configured, err := c.cfg.Get([]string{hostsKey, host, apiHostKey}) |
| 491 | if err != nil || configured == "" { |
| 492 | continue |
| 493 | } |
| 494 | if strings.EqualFold(configured, apiHost) { |
| 495 | return host, true |
| 496 | } |
| 497 | } |
| 498 | return "", false |
| 499 | } |
| 500 | |
| 501 | // SetHosts will override any hosts resolution and return the given |
| 502 | // hosts for all calls to Hosts. Use for testing purposes only. |