MCPcopy Create free account
hub / github.com/cli/cli / activateUser

Method activateUser

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

Source from the content-addressed store, hash-verified

521}
522
523func (c *AuthConfig) activateUser(hostname, user string) error {
524 // We first need to idempotently clear out any set tokens for the host
525 _ = keyring.Delete(keyringServiceName(hostname), "")
526 _ = c.cfg.Remove([]string{hostsKey, hostname, oauthTokenKey})
527
528 // Then we'll move the keyring token or insecure token as necessary, only one of the
529 // following branches should be true.
530
531 // If there is a token in the secure keyring for the user, move it to the active slot
532 var tokenSwitched bool
533 if token, err := keyring.Get(keyringServiceName(hostname), user); err == nil {
534 if err = keyring.Set(keyringServiceName(hostname), "", token); err != nil {
535 return fmt.Errorf("failed to move active token in keyring: %v", err)
536 }
537 tokenSwitched = true
538 }
539
540 // If there is a token in the insecure config for the user, move it to the active field
541 if token, err := c.cfg.Get([]string{hostsKey, hostname, usersKey, user, oauthTokenKey}); err == nil {
542 c.cfg.Set([]string{hostsKey, hostname, oauthTokenKey}, token)
543 tokenSwitched = true
544 }
545
546 if !tokenSwitched {
547 return fmt.Errorf("no token found for %s", user)
548 }
549
550 // Then we'll update the active user for the host
551 c.cfg.Set([]string{hostsKey, hostname, userKey}, user)
552
553 return ghConfig.Write(c.cfg)
554}
555
556func (c *AuthConfig) UsersForHost(hostname string) []string {
557 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