@asymmetrik/yadda-secret
Advanced tools
Comparing version 0.0.8 to 0.0.9
@@ -22,3 +22,4 @@ 'use strict'; | ||
kmsKey: module.exports.getSecretKMSAlias(), | ||
kmsRegion: module.exports.getSecretKMSRegion() | ||
kmsRegion: module.exports.getSecretKMSRegion(), | ||
cacheBuster: module.exports.getSecretCacheBusterKey() | ||
}); | ||
@@ -41,2 +42,3 @@ | ||
module.exports.getSecretKMSRegion = env.getSecretKMSRegion; | ||
module.exports.getSecretCacheBusterKey = env.getSecretCacheBusterKey; | ||
@@ -43,0 +45,0 @@ module.exports.generateSecretKey = require('./src/lib/secretGen'); |
{ | ||
"name": "@asymmetrik/yadda-secret", | ||
"description": "Client secret library", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"main": "index.js", | ||
@@ -6,0 +6,0 @@ "author": "contributors", |
@@ -26,2 +26,3 @@ ## Yadda-Secret | ||
- `__YADDA__DEPLOYMENT_SECRET_REGION__`: The region the KMS key resides in (optional) | ||
- `__YADDA__DEPLOYMENT_SECRET_CACHE_BUSTER_KEY__`: The key for the cache buster secret (optional) | ||
@@ -28,0 +29,0 @@ Developers using this tool will not need access to the CMK but the resulting deployed container will need |
@@ -7,2 +7,3 @@ 'use strict'; | ||
module.exports.getSecretKMSAlias = function(){ return process.env.__YADDA__DEPLOYMENT_SECRET_KMSALIAS__ || null }; | ||
module.exports.getSecretKMSRegion = function(){ return process.env.__YADDA__DEPLOYMENT_SECRET_REGION__ || process.env.__YADDA__DEPLOYMENT_SECRET_TABLE_REGION__ || null }; | ||
module.exports.getSecretKMSRegion = function(){ return process.env.__YADDA__DEPLOYMENT_SECRET_REGION__ || process.env.__YADDA__DEPLOYMENT_SECRET_TABLE_REGION__ || null }; | ||
module.exports.getSecretCacheBusterKey = function(){ return process.env.__YADDA__DEPLOYMENT_SECRET_CACHE_BUSTER_KEY__ || null }; |
@@ -17,2 +17,10 @@ 'use strict'; | ||
if(options.cacheBuster) { | ||
// check the cache buster key every minute | ||
const cacheBusterKey = options.cacheBuster; | ||
setInterval(() => { | ||
this.getSecret({name: cacheBusterKey}).then(secret => this.cacheRefreshTime = Number(secret)); | ||
}, 60000); | ||
delete options.cacheBuster; | ||
} | ||
this.options = options; | ||
@@ -34,4 +42,9 @@ this.store = new Credstash(options); | ||
if(key in this.cache) | ||
return void resolve(this.cache[key]); | ||
if(key in this.cache) { | ||
// doing a less than comparison for a time to a null/undefined value will be false | ||
if(this.cache[key].timestamp < this.cacheRefreshTime) | ||
delete this.cache[key]; | ||
else | ||
return void resolve(this.cache[key].value); | ||
} | ||
@@ -44,3 +57,9 @@ //Can't return this as it's not interpreted as a promise... | ||
}) | ||
.then(secret => resolve(this.cache[key] = secret)) | ||
.then((secret) => { | ||
this.cache[key] = { | ||
timestamp: Date.now(), | ||
value: secret | ||
}; | ||
resolve(secret); | ||
}) | ||
.catch(err => reject(err)); | ||
@@ -47,0 +66,0 @@ }); |
@@ -34,5 +34,5 @@ 'use strict'; | ||
const { region, table, kmsKey, kmsRegion } = this.options; | ||
const { region, table, kmsKey, kmsRegion, cacheBuster } = this.options; | ||
if(region && table) | ||
this.store = new SecretStore({ table, awsOpts: { region }, kmsOpts: { region: kmsRegion }, kmsKey }); | ||
this.store = new SecretStore({ table, awsOpts: { region }, kmsOpts: { region: kmsRegion }, kmsKey, cacheBuster }); | ||
else { | ||
@@ -39,0 +39,0 @@ console.warn('region and table are not defined!'); |
14981
228
126