Skip to content

Commit

Permalink
feat: add SECRET_KEY_BASE instead of SECRET_TOKEN
Browse files Browse the repository at this point in the history
  • Loading branch information
icyleaf committed Sep 19, 2024
1 parent 08557bc commit 92097ea
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion config.env
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ ZEALOT_SENTRY_DISABLE=false
COMPOSE_PROJECT_NAME=zealot

# 加密密钥,建议使用 openssl 或者 rails secret 生成
SECRET_TOKEN=
SECRET_KEY_BASE=

# Puma 外部控制 API
PUMA_CONTROL_URL=0.0.0.0:9293
Expand Down
9 changes: 5 additions & 4 deletions scripts/generate-secret-key.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
echo "${_group}Generating secret key ..."

HAS_SECRET_TOKEN=$(grep 'SECRET_TOKEN' $ENV_FILE | awk '{split($0,a,"="); print a[2]}')
HAS_SECRET_TOKEN=$(grep -E 'SECRET_KEY_BASE|SECRET_TOKEN' $ENV_FILE | awk '{split($0,a,"="); print a[2]}')

if [ -z "$HAS_SECRET_TOKEN" ]; then
SECRET_TOKEN=$(export LC_ALL=C; head /dev/urandom | tr -dc "a-z0-9" | head -c 128 | sed -e 's/[\/&]/\\&/g')
sed -i -e 's/^SECRET_TOKEN=.*$/SECRET_TOKEN='"'$SECRET_TOKEN'"'/' $ENV_FILE
token=$(export LC_ALL=C; head /dev/urandom | tr -dc "a-z0-9" | head -c 128 | sed -e 's/[\/&]/\\&/g')
sed -i -e 's/^SECRET_TOKEN=.*$/SECRET_TOKEN='"'$token'"'/' $ENV_FILE
sed -i -e 's/^SECRET_KEY_BASE=.*$/SECRET_KEY_BASE='"'$token'"'/' $ENV_FILE
clean_sed_temp_file $ENV_FILE
echo "Secret key written to .env: \`${SECRET_TOKEN}\`"
echo "Secret key written to .env: \`${token}\`"
else
echo "Secret key had been write, skipped"
fi
Expand Down

0 comments on commit 92097ea

Please sign in to comment.