Connect local SXCHNGE to the Sendico stand
This commit was merged in pull request #53.
This commit is contained in:
1 parent
34d8ef18d1
commit
a5689876ff
14 files changed
+336
-9
No files matched your search
@@ -0,0 +1,11 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
umask 077
|
||||
check=$(mktemp -d /private/check.XXXXXX)
|
||||
trap 'rm -rf "$check"' EXIT
|
||||
printf 'Authorization: Bearer %s\n' "$(cat /run/sendico/access-token)" > "$check/header"
|
||||
for path in "payments/fx/currencies/$SENDICO_ORGANIZATION_REF" "ledger_accounts/$SENDICO_ORGANIZATION_REF"; do
|
||||
curl -fsS --max-time 15 -H "@$check/header" "http://127.0.0.1:18081/api/v1/$path" > "$check/response" 2>/dev/null || { echo 'Local Sendico authenticated API check failed' >&2; exit 1; }
|
||||
jq -e '.status=="success"' "$check/response" >/dev/null
|
||||
done
|
||||
echo 'PASS: local Sendico authenticated currency and ledger APIs are accessible'
|
||||
@@ -0,0 +1,30 @@
|
||||
# Enabled by make sendico; settings contain no credentials.
|
||||
services:
|
||||
bff:
|
||||
environment:
|
||||
SXCHNGE_SENDICO_LOCAL: '1'
|
||||
volumes:
|
||||
- ./.local/dev/sendico/runtime.yml:/etc/sxchnge/bff.yml:ro
|
||||
- sendico-session:/run/sendico:ro
|
||||
|
||||
sendico:
|
||||
image: sxchnge-local/tools:dev
|
||||
restart: unless-stopped
|
||||
# Keep the adapter's loopback-only HTTP rule; forward to the public stand API.
|
||||
network_mode: service:bff
|
||||
entrypoint: [/bin/sh, /etc/sendico/session.sh]
|
||||
env_file: ./.local/dev/sendico/settings.env
|
||||
volumes:
|
||||
- ./infra/local/sendico/session.sh:/etc/sendico/session.sh:ro
|
||||
- ./infra/local/sendico/check.sh:/etc/sendico/check.sh:ro
|
||||
- ./.local/dev/agents/sendico:/etc/agent:ro
|
||||
- sendico-session:/run/sendico
|
||||
tmpfs: [/private:mode=0700]
|
||||
healthcheck:
|
||||
test: [CMD-SHELL, 'test -f /private/ready && test $$(($$(date +%s) - $$(stat -c %Y /private/ready))) -lt 1500 && curl -fsS --max-time 2 http://127.0.0.1:18081/api/v1/health >/dev/null']
|
||||
interval: 10s
|
||||
timeout: 3s
|
||||
retries: 30
|
||||
|
||||
volumes:
|
||||
sendico-session:
|
||||
@@ -0,0 +1,45 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
umask 077
|
||||
mkdir -p /private /run/sendico
|
||||
chmod 755 /run/sendico
|
||||
cd /private
|
||||
socat TCP4-LISTEN:18081,bind=127.0.0.1,reuseaddr,fork TCP4:host.docker.internal:8080 &
|
||||
bridge=$!
|
||||
trap 'kill "$bridge" 2>/dev/null || true' EXIT
|
||||
trap 'exit 0' INT TERM
|
||||
|
||||
session() {
|
||||
jq -n --rawfile role /etc/agent/role-id --rawfile secret /etc/agent/secret-id \
|
||||
'{role_id:($role|rtrimstr("\n")),secret_id:($secret|rtrimstr("\n"))}' > login.json
|
||||
curl -fsS --max-time 15 -H 'Content-Type: application/json' --data-binary @login.json \
|
||||
http://vault:8200/v1/auth/approle/login > vault.json 2>/dev/null || return 1
|
||||
jq -er '"X-Vault-Token: "+.auth.client_token' vault.json > vault.header || return 1
|
||||
curl -fsS --max-time 15 -H @vault.header http://vault:8200/v1/kv/data/services/bff/sendico > credentials.json 2>/dev/null || return 1
|
||||
jq -e --arg client "$SENDICO_CLIENT_ID" --arg device "$SENDICO_DEVICE_ID" \
|
||||
'.data.data | {login:{login,password},clientSecret:.client_secret,clientId:$client,deviceId:$device}' credentials.json > request.json || return 1
|
||||
curl -fsS --max-time 15 -H @vault.header -X POST http://vault:8200/v1/auth/token/revoke-self >/dev/null 2>&1 || return 1
|
||||
rm -f vault.header vault.json credentials.json login.json
|
||||
curl -fsS --max-time 20 -H 'Content-Type: application/json' --data-binary @request.json \
|
||||
http://127.0.0.1:18081/api/v1/accounts/login/api > response.json 2>/dev/null || return 1
|
||||
rm -f request.json
|
||||
jq -er '.data.accessToken.token' response.json > token 2>/dev/null || return 1
|
||||
jq -e --arg source "$SENDICO_SOURCE_ACCOUNT_REF" \
|
||||
'.data.accessToken.token | split(".")[1] | gsub("-";"+") | gsub("_";"/") | @base64d | fromjson | .id==$source and .pending!=true and .exp>(now+1500)' response.json >/dev/null 2>&1 || return 1
|
||||
cp token /run/sendico/access-token.new
|
||||
chmod 444 /run/sendico/access-token.new
|
||||
mv /run/sendico/access-token.new /run/sendico/access-token
|
||||
rm -f token response.json
|
||||
touch ready
|
||||
}
|
||||
|
||||
while :; do
|
||||
if session; then
|
||||
echo 'Local Sendico session ready; next renewal in 20 minutes.'
|
||||
sleep 1200 & wait $!
|
||||
else
|
||||
echo 'Local Sendico session unavailable; check stand health and integration credentials. Retrying in 5 minutes.' >&2
|
||||
rm -f request.json response.json token vault.header vault.json credentials.json login.json
|
||||
sleep 300 & wait $!
|
||||
fi
|
||||
done
|
||||
Reference in new issue
Block a user