node-convict
node-convict copied to clipboard
Use Promises with coerce
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.
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.