HasEnvToken returns true when a token has been specified in an environment variable, else returns false.
()
| 372 | // HasEnvToken returns true when a token has been specified in an |
| 373 | // environment variable, else returns false. |
| 374 | func (c *AuthConfig) HasEnvToken() bool { |
| 375 | // This will check if there are any environment variable |
| 376 | // authentication tokens set for enterprise hosts. |
| 377 | // Any non-github.com hostname is fine here |
| 378 | hostname := "example.com" |
| 379 | if c.tokenOverride != nil { |
| 380 | token, _ := c.tokenOverride(hostname) |
| 381 | if token != "" { |
| 382 | return true |
| 383 | } |
| 384 | } |
| 385 | // TODO: This is _extremely_ knowledgeable about the implementation of TokenFromEnvOrConfig |
| 386 | // It has to use a hostname that is not going to be found in the hosts so that it |
| 387 | // can guarantee that tokens will only be returned from a set env var. |
| 388 | // Discussed here, but maybe worth revisiting: https://github.com/cli/cli/pull/7169#discussion_r1136979033 |
| 389 | token, _ := ghauth.TokenFromEnvOrConfig(hostname) |
| 390 | return token != "" |
| 391 | } |
| 392 | |
| 393 | // SetActiveToken will override any token resolution and return the given |
| 394 | // token and source for all calls to ActiveToken. Use for testing purposes only. |
nothing calls this directly
no outgoing calls
no test coverage detected