sandcastle-amp-email (5033B)
1 #!/bin/bash 2 # 3 # This file is part of TALER 4 # Copyright (C) 2014-2024 Taler Systems SA 5 # 6 # TALER is free software; you can redistribute it and/or modify it under the 7 # terms of the GNU General Public License as published by the Free Software 8 # Foundation; either version 3, or (at your option) any later version. 9 # 10 # TALER is distributed in the hope that it will be useful, but WITHOUT ANY 11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details. 13 # 14 # You should have received a copy of the GNU General Public License along with 15 # TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/license> 16 # 17 18 # Hard error reporting on. 19 set -eu 20 21 22 # Exit, with error message (hard failure) 23 function exit_fail() { 24 echo " FAIL: " "$@" >&2 25 EXIT_STATUS=1 26 exit "$EXIT_STATUS" 27 } 28 29 CONF="$HOME/.config/taler-exchange.conf" 30 VERBOSE=0 31 32 while getopts 'aic:hrvV' OPTION; 33 do 34 case "$OPTION" in 35 a) 36 # Expected inputs (one per line) 37 echo "email" 38 exit 0 39 ;; 40 c) 41 # shellcheck disable=SC2034 42 CONF="$OPTARG" 43 ;; 44 h) 45 echo 'This is a sample AML measure program' 46 echo 'Supported options:' 47 echo ' -a -- show required attributes' 48 # shellcheck disable=SC2016 49 echo ' -c $CONF -- set configuration' 50 echo ' -h -- print this help' 51 echo ' -r -- show required context' 52 echo ' -v -- show version' 53 echo ' -V -- be verbose' 54 ;; 55 r) 56 # No context is required. 57 exit 0 58 ;; 59 i) 60 echo attributes 61 exit 0 62 ;; 63 v) 64 echo "$0 v0.0.0" 65 exit 0 66 ;; 67 V) 68 VERBOSE=1 69 ;; 70 ?) 71 exit_fail "Unrecognized command line option" 72 ;; 73 esac 74 done 75 76 if [ 1 = "$VERBOSE" ] 77 then 78 echo "Running $0" 1>&2 79 fi 80 81 # First, check everything we expect is in stdin. 82 A=$(jq -r .attributes) 83 J=$(echo "$A" | jq -r 'def get($k): 84 if has($k) 85 then .[$k] 86 else error("attribute missing") 87 end; 88 {"email":get("email")}') 89 90 # Here we could use those values... 91 echo "$J" >> /dev/null 92 93 # See https://docs.taler.net/taler-exchange-manual.html#tsref-type-AmlProgramInput 94 # for the full JSON with possible inputs. 95 96 # New rules apply for 30 days. 97 EXPIRATION=$((3600 * 30 + $(date +%s))) 98 99 # Read currency from the config 100 CURRENCY=$(taler-exchange-config -c $CONF -s exchange -o currency) 101 102 # Finally, output the new rules. 103 # See https://docs.taler.net/taler-exchange-manual.html#tsref-type-AmlOutcome 104 # for the required output format. 105 106 jq -n \ 107 --argjson expiration "$EXPIRATION" \ 108 --arg currency "$CURRENCY" \ 109 '{ "to_investigate": false, 110 "new_rules" : { 111 "new_check" : "info-oauth-test-passed", 112 "expiration_time" : { "t_s": $expiration }, 113 "custom_measures" : {}, 114 "rules" : [ 115 { 116 "operation_type": "WITHDRAW", 117 "threshold" : "\($currency):1000", 118 "timeframe" : { "d_us" : 3600000000 }, 119 "measures" : [ "verboten" ], 120 "display_priority" : 1, 121 "exposed" : true, 122 "is_and_combinator" : true 123 }, 124 { 125 "operation_type": "DEPOSIT", 126 "threshold" : "\($currency):1000", 127 "timeframe" : { "d_us" : 3600000000 }, 128 "measures" : [ "verboten" ], 129 "display_priority" : 1, 130 "exposed" : true, 131 "is_and_combinator" : true 132 }, 133 { 134 "operation_type": "AGGREGATE", 135 "threshold" : "\($currency):1000", 136 "timeframe" : { "d_us" : 3600000000 }, 137 "measures" : [ "verboten" ], 138 "display_priority" : 1, 139 "exposed" : true, 140 "is_and_combinator" : true 141 }, 142 { 143 "operation_type": "MERGE", 144 "threshold" : "\($currency):1000", 145 "timeframe" : { "d_us" : 3600000000 }, 146 "measures" : [ "verboten" ], 147 "display_priority" : 1, 148 "exposed" : true, 149 "is_and_combinator" : true 150 }, 151 { 152 "operation_type": "BALANCE", 153 "threshold" : "\($currency):1000", 154 "timeframe" : { "d_us" : 3600000000 }, 155 "measures" : [ "verboten" ], 156 "display_priority" : 1, 157 "exposed" : true, 158 "is_and_combinator" : true 159 }, 160 { 161 "operation_type": "CLOSE", 162 "threshold" : "\($currency):1000", 163 "timeframe" : { "d_us" : 3600000000 }, 164 "measures" : [ "verboten" ], 165 "display_priority" : 1, 166 "exposed" : true, 167 "is_and_combinator" : true 168 } 169 ] 170 } 171 }' < /dev/null 172 173 exit 0