commit 71e7bf2c5c49e2be354adb82a3f0d335ee526e22
parent a200d4b3b2f01a33e6b2ff12c07760396126e45d
Author: Christian Grothoff <christian@grothoff.org>
Date: Sun, 13 Apr 2025 15:53:22 +0200
modify rules, do not select and trim the rest'
Diffstat:
6 files changed, 31 insertions(+), 31 deletions(-)
diff --git a/src/kyclogic/taler-exchange-helper-measure-inform-investigate b/src/kyclogic/taler-exchange-helper-measure-inform-investigate
@@ -89,7 +89,7 @@ CURRENT_RULES=$(jq '.current_rules')
# FIXME: not generic, figure out how to do this nicely regardless of
# what rule we are at.
-NEW_RULES=$(echo "$CURRENT_RULES" | jq '(.rules[] | select (.rule_name=="deposit-limit-zero").measures=["form-info-investigation"])')
+NEW_RULES=$(echo "$CURRENT_RULES" | jq '(.rules[] |= if (.rule_name=="deposit-limit-zero") then .measures=["form-info-investigation"] else . end)')
# Finally, output the new rules.
diff --git a/src/kyclogic/taler-exchange-helper-measure-tops-3rdparty-check b/src/kyclogic/taler-exchange-helper-measure-tops-3rdparty-check
@@ -113,7 +113,7 @@ in
"error")
# This should not happen, immediately trigger investigation and show error to the user.
echo "ERROR: Unexpected value for controlling entity is 3rd person '${CONTROL3P}'" 1>&2
- NEW_RULES=$(echo "$CURRENT_RULES" | jq '(.rules[] | select (.rule_name=="deposit-limit-zero").measures=["form-info-internal-error"])')
+ NEW_RULES=$(echo "$CURRENT_RULES" | jq '(.rules[] | select (.rule_name=="deposit-limit-zero") | .measures=["form-info-internal-error"])')
INVESTIGATE="true"
;;
"none")
@@ -126,7 +126,7 @@ in
echo "Selected VQF form ${FORM}." 1&>2
# Force user to fill in $FORM
- NEW_RULES=$(echo "$CURRENT_RULES" | jq '(.rules[] | select (.rule_name=="deposit-limit-zero").measures=["form-${FORM}"])')
+ NEW_RULES=$(echo "$CURRENT_RULES" | jq '(.rules[] |= if (.rule_name=="deposit-limit-zero") then .measures=["form-${FORM}"] else . end)')
INVESTIGATE="false"
;;
esac
diff --git a/src/kyclogic/taler-exchange-helper-measure-tops-address-check b/src/kyclogic/taler-exchange-helper-measure-tops-address-check
@@ -18,7 +18,6 @@
# Hard error reporting on.
set -eu
-
# Exit, with error message (hard failure)
function exit_fail() {
echo " FAIL: " "$@" >&2
@@ -90,15 +89,15 @@ fi
INPUTS=$(jq '{"current_rules":.current_rules,"attributes":.attributes}')
# Get address data
-CUSTOMER_TYPE=$(echo "$INPUTS" | jq '.attributes.CUSTOMER_TYPE // null')
+CUSTOMER_TYPE=$(echo "$INPUTS" | jq -r '.attributes.CUSTOMER_TYPE // null')
case "$CUSTOMER_TYPE"
in
"NATURAL_PERSON")
- CONTACT_NAME=$(echo "$INPUTS" | jq '.attributes.FULL_NAME')
+ CONTACT_NAME=$(echo "$INPUTS" | jq -r '.attributes.FULL_NAME')
;;
"LEGAL_ENTITY")
- BUSINESS_NAME=$(echo "$INPUTS" | jq '.attributes.COMPANY_NAME')
- CONTACT_PERSON=$(echo "$INPUTS" | jq '.attributes.CONTACT_PERSON_NAME // null')
+ BUSINESS_NAME=$(echo "$INPUTS" | jq -r '.attributes.COMPANY_NAME')
+ CONTACT_PERSON=$(echo "$INPUTS" | jq -r '.attributes.CONTACT_PERSON_NAME // null')
if [ "null" != "$CONTACT_PERSON" ]
then
CONTACT_NAME=$(echo -en "${BUSINESS_NAME}\nAttn. ${CONTACT_PERSON_NAME}")
@@ -106,19 +105,19 @@ in
CONTACT_NAME="$BUSINESS_NAME"
fi
;;
- "OTHER")
*)
# Strange, we don't know. Let's try everything...
- CONTACT_NAME=$(echo "$INPUTS" | jq '.attributes.CONTACT_NAME // attributes.FULL_NAME // .attributes.COMPANY_NAME')
+ CONTACT_NAME=$(echo "$INPUTS" | jq -r '.attributes.CONTACT_NAME // attributes.FULL_NAME // .attributes.COMPANY_NAME')
;;
esac
ADDRESS_LINES=$(echo "$INPUTS" | jq '.attributes.DOMICILE_ADDRESS')
-ADDRESS_COUNTRY=$(echo "$INPUTS" | jq '.attributes.ADDRESS_COUNTRY')
+# We ONLY allow Swiss addresses
+ADDRESS_COUNTRY='"CH"'
# Convert address data to Challenger format as best we can.
-ADDRESS=$(jq \
- --argjson contact_name "$CONTACT_NAME" \
+ADDRESS=$(jq -n \
+ --argjson contact_name \""$CONTACT_NAME"\" \
--argjson address_lines "$ADDRESS_LINES" \
--argjson address_country "$ADDRESS_COUNTRY" \
'{"contact_name":$contact_name,"address_lines":$address_lines,"address_country":$address_country}')
@@ -131,21 +130,22 @@ EXPIRATION_TIME=$(echo "$INPUTS" | jq '.context.expiration_time // .current_rule
SUCCESSOR_MEASURE=$(echo "$INPUTS" | jq '.current_rules.successor_measure // null')
# Define custom measure for address validation
-CUSTOM_MEASURES=$(jq \
+CUSTOM_MEASURES=$(jq -n \
--argjson address "$ADDRESS" \
'{"custom-address-investigation":{"context":{"initial_address":$address},"check_name":"postal-registration","prog_name":"inform-investigate","operation_type":"DEPOSIT"}}')
# Then trigger Challenger address check via oauth2, kyc-check-postal-registration
-NEW_RULES=$(echo "$CURRENT_RULES" | jq '(.rules[] | select (.rule_name=="deposit-limit-zero").measures=["custom-address-investigation"])' | jq --argjson cm "$CUSTOM_MEASURES" '.custom_measures=$cm')
+NEW_RULES=$(echo "$CURRENT_RULES" | jq '(.rules[] |= if (.rule_name=="deposit-limit-zero") then .measures=["custom-address-investigation"] else . end)' | jq --argjson cm "$CUSTOM_MEASURES" '.custom_measures=$cm')
# Finally, output the new rules.
# See https://docs.taler.net/taler-kyc-manual.html#tsref-type-AmlOutcome
# for the required output format.
-jq \
+
+jq -n \
--argjson et "$EXPIRATION_TIME" \
--argjson sm "$SUCCESSOR_MEASURE" \
--argjson cm "$CUSTOM_MEASURES" \
--argjson nr "$NEW_RULES" \
- '{"new_rules":$nr+{"expiration_time":$et,"successor_measure":$sm,"custom_measures":({}+$nr.custom_measures+$cm)}}|del(..|nulls)'
+ '{"new_rules":($nr+{"expiration_time":$et,"successor_measure":$sm,"custom_measures":({}+$nr.custom_measures+$cm)})}|del(..|nulls)'
exit 0
diff --git a/src/kyclogic/taler-exchange-helper-measure-tops-kyx-check b/src/kyclogic/taler-exchange-helper-measure-tops-kyx-check
@@ -90,7 +90,7 @@ fi
INPUTS=$(jq '{"current_rules":.current_rules,"attributes":.attributes}')
# Get entity type
-LEGAL_ENTITY=$(echo "$INPUTS" | jq '.attributes.CUSTOMER_TYPE_VQF // null')
+LEGAL_ENTITY=$(echo "$INPUTS" | jq -r '.attributes.CUSTOMER_TYPE_VQF // null')
# Get current rules.
CURRENT_RULES=$(echo "$INPUTS" | jq '.current_rules // null')
# Get context values.
@@ -102,22 +102,22 @@ case "$LEGAL_ENTITY"
in
"NATURAL_PERSON")
FORM="none"
- ;;
+ ;;
"OPERATIONAL")
FORM="902.11"
- ;;
+ ;;
"FOUNDATION")
FORM="902.12"
- ;;
+ ;;
"TRUST")
FORM="902.13"
- ;;
+ ;;
"LIFE_INSURANCE")
FORM="902.15"
- ;;
+ ;;
"OTHER")
FORM="902.9"
- ;;
+ ;;
esac
# Check high-level case
@@ -126,7 +126,7 @@ in
"error")
# This should not happen, immediately trigger investigation and show error to the user.
echo "ERROR: Unexpected legal entity '${LEGAL_ENTITY}'" 1>&2
- NEW_RULES=$(echo "$CURRENT_RULES" | jq '(.rules[] | select (.rule_name=="deposit-limit-zero").measures=["form-info-internal-error"])')
+ NEW_RULES=$(echo "$CURRENT_RULES" | jq '(.rules[] |= if (.rule_name=="deposit-limit-zero") then .measures=["form-info-internal-error"] else . end)')
INVESTIGATE="true"
;;
"none")
@@ -139,24 +139,24 @@ in
echo "Selected VQF form ${FORM}." 1&>2
# Force user to fill in $FORM
- NEW_RULES=$(echo "$CURRENT_RULES" | jq '(.rules[] | select (.rule_name=="deposit-limit-zero").measures=["form-${FORM}"])')
+ NEW_RULES=$(echo "$CURRENT_RULES" | jq '(.rules[] |= if (.rule_name=="deposit-limit-zero") then .measures=["form-${FORM}"] else . end)')
INVESTIGATE="false"
;;
esac
# When the information expires, simply ask the user to do the
# same form again.
-SUCCESSOR_MEASURE="kyx"
+SUCCESSOR_MEASURE='"kyx"'
# Finally, output the new rules.
# See https://docs.taler.net/taler-kyc-manual.html#tsref-type-AmlOutcome
# for the required output format.
+
jq -n \
--argjson inv "$INVESTIGATE" \
--argjson et "$EXPIRATION_TIME" \
--argjson sm "$SUCCESSOR_MEASURE" \
- --argjson cm "$CUSTOM_MEASURES" \
--argjson nr "$NEW_RULES" \
- '{"to_investigate":$inv,"new_rules":($nr+{"expiration_time":$et,"successor_measure":$sm,"custom_measures":($nr.custom_measures+$cm)})}|del(..|nulls)'
+ '{"to_investigate":$inv,"new_rules":($nr+{"expiration_time":$et,"successor_measure":$sm,"custom_measures":($nr.custom_measures)})}|del(..|nulls)'
exit 0
diff --git a/src/kyclogic/taler-exchange-helper-measure-tops-postal-check b/src/kyclogic/taler-exchange-helper-measure-tops-postal-check
@@ -92,7 +92,7 @@ fi
INPUTS=$(jq '{"current_rules":.current_rules,"attributes":.attributes,"context":.context}')
# Get country number.
-COUNTRY=$(echo "$INPUTS" | jq '.attributes.ADDRESS_COUNTRY_CC // null')
+COUNTRY=$(echo "$INPUTS" | jq -r '.attributes.ADDRESS_COUNTRY_CC // null')
# Get current rules.
CURRENT_RULES=$(echo "$INPUTS" | jq '.current_rules // null')
# Get context values.
diff --git a/src/kyclogic/taler-exchange-helper-measure-tops-sms-check b/src/kyclogic/taler-exchange-helper-measure-tops-sms-check
@@ -88,7 +88,7 @@ fi
INPUTS=$(jq '{"current_rules":.current_rules,"attributes":.attributes,"context":.context}')
# Get phone number.
-PHONE_NUMBER=$(echo "$INPUTS" | jq '.attributes.CONTACT_PHONE // null')
+PHONE_NUMBER=$(echo "$INPUTS" | jq -r '.attributes.CONTACT_PHONE // null')
# Get current rules.
CURRENT_RULES=$(echo "$INPUTS" | jq '.current_rules // null')
# Get context values.