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

Method activateUser

internal/config/config.go:460–491  ·  view source on GitHub ↗
(hostname, user string)

Source from the content-addressed store, hash-verified

458}
459
460func (c *AuthConfig) activateUser(hostname, user string) error {
461 // We first need to idempotently clear out any set tokens for the host
462 _ = keyring.Delete(keyringServiceName(hostname), "")
463 _ = c.cfg.Remove([]string{hostsKey, hostname, oauthTokenKey})
464
465 // Then we'll move the keyring token or insecure token as necessary, only one of the
466 // following branches should be true.
467
468 // If there is a token in the secure keyring for the user, move it to the active slot
469 var tokenSwitched bool
470 if token, err := keyring.Get(keyringServiceName(hostname), user); err == nil {
471 if err = keyring.Set(keyringServiceName(hostname), "", token); err != nil {
472 return fmt.Errorf("failed to move active token in keyring: %v", err)
473 }
474 tokenSwitched = true
475 }
476
477 // If there is a token in the insecure config for the user, move it to the active field
478 if token, err := c.cfg.Get([]string{hostsKey, hostname, usersKey, user, oauthTokenKey}); err == nil {
479 c.cfg.Set([]string{hostsKey, hostname, oauthTokenKey}, token)
480 tokenSwitched = true
481 }
482
483 if !tokenSwitched {
484 return fmt.Errorf("no token found for %s", user)
485 }
486
487 // Then we'll update the active user for the host
488 c.cfg.Set([]string{hostsKey, hostname, userKey}, user)
489
490 return ghConfig.Write(c.cfg)
491}
492
493func (c *AuthConfig) UsersForHost(hostname string) []string {
494 users, err := c.cfg.Keys([]string{hostsKey, hostname, usersKey})

Callers 3

LoginMethod · 0.95
SwitchUserMethod · 0.95
LogoutMethod · 0.95

Calls 9

DeleteFunction · 0.92
GetFunction · 0.92
SetFunction · 0.92
keyringServiceNameFunction · 0.70
RemoveMethod · 0.65
ErrorfMethod · 0.65
GetMethod · 0.65
SetMethod · 0.65
WriteMethod · 0.65

Tested by

no test coverage detected