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

Function writeJSONConfig

internal/mcp/install.go:357–379  ·  view source on GitHub ↗
(path string, cfg map[string]any)

Source from the content-addressed store, hash-verified

355}
356
357func writeJSONConfig(path string, cfg map[string]any) error {
358 if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
359 return fmt.Errorf("mkdir %s: %w", filepath.Dir(path), err)
360 }
361 b, err := json.MarshalIndent(cfg, "", " ")
362 if err != nil {
363 return fmt.Errorf("marshal config: %w", err)
364 }
365 // 0o600 — config files often hold credentials for OTHER MCP
366 // servers (postgres URIs, OpenAI keys, etc.); tighten perms even
367 // though pad's own entry has no secrets.
368 //
369 // os.WriteFile only honors the mode when CREATING the file — an
370 // existing 0644 config keeps 0644 after the write (TASK-948),
371 // so we Chmod after writing. Best-effort:
372 // chmod failures don't fail the install (the data write
373 // succeeded; the user can re-tighten manually).
374 if err := os.WriteFile(path, append(b, '\n'), 0o600); err != nil {
375 return fmt.Errorf("write %s: %w", path, err)
376 }
377 tightenPerms(path)
378 return nil
379}
380
381// jsonEqual compares two parsed-JSON maps for value equality. Cheaper
382// than reflect.DeepEqual and accepts the float/string nuances of

Callers 2

addPadEntryJSONFunction · 0.85
RemovePadEntryFunction · 0.85

Calls 2

appendFunction · 0.85
tightenPermsFunction · 0.85

Tested by

no test coverage detected