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

Method Save

internal/cli/credentials.go:209–233  ·  view source on GitHub ↗

Save writes the store to disk in v2 format with mode 0600. Always writes the current version constant — even if the store was loaded from v1, this is the migration moment.

()

Source from the content-addressed store, hash-verified

207// writes the current version constant — even if the store was loaded
208// from v1, this is the migration moment.
209func (s *CredentialStore) Save() error {
210 path, err := credentialsPath()
211 if err != nil {
212 return err
213 }
214
215 if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
216 return fmt.Errorf("create credentials directory: %w", err)
217 }
218
219 s.Version = credentialsVersion
220 if s.Credentials == nil {
221 s.Credentials = map[string]*Credentials{}
222 }
223
224 data, err := json.MarshalIndent(s, "", " ")
225 if err != nil {
226 return fmt.Errorf("marshal credentials: %w", err)
227 }
228
229 if err := os.WriteFile(path, data, 0600); err != nil {
230 return fmt.Errorf("write credentials: %w", err)
231 }
232 return nil
233}
234
235// WipeCredentialsFile removes ~/.pad/credentials.json entirely. Distinct
236// from CredentialStore.Delete (which removes a single server's entry)

Calls 1

credentialsPathFunction · 0.85

Tested by 1