Skip to content

Instantly share code, notes, and snippets.

@brasten
Created December 3, 2020 01:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brasten/1e16ff1d6f1ca5c00584c572d06df1f4 to your computer and use it in GitHub Desktop.
Save brasten/1e16ff1d6f1ca5c00584c572d06df1f4 to your computer and use it in GitHub Desktop.
ConfigKit

Purpose

I don't like shuffling configuration files around. Often chunks of config are related to a specific entity in a specific environment (like the "production redis service" or some such). ConfigKit resolves a series of URI-like references until a concrete value it located, making it easy to provide sensible defaults for local development while also pointing to environmentally-appropriate configuration in an operationally-appropriate repository (GCP Secret Manager or the like).

// In server.ts for example:
//
const configKit = new ConfigKit();

const serviceAccount = await configKit.fetch(process.env.SA_EMAIL || '$ref=file:./config/identity.json#/email');
const redisConfig    = await configKit.fetch(process.env.REDIS_CONF || '$ref=file:./config/redis.toml');

Example environment on production:

SA_EMAIL: $ref=gcp:metadata::service-accounts/default/email
REDIS_CONF: $ref=gcp:secret::redis

// serviceAccount is resolved from instance metadata, while redisConfig is resolved from Secret Manager (assuming // the proper permissions have been granted to that secret payload.

# @ck:type=toml
[redis]
host = "x.y.z.z"
port = 6379
# Note: @ck:type annotation at top of file instructs ConfigKit on how to -- or if -- to parse the file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment