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