#!/usr/bin/env bash
# fake juju for the amphora-pipeline harness.
#   config [-m M] <app> <key> -> env-driven value (CFG_* with sane defaults)
#   run <unit> retrofit-image ... -> "builds" the amphora by touching $MARKER, prints a completed op
sub="${1:-}"
case "$sub" in
  config)
    args=(); while [ $# -gt 0 ]; do case "$1" in -m) shift 2 ;; *) args+=("$1"); shift ;; esac; done
    app="${args[1]:-}"; key="${args[2]:-}"   # args = (config app key)
    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 ;;
  run)
    : > "${MARKER:?MARKER not set}"   # the retrofit "builds + tags" the amphora
    echo "Running operation 99 with 1 task"
    echo "  - task 100 on unit-octavia-diskimage-retrofit-0"
    echo "task 100 completed" ;;
esac
