MCPcopy
hub / github.com/pocketbase/pocketbase / loadParam

Method loadParam

core/settings_query.go:57–88  ·  view source on GitHub ↗

loadParam loads the settings from the stored param into the app ones. @todo note that the encryption may get removed in the future since it doesn't really accomplish much and it might be better to find a way to encrypt the backups or implement support for resolving env variables.

(app App, param *Param)

Source from the content-addressed store, hash-verified

55// really accomplish much and it might be better to find a way to encrypt the backups
56// or implement support for resolving env variables.
57func (s *Settings) loadParam(app App, param *Param) error {
58 // try first without decryption
59 s.mu.Lock()
60 plainDecodeErr := json.Unmarshal(param.Value, s)
61 s.mu.Unlock()
62
63 // failed, try to decrypt
64 if plainDecodeErr != nil {
65 encryptionKey := os.Getenv(app.EncryptionEnv())
66
67 // load without decryption has failed and there is no encryption key to use for decrypt
68 if encryptionKey == "" {
69 return fmt.Errorf("invalid settings db data or missing encryption key %q", app.EncryptionEnv())
70 }
71
72 // decrypt
73 decrypted, decryptErr := security.Decrypt(string(param.Value), encryptionKey)
74 if decryptErr != nil {
75 return decryptErr
76 }
77
78 // decode again
79 s.mu.Lock()
80 decryptedDecodeErr := json.Unmarshal(decrypted, s)
81 s.mu.Unlock()
82 if decryptedDecodeErr != nil {
83 return decryptedDecodeErr
84 }
85 }
86
87 return s.PostScan()
88}

Callers 1

ReloadSettingsMethod · 0.80

Calls 3

PostScanMethod · 0.95
DecryptFunction · 0.92
EncryptionEnvMethod · 0.65

Tested by

no test coverage detected