Persists secret_key between updates

pull/1395/head
Piero Toffanin 2023-09-16 13:46:15 -04:00
rodzic c0fe407157
commit ef5336927d
5 zmienionych plików z 38 dodań i 17 usunięć

Wyświetl plik

@ -1 +1,2 @@
**/.git **/.git
.secret_key

1
.gitignore vendored
Wyświetl plik

@ -103,3 +103,4 @@ package-lock.json
# Debian builds # Debian builds
dpkg/build dpkg/build
dpkg/deb dpkg/deb
.secret_key

Wyświetl plik

@ -33,6 +33,7 @@ services:
- WO_BROKER - WO_BROKER
- WO_DEV - WO_DEV
- WO_DEV_WATCH_PLUGINS - WO_DEV_WATCH_PLUGINS
- WO_SECRET_KEY
restart: unless-stopped restart: unless-stopped
oom_score_adj: 0 oom_score_adj: 0
broker: broker:
@ -52,5 +53,6 @@ services:
environment: environment:
- WO_BROKER - WO_BROKER
- WO_DEBUG - WO_DEBUG
- WO_SECRET_KEY
restart: unless-stopped restart: unless-stopped
oom_score_adj: 250 oom_score_adj: 250

Wyświetl plik

@ -335,7 +335,21 @@ run(){
eval "$1" eval "$1"
} }
get_secret(){
if [ ! -e ./.secret_key ] && [ -e /dev/random ]; then
echo "Generating secret in ./.secret_key"
export WO_SECRET_KEY=$(head -c50 < /dev/random | base64)
echo $WO_SECRET_KEY > ./.secret_key
elif [ -e ./.secret_key ]; then
export WO_SECRET_KEY=$(cat ./.secret_key)
else
export WO_SECRET_KEY=""
fi
}
start(){ start(){
get_secret
if [[ $dev_mode = true ]]; then if [[ $dev_mode = true ]]; then
echo "Starting WebODM in development mode..." echo "Starting WebODM in development mode..."
down down

Wyświetl plik

@ -27,6 +27,9 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
try: try:
from .secret_key import SECRET_KEY from .secret_key import SECRET_KEY
except ImportError: except ImportError:
if os.environ.get("WO_SECRET_KEY", "") != "":
SECRET_KEY = os.environ.get("WO_SECRET_KEY")
else:
# This will be executed the first time Django runs # This will be executed the first time Django runs
# It generates a secret_key.py file that contains the SECRET_KEY # It generates a secret_key.py file that contains the SECRET_KEY
from django.utils.crypto import get_random_string from django.utils.crypto import get_random_string