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

Function migrateConfig

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

Source from the content-addressed store, hash-verified

195}
196
197func migrateConfig(c *config.Config, hostname, username string) error {
198 // Set the user key in case it was previously an anonymous user.
199 c.Set(append(hostsKey, hostname, "user"), username)
200 // Create the username key with an empty value so it will be
201 // written even if there are no keys set under it.
202 c.Set(append(hostsKey, hostname, "users", username), "")
203
204 insecureToken, err := c.Get(append(hostsKey, hostname, "oauth_token"))
205 var keyNotFoundError *config.KeyNotFoundError
206 // If there is no token then we're done here
207 if errors.As(err, &keyNotFoundError) {
208 return nil
209 }
210
211 // If there's another error (current implementation doesn't have any other error but we'll be defensive)
212 // then bubble something up.
213 if err != nil {
214 return fmt.Errorf("couldn't get oauth token for %s: %s", hostname, err)
215 }
216
217 // Otherwise we'll set the token under the new key
218 c.Set(append(hostsKey, hostname, "users", username, "oauth_token"), insecureToken)
219 return nil
220}
221
222func keyringServiceName(hostname string) string {
223 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