parseStore parses a non-empty credentials file, v1 or v2.
(data []byte)
| 259 | |
| 260 | // parseStore parses a non-empty credentials file, v1 or v2. |
| 261 | func parseStore(data []byte) (*CredentialStore, error) { |
| 262 | |
| 263 | // Detect format. v1 has a top-level `token` string; v2 has a |
| 264 | // top-level `credentials` object. Probe with a generic map so a |
| 265 | // garbage file fails loudly here rather than silently parsing as |
| 266 | // "empty v2." |
| 267 | var probe map[string]json.RawMessage |
| 268 | if err := json.Unmarshal(data, &probe); err != nil { |
| 269 | return nil, fmt.Errorf("parse credentials: %w", err) |
| 270 | } |
| 271 | if _, hasToken := probe["token"]; hasToken { |
| 272 | return migrateV1(data) |
| 273 | } |
| 274 | return parseV2(data) |
| 275 | } |
| 276 | |
| 277 | // migrateV1 reads a v1 single-blob file and returns an in-memory v2 store |
| 278 | // keyed by the legacy ServerURL. A v1 file with an empty server_url is |