Skip to content

Commit

Permalink
refactor(cu): allow WALLET and WALLET_FILE, WALLET taking precendent
Browse files Browse the repository at this point in the history
  • Loading branch information
TillaTheHun0 committed Sep 4, 2024
1 parent 7465389 commit d370474
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions servers/cu/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,18 @@ const serverConfigSchema = domainConfigSchema.extend({
/* eslint-disable no-throw-literal */

/**
* If the WALLET_FILE env var is defined, load the contents from the file.
* Refuse to boot the app if both or none of WALLET and WALLET_FILE are defined.
* If the WALLET is defined, then do nothing.
*
* Otherwise, check whether the WALLET_FILE env var is defined and load it contents
* as WALLET
*/
export const preprocessWallet = (envConfig) => {
const { WALLET, WALLET_FILE, ...theRestOfTheConfig } = envConfig

// nothing to do here
if (!!WALLET && !WALLET_FILE) return envConfig
// WALLET takes precendent. nothing to do here
if (WALLET) return envConfig

if (!WALLET && !WALLET_FILE) throw 'One of WALLET or WALLET_FILE is required'
if (!!WALLET && !!WALLET_FILE) throw 'Do not define both WALLET and WALLET_FILE'

const walletPath = path.resolve(WALLET_FILE)
if (!existsSync(walletPath)) throw `WALLET_FILE does not exist: ${walletPath}`
Expand Down

0 comments on commit d370474

Please sign in to comment.