taler-exchange-helper-measure-test-oauth (5167B)
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 # Exit, with error message (hard failure) 22 function exit_fail() { 23 echo " FAIL: " "$@" >&2 24 EXIT_STATUS=1 25 exit "$EXIT_STATUS" 26 } 27 28 CONF="$HOME/.config/taler-exchange.conf" 29 VERBOSE=0 30 31 while getopts 'ac:hirvV' OPTION; 32 do 33 case "$OPTION" in 34 a) 35 # This AML program expects the following inputs 36 echo "FULL_NAME" 37 echo "DATE_OF_BIRTH" 38 exit 0 39 ;; 40 c) 41 # shellcheck disable=SC2034 42 CONF="$OPTARG" 43 ;; 44 h) 45 echo "This is a KYC measure program that checks the output of an OAuth2 authentication, and if it passed, increases all limits to EUR:1000. (and does not impose any other limits)" 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 ' -i -- show required inputs' 52 echo ' -r -- show required context' 53 echo ' -v -- show version' 54 echo ' -V -- be verbose' 55 exit 0 56 ;; 57 i) 58 # Only attribute inputs are required 59 echo "attributes" 60 exit 0 61 ;; 62 r) 63 # No context is required. 64 exit 0 65 ;; 66 v) 67 echo "$0 v0.0.0" 68 exit 0 69 ;; 70 V) 71 VERBOSE=1 72 ;; 73 ?) 74 exit_fail "Unrecognized command line option" 75 ;; 76 esac 77 done 78 79 if [ 1 = "$VERBOSE" ] 80 then 81 echo "Running $0" 1>&2 82 fi 83 84 # First, check everything we expect is in stdin. 85 A=$(jq -r .attributes) 86 J=$(echo "$A" | jq -r 'def get($k): 87 if has($k) 88 then .[$k] 89 else error("attribute missing") 90 end; 91 {"FULL_NAME":get("FULL_NAME"), 92 "DATE_OF_BIRTH":get("DATE_OF_BIRTH")}') 93 94 # Here we could use those values... 95 echo "$J" >> /dev/null 96 97 # See https://docs.taler.net/taler-kyc-manual.html#tsref-type-AmlProgramInput 98 # for the full JSON with possible inputs. 99 100 # New rules apply for 30 days. 101 EXPIRATION=$((3600 * 30 + $(date +%s))) 102 103 # Finally, output the new rules. 104 # See https://docs.taler.net/taler-exchange-manual.html#tsref-type-AmlOutcome 105 # for the required output format. 106 107 jq -n \ 108 --argjson expiration "$EXPIRATION" \ 109 '{ "to_investigate": false, 110 "new_rules" : { 111 "custom_measures" : {}, 112 "expiration_time" : { "t_s": $expiration }, 113 "rules" : [ 114 { 115 "operation_type": "WITHDRAW", 116 "threshold" : "EUR:1000", 117 "timeframe" : { "d_us" : 3600000000 }, 118 "measures" : [ "verboten" ], 119 "display_priority" : 1, 120 "exposed" : true, 121 "is_and_combinator" : true 122 }, 123 { 124 "operation_type": "DEPOSIT", 125 "threshold" : "EUR:1000", 126 "timeframe" : { "d_us" : 3600000000 }, 127 "measures" : [ "verboten" ], 128 "display_priority" : 1, 129 "exposed" : true, 130 "is_and_combinator" : true 131 }, 132 { 133 "operation_type": "AGGREGATE", 134 "threshold" : "EUR:1000", 135 "timeframe" : { "d_us" : 3600000000 }, 136 "measures" : [ "verboten" ], 137 "display_priority" : 1, 138 "exposed" : true, 139 "is_and_combinator" : true 140 }, 141 { 142 "operation_type": "MERGE", 143 "threshold" : "EUR:1000", 144 "timeframe" : { "d_us" : 3600000000 }, 145 "measures" : [ "verboten" ], 146 "display_priority" : 1, 147 "exposed" : true, 148 "is_and_combinator" : true 149 }, 150 { 151 "operation_type": "BALANCE", 152 "threshold" : "EUR:1000", 153 "timeframe" : { "d_us" : 3600000000 }, 154 "measures" : [ "verboten" ], 155 "display_priority" : 1, 156 "exposed" : true, 157 "is_and_combinator" : true 158 }, 159 { 160 "operation_type": "CLOSE", 161 "threshold" : "EUR:1000", 162 "timeframe" : { "d_us" : 3600000000 }, 163 "measures" : [ "verboten" ], 164 "display_priority" : 1, 165 "exposed" : true, 166 "is_and_combinator" : true 167 } 168 ] 169 } 170 }' < /dev/null 171 172 exit 0