@basic-tools/secrets-resolver
v1.1.4
Published
Secrets Resolver Package for any node project.
Downloads
169
Readme
Secret Resolver
This package allows you to load secrets from different methods. You can use .env for local development and AWS for staging and production.
You just need to configure it using SecretResolver.config(options). These are the available resolver types:
- data: Loads secrets from a variable.
- aws: Loads secrets from AWS Secrets Manager.
- environments: Loads secrets from a .env file.
- file: Loads secrets from a file.
Configuration
- Add it to your package.json:
"dependencies": {
"@basic-tools/secrets-resolver": "^1.0.0",
},- Init secret-resolver in your code:
For Example in your
main.tsorindex.ts.
import { SecretResolver } from '@basic-tools/secrets-resolver';
...
const configSecrets = async () => {
const options: SecretResolverByEnviromentOptions = {
resolverInDevelopment: { resolveFrom: RESOLVER_TYPES.environments },
resolverInProduction: { resolveFrom: RESOLVER_TYPES.aws },
resolverInTest: { resolveFrom: RESOLVER_TYPES.aws }
}
await SecretResolver.config(options)
}
configSecrets()
...If your code is running on AWS ECS or AWS Lambdas, it will automatically detect the environment and attempt to retrieve secrets from AWS Secrets Manager.
- Use it anywhere in your code.
import { SecretResolver } from '@basic-tools/secrets-resolver';
SecretResolver.get('MY_PRECIOUS')Configuration with AWS Secret Manager
You need to declare it as an environment variable or in your .env file:
AWS_REGION=
AWS_SECRET_ID=Configuration on local
If you need to test it locally, you'll also need these variables set in your local .env file or your system's environment variables:
AWS_ACCESS_KEY_ID=your-access-key
AWS_SECRET_ACCESS_KEY=your-secret-key
AWS_REGION=your-region
AWS_SESSION_TOKEN=your-session-tokenDEBUGGING
Add this variable in your envs:
RESOLVER_SECRETS_DEBUG=true