mirror of
https://github.com/sissbruecker/linkding
synced 2024-11-22 11:23:02 +00:00
38204c87cf
* Persist secret key in data folder * use random secret key by default in prod * fix e2e test
24 lines
671 B
Python
24 lines
671 B
Python
import logging
|
|
import os
|
|
|
|
from django.core.management.base import BaseCommand
|
|
from django.core.management.utils import get_random_secret_key
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class Command(BaseCommand):
|
|
help = "Generate secret key file if it does not exist"
|
|
|
|
def handle(self, *args, **options):
|
|
secret_key_file = os.path.join("data", "secretkey.txt")
|
|
|
|
if os.path.exists(secret_key_file):
|
|
logger.info(f"Secret key file already exists")
|
|
return
|
|
|
|
secret_key = get_random_secret_key()
|
|
with open(secret_key_file, "w") as f:
|
|
f.write(secret_key)
|
|
logger.info(f"Generated secret key file")
|