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

Method HasEnvToken

internal/config/config.go:398–415  ·  view source on GitHub ↗

HasEnvToken returns true when a token has been specified in an environment variable, else returns false.

()

Source from the content-addressed store, hash-verified

396// HasEnvToken returns true when a token has been specified in an
397// environment variable, else returns false.
398func (c *AuthConfig) HasEnvToken() bool {
399 // This will check if there are any environment variable
400 // authentication tokens set for enterprise hosts.
401 // Any non-github.com hostname is fine here
402 hostname := "example.com"
403 if c.tokenOverride != nil {
404 token, _ := c.tokenOverride(hostname)
405 if token != "" {
406 return true
407 }
408 }
409 // TODO: This is _extremely_ knowledgeable about the implementation of TokenFromEnvOrConfig
410 // It has to use a hostname that is not going to be found in the hosts so that it
411 // can guarantee that tokens will only be returned from a set env var.
412 // Discussed here, but maybe worth revisiting: https://github.com/cli/cli/pull/7169#discussion_r1136979033
413 token, _ := ghauth.TokenFromEnvOrConfig(hostname)
414 return token != ""
415}
416
417// SetActiveToken will override any token resolution and return the given
418// token and source for all calls to ActiveToken. Use for testing purposes only.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected