taler-devtesting (2629B)
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("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 check=True, 82 ) 83 84 @cli.command() 85 @click.argument('section', nargs=1, type=click.STRING) 86 def challenger(section): 87 subprocess.run( 88 [ 89 "sudo", 90 "-u", 91 "taler-exchange-httpd", 92 "taler-devtesting-exchange-challenger-setup", 93 "-c", 94 "/etc/taler-exchange/taler-exchange.conf", 95 section 96 ], 97 check=True, 98 ) 99 100 if __name__ == "__main__": 101 orig_cmd = os.environ.get("SSH_ORIGINAL_COMMAND") 102 if orig_cmd: 103 print("Running command", repr(orig_cmd), file=sys.stderr) 104 cmd = shlex.split(orig_cmd) 105 else: 106 cmd = sys.argv[1:] 107 cli(cmd)