Beispiel #1
0
# and those values must be read from settings.toml config file

# The `password` is sensitive so it comes from .secrets.toml file
# or even better it may come from vaultproject.io

# Dynaconf takes care of it!

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")
with io.open(
        settings.find_file("settings.toml"),
        encoding=os.environ.get("ENCODING_FOR_DYNACONF"),
) as settings_file:
    print(settings_file.read())
print("$ cat .secrets.toml")
with io.open(
        settings.find_file(".secrets.toml"),
        encoding=os.environ.get("ENCODING_FOR_DYNACONF"),
) as secrets_file:
    print(secrets_file.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)
Beispiel #2
0
from dynaconf import settings

with open(settings.find_file("settings.sff")) as settings_file:
    print("settings from sff file\n", settings_file.read())

assert settings.NAME == "Bruno Rocha"
assert settings.EMAIL == "[email protected]_env"

print("Name is:", settings.NAME)
print("Email is:", settings.EMAIL)

print(settings.get_fresh("NAME"))
Beispiel #3
0
print("# Starting", __file__)
print("# On import level dynaconf will read .env and config envvars")
print("# It will also setup the initial search tree.")
print("\n")

from dynaconf import settings  # noqa

print("\n")
print("IS Dynaconf loaded yet?", settings.configured)
print("# ^ That means that no settings file was read yet! dynaconf is empty")
print("# Dynaconf is LAzy so it will load at the first access.")
print("# Lets make the first call to `settings.VALUE` watch the  logs...")
print("\n")
print(settings.VALUE)
print("\n")
print("# Now a second call to `settings.VALUE` already loaded:")
print("\n")
print(settings.VALUE)
print("\n")
print("IS Dynaconf loaded?", settings.configured)
print("# ^ That means that settings was read! dynaconf is loaded")
print("# Lets read a file using settings.find_file...")
print("\n")
with open(settings.find_file("settings.toml")) as settings_file:
    print(settings_file.read())

from dynaconf.utils.files import SEARCHTREE  # noqa

print("Searchtree", SEARCHTREE)
Beispiel #4
0
# The `connect` function needs to take the server, username and value
# and those values must be read from settings.toml config file

# The `password` is sensitive so it comes from .secrets.toml file
# or even better it may come from vaultproject.io

# Dynaconf takes care of it!

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")