MCPcopy Index your code
hub / github.com/cli/cli / Logout

Method Logout

internal/config/config.go:428–458  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

426// Logout will remove user, git protocol, and auth token for the given hostname.
427// It will remove the auth token from the encrypted storage if it exists there.
428func (c *AuthConfig) Logout(hostname, username string) error {
429 users := c.UsersForHost(hostname)
430
431 // If there is only one (or zero) users, then we remove the host
432 // and unset the keyring tokens.
433 if len(users) < 2 {
434 _ = c.cfg.Remove([]string{hostsKey, hostname})
435 _ = keyring.Delete(keyringServiceName(hostname), "")
436 _ = keyring.Delete(keyringServiceName(hostname), username)
437 return ghConfig.Write(c.cfg)
438 }
439
440 // Otherwise, we remove the user from this host
441 _ = c.cfg.Remove([]string{hostsKey, hostname, usersKey, username})
442
443 // This error is ignorable because we already know there is an active user for the host
444 activeUser, _ := c.ActiveUser(hostname)
445
446 // If the user we're removing isn't active, then we just write the config
447 if activeUser != username {
448 return ghConfig.Write(c.cfg)
449 }
450
451 // Otherwise we get the first user in the slice that isn't the user we're removing
452 switchUserIdx := slices.IndexFunc(users, func(n string) bool {
453 return n != username
454 })
455
456 // And activate them
457 return c.activateUser(hostname, users[switchUserIdx])
458}
459
460func (c *AuthConfig) activateUser(hostname, user string) error {
461 // We first need to idempotently clear out any set tokens for the host

Callers

nothing calls this directly

Calls 7

UsersForHostMethod · 0.95
ActiveUserMethod · 0.95
activateUserMethod · 0.95
DeleteFunction · 0.92
keyringServiceNameFunction · 0.70
RemoveMethod · 0.65
WriteMethod · 0.65

Tested by

no test coverage detected