ekmartin / slack-irc

Connects Slack and IRC channels by sending messages back and forth.
MIT License
588 stars 157 forks source link

Allow for env vars for config.json secrets at runtime #138

Closed filler closed 7 years ago

filler commented 8 years ago

In support of making things more shareable and more like a 12-factor app, it would be great to be able to pass in some bits from config.json at runtime as opposed to flat-file. This could include secrets like the slack token, any SASL creds. Also any site-specificity in terms of channel maps, botnicks, etc.

Doing this would allow someone who Docker-ize's the app to pass in environment variables at runtime, keeping them out of config.json, making the code more 'shareable' and less of risk should it be compromised.

Looking over my existing config.json, I would love to externalize the following:

nickname
server
token
channelMapping{}
ircOptions.nick
ircOptions.userName
ircOptions.saslUserName
ircOptions.password

My node-fu is pretty weak, but it looks like this isnt possible now. If it is, please do let me know!

Thanks for this awesome project. 👍 💯 ✨ 🌟

ekmartin commented 8 years ago

Hi, and thanks for the kind words!

slack-irc was actually configured solely with environment variables in the beginning, but I changed it when channel mappings and similar were introduced, as it quickly got quite complex. I've thought of allowing the configuration to be passed in through one large env variable before, i.e. something like JSON_CONFIG="{"nickname": "nick, "server": "irc.freenode.net", ... }".

However, if you don't mind adding an extra file to your Docker image this can be done today by using a JS config file, instead of JSON: Example:

module.exports = {
    nickname: process.env.NICKNAME,
    server: process.env.IRC_SERVER,
    token: process.env.SLACK_TOKEN,
    channelMapping: JSON.parse(process.env.CHANNEL_MAPPING), // pass the mapping as a JSON string
    ircOptions: JSON.parse(process.env.IRC_OPTIONS) // or create specific env variables for the underlying options
};