#!/bin/sh # Seed the Topaz directory: push the manifest, then objects and relations. # Uses Topaz's directory REST gateway. Exits 0 on success. set -eu apk add --no-cache curl jq >/dev/null DIR="${DIRECTORY_REST:-http://topaz:9393}" echo "seed: directory REST = $DIR" # 1. Push the directory model (manifest). echo "seed: setting model" curl -sf -X POST "$DIR/api/v3/directory/manifest" \ -H 'Content-Type: application/yaml' \ --data-binary @/manifest.yaml \ || curl -sf -X POST "$DIR/api/v3/model" \ -H 'Content-Type: application/yaml' \ --data-binary @/manifest.yaml echo # 2. Push objects. echo "seed: writing objects" jq -c '.objects[]' /data/objects.json | while IFS= read -r obj; do curl -sf -X POST "$DIR/api/v3/directory/object" \ -H 'Content-Type: application/json' \ -d "{\"object\":$obj}" >/dev/null printf '.' done echo # 3. Push relations. echo "seed: writing relations" jq -c '.relations[]' /data/relations.json | while IFS= read -r rel; do curl -sf -X POST "$DIR/api/v3/directory/relation" \ -H 'Content-Type: application/json' \ -d "{\"relation\":$rel}" >/dev/null printf '.' done echo echo "seed: done"