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

Function migrateConfig

internal/config/migration/multi_account.go:205–227  ·  view source on GitHub ↗
(c *config.Config, hostname, username string)

Source from the content-addressed store, hash-verified

203}
204
205func migrateConfig(c *config.Config, hostname, username string) error {
206 // Set the user key in case it was previously an anonymous user.
207 c.Set(append(hostsKey, hostname, "user"), username)
208 // Create the username key with an empty value so it will be
209 // written even if there are no keys set under it.
210 c.Set(append(hostsKey, hostname, "users", username), "")
211
212 insecureToken, err := c.Get(append(hostsKey, hostname, "oauth_token"))
213 // If there is no token then we're done here
214 if _, ok := errors.AsType[*config.KeyNotFoundError](err); ok {
215 return nil
216 }
217
218 // If there's another error (current implementation doesn't have any other error but we'll be defensive)
219 // then bubble something up.
220 if err != nil {
221 return fmt.Errorf("couldn't get oauth token for %s: %s", hostname, err)
222 }
223
224 // Otherwise we'll set the token under the new key
225 c.Set(append(hostsKey, hostname, "users", username, "oauth_token"), insecureToken)
226 return nil
227}
228
229func keyringServiceName(hostname string) string {
230 return "gh:" + hostname

Callers 1

DoMethod · 0.85

Calls 3

SetMethod · 0.65
GetMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected