ansible-taler-exchange

Ansible playbook to deploy a production Taler Exchange
Log | Files | Refs | Submodules | README | LICENSE

taler-devtesting (2610B)


      1 #!/usr/bin/env python3
      2 
      3 import click
      4 import shlex
      5 import os
      6 import sys
      7 import subprocess
      8 
      9 
     10 @click.group()
     11 def cli():
     12     pass
     13 
     14 
     15 def get_nexus_currency():
     16     currency_out = subprocess.check_output(
     17         "libeufin-nexus config get nexus-ebics currency",
     18         shell=True,
     19         encoding="utf-8",
     20         stderr=subprocess.DEVNULL,
     21     )
     22     return currency_out.strip().upper()
     23 
     24 
     25 @cli.command()
     26 @click.option("--credit-payto", help="The credited account IBAN payto URI")
     27 @click.option("--debit-payto", help="The debited account IBAN payto URI")
     28 @click.option(
     29     "--subject",
     30     help="The payment subject, credit-payto 'message' parameter takes the precedence",
     31 )
     32 @click.option(
     33     "--amount",
     34     help="The payment amount, credit-payto 'amount' parameter takes the precedence",
     35 )
     36 def fake_incoming(credit_payto, debit_payto, subject, amount):
     37     currency = get_nexus_currency()
     38     opts = []
     39     if debit_payto is not None:
     40         opts += ["--debit-payto", debit_payto]
     41     if credit_payto is not None:
     42         opts += ["--credit-payto", credit_payto]
     43     if subject is not None:
     44         opts += ["--subject", subject]
     45     if amount is not None:
     46         opts += ["--amount", amount]
     47     print(f"Faking incoming {currency} transaction", file=sys.stderr)
     48     print(f"Debit Payto: ", debit_payto, file=sys.stderr)
     49     subprocess.run(
     50         [
     51             "sudo",
     52             "-u",
     53             "libeufin-nexus",
     54             "libeufin-nexus",
     55             "testing",
     56             "fake-incoming",
     57             *opts,
     58         ],
     59         check=True,
     60     )
     61 
     62 
     63 @cli.command()
     64 def geniban():
     65     currency = get_nexus_currency()
     66     if currency == "CHF":
     67         cc = "CH"
     68     elif currency == "EUR":
     69         cc = "DE"
     70     else:
     71         raise Exception(f"unsupported currency {repr(currency)}")
     72     subprocess.run(
     73         [
     74             "libeufin-nexus",
     75             "testing",
     76             "iban",
     77             "gen",
     78             "--country",
     79             cc,
     80         ]
     81     )
     82 
     83 @cli.command()
     84 @click.argument('section', nargs=1, type=click.STRING)
     85 def challenger(section):
     86     subprocess.run(
     87         [
     88             "sudo",
     89             "-u",
     90             "taler-exchange-httpd",
     91             "taler-devtesting-exchange-challenger-setup",
     92             "-c",
     93             "/etc/taler-exchange/taler-exchange.conf",
     94             section
     95         ],
     96         check=True,
     97     )
     98 
     99 if __name__ == "__main__":
    100     orig_cmd = os.environ.get("SSH_ORIGINAL_COMMAND")
    101     if orig_cmd:
    102         print("Running command", repr(orig_cmd), file=sys.stderr)
    103         cmd = shlex.split(orig_cmd)
    104     else:
    105         cmd = sys.argv[1:]
    106     cli(cmd)