MCPcopy Create free account
hub / github.com/cli/cli / HostForAPIHost

Method HostForAPIHost

internal/config/config.go:459–475  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

457// A misconfiguration where several hosts share one api_host resolves to the
458// first match in lexical Hosts order.
459func (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.

Callers

nothing calls this directly

Calls 3

HostsMethod · 0.95
CloneMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected