From dc7a3fa2834a7e47c2f20692e8048cc0f7deaecd Mon Sep 17 00:00:00 2001 From: Artur Galyamov Date: Wed, 21 Dec 2022 17:46:25 +0500 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=B2=D1=8B=D1=88=D0=B5=D0=BD?= =?UTF-8?q?=D0=B0=20=D0=B7=D0=B0=D1=89=D0=B8=D1=89=D1=91=D0=BD=D0=BD=D0=BE?= =?UTF-8?q?=D1=81=D1=82=D1=8C=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D1=85,=20?= =?UTF-8?q?=D0=B8=D0=B4=20=D0=BA=D0=B0=D0=BD=D0=B0=D0=BB=D0=B0=20=D0=B7?= =?UTF-8?q?=D0=B0=D1=88=D0=B8=D1=84=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=20=D1=81?= =?UTF-8?q?=D1=80=D0=B5=D0=B4=D1=81=D1=82=D0=B2=D0=B0=D0=BC=D0=B8=20django?= =?UTF-8?q?=20#19?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit и в настройках мы дешифруем значение канала --- .gitignore | 2 +- cms/promoters.py | 2 +- crossposting_backend/private/__init__.py | 0 crossposting_backend/private/settings.example.py | 7 +++++++ crossposting_backend/settings.py | 23 +++++++++++++++-------- 5 files changed, 24 insertions(+), 10 deletions(-) create mode 100644 crossposting_backend/private/__init__.py create mode 100644 crossposting_backend/private/settings.example.py diff --git a/.gitignore b/.gitignore index 0af966a..2d67043 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,4 @@ db.sqlite3 __pycache__/ identifier.sqlite vk_config.v2.json -crossposting_backend/private_settings.py \ No newline at end of file +crossposting_backend/private/settings.py \ No newline at end of file diff --git a/cms/promoters.py b/cms/promoters.py index 3e2dd0e..46e1ab9 100644 --- a/cms/promoters.py +++ b/cms/promoters.py @@ -21,7 +21,7 @@ class Promoter(abc.ABC): class TelegramPromoter(Promoter): def promote(self): - from crossposting_backend.private_settings import BOT_TOKEN, CHANNEL_ID + from crossposting_backend.settings import BOT_TOKEN, CHANNEL_ID long_text = f'{self.article.body}\n{self.article.link}' querystring = (('chat_id', CHANNEL_ID), ('text', long_text)) diff --git a/crossposting_backend/private/__init__.py b/crossposting_backend/private/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/crossposting_backend/private/settings.example.py b/crossposting_backend/private/settings.example.py new file mode 100644 index 0000000..d709879 --- /dev/null +++ b/crossposting_backend/private/settings.example.py @@ -0,0 +1,7 @@ +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = False +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'django-insecure-aaaa' + +SALT = 'aaaaaaaa' +ALLOWED_HOSTS = [] \ No newline at end of file diff --git a/crossposting_backend/settings.py b/crossposting_backend/settings.py index 32908c2..d1c1e01 100644 --- a/crossposting_backend/settings.py +++ b/crossposting_backend/settings.py @@ -10,18 +10,29 @@ For the full list of settings and their values, see https://docs.djangoproject.com/en/4.1/ref/settings/ """ +from os import path, getenv +from pathlib import Path -from .private_settings import * +import dotenv +from django.core import signing -# Build paths inside the project like this: BASE_DIR / 'subdir'. -from django.urls import reverse +from .private.settings import * + +BASE_DIR = Path(__file__).resolve().parent.parent +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 # See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/ -ALLOWED_HOSTS = [] LOGIN_URL = '/cms/' @@ -68,7 +79,6 @@ TEMPLATES = [ WSGI_APPLICATION = 'crossposting_backend.wsgi.application' - # Database # https://docs.djangoproject.com/en/4.1/ref/settings/#databases @@ -79,7 +89,6 @@ DATABASES = { } } - # Password validation # https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators @@ -98,7 +107,6 @@ AUTH_PASSWORD_VALIDATORS = [ }, ] - # Internationalization # https://docs.djangoproject.com/en/4.1/topics/i18n/ @@ -110,7 +118,6 @@ USE_I18N = True USE_TZ = True - # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/4.1/howto/static-files/