Repository Public
1#!/usr/bin/env bash2# =============================================================================3# SP BOUCHER | INFRASTRUCTURE & AUTOMATION4# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5# =============================================================================6#7# Project : MacLustr Identity8# File : integrations/lib/provision.sh9# Module : integrations10# Repository : https://git.spboucher.ai/maclustr-identity11# Project Website : https://identity.spboucher.ai12# Created : 2026-12-0113# Last Modified : 2026-12-0114#15# Author : Simon-Pierre Boucher16# Position : Professor of Finance17# Institution : Université du Québec en Outaouais (UQO)18# Organization : SP Boucher19# Website : https://spboucher.ai20# Git : https://git.spboucher.ai21#22# Preferred Contact: admin@spboucher.ai23# Technical Contact: dev@spboucher.ai24# Security/Admin : admin@spboucher.ai25#26# Copyright (c) 202627# Simon-Pierre Boucher28# All rights reserved where applicable. This file is governed by the29# applicable project license, copyright notices and relevant law.30# Existing third-party rights and notices remain unaffected.31#32# License : None specified (no license file in this repository)33#34# Do not embed credentials, private keys, access tokens,35# certificates or confidential personal information.36#37# =============================================================================38# END OF SP BOUCHER SOURCE HEADER39# =============================================================================4041# Provisions one demo application on a LOCAL MacLustr Identity backend:42# application (CLI) -> allowed origins / redirect URLs -> sandbox key (CLI) -> webhook endpoint (public API).43# Writes the three values the demo needs to <out-file> (mode 600). Never run this against production.44#45# usage: provision.sh <slug> <name> <webhook-url> <out-file> [allowed-origin] [redirect-url]46set -euo pipefail4748SLUG="$1"; NAME="$2"; WEBHOOK_URL="$3"; OUT="$4"; ORIGIN="${5:-}"; REDIRECT="${6:-}"49REPO="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"50PY="$REPO/.venv/bin/python"51export MLID_BASE_URL="${MLID_BASE_URL:-http://localhost:8870}"52export DATABASE_URL="${DATABASE_URL:-postgres://127.0.0.1/maclustr_identity_sdk}"53export MLID_DATA_DIR="${MLID_DATA_DIR:-/tmp/mlid-sdk/data}"54export MLID_MASTER_KEY_FILE="${MLID_MASTER_KEY_FILE:-/tmp/mlid-sdk/master.key}"5556case "$MLID_BASE_URL" in57 http://localhost:*|http://127.0.0.1:*) ;;58 *) echo "provision.sh only targets a local backend (got $MLID_BASE_URL)" >&2; exit 2 ;;59esac60[ -x "$PY" ] || { echo "backend virtualenv not found: $PY" >&2; exit 2; }61curl -fsS "$MLID_BASE_URL/health" >/dev/null || { echo "no backend at $MLID_BASE_URL" >&2; exit 2; }6263cd "$REPO"64# 1. Application (kept when it already exists).65"$PY" -m services.mlid.cli app-create "$SLUG" "$NAME" >/dev/null 2>&1 || true6667# 2. Origins allowed to frame the hosted page, and allowed return URLs (a value that is not given is left as it is).68SET_ARGS=()69[ -n "$ORIGIN" ] && SET_ARGS+=(--origin "$ORIGIN")70[ -n "$REDIRECT" ] && SET_ARGS+=(--redirect "$REDIRECT")71if [ "${#SET_ARGS[@]}" -gt 0 ]; then72 "$PY" -m services.mlid.cli app-set "$SLUG" "${SET_ARGS[@]}" >/dev/null73fi7475# 3. A fresh sandbox key (a secret is shown once, so every setup run issues a new one).76KEY="$("$PY" -m services.mlid.cli key-create "$SLUG" --label demo | tail -n 1)"77case "$KEY" in mlid_sk_test_*) ;; *) echo "unexpected key output" >&2; exit 1 ;; esac7879# 4. Webhook endpoint through the public API: previous endpoints of this application are replaced.80api() { curl -fsS -H "Authorization: Bearer $KEY" -H "Content-Type: application/json" "$@"; }81for ID in $(api "$MLID_BASE_URL/v1/webhooks" | "$PY" -c 'import json,sys; print(" ".join(e["id"] for e in json.load(sys.stdin)["data"]))'); do82 api -X DELETE "$MLID_BASE_URL/v1/webhooks/$ID" >/dev/null83done84WH="$(api -X POST "$MLID_BASE_URL/v1/webhooks" -d "{\"url\": \"$WEBHOOK_URL\", \"events\": [\"*\"], \"description\": \"$SLUG demo\"}")"85SECRET="$(printf '%s' "$WH" | "$PY" -c 'import json,sys; print(json.load(sys.stdin)["secret"])')"8687umask 07788cat > "$OUT" <<ENV89# Generated by integrations/lib/provision.sh for the LOCAL sandbox. Server-side only. Not committed.90MLID_BASE_URL=$MLID_BASE_URL91MLID_SECRET_KEY=$KEY92MLID_WEBHOOK_SECRET=$SECRET93ENV94echo "provisioned $SLUG -> $OUT (key ${KEY:0:17}..., webhook $WEBHOOK_URL)"95