Files
proxmox/scripts/omnl/lib/omnl-fineract-common.sh
defiQUG 95522d3bca
Some checks failed
Deploy to Phoenix / deploy (push) Has been cancelled
feat(omnl): HYBX-BATCH-001 package, rail scripts, regulatory docs, CI
- Add OMNL/CBK Indonesia submission and audit binder docs, manifests, attestations
- Add scripts/omnl transaction-package pipeline, LEI/PvP helpers, jq/lib fixtures
- Update entity master data, MASTER_INDEX, TODOS, dbis-rail docs and rulebook
- Add proof_package/regulatory skeleton and transaction package zip + snapshot JSON
- validate-omnl-rail workflow, forge-verification-proxy tweak, .gitignore hygiene
- Bump smom-dbis-138 (cronos verify docs/scripts) and explorer-monorepo (SPA + env report)

Made-with: Cursor
2026-03-24 18:11:36 -07:00

85 lines
3.0 KiB
Bash

#!/usr/bin/env bash
# shellcheck shell=bash
# Sourced by OMNL Fineract scripts. Defines env load, CURL_OPTS, and paginated client fetch.
# Expects caller to set nothing, or REPO_ROOT before sourcing.
_LIB_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
if [ -z "${REPO_ROOT:-}" ]; then
REPO_ROOT="$(cd "${_LIB_DIR}/../../.." && pwd)"
fi
omnl_fineract_load_env() {
if [ -f "${REPO_ROOT}/omnl-fineract/.env" ]; then
set +u
# shellcheck disable=SC1090
source "${REPO_ROOT}/omnl-fineract/.env" 2>/dev/null || true
set -u
elif [ -f "${REPO_ROOT}/.env" ]; then
set +u
# shellcheck disable=SC1090
source "${REPO_ROOT}/.env" 2>/dev/null || true
set -u
fi
}
# After load_env and setting CURL_OPTS via omnl_fineract_init_curl:
# Returns a JSON object { "pageItems": [ ... ] } for all clients (paginated).
omnl_fineract_fetch_all_clients_pageitems() {
local limit="${OMNL_CLIENTS_PAGE_LIMIT:-200}"
local offset=0
local acc="[]"
while true; do
local resp batch n
resp=$(curl "${CURL_OPTS[@]}" "${BASE_URL}/clients?offset=${offset}&limit=${limit}")
batch=$(echo "$resp" | jq -c 'if .pageItems != null then .pageItems elif type == "array" then . else [] end')
n=$(echo "$batch" | jq 'length')
acc=$(jq -n --argjson a "$acc" --argjson b "$batch" '$a + $b')
if [ "$n" -lt "$limit" ] || [ "$n" -eq 0 ]; then
break
fi
offset=$((offset + limit))
done
jq -n --argjson items "$acc" '{pageItems: $items}'
}
omnl_fineract_init_curl() {
BASE_URL="${OMNL_FINERACT_BASE_URL:-}"
TENANT="${OMNL_FINERACT_TENANT:-omnl}"
USER="${OMNL_FINERACT_USER:-app.omnl}"
PASS="${OMNL_FINERACT_PASSWORD:-}"
if [ -z "$BASE_URL" ] || [ -z "$PASS" ]; then
echo "Set OMNL_FINERACT_BASE_URL and OMNL_FINERACT_PASSWORD (e.g. in omnl-fineract/.env)" >&2
return 1
fi
CURL_OPTS=(-s -S -H "Fineract-Platform-TenantId: ${TENANT}" -H "Content-Type: application/json" -u "${USER}:${PASS}")
}
# LEI document type from identifiers template (name contains LEI, else first type).
omnl_fineract_get_lei_document_type_id() {
local client_id="$1"
local template id
template=$(curl "${CURL_OPTS[@]}" "${BASE_URL}/clients/${client_id}/identifiers/template" 2>/dev/null) || true
if [ -z "$template" ]; then
echo ""
return
fi
id=$(echo "$template" | jq -r '(.allowedDocumentTypes // [])[] | select(.name | ascii_upcase | test("LEI")) | .id' 2>/dev/null | head -1)
if [ -z "$id" ] || [ "$id" = "null" ]; then
id=$(echo "$template" | jq -r '(.allowedDocumentTypes // [])[0].id // empty' 2>/dev/null)
fi
echo "$id"
}
# True if client has an identifier with this documentKey.
omnl_fineract_client_has_document_key() {
local client_id="$1"
local want_key="$2"
local list
list=$(curl "${CURL_OPTS[@]}" "${BASE_URL}/clients/${client_id}/identifiers" 2>/dev/null) || return 1
echo "$list" | jq -e --arg k "$want_key" '
(if type == "array" then . else (.pageItems // []) end)
| map(select((.documentKey // "") == $k))
| length > 0
' >/dev/null 2>&1
}