Login will set user, git protocol, and auth token for the given hostname. If the encrypt option is specified it will first try to store the auth token in encrypted storage and will fall back to the plain text config file.
(hostname, username, token, gitProtocol string, secureStorage bool)
| 354 | // If the encrypt option is specified it will first try to store the auth token |
| 355 | // in encrypted storage and will fall back to the plain text config file. |
| 356 | func (c *AuthConfig) Login(hostname, username, token, gitProtocol string, secureStorage bool) (bool, error) { |
| 357 | // In this section we set up the users config |
| 358 | var setErr error |
| 359 | if secureStorage { |
| 360 | // Try to set the token for this user in the encrypted storage for later switching |
| 361 | setErr = keyring.Set(keyringServiceName(hostname), username, token) |
| 362 | if setErr == nil { |
| 363 | // Clean up the previous oauth_token from the config file, if there were one |
| 364 | _ = c.cfg.Remove([]string{hostsKey, hostname, usersKey, username, oauthTokenKey}) |
| 365 | } |
| 366 | } |
| 367 | insecureStorageUsed := false |
| 368 | if !secureStorage || setErr != nil { |
| 369 | // And set the oauth token under the user for later switching |
| 370 | c.cfg.Set([]string{hostsKey, hostname, usersKey, username, oauthTokenKey}, token) |
| 371 | insecureStorageUsed = true |
| 372 | } |
| 373 | |
| 374 | if gitProtocol != "" { |
| 375 | // Set the host level git protocol |
| 376 | // Although it might be expected that this is handled by switch, git protocol |
| 377 | // is currently a host level config and not a user level config, so any change |
| 378 | // will overwrite the protocol for all users on the host. |
| 379 | c.cfg.Set([]string{hostsKey, hostname, gitProtocolKey}, gitProtocol) |
| 380 | } |
| 381 | |
| 382 | // Create the username key with an empty value so it will be |
| 383 | // written even when there are no keys set under it. |
| 384 | if _, getErr := c.cfg.Get([]string{hostsKey, hostname, usersKey, username}); getErr != nil { |
| 385 | c.cfg.Set([]string{hostsKey, hostname, usersKey, username}, "") |
| 386 | } |
| 387 | |
| 388 | // Then we activate the new user |
| 389 | return insecureStorageUsed, c.activateUser(hostname, username) |
| 390 | } |
| 391 | |
| 392 | func (c *AuthConfig) SwitchUser(hostname, user string) error { |
| 393 | previouslyActiveUser, err := c.ActiveUser(hostname) |
nothing calls this directly
no test coverage detected