Реализовал флаг в settings, который управляет, данные в .env защищены либо же нет #38
This commit is contained in:
parent
7122b0248a
commit
885f552067
@ -11,6 +11,10 @@ ALLOWED_HOSTS = ['localhost']
|
|||||||
|
|
||||||
CSRF_TRUSTED_ORIGINS = ['http://zakonvremeni.ru:8989',]
|
CSRF_TRUSTED_ORIGINS = ['http://zakonvremeni.ru:8989',]
|
||||||
|
|
||||||
|
# Если False, то данные в .env хранятся в открытом виде,
|
||||||
|
# иначе в зашифрованном.
|
||||||
|
ENV_ENCODED = False
|
||||||
|
|
||||||
LOG_DIR = path.join(Path(__file__).resolve().parent.parent.parent, 'logs/')
|
LOG_DIR = path.join(Path(__file__).resolve().parent.parent.parent, 'logs/')
|
||||||
|
|
||||||
LOGGING = {
|
LOGGING = {
|
||||||
|
@ -25,6 +25,15 @@ def decode_env(env_key: str) -> str:
|
|||||||
return signer.unsign_object(signed_telegram_chat_id_dict)[env_key]
|
return signer.unsign_object(signed_telegram_chat_id_dict)[env_key]
|
||||||
|
|
||||||
|
|
||||||
|
def return_env(env_key: str) -> str:
|
||||||
|
"""
|
||||||
|
Функция нужна как стратегия, если not ENV_ENCODED
|
||||||
|
:param env_key:
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
return getenv(env_key)
|
||||||
|
|
||||||
|
|
||||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||||
env_file = path.join(BASE_DIR, '.env')
|
env_file = path.join(BASE_DIR, '.env')
|
||||||
|
|
||||||
@ -36,8 +45,13 @@ promoter_env_keys = (
|
|||||||
'OK_APPLICATION_SECRET_KEY',
|
'OK_APPLICATION_SECRET_KEY',
|
||||||
)
|
)
|
||||||
promoter_secrets = {}
|
promoter_secrets = {}
|
||||||
|
if ENV_ENCODED:
|
||||||
|
decode_strategy = decode_env
|
||||||
|
else:
|
||||||
|
decode_strategy = return_env
|
||||||
|
|
||||||
for promoter_env_key in promoter_env_keys:
|
for promoter_env_key in promoter_env_keys:
|
||||||
promoter_secrets[promoter_env_key] = decode_env(promoter_env_key)
|
promoter_secrets[promoter_env_key] = decode_strategy(promoter_env_key)
|
||||||
|
|
||||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user