Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Process values on initialization #21

Closed
codev0 opened this issue Oct 3, 2019 · 2 comments
Closed

Process values on initialization #21

codev0 opened this issue Oct 3, 2019 · 2 comments

Comments

@codev0
Copy link

codev0 commented Oct 3, 2019

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?

@kerimdzhanov
Copy link
Owner

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.

@kerimdzhanov
Copy link
Owner

dotenv-processor could be a good name for the plugin 😉.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants