Logout will remove user, git protocol, and auth token for the given hostname. It will remove the auth token from the encrypted storage if it exists there.
(hostname, username string)
| 483 | // Logout will remove user, git protocol, and auth token for the given hostname. |
| 484 | // It will remove the auth token from the encrypted storage if it exists there. |
| 485 | func (c *AuthConfig) Logout(hostname, username string) error { |
| 486 | users := c.UsersForHost(hostname) |
| 487 | |
| 488 | // If there is only one (or zero) users, then we remove the host |
| 489 | // and unset the keyring tokens. |
| 490 | if len(users) < 2 { |
| 491 | _ = c.cfg.Remove([]string{hostsKey, hostname}) |
| 492 | _ = keyring.Delete(keyringServiceName(hostname), "") |
| 493 | _ = keyring.Delete(keyringServiceName(hostname), username) |
| 494 | return ghConfig.Write(c.cfg) |
| 495 | } |
| 496 | |
| 497 | // Otherwise, we remove the user from this host |
| 498 | _ = c.cfg.Remove([]string{hostsKey, hostname, usersKey, username}) |
| 499 | |
| 500 | // This error is ignorable because we already know there is an active user for the host |
| 501 | activeUser, _ := c.ActiveUser(hostname) |
| 502 | |
| 503 | // If the user we're removing isn't active, then we just write the config |
| 504 | if activeUser != username { |
| 505 | return ghConfig.Write(c.cfg) |
| 506 | } |
| 507 | |
| 508 | // Otherwise we get the first user in the slice that isn't the user we're removing |
| 509 | switchUserIdx := slices.IndexFunc(users, func(n string) bool { |
| 510 | return n != username |
| 511 | }) |
| 512 | |
| 513 | // And activate them |
| 514 | return c.activateUser(hostname, users[switchUserIdx]) |
| 515 | } |
| 516 | |
| 517 | func (c *AuthConfig) activateUser(hostname, user string) error { |
| 518 | // We first need to idempotently clear out any set tokens for the host |
nothing calls this directly
no test coverage detected