| 195 | } |
| 196 | |
| 197 | func 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 | |
| 222 | func keyringServiceName(hostname string) string { |
| 223 | return "gh:" + hostname |