35 lines
786 B
Bash
35 lines
786 B
Bash
|
|
#!/usr/bin/env bash
|
||
|
|
set -euo pipefail
|
||
|
|
|
||
|
|
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||
|
|
ENV_FILE="${ROOT_DIR}/config/env.local"
|
||
|
|
if [[ ! -f "${ENV_FILE}" ]]; then
|
||
|
|
ENV_FILE="${ROOT_DIR}/config/env.example"
|
||
|
|
fi
|
||
|
|
# shellcheck source=/dev/null
|
||
|
|
source "${ENV_FILE}"
|
||
|
|
|
||
|
|
SOCK="${SOCK:-../amduatd.sock}"
|
||
|
|
BASE="${BASE:-http://localhost}"
|
||
|
|
SPACE="${SPACE:-app1}"
|
||
|
|
|
||
|
|
api_get() {
|
||
|
|
local path="$1"
|
||
|
|
curl --silent --show-error --fail \
|
||
|
|
--unix-socket "${SOCK}" \
|
||
|
|
-H "X-Amduat-Space: ${SPACE}" \
|
||
|
|
"${BASE}${path}"
|
||
|
|
}
|
||
|
|
|
||
|
|
api_post_json() {
|
||
|
|
local path="$1"
|
||
|
|
local body="$2"
|
||
|
|
curl --silent --show-error --fail \
|
||
|
|
--unix-socket "${SOCK}" \
|
||
|
|
-H "Content-Type: application/json" \
|
||
|
|
-H "X-Amduat-Space: ${SPACE}" \
|
||
|
|
-X POST \
|
||
|
|
--data-binary "${body}" \
|
||
|
|
"${BASE}${path}"
|
||
|
|
}
|