#!/usr/bin/env bash
# fake juju for the phase-05 verify harness.
#   status ...        -> $FIX_JUJU_STATUS (octavia status JSON)
#   config <app> <key> -> env-driven value (CFG_* with sane defaults)
#   exec ... 'ip -br addr'  -> $OHM0_OUT   (the 'ip -br addr show o-hm0' line)
#   exec ... 'ip -o link'   -> $OHM0_LINK  (the 'ip -o link show o-hm0' line, for MTU)
sub="${1:-}"
case "$sub" in
  status) cat "${FIX_JUJU_STATUS:?FIX_JUJU_STATUS not set}" ;;
  config)
    app="${2:-}"; key="${3:-}"
    case "$app/$key" in
      octavia-diskimage-retrofit/use-internal-endpoints) printf '%s\n' "${CFG_UIE:-true}" ;;
      octavia-diskimage-retrofit/image-format)           printf '%s\n' "${CFG_IMGFMT:-raw}" ;;
      octavia-diskimage-retrofit/amp-image-tag)          printf '%s\n' "${CFG_RTAG:-octavia-amphora}" ;;
      octavia/amp-image-tag)                             printf '%s\n' "${CFG_OTAG:-octavia-amphora}" ;;
    esac ;;
  exec)
    # R8a: the verify now issues TWO exec calls -- `ip -br addr` for the ULA and
    # `ip -o link` for the MTU. Dispatch on which, or the MTU check reads an address.
    if printf '%s' "$*" | grep -q -- '-o link'; then
      printf '%s\n' "${OHM0_LINK:-}"
    else
      printf '%s\n' "${OHM0_OUT:-}"
    fi ;;
esac
