Some checks failed
Deploy to Phoenix / deploy (push) Has been cancelled
- ADD_CHAIN138_TO_LEDGER_LIVE: Ledger form done; public code review repo bis-innovations/LedgerLive; init/push commands - CONTRACT_DEPLOYMENT_RUNBOOK: Chain 138 gas price 1 gwei, 36-addr check, TransactionMirror workaround - CONTRACT_*: AddressMapper, MirrorManager deployed 2026-02-12; 36-address on-chain check - NEXT_STEPS_FOR_YOU: Ledger done; steps completable now (no LAN); run-completable-tasks-from-anywhere - MASTER_INDEX, OPERATOR_OPTIONAL, SMART_CONTRACTS_INVENTORY_SIMPLE: updates - LEDGER_BLOCKCHAIN_INTEGRATION_COMPLETE: bis-innovations/LedgerLive reference Co-authored-by: Cursor <cursoragent@cursor.com>
77 lines
2.5 KiB
Bash
77 lines
2.5 KiB
Bash
# Shared helpers for OMNL central bank config scripts.
|
|
# Source from scripts: source "$(dirname "$0")/lib.sh" or similar after setting SCRIPT_DIR.
|
|
|
|
set -euo pipefail
|
|
|
|
# Project root: central-bank-config is scripts/mifos/central-bank-config -> ../../.. = repo root
|
|
SCRIPT_DIR="${SCRIPT_DIR:-$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)}"
|
|
PROJECT_ROOT="${PROJECT_ROOT:-$(cd "$SCRIPT_DIR/../../.." && pwd)}"
|
|
|
|
# Load config and env
|
|
if [ -f "${PROJECT_ROOT}/config/ip-addresses.conf" ]; then
|
|
# shellcheck source=../../config/ip-addresses.conf
|
|
source "${PROJECT_ROOT}/config/ip-addresses.conf"
|
|
fi
|
|
if [ -f "${PROJECT_ROOT}/.env" ]; then
|
|
set +u
|
|
# shellcheck source=../../.env
|
|
source "${PROJECT_ROOT}/.env" 2>/dev/null || true
|
|
set -u
|
|
fi
|
|
|
|
# Fineract API base URL (full path to api/v1), e.g. https://mifos.d-bis.org/fineract-provider/api/v1
|
|
MIFOS_BASE_URL="${MIFOS_BASE_URL:-}"
|
|
MIFOS_TENANT="${MIFOS_TENANT:-default}"
|
|
MIFOS_USER="${MIFOS_USER:-mifos}"
|
|
MIFOS_PASSWORD="${MIFOS_PASSWORD:-}"
|
|
MIFOS_INSECURE="${MIFOS_INSECURE:-0}"
|
|
|
|
# Default to VMID 5800 IP if base URL not set
|
|
if [ -z "$MIFOS_BASE_URL" ]; then
|
|
MIFOS_IP="${MIFOS_IP:-192.168.11.85}"
|
|
MIFOS_BASE_URL="http://${MIFOS_IP}/fineract-provider/api/v1"
|
|
fi
|
|
|
|
# Basic auth
|
|
MIFOS_AUTH="${MIFOS_USER}:${MIFOS_PASSWORD}"
|
|
|
|
curl_opts=(-s -w "\n%{http_code}" -H "X-Fineract-Platform-TenantId: ${MIFOS_TENANT}" -H "Content-Type: application/json")
|
|
[ "$MIFOS_INSECURE" = "1" ] && curl_opts+=(-k)
|
|
|
|
# Usage: api_get <path> -> outputs body on stdout, returns HTTP code in MIFOS_HTTP_CODE
|
|
api_get() {
|
|
local path="$1"
|
|
local out
|
|
out=$(curl "${curl_opts[@]}" -u "$MIFOS_AUTH" "${MIFOS_BASE_URL}/${path}")
|
|
MIFOS_HTTP_CODE=$(echo "$out" | tail -n1)
|
|
echo "$out" | sed '$d'
|
|
}
|
|
|
|
# Usage: api_post <path> <json_body> -> outputs body, sets MIFOS_HTTP_CODE
|
|
api_post() {
|
|
local path="$1"
|
|
local body="$2"
|
|
local out
|
|
out=$(curl "${curl_opts[@]}" -X POST -u "$MIFOS_AUTH" -d "$body" "${MIFOS_BASE_URL}/${path}")
|
|
MIFOS_HTTP_CODE=$(echo "$out" | tail -n1)
|
|
echo "$out" | sed '$d'
|
|
}
|
|
|
|
# Usage: api_put <path> <json_body>
|
|
api_put() {
|
|
local path="$1"
|
|
local body="$2"
|
|
local out
|
|
out=$(curl "${curl_opts[@]}" -X PUT -u "$MIFOS_AUTH" -d "$body" "${MIFOS_BASE_URL}/${path}")
|
|
MIFOS_HTTP_CODE=$(echo "$out" | tail -n1)
|
|
echo "$out" | sed '$d'
|
|
}
|
|
|
|
fail_if_no_credentials() {
|
|
if [ -z "$MIFOS_PASSWORD" ]; then
|
|
echo "Error: MIFOS_PASSWORD (and optionally MIFOS_BASE_URL, MIFOS_TENANT, MIFOS_USER) must be set in .env or environment." >&2
|
|
echo "See scripts/mifos/central-bank-config/README.md" >&2
|
|
exit 1
|
|
fi
|
|
}
|