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

Function parseStore

internal/cli/credentials.go:261–275  ·  view source on GitHub ↗

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

(data []byte)

Source from the content-addressed store, hash-verified

259
260// parseStore parses a non-empty credentials file, v1 or v2.
261func 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

Callers 3

loadStoreLockedFunction · 0.85
loadStoreUnlockedFunction · 0.85

Calls 2

migrateV1Function · 0.85
parseV2Function · 0.85