config-dug
Advanced tools
Comparing version 1.5.0 to 1.6.0
@@ -13,3 +13,3 @@ "use strict"; | ||
const get_secret_1 = __importDefault(require("./get-secret")); | ||
const validate_config_1 = __importDefault(require("./validate-config")); | ||
const validate_config_1 = require("./validate-config"); | ||
const debug = debug_1.default('config-dug'); | ||
@@ -62,22 +62,27 @@ const resolveFile = (appDirectory, configPath, fileName) => { | ||
const loadSecrets = (config) => { | ||
const secretNames = config.AWS_SECRETS_MANAGER_NAMES || config.awsSecretsManagerNames; | ||
const secretName = config.AWS_SECRETS_MANAGER_NAME || config.awsSecretsManagerName; | ||
const region = config.AWS_SECRETS_MANAGER_REGION || config.awsSecretsManagerRegion || 'us-east-1'; | ||
const timeout = config.AWS_SECRETS_MANAGER_TIMEOUT || config.awsSecretsManagerTimeout || 5000; | ||
const mergedSecretNames = new Set(); | ||
if (secretName) { | ||
const secrets = convertToArray(secretName).map(name => { | ||
debug('loading config from AWS Secrets Manager', name, region); | ||
return get_secret_1.default(name, region, timeout); | ||
mergedSecretNames.add(secretName); | ||
} | ||
if (secretNames) { | ||
convertToArray(secretNames).forEach(secretName => { | ||
mergedSecretNames.add(secretName); | ||
}); | ||
const mergedSecrets = {}; | ||
secrets.forEach(secret => { | ||
Object.assign(mergedSecrets, secret); | ||
}); | ||
return Object.entries(mergedSecrets).reduce((result, [key, value]) => { | ||
result[key] = convertString(value); | ||
return result; | ||
}, {}); | ||
} | ||
else { | ||
return {}; | ||
} | ||
const secrets = [...mergedSecretNames].map(name => { | ||
debug('loading config from AWS Secrets Manager', name, region); | ||
return get_secret_1.default(name, region, timeout); | ||
}); | ||
const mergedSecrets = {}; | ||
secrets.forEach(secret => { | ||
Object.assign(mergedSecrets, secret); | ||
}); | ||
return Object.entries(mergedSecrets).reduce((result, [key, value]) => { | ||
result[key] = convertString(value); | ||
return result; | ||
}, {}); | ||
}; | ||
@@ -105,3 +110,8 @@ const loadEnvironment = () => { | ||
const config = Object.assign({}, fileConfig, loadSecrets(fileConfig), loadEnvironment()); | ||
return validate_config_1.default(config); | ||
if (environment === 'test') { | ||
return config; | ||
} | ||
else { | ||
return validate_config_1.validateConfig(config); | ||
} | ||
}; | ||
@@ -108,0 +118,0 @@ exports.loadConfig = loadConfig; |
import { ConfigObject } from '.'; | ||
declare const hasTrailingOrLeadingWhitespace: (value: string) => boolean; | ||
declare const validateConfig: (config: ConfigObject) => ConfigObject; | ||
export default validateConfig; | ||
export { validateConfig, hasTrailingOrLeadingWhitespace }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.hasTrailingOrLeadingWhitespace = exports.validateConfig = void 0; | ||
const hasTrailingOrLeadingWhitespace = (value) => { | ||
const trailingOrLeadingWhiteSpace = new RegExp('^[ \\s]+|[ \\s]+$'); | ||
return trailingOrLeadingWhiteSpace.test(value); | ||
}; | ||
exports.hasTrailingOrLeadingWhitespace = hasTrailingOrLeadingWhitespace; | ||
const validateConfig = (config) => { | ||
@@ -9,6 +15,9 @@ Object.keys(config).forEach(key => { | ||
} | ||
if (typeof value === 'string' && hasTrailingOrLeadingWhitespace(value)) { | ||
console.warn(`WARNING: Found leading and/or trailing whitespace within config value for ${key}`); | ||
} | ||
}); | ||
return config; | ||
}; | ||
exports.default = validateConfig; | ||
exports.validateConfig = validateConfig; | ||
//# sourceMappingURL=validate-config.js.map |
# Changelog | ||
## 1.6.0 (October 26, 2020) | ||
- Warn on leading or trailing whitespace in secret value | ||
- Suppress secret undefined warning if running tests | ||
- Add `AWS_SECRETS_MANAGER_NAMES` key to define multiple secrets in a backwards compatible way | ||
## 1.5.0 (October 17, 2020) | ||
@@ -4,0 +10,0 @@ |
{ | ||
"name": "config-dug", | ||
"version": "1.5.0", | ||
"version": "1.6.0", | ||
"description": "Config loader with support for AWS Secrets Manager", | ||
@@ -5,0 +5,0 @@ "author": "Neo Financial Engineering <engineering@neofinancial.com>", |
@@ -84,3 +84,3 @@ # Config Dug | ||
`AWS_SECRETS_MANAGER_NAME` can also be a comma separated list to allow connection to multiple secrets in AWS Secrets Manager. Each secret from the list is evaluated in order mean that if a specific key appears in two secrets the value will be overwritten by the last secret in the list. | ||
If you need to read from multiple secret buckets, `AWS_SECRETS_MANAGER_NAMES` takes a comma separated list to allow connection to multiple secrets in AWS Secrets Manager. Each secret from the list is evaluated in order mean that if a specific key appears in two secrets the value will be overwritten by the last secret in the list. | ||
@@ -90,3 +90,3 @@ ```ts | ||
export default { | ||
AWS_SECRETS_MANAGER_NAME: 'production/myapp/config, production/myapp/another-config', | ||
AWS_SECRETS_MANAGER_NAMES: 'production/myapp/config,production/myapp/another-config', | ||
API_ENDPOINT: 'https://api.kanye.rest/' | ||
@@ -93,0 +93,0 @@ }; |
17625
187