dynaconf icon indicating copy to clipboard operation
dynaconf copied to clipboard

[RFC] Allow multiple envvar prefixes. was: Switch env with additional env variables

Open Guo-Zhang opened this issue 2 years ago • 2 comments

I am wondering whether it exists some simple method to switch the env label with additional env variables.

I am writing a SDK for TencentCloud. I want to the environment variables in the runtime of function computing. A environment variable, "TENCENTCLOUD_RUNTIME"="SCF" , can be used to identify the environment. I hope to use them as additional default value or replace some addtional default value, for example, "TENCENTCLOUD_SECRETID" in replace of SDK's "QCLOUDSDK_SECRET_ID"。

I cannot understand how to use custom loader, or use proper parameters to control settings class.

In addition, the docs have no detailed description about "@str format" and "@jlina " with env. I cannot find proper ways to deal with more complicated condition, for example, "TENCENTCLOUD_SECRETID" only exists when access role is setted.

Guo-Zhang avatar Apr 01 '22 08:04 Guo-Zhang

maybe what you are lokking for is dynaconf_hooks? https://www.dynaconf.com/advanced/#hooks

rochacbruno avatar Jun 02 '22 14:06 rochacbruno

Revisiting this issue and IIUC this is an RFC to include something like:

  1. Allow multiple prefixes when loading envvars
settings = Dynaconf(envvar_prefix=["PREFIX1", "PREFIX2"])

and the order of the prefix list defines its precedence, so if both PREFIX1_KEY and PREFIX2_KEY exists, the first has precedence.

On #683 there will be support for setting envvars per variable defined in the schema

rochacbruno avatar Sep 21 '22 15:09 rochacbruno