#!/bin/sh # Odile Gate quickstart: four moments in about a minute, against a public test API (jsonplaceholder.typicode.com). # Needs curl. Prints every status Gate returns. Creates one free project named "Gate quickstart". set -e G=https://gate.odilelabs.com j() { sed -n "s/.*\"$1\":\"\([^\"]*\)\".*/\1/p"; } echo "1. Create a project in front of the test API" P=$(curl -s -X POST $G/api/projects -H 'content-type: application/json' -d '{"name":"Gate quickstart","upstream":"https://jsonplaceholder.typicode.com"}') PID=$(echo "$P" | j project_id); ADMIN=$(echo "$P" | j admin_key) [ -n "$PID" ] || { echo " could not create the project: $P"; exit 1; } echo " project $PID (admin key shown once; this script keeps it only in memory)" echo "2. Register a reporting app that may only read posts" A=$(curl -s -X POST $G/api/projects/$PID/apps -H "Authorization: Bearer $ADMIN" -H 'content-type: application/json' -d '{"name":"reporting-app","routes":["GET /posts/:id"],"per_minute":60}') KEY=$(echo "$A" | j key) call() { curl -s -o /dev/null -D - -X "$1" "$G/g/$PID$2" -H "Authorization: Bearer $KEY" | tr -d '\r' | awk 'NR==1{c=$2} tolower($1)=="x-gate-refused:"{r=" refused: "$2} END{print c r}'; } echo "3. Allowed read: GET /posts/1 -> $(call GET /posts/1)" echo "4. Forbidden delete: DELETE /posts/1 -> $(call DELETE /posts/1)" printf "5. Agent stuck in a loop, same call 12 times:" for i in 1 2 3 4 5 6 7 8 9 10 11 12; do printf " %s" "$(call GET /posts/2 | cut -c1-3)"; done; echo echo "6. The audit log (no bodies, no query values, no headers):" curl -s "$G/api/projects/$PID/audit.csv" -H "Authorization: Bearer $ADMIN" | head -6 echo echo "Dashboard: $G/dashboard (project $PID). Next: put your own API in 'upstream' and list the calls each app needs."