Files
sxchnge/infra/local/scripts/sendico.sh

21 lines
1.2 KiB
Bash

# Operator input is JSON on stdin. Only credential values are stored in Vault.
configure_sendico() {
existing
cat > "$WORK/input"
jq -e '
(.organization_ref|test("^[0-9a-f]{24}$") and .!="000000000000000000000000") and
(.source_account_ref|test("^[0-9a-f]{24}$") and .!="000000000000000000000000") and
([.client_id,.device_id,.login,.password,.client_secret] | all(.[]; type=="string" and test("\\S"))) and
([.client_id,.device_id] | all(.[]; test("^[A-Za-z0-9._-]+$")))
' "$WORK/input" >/dev/null || fail 'Invalid Sendico operator input'
jq '{login,password,client_secret}' "$WORK/input" | put services/bff/sendico
mkdir -p "$STATE/sendico"
jq -r '"SENDICO_ORGANIZATION_REF="+.organization_ref+"\nSENDICO_SOURCE_ACCOUNT_REF="+.source_account_ref+"\nSENDICO_CLIENT_ID="+.client_id+"\nSENDICO_DEVICE_ID="+.device_id' "$WORK/input" | write "$STATE/sendico/settings.env"
{
cat infra/local/bff/runtime.yml
jq -r '"\n sendico:\n api_url: http://127.0.0.1:18081/api/v1\n organization_ref: "+.organization_ref+"\n source_account_ref: "+.source_account_ref+"\n token_file: /run/sendico/access-token"' "$WORK/input"
} | write "$STATE/sendico/runtime.yml" 644
provision_agents
echo 'Local Sendico connection configured. Run make up.'
}