node-convict icon indicating copy to clipboard operation
node-convict copied to clipboard

Use Promises with coerce

Open ihachani opened this issue 6 years ago • 1 comments

Hi, I am trying to use coerce with an async function to decrypt some values on KMS.

convict.addFormat({
  name: 'secret',
  validate: val => {
    return typeof val !== 'undefined';
  },
  coerce:  val => {
    return Promise.resolve(val + 'decrypted');
  },
});

When I try to get the config config.get('key').then() I get then is not a function And if I try with await

const secret = await config.get('key');
console.log(secret);

I get {} as the value.

What I want to do is to decrypt values when you read them from the file.

ihachani avatar Aug 05 '19 10:08 ihachani

I'd love this too as I'm doing a small hack using 'coerce' to take a value as a key in a lookup in AWS SecretsManager.. which obviously needs an await.

Actually what I want is convict, when calling coerce, to check if it's a promise and call await on it.

gjbaxter avatar Sep 14 '22 00:09 gjbaxter