migrateOldCredentials migrates credentials from the old config.json format to the new credential store (keyring or credentials.json).
(_ string)
| 172 | } |
| 173 | |
| 174 | // migrateOldCredentials migrates credentials from the old config.json format |
| 175 | // to the new credential store (keyring or credentials.json). |
| 176 | func migrateOldCredentials(_ string) { |
| 177 | old, err := config.LoadOld() |
| 178 | if err != nil { |
| 179 | return |
| 180 | } |
| 181 | |
| 182 | if old.AccessToken == "" && old.SessionCookie == "" { |
| 183 | return |
| 184 | } |
| 185 | |
| 186 | store := authMgr.GetStore() |
| 187 | credKey := authMgr.CredentialKey() |
| 188 | |
| 189 | if _, err := store.Load(credKey); err == nil { |
| 190 | return |
| 191 | } |
| 192 | |
| 193 | creds := &auth.Credentials{ |
| 194 | AccessToken: old.AccessToken, |
| 195 | RefreshToken: old.RefreshToken, |
| 196 | } |
| 197 | if old.TokenExpiry > 0 { |
| 198 | creds.ExpiresAt = old.TokenExpiry |
| 199 | } |
| 200 | if old.SessionCookie != "" { |
| 201 | creds.SessionCookie = old.SessionCookie |
| 202 | } |
| 203 | |
| 204 | if err := store.Save(credKey, creds); err != nil { |
| 205 | fmt.Fprintf(os.Stderr, "warning: could not migrate credentials: %v\n", err) |
| 206 | return |
| 207 | } |
| 208 | |
| 209 | if err := cfg.Save(); err != nil { |
| 210 | fmt.Fprintf(os.Stderr, "warning: could not update config after migration: %v\n", err) |
| 211 | } |
| 212 | |
| 213 | fmt.Fprintln(os.Stderr, "notice: credentials migrated from config.json to credential store") |
| 214 | } |
| 215 |
no test coverage detected