#!/usr/bin/env bash
obj="${1:-}"; act="${2:-}"; rest=" $* "
imgpresent() { [ "${IMG_PRESENT:-0}" = 1 ] || [ -f "${MK_IMAGE:-/nonexistent}" ]; }
case "$obj $act" in
"token issue") exit 0 ;;
"domain show") [ "${DOMAIN_PRESENT:-0}" = 1 ] && { echo id; exit 0; }; exit 1 ;;
"domain create") echo id; exit 0 ;;
"project show") [ "${PROJECT_PRESENT:-0}" = 1 ] && { echo id; exit 0; }; exit 1 ;;
"project create") echo id; exit 0 ;;
"role assignment") [ "${ROLES_PRESENT:-0}" = 1 ] && echo "assign-line"; exit 0 ;;
"role add") exit 0 ;;
"flavor show") [ "${FLAVORS_PRESENT:-0}" = 1 ] && { echo id; exit 0; }; exit 1 ;;
"flavor create") exit 0 ;;
"image show")
if imgpresent; then
if printf '%s' "$rest" | grep -q -- '-f json'; then
echo '{"status":"active","disk_format":"raw","visibility":"public"}'
elif printf '%s' "$rest" | grep -q -- '-c status'; then
[ "${POLL_FAIL:-0}" = 1 ] && echo saving || echo active
else
echo img-id
fi
exit 0
fi
exit 1 ;;
"image create") : > "${MK_IMAGE:?}"; exit 0 ;;
esac
exit 0