Skip to content

Commit

Permalink
fix(core): variable in config (#11548)
Browse files Browse the repository at this point in the history
* fix(core): variable in config

* clean

* remove dupe code
  • Loading branch information
allardy committed Mar 7, 2022
1 parent e28ebb4 commit 5052058
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 18 deletions.
5 changes: 5 additions & 0 deletions packages/bp/src/core/config/config-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,11 @@ export class ConfigProvider {
content = content.replace('"$isProduction"', process.IS_PRODUCTION ? 'true' : 'false')
content = content.replace('"$isDevelopment"', process.IS_PRODUCTION ? 'false' : 'true')

const vars = content.match(/%([a-zA-Z0-9_]+)%/gim)
vars?.forEach(varName => {
content = content.replace(varName, getValueFromEnvKey(varName.replace(/%/g, '')))
})

return <T>JSON.parse(content)
} catch (e) {
throw new FatalError(e, `Error reading configuration file "${fileName}"`)
Expand Down
18 changes: 0 additions & 18 deletions packages/bp/src/core/messaging/messaging-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,24 +125,6 @@ export class MessagingService {
: // We set a dummy webhook to get back a webhook token. The actual url that will be called is SPINNED_URL
'http://dummy.com'

// Fill env variables into bot messages.channels using template:
// %MY_ENV_VAR%
if (messaging.channels) {
messaging.channels = Object.keys(messaging.channels).reduce((newChannels, chKey) => {
const { channels } = messaging as any // @ts-hack, channels will exist because of conditional above
newChannels[chKey] = Object.keys(channels[chKey]).reduce((channel, key) => {
const value: string = channels[chKey][key]
if (typeof value === 'string') {
channel[key] = value.match(/^%.*%$/) ? process.env[value.replace(/%/g, '')] || value : value
} else {
channel[key] = value
}
return channel
}, {})
return newChannels
}, {})
}

const setupConfig = {
channels: messaging.channels,
webhooks: [{ url: webhookUrl }]
Expand Down

0 comments on commit 5052058

Please sign in to comment.