Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Change the BASE_NAMESPACE from DYNACONF to DEFAULT #54

Closed
rochacbruno opened this issue May 21, 2018 · 0 comments · Fixed by #56
Closed

RFC: Change the BASE_NAMESPACE from DYNACONF to DEFAULT #54

rochacbruno opened this issue May 21, 2018 · 0 comments · Fixed by #56

Comments

@rochacbruno
Copy link
Member

rochacbruno commented May 21, 2018

  1. Change the use of term namespace to use env so variable names like NAMESPACE_FOR_DYNACONF will be changed to ENV_FOR_DYNACONF, also functions like using_namespace will be called using_env and a compat layer must be added to not break. The reason is that it meets the use of ENV in other frameworks.

  2. Rename the base DYNACONF env to DEFAULT, currently, the base env is called DYNACONF it is the default namespace for variables and must be renamed to DEFAULT (this will be a breaking change)

  3. Change the order of loading setting .toml as the preferred config format.

  4. Add to CLI Cli tool  #2 a command called init which will add a new settings.* file (defautls to toml) containing the scaffolding.

So with this change, an application config file will look like this.

settings.toml

[default]
server = 'defaulserver.com'
# value in [default]  env will serve as default when it is not defined in specific env
# default is optional and can also be empty or ommited

# values from other [envs] will overrride existing default values

[development]
server = 'devserver.com'

[staging]
server = 'stagingserver.com'
user = 'staging user'

[testing]
server = 'ciserver.com'

[production]
server = 'prodserver.com'

[custom]
server = 'customserver.com'

# If it is needed to override all values in every namespace declare a [global] env
[global]
server = 'itoverrideseverything.com'

IN a .secrets file there is no reason to have different envs as easch environment must have its own secrets file.
.secrets.toml

[default]
password = 'SuperSecret'

The variable ENV_FOR_DYNACONF must default to DEVELOPMENT and when it is time to change a variable must be defined.

export ENV_FOR_DYNACONF=PRODUCTION

That is all


Programatically switching namespaces may be useful for testing and also to use Dynaconf as a Feature flag system so to switch:

with settings.using_env('staging'):
    assert settings.USERNAME == 'staging user'
    assert settings.SERVER == itoverrideseverything.com'  # override by [global]

The higher precedence is always for the DYNACONF env it works as a global and is named DYNACONF instead of GLOBAl to avoid conflicts with existing envvars.

To overwrite values in any of the namespaces do:

export DYNACONF_SERVER='ThisOverwritesEverything.com'
This was referenced May 21, 2018
@rochacbruno rochacbruno changed the title RFC: Change the BASE_NAMESPACE from DYNACONF to GLOBAL RFC: Change the BASE_NAMESPACE from DYNACONF to DEFAUL May 22, 2018
@rochacbruno rochacbruno changed the title RFC: Change the BASE_NAMESPACE from DYNACONF to DEFAUL RFC: Change the BASE_NAMESPACE from DYNACONF to DEFAULT May 22, 2018
rochacbruno added a commit that referenced this issue May 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant