#!/usr/bin/env bash
# MongoDB entrypoint wrapper for dev environment
# Reads credentials from Vault secrets and initializes MongoDB
set -euo pipefail

# Read credentials from Vault Agent-rendered files
if [ -s /vault/secrets/MONGO_ROOT_USER ] && [ -s /vault/secrets/MONGO_ROOT_PASSWORD ]; then
  export MONGO_INITDB_ROOT_USERNAME="$(cat /vault/secrets/MONGO_ROOT_USER)"
  export MONGO_INITDB_ROOT_PASSWORD="$(cat /vault/secrets/MONGO_ROOT_PASSWORD)"
fi

# Execute original MongoDB entrypoint
exec docker-entrypoint.sh "$@"
