#!/bin/sh

# Create secret file from environment variables for testing ConfigLoader
# This simulates the mounted secret file approach used in Inferno

SECRET_FILE="/run/secrets/honey-config.properties"
SECRET_DIR="/run/secrets"

# Create directory if it doesn't exist
mkdir -p "$SECRET_DIR"

# Create properties file from environment variables
cat > "$SECRET_FILE" << EOF
# Configuration loaded from secret file (created from env vars for testing)
SPRING_DATASOURCE_URL=${SPRING_DATASOURCE_URL}
SPRING_DATASOURCE_USERNAME=${SPRING_DATASOURCE_USERNAME}
SPRING_DATASOURCE_PASSWORD=${SPRING_DATASOURCE_PASSWORD}
TELEGRAM_BOT_TOKEN=${TELEGRAM_BOT_TOKEN}
FRONTEND_URL=${FRONTEND_URL}
PORT=${PORT}
EOF

# Set permissions (readable by the application user)
chmod 644 "$SECRET_FILE"

echo "✅ Secret file created at $SECRET_FILE from environment variables"


