How to use the dynaconf.settings.PASSWORD function in dynaconf

To help you get started, weā€™ve selected a few dynaconf examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rochacbruno / dynaconf / example / jenkins_secrets_file / app.py View on Github external
from dynaconf import settings

# Assuming this app is running on CI the secret values would be read from
# jenkins_secrets.toml that was  defined by SECRETS_FOR_DYNACONF envvar

assert settings.USERNAME == "jenkins"
assert settings.PASSWORD == "s3cr3t"
github rochacbruno / dynaconf / example / common-encoding / program.py View on Github external
assert settings.USERNAME == "admin"
assert settings.PASSWORD == "SuperSecret"  # will use the [default]

print("#" * 79)
print("\n* Default and Global settings\n")
print("The env [global] is to override values defined in any other env")
print("It means a value in [global] will always take high precedence")
print("To override any value in [global] just put the value in .toml file")
print("Or via envvars export a value with DYNACONF_ prefix")
print('$ export DYNACONF_USERNAME="NewUsername"')
print('You can also put the value in .env file"')
# this next line is not needed in your program, it is the same as
# `export DYNACONF_USERNAME..`
os.environ["DYNACONF_USERNAME"] = "NewUsername"
settings.reload()  # noqa
connect(settings.SERVER, settings.PORT, settings.USERNAME, settings.PASSWORD)
print("settings.EXTRA_VALUE = ", settings.EXTRA_VALUE)
assert settings.SERVER == "customserver.com"
assert settings.PORT == 5555
assert settings.USERNAME == "NewUsername"
assert settings.PASSWORD == "SuperSecret"  # will use the [default]
assert settings.EXTRA_VALUE == "Value defined in .env"

print("#" * 79)
print("\n* Using environment variables at program call\n")
print("Another common pattern is defining the value in the program call")
print("$ DYNACONF_USERNAME=YetAnotherUser python program.py")
# this next line is not needed in your program, it is the same as
# `export DYNACONF_USERNAME..`
os.environ["DYNACONF_USERNAME"] = "YetAnotherUser"
settings.reload()  # noqa
connect(settings.SERVER, settings.PORT, settings.USERNAME, settings.PASSWORD)
github rochacbruno / dynaconf / example / yaml_example / settings_file / app.py View on Github external
from dynaconf import settings

# print all values in the file
# using [default] + [development] + [global] values
print("* All values")
print(settings.HOST)
print(settings.PORT)
print(settings.USERNAME)
print(settings.PASSWORD)
print(settings.LEVELS)
print(settings.TEST_LOADERS)
print(settings.MONEY)
print(settings.AGE)
print(settings.ENABLED)
print(settings.CUSTOM)

print("* Switiching to production")
# using [production] env values for context
with settings.using_env("PRODUCTION"):
    print(settings.CUSTOM)
    print(settings.HOST)

print("* Switiching to development")
# back to default [development] env
print(settings.get("CUSTOM"))
github rochacbruno / dynaconf / example / common / program.py View on Github external
print("#" * 79)
print("\n* The settings are defined in .toml files\n")
print("$ cat settings.toml")
print(open(settings.find_file("./settings.toml")).read())
print("$ cat .secrets.toml")
print(open(settings.find_file(".secrets.toml")).read())

print("#" * 79)
print("\n* Acessing settings defined in .toml files\n")
print('By default dynaconf will always work in "development" env')
print("Take a look at settings.toml and .secrets.toml")
connect(settings.SERVER, settings.PORT, settings.USERNAME, settings.PASSWORD)
assert settings.SERVER == "devserver.com"
assert settings.PORT == 5555
assert settings.USERNAME == "admin"
assert settings.PASSWORD == "SuperSecretDev"

print("#" * 79)
print("\n* Working on a different environment\n")
print("To switch the env export the ENV_FOR_DYNACONF variable")
print("$ export ENV_FOR_DYNACONF=production")
print("Now reading settings from PRODUCTION env:")
# this next line is not needed in your program, it is the same as
# `export ENV_FOR_DYNACONF..`
import os

os.environ["ENV_FOR_DYNACONF"] = "production"
settings.reload()  # noqa
connect(settings.SERVER, settings.PORT, settings.USERNAME, settings.PASSWORD)
assert settings.SERVER == "prodserver.com"
assert settings.PORT == 5555
assert settings.USERNAME == "admin"
github rochacbruno / dynaconf / example / common-encoding / program.py View on Github external
print("#" * 79)
print("\n* Type definitions for environment variables\n")
print("Note that the PORT variable must be integer")
print("And envvars are by default string typed")
print("Dynaconf allows type definition on exporting an envvar")
print('$ export DYNACONF_PORT="@int 8888"')
# this next line is not needed in your program, it is the same as
# `export DYNACONF_USERNAME..`
os.environ["DYNACONF_PORT"] = "@int 8888"
settings.reload()  # noqa
connect(settings.SERVER, settings.PORT, settings.USERNAME, settings.PASSWORD)
assert settings.SERVER == "customserver.com"
assert settings.PORT == 8888
assert settings.USERNAME == "YetAnotherUser"
assert settings.PASSWORD == "SuperSecret"  # will use the [default]
print("DONT WORRY: if you dont like the `@type` strategy you can disable it")
print("and perform the explicit cast when reading")
print('>>> connect(..., settings.as_int("PORT"), ...)')
print(
    "types: @int|.as_int, @float|.as_float, @bool|.as_bool and @json|.as_json"
)

print("#" * 79)
print("\n* There is more!\n")
print(
    "Dynaconf can switch environments programatically with context managers."
)
print("Dynaconf has extensions for Flask and Django.")
print("Dynaconf can read values from yaml, ini, json and py files.")
print("Dynaconf can load sensitive values from vaultproject.io.")
print(
github rochacbruno / dynaconf / example / common / program.py View on Github external
assert settings.PORT == 5555
assert settings.USERNAME == "admin"
assert settings.PASSWORD == "SuperSecretDev"

print("#" * 79)
print("\n* Working on a different environment\n")
print("To switch the env export the ENV_FOR_DYNACONF variable")
print("$ export ENV_FOR_DYNACONF=production")
print("Now reading settings from PRODUCTION env:")
# this next line is not needed in your program, it is the same as
# `export ENV_FOR_DYNACONF..`
import os

os.environ["ENV_FOR_DYNACONF"] = "production"
settings.reload()  # noqa
connect(settings.SERVER, settings.PORT, settings.USERNAME, settings.PASSWORD)
assert settings.SERVER == "prodserver.com"
assert settings.PORT == 5555
assert settings.USERNAME == "admin"
assert settings.PASSWORD == "SuperSecretProd"

print("#" * 79)
print("\n* Switching environments\n")
print("We can easily switch to staging env")
print("$ export ENV_FOR_DYNACONF=staging")
# this next line is not needed in your program, it is the same as
# `export ENV_FOR_DYNACONF..`
os.environ["ENV_FOR_DYNACONF"] = "staging"
settings.reload()  # noqa
connect(settings.SERVER, settings.PORT, settings.USERNAME, settings.PASSWORD)
assert settings.SERVER == "stagserver.com"
assert settings.PORT == 5555
github rochacbruno / dynaconf / example / envs / app.py View on Github external
from dynaconf import settings


print(
    "# 1 all values in {} + {}: env of yaml file:".format(
        settings.DEFAULT_ENV_FOR_DYNACONF, settings.current_env
    )
)
assert settings.current_env == "DEVELOPMENT"
print("HOST::", settings.HOST)
print("PORT:", settings.PORT)
print("USERNAME:", settings.USERNAME)
print("PASSWORD:", settings.PASSWORD)
print("LEVELS:", settings.LEVELS)
print("TEST_LOADERS:", settings.TEST_LOADERS)
print("MONEY:", settings.MONEY)
print("AGE:", settings.AGE)
print("ENABLED:", settings.ENABLED)
print("ENVIRONMENT:", settings.get("ENVIRONMENT"))
print("WORKS:", settings.WORKS)

with settings.using_env("TESTING"):
    print("# 2 using {}: env values for context:".format(settings.current_env))
    assert settings.current_env == "TESTING"
    print("HOST::", settings.HOST)
    print("PORT:", settings.PORT)
    print("USERNAME:", settings.USERNAME)
    print("PASSWORD:", settings.PASSWORD)
    print("LEVELS:", settings.LEVELS)
github rochacbruno / dynaconf / example / envs / app.py View on Github external
print("PASSWORD:", settings.PASSWORD)
print("LEVELS:", settings.LEVELS)
print("TEST_LOADERS:", settings.TEST_LOADERS)
print("MONEY:", settings.MONEY)
print("AGE:", settings.AGE)
print("ENABLED:", settings.ENABLED)
print("ENVIRONMENT:", settings.get("ENVIRONMENT"))
print("WORKS:", settings.WORKS)

settings.setenv("testing")
print("# 4 Set to {}: env:".format(settings.current_env))
assert settings.current_env == "TESTING"
print("HOST::", settings.HOST)
print("PORT:", settings.PORT)
print("USERNAME:", settings.USERNAME)
print("PASSWORD:", settings.PASSWORD)
print("LEVELS:", settings.LEVELS)
print("TEST_LOADERS:", settings.TEST_LOADERS)
print("MONEY:", settings.MONEY)
print("AGE:", settings.AGE)
print("ENABLED:", settings.ENABLED)
print("ENVIRONMENT:", settings.get("ENVIRONMENT"))
print("WORKS:", settings.WORKS)

settings.setenv()
print("# 5 back to default {}: env:".format(settings.current_env))
assert settings.current_env == "DEVELOPMENT"
print("HOST::", settings.HOST)
print("PORT:", settings.PORT)
print("USERNAME:", settings.USERNAME)
print("PASSWORD:", settings.PASSWORD)
print("LEVELS:", settings.LEVELS)
github rochacbruno / dynaconf / example / common / program.py View on Github external
from dynaconf import settings  # noqa

print(settings.dynaconf_banner)

print("#" * 79)
print("\n* The settings are defined in .toml files\n")
print("$ cat settings.toml")
print(open(settings.find_file("./settings.toml")).read())
print("$ cat .secrets.toml")
print(open(settings.find_file(".secrets.toml")).read())

print("#" * 79)
print("\n* Acessing settings defined in .toml files\n")
print('By default dynaconf will always work in "development" env')
print("Take a look at settings.toml and .secrets.toml")
connect(settings.SERVER, settings.PORT, settings.USERNAME, settings.PASSWORD)
assert settings.SERVER == "devserver.com"
assert settings.PORT == 5555
assert settings.USERNAME == "admin"
assert settings.PASSWORD == "SuperSecretDev"

print("#" * 79)
print("\n* Working on a different environment\n")
print("To switch the env export the ENV_FOR_DYNACONF variable")
print("$ export ENV_FOR_DYNACONF=production")
print("Now reading settings from PRODUCTION env:")
# this next line is not needed in your program, it is the same as
# `export ENV_FOR_DYNACONF..`
import os

os.environ["ENV_FOR_DYNACONF"] = "production"
settings.reload()  # noqa
github rochacbruno / dynaconf / example / common-encoding / program.py View on Github external
print("The env [global] is to override values defined in any other env")
print("It means a value in [global] will always take high precedence")
print("To override any value in [global] just put the value in .toml file")
print("Or via envvars export a value with DYNACONF_ prefix")
print('$ export DYNACONF_USERNAME="NewUsername"')
print('You can also put the value in .env file"')
# this next line is not needed in your program, it is the same as
# `export DYNACONF_USERNAME..`
os.environ["DYNACONF_USERNAME"] = "NewUsername"
settings.reload()  # noqa
connect(settings.SERVER, settings.PORT, settings.USERNAME, settings.PASSWORD)
print("settings.EXTRA_VALUE = ", settings.EXTRA_VALUE)
assert settings.SERVER == "customserver.com"
assert settings.PORT == 5555
assert settings.USERNAME == "NewUsername"
assert settings.PASSWORD == "SuperSecret"  # will use the [default]
assert settings.EXTRA_VALUE == "Value defined in .env"

print("#" * 79)
print("\n* Using environment variables at program call\n")
print("Another common pattern is defining the value in the program call")
print("$ DYNACONF_USERNAME=YetAnotherUser python program.py")
# this next line is not needed in your program, it is the same as
# `export DYNACONF_USERNAME..`
os.environ["DYNACONF_USERNAME"] = "YetAnotherUser"
settings.reload()  # noqa
connect(settings.SERVER, settings.PORT, settings.USERNAME, settings.PASSWORD)
assert settings.SERVER == "customserver.com"
assert settings.PORT == 5555
assert settings.USERNAME == "YetAnotherUser"
assert settings.PASSWORD == "SuperSecret"  # will use the [default]