adonisjs / env

Framework agnostic environment variables parser and validator
https://docs.adonisjs.com/guides/environment-variables
MIT License
37 stars 10 forks source link

feat(parser): allow to add identifiers #37

Closed RomainLanz closed 7 months ago

RomainLanz commented 7 months ago

Hey there! 👋🏻

This PR is the continuation of https://github.com/adonisjs/env/pull/35. It adds a way to set up an identifier for an environment variable, helping to interpolate the value of your env.

It can be useful in multiple scenarios.

  1. To manage your secrets, you may use a Secrets Vault like Docker Secret or HashiCorp Vault. Doing so it will generate a path for your secret and won't give you any value directly. You can write a custom logic to read the file content.

    DB_PASSWORD=file:/run/secrets/db_password
  2. You may encrypt your secrets. You will be able to decrypt them on the fly.

    APP_KEY=encrypted:ksadskjadsjkdasjkdsjdjaskjkdjkasdkj
Env.identifier('file', (value: string) => {
  // ...
})

Env.create(new URL('../', import.meta.url), {
  ....
})
thetutlage commented 7 months ago

A couple of things to keep in mind

RomainLanz commented 7 months ago

It is going to be a breaking change for this package.

Why is this a breaking change? The behavior is not changing for current users.

thetutlage commented 7 months ago

We have changed the parse method to async, which was sync earlier.

So anyone relying on this package using the Parser directly (which is publicly exported) has to now await the parse method call

RomainLanz commented 7 months ago

Ah yes, for anyone using the package directly, it is a breaking change, that's true. 😄