Реализовал команду шифровки значений переменных окружения #19
This commit is contained in:
parent
dc7a3fa283
commit
47cbb7905a
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,7 +1,7 @@
|
|||||||
.idea/
|
.idea/
|
||||||
.python-version
|
.python-version
|
||||||
db.sqlite3
|
db.sqlite3
|
||||||
.env
|
.env*
|
||||||
__pycache__/
|
__pycache__/
|
||||||
identifier.sqlite
|
identifier.sqlite
|
||||||
vk_config.v2.json
|
vk_config.v2.json
|
||||||
|
0
cms/management/__init__.py
Normal file
0
cms/management/__init__.py
Normal file
0
cms/management/commands/__init__.py
Normal file
0
cms/management/commands/__init__.py
Normal file
23
cms/management/commands/encode_file.py
Normal file
23
cms/management/commands/encode_file.py
Normal file
@ -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)
|
@ -23,11 +23,6 @@ env_file = path.join(BASE_DIR, '.env')
|
|||||||
|
|
||||||
dotenv.read_dotenv(env_file)
|
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'.
|
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||||
|
|
||||||
# Quick-start development settings - unsuitable for production
|
# Quick-start development settings - unsuitable for production
|
||||||
|
Loading…
x
Reference in New Issue
Block a user