kerimdzhanov/dotenv-flow

Process values on initialization

codev0 opened this issue ยท 2 comments

Hi there,

In my case I need to decode values of env variables through symmetric encryption, cause store passwords in open kind is bad in other side we can't use vault or other secret storage yet (inner infrastructure doesn't ready), so we pass the password from outsite.

Example:

// .env.production
DB_PASSWORD=ENV(96b69e27a5b662b0b98222a424485a35 ) // encrypted
// main.js
const dotenvFlow = require('dotenv-flow');
const decode = requre('decode');

const password = process.env.DOCKER_ENV_PASSWORD // Passed from outside

dotenvFlow.config({
  process: function(key, value) {
    return {
      key: decode(value.match(/\((.*)\)/).pop(), password);
    }
  }
});

What about this feature? Does it possible to do PR?

Assalamu alaikum @codev0,

It sounds like a good plugin for the module, I think.

Your idea reminded me the dotenv-expand plugin that does something like string interpolation in context of environment variables. But in your case I see that you're doing something like a function call (ENV(96b...)), and it looks like we may have a plugin that would allow us to register any function like ENV() or decrypt(), or maybe even boolean(), integer() or json(), then apply them appropriately when we have an environment variable value that matches a "function call expression" (smth. like /^\w+\((.*)\)$/).

Take a look at the implementation of dotenv-expand, it is fully compatible with both dotenv and dotenv-flow modules, so I think it is a good idea to design dotenv-* plugins this way.

dotenv-processor could be a good name for the plugin ๐Ÿ˜‰.