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)
| 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. |
| 57 | func (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 | } |
no test coverage detected