#!/bin/sh
set -e

# Generate kong.yml from template by substituting env vars
if [ -z "$ANON_KEY" ] || [ -z "$SERVICE_ROLE_KEY" ]; then
  echo "ERROR: ANON_KEY and SERVICE_ROLE_KEY must be set"
  exit 1
fi

sed \
  -e "s|__ANON_KEY__|${ANON_KEY}|g" \
  -e "s|__SERVICE_ROLE_KEY__|${SERVICE_ROLE_KEY}|g" \
  /var/lib/kong/kong.yml.template > /var/lib/kong/kong.yml

echo "Kong config generated from template with production API keys"

# Hand off to the original Kong entrypoint
exec /docker-entrypoint.sh "$@"
