secrets-manager-to-config
v1.0.41
Published
Pull secrets from secrets managers as nested json or yml file
Readme
secrets-manager-to-config
Table of Contents
Upload a ts-file as a Secret
ts-node upload.ts --secret_name <secret-name> --ts_path <ts-filepath>
This package aims at managing secrets saved in ts format, so that UAT, PROD etc environments can infer their type from DEV config.
Assume that we have the following env config written in ts file:
// config/test.ts
const someConfig: {
hihi: string;
ohMy: {
value: string;
someArray: string[];
};
} = {
hihi: "bye",
ohMy: {
value: "gosh",
someArray: ["hihi", "hjaaaaaaa"],
},
};
export default someConfig;Then this default export can be uploaded to secrets manager via
ts-node upload.ts --secret_name some-test-config --ts_path config/test.tswhere upload.ts is defined by uploadConfig:
// upload.ts
import { SecretConfig, uploadConfig } from "secrets-manager-to-config";
const secretConfig: SecretConfig = {
awsRegion: "ap-southeast-2",
};
uploadConfig(secretConfig);Sample Result
We have the following in secret manager:
Download Secrets
ts-node download.ts --secret_name <secret-name> --format <format> --save_at <filepath>
Assume that in AWS secret manages we have defined a secret abc with a.b.c = "123", then create a file download.ts and write
// download.ts
import { downloadConfig, SecretConfig } from "secrets-manager-to-config";
const secretConfig: SecretConfig = {
awsRegion: "ap-southeast-2",
};
downloadConfig(secretConfig);now you can pull your secret by
ts-node download.ts --secret_name abc --format yml --save_at test.ymlHere the format is of type json | yml | flat_env. The above results in
In
ymlformat:# test.yml a: b: c: "123"This is suitable for spring boot project where we use
application.yml.In
jsonformat:{ "a": { "b": { "c": "123" } } }This is suitable for
nodejsproject where we useenv-cmd -f .env.jsonto loadenvconfig.In
flat_envformat:a.b.c="123"This is suitable for ordinary
.envfiles or application.properties for spring boot project.
