exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

taler-exchange-helper-measure-test-oauth (5356B)


      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 # Read currency from the config
    104 CURRENCY=$(taler-exchange-config -c "$CONF" -s exchange -o currency)
    105 
    106 # Finally, output the new rules.
    107 # See https://docs.taler.net/taler-exchange-manual.html#tsref-type-AmlOutcome
    108 # for the required output format.
    109 
    110 jq -n \
    111     --argjson expiration "$EXPIRATION" \
    112     --arg currency "$CURRENCY" \
    113     '{ "to_investigate": false,
    114        "new_rules" : {
    115          "custom_measures" : {},
    116          "expiration_time" : { "t_s": $expiration },
    117          "rules" : [
    118          {
    119            "operation_type": "WITHDRAW",
    120            "threshold" : "\($currency):1000",
    121            "timeframe" : { "d_us" : 3600000000 },
    122            "measures" : [ "verboten" ],
    123            "display_priority" : 1,
    124            "exposed" : true,
    125            "is_and_combinator" : true
    126          },
    127          {
    128            "operation_type": "DEPOSIT",
    129            "threshold" : "\($currency):1000",
    130            "timeframe" : { "d_us" : 3600000000 },
    131            "measures" : [ "verboten" ],
    132            "display_priority" : 1,
    133            "exposed" : true,
    134            "is_and_combinator" : true
    135          },
    136          {
    137            "operation_type": "AGGREGATE",
    138            "threshold" : "\($currency):1000",
    139            "timeframe" : { "d_us" : 3600000000 },
    140            "measures" : [ "verboten" ],
    141            "display_priority" : 1,
    142            "exposed" : true,
    143            "is_and_combinator" : true
    144          },
    145          {
    146            "operation_type": "MERGE",
    147            "threshold" : "\($currency):1000",
    148            "timeframe" : { "d_us" : 3600000000 },
    149            "measures" : [ "verboten" ],
    150            "display_priority" : 1,
    151            "exposed" : true,
    152            "is_and_combinator" : true
    153          },
    154          {
    155            "operation_type": "BALANCE",
    156            "threshold" : "\($currency):1000",
    157            "timeframe" : { "d_us" : 3600000000 },
    158            "measures" : [ "verboten" ],
    159            "display_priority" : 1,
    160            "exposed" : true,
    161            "is_and_combinator" : true
    162          },
    163          {
    164            "operation_type": "CLOSE",
    165            "threshold" : "\($currency):1000",
    166            "timeframe" : { "d_us" : 3600000000 },
    167            "measures" : [ "verboten" ],
    168            "display_priority" : 1,
    169            "exposed" : true,
    170            "is_and_combinator" : true
    171          }
    172          ]
    173        }
    174      }' < /dev/null
    175 
    176 exit 0