Validate APP_KEY on initializing with Docker (#240)

This commit is contained in:
Saeed Vaziry 2024-06-18 22:22:17 +03:30 committed by GitHub
parent 5ccbab74b1
commit 109d644ad8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -5,6 +5,39 @@ NAME=${NAME:-"vito"}
EMAIL=${EMAIL:-"vito@vitodeploy.com"} EMAIL=${EMAIL:-"vito@vitodeploy.com"}
PASSWORD=${PASSWORD:-"password"} PASSWORD=${PASSWORD:-"password"}
# Function to check if a string is 32 characters long
check_length() {
local key=$1
if [ ${#key} -ne 32 ]; then
echo "Invalid APP_KEY"
exit 1
fi
}
# Check if APP_KEY is set
if [ -z "$APP_KEY" ]; then
echo "APP_KEY is not set"
exit 1
fi
# Check if APP_KEY starts with 'base64:'
if [[ $APP_KEY == base64:* ]]; then
# Remove 'base64:' prefix and decode the base64 string
decoded_key=$(echo "${APP_KEY:7}" | base64 --decode 2>/dev/null)
# Check if decoding was successful
if [ $? -ne 0 ]; then
echo "Invalid APP_KEY base64 encoding"
exit 1
fi
# Check the length of the decoded key
check_length "$decoded_key"
else
# Check the length of the raw APP_KEY
check_length "$APP_KEY"
fi
# check if the flag file does not exist, indicating a first run # check if the flag file does not exist, indicating a first run
if [ ! -f "$INIT_FLAG" ]; then if [ ! -f "$INIT_FLAG" ]; then
echo "Initializing..." echo "Initializing..."