#!/usr/bin/env bash
# exports all lysnr-* secrets from kv-mywisprai into kv_azure.txt
set -euo pipefail

VAULT_NAME=${AZURE_KEYVAULT_NAME:-kv-mywisprai}
OUTFILE=${1:-kv_azure.txt}

echo "📦 Exporting lysnr-* secrets from $VAULT_NAME → $OUTFILE"
rm -f "$OUTFILE"

secret_names=$(az keyvault secret list \
  --vault-name "$VAULT_NAME" \
  --query "[?starts_with(name,'lysnr-')].name" \
  --output tsv)

for secret in $secret_names; do
  value=$(az keyvault secret show \
    --vault-name "$VAULT_NAME" \
    --name "$secret" \
    --query "value" \
    --output tsv)
  printf "%s=%s\n" "$secret" "$value" >> "$OUTFILE"
done

echo "✅ Done. Run: cat $OUTFILE"
