From 47cbb7905adc06ed6837018d486b8a79c89a4d16 Mon Sep 17 00:00:00 2001 From: Artur Galyamov Date: Wed, 21 Dec 2022 18:14:13 +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=D0=BA=D0=BE=D0=BC=D0=B0=D0=BD=D0=B4=D1=83?= =?UTF-8?q?=20=D1=88=D0=B8=D1=84=D1=80=D0=BE=D0=B2=D0=BA=D0=B8=20=D0=B7?= =?UTF-8?q?=D0=BD=D0=B0=D1=87=D0=B5=D0=BD=D0=B8=D0=B9=20=D0=BF=D0=B5=D1=80?= =?UTF-8?q?=D0=B5=D0=BC=D0=B5=D0=BD=D0=BD=D1=8B=D1=85=20=D0=BE=D0=BA=D1=80?= =?UTF-8?q?=D1=83=D0=B6=D0=B5=D0=BD=D0=B8=D1=8F=20#19?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- cms/management/__init__.py | 0 cms/management/commands/__init__.py | 0 cms/management/commands/encode_file.py | 23 +++++++++++++++++++++++ crossposting_backend/settings.py | 5 ----- 5 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 cms/management/__init__.py create mode 100644 cms/management/commands/__init__.py create mode 100644 cms/management/commands/encode_file.py diff --git a/.gitignore b/.gitignore index 2d67043..a2942fe 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ .idea/ .python-version db.sqlite3 -.env +.env* __pycache__/ identifier.sqlite vk_config.v2.json diff --git a/cms/management/__init__.py b/cms/management/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/cms/management/commands/__init__.py b/cms/management/commands/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/cms/management/commands/encode_file.py b/cms/management/commands/encode_file.py new file mode 100644 index 0000000..0ecba64 --- /dev/null +++ b/cms/management/commands/encode_file.py @@ -0,0 +1,23 @@ +from django.core import signing +from django.core.management import BaseCommand + +from crossposting_backend.settings import SALT, BASE_DIR + + +class Command(BaseCommand): + def handle(self, *args, **options): + environments = {} + with open(BASE_DIR / '.env') as env_file: + for line in env_file: + env_key, env_value = line.split('=') + environments[env_key] = env_value + + signer = signing.Signer(salt=SALT) + with open(BASE_DIR / '.env.encoded', 'w') as out_env_file: + for env_key, env_value in environments.items(): + env_item = { + env_key: env_value + } + encoded_env_item = signer.sign_object(env_item) + line_with_encoded_value = '%s=%s\n' % (env_key, encoded_env_item) + out_env_file.write(line_with_encoded_value) diff --git a/crossposting_backend/settings.py b/crossposting_backend/settings.py index d1c1e01..b931c5c 100644 --- a/crossposting_backend/settings.py +++ b/crossposting_backend/settings.py @@ -23,11 +23,6 @@ env_file = path.join(BASE_DIR, '.env') dotenv.read_dotenv(env_file) -BOT_TOKEN = getenv('TELEGRAM_BOT_TOKEN') -signer = signing.Signer(salt=SALT) -signed_telegram_chat_id_dict = getenv('TELEGRAM_CHAT_ID') -CHANNEL_ID = signer.unsign_object(signed_telegram_chat_id_dict)['TELEGRAM_CHAT_ID'] - # Build paths inside the project like this: BASE_DIR / 'subdir'. # Quick-start development settings - unsuitable for production