#!/usr/bin/env bash
# fake juju for phase-04-internal-cert-san-verify.sh tests.
# Handles 'exec -m MODEL --unit UNIT -- bash -c "... -connect HOST:PORT ..."' by
# returning a canned subjectAltName for the probed HOST:PORT (the real x509 parse runs
# remotely in the script's bash -c; here we emit what that parse would print).
# BARBICAN_MODE env toggles barbican's cert: ok (default) | nosan | nocert.
cmd="$*"
hp="$(printf '%s' "$cmd" | grep -oE '\-connect [0-9.]+:[0-9]+' | awk '{print $2}')"
case "$hp" in
  10.12.12.50:5000)
    echo "    IP Address:10.12.4.50, IP Address:10.12.8.50, IP Address:10.12.12.50, DNS:juju-a" ;;
  10.12.12.51:9311)
    case "${BARBICAN_MODE:-ok}" in
      nosan)  echo "    IP Address:10.12.4.51, IP Address:10.12.8.51, DNS:juju-b" ;;   # missing 10.12.12.51
      nocert) : ;;                                                                     # empty -> NO-CERT
      *)      echo "    IP Address:10.12.4.51, IP Address:10.12.8.51, IP Address:10.12.12.51, DNS:juju-b" ;;
    esac ;;
esac
exit 0
