From 885f5520674c91214c3c8d914f2cd9d8d8f8330d Mon Sep 17 00:00:00 2001 From: Artur Galyamov Date: Thu, 29 Dec 2022 22:44:39 +0500 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BB=20=D1=84=D0=BB=D0=B0=D0=B3=20=D0=B2=20settin?= =?UTF-8?q?gs,=20=D0=BA=D0=BE=D1=82=D0=BE=D1=80=D1=8B=D0=B9=20=D1=83=D0=BF?= =?UTF-8?q?=D1=80=D0=B0=D0=B2=D0=BB=D1=8F=D0=B5=D1=82,=20=D0=B4=D0=B0?= =?UTF-8?q?=D0=BD=D0=BD=D1=8B=D0=B5=20=D0=B2=20.env=20=D0=B7=D0=B0=D1=89?= =?UTF-8?q?=D0=B8=D1=89=D0=B5=D0=BD=D1=8B=20=D0=BB=D0=B8=D0=B1=D0=BE=20?= =?UTF-8?q?=D0=B6=D0=B5=20=D0=BD=D0=B5=D1=82=20#38?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crossposting_backend/private/settings.example.py | 4 ++++ crossposting_backend/settings.py | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/crossposting_backend/private/settings.example.py b/crossposting_backend/private/settings.example.py index eba2761..81c59c7 100644 --- a/crossposting_backend/private/settings.example.py +++ b/crossposting_backend/private/settings.example.py @@ -11,6 +11,10 @@ ALLOWED_HOSTS = ['localhost'] CSRF_TRUSTED_ORIGINS = ['http://zakonvremeni.ru:8989',] +# Если False, то данные в .env хранятся в открытом виде, +# иначе в зашифрованном. +ENV_ENCODED = False + LOG_DIR = path.join(Path(__file__).resolve().parent.parent.parent, 'logs/') LOGGING = { diff --git a/crossposting_backend/settings.py b/crossposting_backend/settings.py index 1ae0c33..9cb42be 100644 --- a/crossposting_backend/settings.py +++ b/crossposting_backend/settings.py @@ -25,6 +25,15 @@ def decode_env(env_key: str) -> str: 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 env_file = path.join(BASE_DIR, '.env') @@ -36,8 +45,13 @@ promoter_env_keys = ( 'OK_APPLICATION_SECRET_KEY', ) promoter_secrets = {} +if ENV_ENCODED: + decode_strategy = decode_env +else: + decode_strategy = return_env + 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'.