#!/bin/sh # Seeds a running multi-node stack: 4 teams, ~40 users, an S3 connection, a scheduled S3 policy, and a webhook source if the build supports it. # Auth uses the Bearer JWT from the login response body (not a cookie) since the global API key can't create teams. # Idempotent-ish: re-running skips existing teams/users; each step is best-effort and logs failures without aborting. set -u BASE_URL="${BASE_URL:-http://localhost:8080}" ADMIN_USER="${ADMIN_USER:-admin}" ADMIN_PASS="${ADMIN_PASS:-stirling}" USER_COUNT="${USER_COUNT:-40}" USER_PASS="${USER_PASS:-Password123!}" PGHOST="${PGHOST:-postgres}" PGUSER="${PGUSER:-stirling}" PGPASSWORD="${PGPASSWORD:-stirling}" PGDATABASE="${PGDATABASE:-stirling}" export PGPASSWORD TEAMS="Engineering Finance Legal Operations" log() { echo "[seed] $*"; } psqlq() { psql -h "$PGHOST" -U "$PGUSER" -d "$PGDATABASE" -tAc "$1" 2>/dev/null | tr -d '[:space:]'; } # --- wait for the load balancer to serve a healthy app ----------------------- log "waiting for $BASE_URL ..." i=0 until curl -fsS "$BASE_URL/api/v1/info/status" 2>/dev/null | grep -q UP; do i=$((i+1)); [ "$i" -gt 120 ] && { log "timed out waiting for API"; exit 1; } sleep 3 done log "API is up" # --- admin login -> Bearer token --------------------------------------------- code=$(curl -sS -o /tmp/login.json -w '%{http_code}' \ -X POST "$BASE_URL/api/v1/auth/login" \ -H 'Content-Type: application/json' \ -d "{\"username\":\"$ADMIN_USER\",\"password\":\"$ADMIN_PASS\"}") log "admin login: HTTP $code" [ "$code" = "200" ] || { log "login failed: $(cat /tmp/login.json)"; exit 1; } TOKEN=$(jq -r '.session.access_token' the in-cluster MinIO 'policy-data' bucket --------------- conn_body=$(cat </dev/null) log "S3 connection id: ${conn_id:-}" # --- a scheduled S3 -> compress -> S3 policy --------------------------------- if [ -n "${conn_id:-}" ]; then src_body=$(cat </dev/null) log "S3 source id: ${src_id:-}" if [ -n "${src_id:-}" ]; then pol_body=$(cat </dev/null) log "webhook source created (deliver to /api/v1/webhooks/$wh_url)" else log "webhook source not created (HTTP $wh) - expected on builds without the webhook branch" fi fi log "seed complete." log " login: $ADMIN_USER / $ADMIN_PASS at $BASE_URL" log " users: user01..$(printf '%02d' "$USER_COUNT")@stirling.test / $USER_PASS"