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