feat(awm): backup awm client configurations#196
feat(awm): backup awm client configurations#196margueriteblair wants to merge 1 commit intomasterfrom
Conversation
f94534e to
059e29d
Compare
e39a781 to
9e0531d
Compare
| // Handle cert loading for backup AWM (only when backup URL is configured) | ||
| if (config.advancedWalletManagerBackupUrl) { | ||
| if (config.awmBackupServerCaCertPath) { | ||
| try { | ||
| if (fs.existsSync(config.awmBackupServerCaCertPath)) { | ||
| config.awmBackupServerCaCert = fs.readFileSync(config.awmBackupServerCaCertPath, 'utf-8'); | ||
| logger.info( | ||
| `✓ AWM backup server CA certificate loaded from file: ${config.awmBackupServerCaCertPath?.substring( | ||
| 0, | ||
| 50, | ||
| )}...`, | ||
| ); | ||
| } else { | ||
| throw new Error(`Certificate file not found: ${config.awmBackupServerCaCertPath}`); | ||
| } | ||
| } catch (e) { | ||
| const err = e instanceof Error ? e : new Error(String(e)); | ||
| throw new Error(`Failed to read AWM backup server CA cert: ${err.message}`); | ||
| } | ||
| } | ||
|
|
||
| if (config.awmBackupClientTlsKeyPath) { | ||
| try { | ||
| config.awmBackupClientTlsKey = fs.readFileSync(config.awmBackupClientTlsKeyPath, 'utf-8'); | ||
| logger.info( | ||
| `✓ AWM backup client key loaded from file: ${config.awmBackupClientTlsKeyPath}`, | ||
| ); | ||
| } catch (e) { | ||
| const err = e instanceof Error ? e : new Error(String(e)); | ||
| throw new Error(`Failed to read AWM backup client key: ${err.message}`); | ||
| } | ||
| } | ||
|
|
||
| if (config.awmBackupClientTlsCertPath) { | ||
| try { | ||
| config.awmBackupClientTlsCert = fs.readFileSync(config.awmBackupClientTlsCertPath, 'utf-8'); | ||
| logger.info( | ||
| `✓ AWM backup client certificate loaded from file: ${config.awmBackupClientTlsCertPath}`, | ||
| ); | ||
| } catch (e) { | ||
| const err = e instanceof Error ? e : new Error(String(e)); | ||
| throw new Error(`Failed to read AWM backup client cert: ${err.message}`); | ||
| } | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
the cert loading block for backup AWM is a near-copy of the primary cert loading above. could extract a small helper like loadCertFromPath(path, label) to avoid the duplication.
There was a problem hiding this comment.
not impl lol. wont block on it - can do in a followup
c58c1a2 to
07d8951
Compare
| return undefined; | ||
| } | ||
| try { | ||
| const backupConfig: MasterExpressConfig = { |
There was a problem hiding this comment.
so with this setup, it it currently possible to have fields (keys or certs) from two different instances, for example key from main client, and cert from backup - we should enforce that it's all or nothing, no? As in, either they use backup fields for all of the config or none of it. Intermixing the two will lead to random state.
There was a problem hiding this comment.
Maybe we can add validation to the starting point of the app, the configureMasterExpressMode() maybe? For the fields that need to move together, perhaps smth like:
if (config.awmBackupClientTlsKey && !config.awmBackupClientTlsCert) {
throw new Error('backup key and cert must both exist');
}
...
There was a problem hiding this comment.
Hm, yeah I'd agree with this - either provide the appropriate certs for the backup instance, or nothing
07d8951 to
233fef6
Compare
| // Handle cert loading for backup AWM (only when backup URL is configured) | ||
| if (config.advancedWalletManagerBackupUrl) { | ||
| if (config.awmBackupServerCaCertPath) { | ||
| try { | ||
| if (fs.existsSync(config.awmBackupServerCaCertPath)) { | ||
| config.awmBackupServerCaCert = fs.readFileSync(config.awmBackupServerCaCertPath, 'utf-8'); | ||
| logger.info( | ||
| `✓ AWM backup server CA certificate loaded from file: ${config.awmBackupServerCaCertPath?.substring( | ||
| 0, | ||
| 50, | ||
| )}...`, | ||
| ); | ||
| } else { | ||
| throw new Error(`Certificate file not found: ${config.awmBackupServerCaCertPath}`); | ||
| } | ||
| } catch (e) { | ||
| const err = e instanceof Error ? e : new Error(String(e)); | ||
| throw new Error(`Failed to read AWM backup server CA cert: ${err.message}`); | ||
| } | ||
| } | ||
|
|
||
| if (config.awmBackupClientTlsKeyPath) { | ||
| try { | ||
| config.awmBackupClientTlsKey = fs.readFileSync(config.awmBackupClientTlsKeyPath, 'utf-8'); | ||
| logger.info( | ||
| `✓ AWM backup client key loaded from file: ${config.awmBackupClientTlsKeyPath}`, | ||
| ); | ||
| } catch (e) { | ||
| const err = e instanceof Error ? e : new Error(String(e)); | ||
| throw new Error(`Failed to read AWM backup client key: ${err.message}`); | ||
| } | ||
| } | ||
|
|
||
| if (config.awmBackupClientTlsCertPath) { | ||
| try { | ||
| config.awmBackupClientTlsCert = fs.readFileSync(config.awmBackupClientTlsCertPath, 'utf-8'); | ||
| logger.info( | ||
| `✓ AWM backup client certificate loaded from file: ${config.awmBackupClientTlsCertPath}`, | ||
| ); | ||
| } catch (e) { | ||
| const err = e instanceof Error ? e : new Error(String(e)); | ||
| throw new Error(`Failed to read AWM backup client cert: ${err.message}`); | ||
| } | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
not impl lol. wont block on it - can do in a followup
| // Create backup client if backup URL is configured; falls back to primary client | ||
| try { | ||
| const awmBackupClient = createAwmBackupClient(bitgoReq.config, bitgoReq.params?.coin); | ||
| bitgoReq.awmBackupClient = awmBackupClient ?? awmClient; |
There was a problem hiding this comment.
Might be worth noting this in the README that we fall back to the default
pranishnepal
left a comment
There was a problem hiding this comment.
LGTM, though you might need to update some tests
Ticket: WCN-362