| 203 | } |
| 204 | |
| 205 | func 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 | |
| 229 | func keyringServiceName(hostname string) string { |
| 230 | return "gh:" + hostname |