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'.