def test_path_not_string(): if sys.version_info[0] == 2: message = "'path' must be <type 'str'>" else: message = "'path' must be <class 'str'>" with pytest.raises(TypeError, match=message): vault(1)
def test_vault_var_reusage(vault_prefix, vault_addr, vault_token): variable = vault("path/to") class Test: VAULT_ADDR = vault_addr VAULT_TOKEN = vault_token SECRET = variable["SECRET"] IS_SECRET = variable["IS_SECRET"] config = Konfig.from_object(Test, vault_backend=VaultBackend(vault_prefix)) assert config.asdict() == { "SECRET": "value", "IS_SECRET": True, "VAULT_ADDR": vault_addr, "VAULT_TOKEN": vault_token, }
from datetime import date, datetime from decimal import Decimal from konfetti import env, lazy, vault, vault_file KEY = "value" DEBUG = env("DEBUG", default=True, cast=bool) REQUIRED = env("REQUIRED") INTEGER = env("INTEGER", default=1, cast=int) FROM_DOTENV = env("FROM_DOTENV", default="not_loaded") SECRET = vault("path/to")["SECRET"] ANOTHER_SECRET = vault("path/to")["ANOTHER_SECRET"] WHOLE_SECRET = vault("path/to") NESTED_SECRET = vault("path/to/nested")["NESTED_SECRET"]["nested"] SECRET_FILE = vault_file("path/to/file")["SECRET_FILE"] DEFAULT = vault("path/to", default="default")["DEFAULT"] def get_default(): return 42 CALLABLE_DEFAULT = env("path/to", default=get_default) IS_SECRET = vault("path/to", cast=bool)["IS_SECRET"] DECIMAL = vault("path/to", cast=Decimal)["DECIMAL"] FLOAT_DECIMAL = vault("path/to/cast", cast=Decimal)["DECIMAL"] DATE = vault("path/to/cast", cast=date)["DATE"] DATETIME = vault("path/to/cast", cast=datetime)["DATETIME"]
import os from konfetti import env, vault, VaultBackend from konfetti.contrib.django import install SECRET_KEY = "foo" ROOT_URLCONF = "django_app.views" DEBUG = env("DEBUG", default=True, cast=bool) REQUIRED = env("REQUIRED") VAULT_ADDR = env("VAULT_ADDR") VAULT_TOKEN = env("VAULT_TOKEN") SECRET = vault("path/to")["SECRET"] config = install(__name__, vault_backend=VaultBackend(os.getenv("VAULT_PREFIX"))) config.extend_with_object({"KEY": 42})
class Test: VALUE = 42 VAULT_ADDR = env("VAULT_ADDR") VAULT_TOKEN = env("VAULT_TOKEN") SECRET = vault("path/to")["SECRET"]
from konfetti import env, vault KEY = "value" DEBUG = env("DEBUG", default=True, cast=bool) SECRET = vault("path/to")["SECRET"] WHOLE_SECRET = vault("path/to") NESTED_SECRET = vault("path/to/nested")["NESTED_SECRET"]["nested"] VAULT_ADDR = env("VAULT_ADDR") VAULT_TOKEN = env("VAULT_TOKEN") not_a_config_option = 1 DICTIONARY = { "static": 1, "vault": vault("path/to")["SECRET"], "env": env("DEBUG", default=True, cast=bool) }