MCPcopy Create free account
hub / github.com/PerpetualSoftware/pad / parseStore

Function parseStore

internal/cli/credentials.go:263–277  ·  view source on GitHub ↗

parseStore parses a non-empty credentials file, v1 or v2.

(data []byte)

Source from the content-addressed store, hash-verified

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

Callers 3

loadStoreLockedFunction · 0.85
loadStoreUnlockedFunction · 0.85

Calls 2

migrateV1Function · 0.85
parseV2Function · 0.85