ActiveToken will retrieve the active auth token for the given hostname, searching environment variables, plain text config, and lastly encrypted storage.
(hostname string)
| 248 | // searching environment variables, plain text config, and |
| 249 | // lastly encrypted storage. |
| 250 | func (c *AuthConfig) ActiveToken(hostname string) (string, string) { |
| 251 | if c.tokenOverride != nil { |
| 252 | return c.tokenOverride(hostname) |
| 253 | } |
| 254 | token, source := ghauth.TokenFromEnvOrConfig(hostname) |
| 255 | if token == "" { |
| 256 | var user string |
| 257 | var err error |
| 258 | if user, err = c.ActiveUser(hostname); err == nil { |
| 259 | token, err = c.TokenFromKeyringForUser(hostname, user) |
| 260 | } |
| 261 | if err != nil { |
| 262 | // We should generally be able to find a token for the active user, |
| 263 | // but in some cases such as if the keyring was set up in a very old |
| 264 | // version of the CLI, it may only have a unkeyed token, so fallback |
| 265 | // to it. |
| 266 | token, err = c.TokenFromKeyring(hostname) |
| 267 | } |
| 268 | if err == nil { |
| 269 | source = "keyring" |
| 270 | } |
| 271 | } |
| 272 | return token, source |
| 273 | } |
| 274 | |
| 275 | // HasActiveToken returns true when a token for the hostname is present. |
| 276 | func (c *AuthConfig) HasActiveToken(hostname string) bool { |
no test coverage detected