diff options
author | ms <ms@taler.net> | 2021-11-20 21:15:48 +0100 |
---|---|---|
committer | ms <ms@taler.net> | 2021-11-20 21:15:48 +0100 |
commit | 7aff41bc86bfffc10783506cc0404e3aeabc8da0 (patch) | |
tree | c50b97ecfaac5ee8222178d2f34e573b95753285 /bin | |
parent | 79319d11ca1c0aa5f10d81faebe0e5dd2ed10e25 (diff) | |
download | deployment-7aff41bc86bfffc10783506cc0404e3aeabc8da0.tar.gz deployment-7aff41bc86bfffc10783506cc0404e3aeabc8da0.tar.bz2 deployment-7aff41bc86bfffc10783506cc0404e3aeabc8da0.zip |
Get donations to function with taler-local.
And provide a 'withdraw' subcommand to automate
the withdrawal creation -> selection -> confirmation
steps.
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/WIP/taler-local | 363 |
1 files changed, 206 insertions, 157 deletions
diff --git a/bin/WIP/taler-local b/bin/WIP/taler-local index a0a0248..e26610b 100755 --- a/bin/WIP/taler-local +++ b/bin/WIP/taler-local @@ -548,6 +548,8 @@ class TalerReverseProxy(Flask): return self +# Defining certain globals here because 'prepare', +# 'launch' and 'withdraw' need them. LOG_DIR = TALER_ROOT_DIR / "logs" UNIX_SOCKETS_DIR = TALER_ROOT_DIR / "sockets" REV_PROXY_NETLOC = "localhost:8080" @@ -555,8 +557,16 @@ REV_PROXY_PROTO = "http" NEXUS_DB_FILE = "/tmp/nexus.sqlite" SANDBOX_DB_FILE = "/tmp/sandbox.sqlite" REV_PROXY_URL = f"{REV_PROXY_PROTO}://{REV_PROXY_NETLOC}" +SANDBOX_ADMIN_USERNAME = "admin" SANDBOX_ADMIN_PASSWORD = "secret" - +EXCHANGE_BANK_ACCOUNT_SANDBOX = "exchange-account-sandbox" +CUSTOMER_BANK_ACCOUNT = "sandbox-account-customer" +CURRENCY = "EUR" + +# FIXME: see whether the hard-coded proxy can be replaced +# by a Nginx instance, and the Command class can be replaced +# by tasking SystemD to launch and stop the services along +# the preparation. @cli.command() def prepare(): @@ -727,8 +737,7 @@ def prepare(): env ).run() - CURRENCY = "EUR" - WIRE_METHOD = "sepa" + WIRE_METHOD = "iban" # euFin URLs SANDBOX_URL = REV_PROXY_URL + "/sandbox" @@ -738,21 +747,26 @@ def prepare(): CFG_OUTDIR = TALER_ROOT_DIR / "config" TALER_RUNTIME_DIR = TALER_ROOT_DIR / "runtime" TALER_DATA_DIR = TALER_ROOT_DIR / "data" - TALER_UNIT_FILES_DIR = TALER_ROOT_DIR / "systemd-unit-files" + TALER_UNIT_FILES_DIR = systemd_user_dir = Path.home() / ".config" / "systemd" / "user" + def get_random_iban(): + cc_no_check = 131400 # is "DE00" + bban = "".join(random.choices("0123456789", k=4)) + check_digits = 98 - (int(f"{bban}{cc_no_check}") % 97) + return "DE" + (f"0{check_digits}"[-2:]) + bban + # IBANs - IBAN_EXCHANGE = "EX00000000000000000000" - IBAN_CUSTOMER = "WA00000000000000000000" - IBAN_MERCHANT_DEFAULT = "ME00000000000000000000" - IBAN_MERCHANT_DEMOSHOP = "ME00000000000000000001" + IBAN_EXCHANGE = get_random_iban() + IBAN_CUSTOMER = get_random_iban() + IBAN_MERCHANT_DEFAULT = get_random_iban() + IBAN_MERCHANT_DEMOSHOP = get_random_iban() # Instances INSTANCES = { - "demoshop": IBAN_MERCHANT_DEMOSHOP + "GNUnet": IBAN_MERCHANT_DEMOSHOP } # Credentials / API keys - SANDBOX_ADMIN_USERNAME = "admin" EXCHANGE_NEXUS_USERNAME = "exchange-nexus-user" EXCHANGE_NEXUS_PASSWORD = "exchange-nexus-password" FRONTENDS_API_TOKEN = "secret-token:secret" @@ -766,7 +780,6 @@ def prepare(): # euFin EXCHANGE_BANK_ACCOUNT_NEXUS = "exchange-imported-account-nexus" - EXCHANGE_BANK_ACCOUNT_SANDBOX = "exchange-account-sandbox" EXCHANGE_BANK_CONNECTION = "exchange-ebics-connection" EXCHANGE_FACADE_NAME = "exchange-taler-facade" @@ -776,12 +789,12 @@ def prepare(): custom_name=None, capture_stdout=False ): if len(cmd) == 0: - fail("Could not find a command to execute") + fail("Command to execute was given empty.") self.name = custom_name if custom_name else cmd[0] self.cmd = cmd - self.env = env self.capture_stdout = capture_stdout self.log_dir = log_dir + self.env = env @staticmethod def is_serving(check_url, tries=10): @@ -848,7 +861,7 @@ def prepare(): env=self.env ) except Exception as error: - fail(f"Could not execute: {' '.join(self.cmd)} (a.k.a. {self.name}): {error}") + fail(f"Could not execute: {' '.join(self.cmd)}: {error}") atexit.register(self.stop) class ConfigFile: @@ -909,7 +922,7 @@ def prepare(): currency, rev_proxy_url, wire_method, - exchange_wire_address, + exchange_iban, merchant_wire_address, exchange_wire_gateway_username, exchange_wire_gateway_password, @@ -1031,10 +1044,10 @@ def prepare(): obj.cfg_put("auditordb-postgres", "db_conn_str", "postgres:///taler") obj.cfg_put("auditordb-postgres", "config", "postgres:///taler") + # Better to get this value from GET /accounts at Sandbox. obj.cfg_put( "exchange-account-1", - "payto_uri", - f"payto://{wire_method}/{rev_proxy_url + '/bank'}/{exchange_wire_address}" + "payto_uri", f"payto://iban/SANDBOXX/{exchange_iban}?receiver-name=Unknown" ) obj.cfg_put("exchange-account-1", "enable_debit", "yes") obj.cfg_put("exchange-account-1", "enable_credit", "yes") @@ -1119,7 +1132,7 @@ def prepare(): currency=CURRENCY, rev_proxy_url=REV_PROXY_URL, wire_method=WIRE_METHOD, - exchange_wire_address=IBAN_EXCHANGE, + exchange_iban=IBAN_EXCHANGE, merchant_wire_address=IBAN_MERCHANT_DEFAULT, exchange_wire_gateway_username=EXCHANGE_NEXUS_USERNAME, exchange_wire_gateway_password=EXCHANGE_NEXUS_PASSWORD, @@ -1215,12 +1228,12 @@ Logs: {rev_proxy.get_log_filename()}" "download", "sign", "upload" ]).run() print(" OK") - PAYTO_URI=mc.sections["exchange-account-1"]["payto_uri"] - print_nn(f"exchange-offline: enabling {PAYTO_URI}...") + EXCHANGE_PAYTO=mc.sections["exchange-account-1"]["payto_uri"] + print_nn(f"exchange-offline: enabling {EXCHANGE_PAYTO}...") Command([ "taler-exchange-offline", "-c", CFG_OUTDIR / "taler.conf", - "enable-account", PAYTO_URI, "upload"] + "enable-account", EXCHANGE_PAYTO, "upload"] ).run() print(" OK") # Set up wire fees for next 5 years @@ -1247,6 +1260,13 @@ Logs: {rev_proxy.get_log_filename()}" exchange_eddsa_handle.stop() exchange_handle.stop() print(" OK") + print_nn("Reset and init auditor DB..") + Command([ + "taler-auditor-dbinit", + "-c", CFG_OUTDIR / "taler.conf", + "--reset"] + ).run() + print(" OK") print_nn("Add this exchange to the auditor...") Command( [ @@ -1343,7 +1363,7 @@ Logs: {rev_proxy.get_log_filename()}" ebics_partner_id="unusedCustomerEbicsPartnerId", ebics_user_id="unusedCustomerEbicsUserId", person_name="Customer Person", - bank_account_name="sandbox-account-customer", + bank_account_name=CUSTOMER_BANK_ACCOUNT, bank_account_iban=IBAN_CUSTOMER, env=get_sandbox_cli_env( SANDBOX_ADMIN_USERNAME, @@ -1435,13 +1455,34 @@ Logs: {rev_proxy.get_log_filename()}" print_nn("Terminating Sandbox...") sandbox_handle.stop() print(" OK") + print_nn("Set suggested exchange at Sandbox...") + Command([ + "libeufin-sandbox", + "default-exchange", + REV_PROXY_URL + "/exchange/", + EXCHANGE_PAYTO], + env={ + "PATH": os.environ["PATH"], + "LIBEUFIN_SANDBOX_DB_CONNECTION": f"jdbc:sqlite:{SANDBOX_DB_FILE}" + }).run() + print(" OK") # Point the exchange to the facade. Command( [ - "taler-config", "-s", + "taler-config", + "-c", CFG_OUTDIR / "taler.conf", + "-s", "exchange-accountcredentials-1", + "-o" "wire_gateway_auth_method", + "-V", "basic" + ], + custom_name="specify-wire-gateway-auth-method", + ).run() + Command( + [ + "taler-config", "-c", CFG_OUTDIR / "taler.conf", - f"exchange-account-credentials-1", + "-s", "exchange-accountcredentials-1", "-o" "wire_gateway_url", "-V", FACADE_URL ], @@ -1449,9 +1490,9 @@ Logs: {rev_proxy.get_log_filename()}" ).run() Command( [ - "taler-config", "-s", + "taler-config", "-c", CFG_OUTDIR / "taler.conf", - "exchange-account-credentials-1", + "-s", "exchange-accountcredentials-1", "-o" "username", "-V", EXCHANGE_NEXUS_USERNAME ], @@ -1459,9 +1500,9 @@ Logs: {rev_proxy.get_log_filename()}" ).run() Command( [ - "taler-config", "-s", + "taler-config", "-c", CFG_OUTDIR / "taler.conf", - "exchange-account-credentials-1", + "-s", "exchange-accountcredentials-1", "-o" "password", "-V", EXCHANGE_NEXUS_PASSWORD ], @@ -1492,7 +1533,9 @@ Logs: {rev_proxy.get_log_filename()}" req = dict( id=instance_id, name=f"Name of '{instance_id}'", - payto_uris=[f"payto://{wire_method}/{bank_hostname}/{merchant_wire_address}"], + payto_uris=[ + f"payto://{wire_method}/{bank_hostname}/{merchant_wire_address}?receiver-name=Unknown" + ], address=dict(), jurisdiction=dict(), default_max_wire_fee=f"{currency}:1", @@ -1540,7 +1583,7 @@ Logs: {rev_proxy.get_log_filename()}" instance_id="default", backend_url = REV_PROXY_URL + "/merchant-backend", bank_hostname = REV_PROXY_NETLOC + "/sandbox", - wire_method = "sepa", + wire_method = "iban", merchant_wire_address = IBAN_MERCHANT_DEFAULT, auth_token=FRONTENDS_API_TOKEN ) @@ -1565,7 +1608,7 @@ Logs: {rev_proxy.get_log_filename()}" instance_id=instance_id, backend_url = REV_PROXY_URL + "/merchant-backend", bank_hostname = REV_PROXY_NETLOC + "/sandbox", - wire_method = "sepa", + wire_method = "iban", merchant_wire_address = iban, auth_token=FRONTENDS_API_TOKEN ) @@ -1579,7 +1622,6 @@ Logs: {rev_proxy.get_log_filename()}" print(" OK") print_nn("Installing SystemD unit files...") - systemd_user_dir = Path.home() / ".config" / "systemd" / "user" if not systemd_user_dir.exists(): systemd_user_dir.mkdir(parents=True, exist_ok=True) @@ -1587,122 +1629,89 @@ Logs: {rev_proxy.get_log_filename()}" if not TALER_UNIT_FILES_DIR.exists(): TALER_UNIT_FILES_DIR.mkdir(parents=True, exist_ok=True) - # Exchange unit file. - exchange_unit = open(TALER_UNIT_FILES_DIR / "exchange.service", "w") - exchange_unit.write("[Unit]\n") - exchange_unit.write('Description="Taler Exchange"\n') - exchange_unit.write("[Service]\n") - exchange_unit.write( - f"ExecStart={TALER_PREFIX}/bin/taler-exchange-httpd -c {CFG_OUTDIR / 'taler.conf'}\n" - ) - # Exchange RSA helper unit file. - exchange_rsa_unit = open(TALER_UNIT_FILES_DIR / "exchange-secmod-rsa.service", "w") - exchange_rsa_unit.write("[Unit]\n") - exchange_rsa_unit.write('Description="Taler Exchange RSA security module."\n') - exchange_rsa_unit.write("[Service]\n") - exchange_rsa_unit.write( - f"ExecStart={TALER_PREFIX}/bin/taler-exchange-secmod-rsa -c {CFG_OUTDIR / 'taler.conf'}\n" - ) - exchange_rsa_unit.close() - # Exchange EDDSA helper unit file. - exchange_eddsa_unit = open(TALER_UNIT_FILES_DIR / "exchange-secmod-eddsa.service", "w") - exchange_eddsa_unit.write("[Unit]\n") - exchange_eddsa_unit.write('Description="Taler Exchange EDDSA security module."\n') - exchange_eddsa_unit.write("[Service]\n") - exchange_eddsa_unit.write( - f"ExecStart={TALER_PREFIX}/bin/taler-exchange-secmod-eddsa -c {CFG_OUTDIR / 'taler.conf'}\n" - ) - exchange_eddsa_unit.close() - # Merchant unit file. - merchant_unit = open(TALER_UNIT_FILES_DIR / "merchant-backend.service", "w") - merchant_unit.write("[Unit]\n") - merchant_unit.write('Description="Taler Merchant Backend"\n') - merchant_unit.write("[Service]\n") - merchant_unit.write( - f"ExecStart={TALER_PREFIX}/bin/taler-merchant-httpd -c {CFG_OUTDIR / 'taler.conf'}\n" - ) - + def unit_file_content(description, cmd, env=None): + executable_name = cmd.split(" ")[0].split("/")[-1] + content = ( + "[Unit]\n" + f"Description={description}\n" + "[Service]\n" + f"ExecStart={cmd}\n" + f"StandardOutput=append:{LOG_DIR / executable_name}.log\n" + f"StandardError=append:{LOG_DIR / executable_name}.log" + ) + if env: + content += f"\nEnvironmentFile={env}" + return content + + # Exchange HTTPD unit file. + with open(TALER_UNIT_FILES_DIR / "taler-exchange-httpd-local.service", "w") as exchange_unit: + exchange_unit.write(unit_file_content( + description = "Taler Exchange HTTP daemon", + cmd = f"{TALER_PREFIX}/bin/taler-exchange-httpd -L DEBUG -c {CFG_OUTDIR / 'taler.conf'}", + env = TALER_UNIT_FILES_DIR / "taler-postgres-local.env" if os.environ.get("PGPORT") else None + )) + with open(TALER_UNIT_FILES_DIR / "taler-exchange-wirewatch-local.service", "w") as exchange_wirewatch_unit: + exchange_wirewatch_unit.write(unit_file_content( + description = "Taler Exchange Wirewatch", + cmd = f"{TALER_PREFIX}/bin/taler-exchange-wirewatch -L DEBUG -c {CFG_OUTDIR / 'taler.conf'}", + env = TALER_UNIT_FILES_DIR / "taler-postgres-local.env" if os.environ.get("PGPORT") else None + )) + with open(TALER_UNIT_FILES_DIR / "taler-exchange-secmod-rsa-local.service", "w") as exchange_rsa_unit: + exchange_rsa_unit.write(unit_file_content( + description = "Taler Exchange RSA security module", + cmd = f"{TALER_PREFIX}/bin/taler-exchange-secmod-rsa -L DEBUG -c {CFG_OUTDIR / 'taler.conf'}" + )) + with open(TALER_UNIT_FILES_DIR / "taler-exchange-secmod-eddsa-local.service", "w") as exchange_eddsa_unit: + exchange_eddsa_unit.write(unit_file_content( + description = "Taler Exchange EDDSA security module", + cmd = f"{TALER_PREFIX}/bin/taler-exchange-secmod-eddsa -L DEBUG -c {CFG_OUTDIR / 'taler.conf'}" + )) + with open(TALER_UNIT_FILES_DIR / "taler-merchant-httpd-local.service", "w") as merchant_unit: + merchant_unit.write(unit_file_content( + description = "Taler Merchant backend", + cmd = f"{TALER_PREFIX}/bin/taler-merchant-httpd -L DEBUG -c {CFG_OUTDIR / 'taler.conf'}", + env = TALER_UNIT_FILES_DIR / "taler-postgres-local.env" if os.environ.get("PGPORT") else None + )) # Custom Postgres connection. if os.environ.get("PGPORT"): - exchange_unit.write(f"EnvironmentFile={systemd_user_dir / 'exchange.env'}") - merchant_unit.write(f"EnvironmentFile={systemd_user_dir / 'merchant-backend.env'}") - with open(TALER_UNIT_FILES_DIR / "exchange.env", "w") as exchange_env: - exchange_env.write(f"PGPORT={os.environ.get('PGPORT')}") - with open(TALER_UNIT_FILES_DIR / "merchant-backend.env", "w") as merchant_env: - merchant_env.write(f"PGPORT={os.environ.get('PGPORT')}") - # Symlinking the environment files into the SystemD canonical user directory. - if not os.path.islink(systemd_user_dir / "exchange.env"): - os.symlink(exchange_env.name, systemd_user_dir / "exchange.env") - if not os.path.islink(systemd_user_dir / "merchant-backend.env"): - os.symlink(merchant_env.name, systemd_user_dir / "merchant-backend.env") - - exchange_unit.close() - merchant_unit.close() + with open(TALER_UNIT_FILES_DIR / "taler-postgres-local.env", "w") as postgres_env: + postgres_env.write(f"PGPORT={os.environ.get('PGPORT')}") # euFin unit files. - sandbox_unit = open(TALER_UNIT_FILES_DIR / "sandbox.service", "w") - sandbox_unit.write("[Unit]\n") - sandbox_unit.write('Description="euFin Sandbox"\n') - sandbox_unit.write("[Service]\n") - sandbox_unit.write( - f"ExecStart={TALER_PREFIX}/bin/libeufin-sandbox serve --with-unix-socket {UNIX_SOCKETS_DIR / 'sandbox.sock'}\n" - ) - sandbox_unit.write(f"EnvironmentFile={systemd_user_dir / 'sandbox.env'}") - sandbox_unit.close() - - nexus_unit = open(TALER_UNIT_FILES_DIR / "nexus.service", "w") - nexus_unit.write("[Unit]\n") - nexus_unit.write('Description="euFin Nexus"\n') - nexus_unit.write("[Service]\n") - nexus_unit.write( - f"ExecStart={TALER_PREFIX}/bin/libeufin-nexus serve --with-unix-socket {UNIX_SOCKETS_DIR / 'nexus.sock'}\n" - ) - nexus_unit.write(f"EnvironmentFile={systemd_user_dir / 'nexus.env'}") - nexus_unit.close() + with open(TALER_UNIT_FILES_DIR / "libeufin-sandbox-local.service", "w") as sandbox_unit: + sandbox_unit.write(unit_file_content( + description = "euFin Sandbox", + cmd = f"{TALER_PREFIX}/bin/libeufin-sandbox serve --with-unix-socket {UNIX_SOCKETS_DIR / 'sandbox.sock'}", + env = TALER_UNIT_FILES_DIR / "libeufin-sandbox-local.env" + )) + with open(TALER_UNIT_FILES_DIR / "libeufin-nexus-local.service", "w") as nexus_unit: + nexus_unit.write(unit_file_content( + description = "euFin Nexus", + cmd = f"{TALER_PREFIX}/bin/libeufin-nexus serve --with-unix-socket {UNIX_SOCKETS_DIR / 'nexus.sock'}", + env = TALER_UNIT_FILES_DIR / "libeufin-nexus-local.env" + )) # euFin env files. - sandbox_env = open(TALER_UNIT_FILES_DIR / "sandbox.env", "w") - sandbox_env.write(f"LIBEUFIN_SANDBOX_DB_CONNECTION=jdbc:sqlite:{SANDBOX_DB_FILE}\n") - sandbox_env.write(f"LIBEUFIN_SANDBOX_ADMIN_PASSWORD={SANDBOX_ADMIN_PASSWORD}") - sandbox_env.close() - nexus_env = open(TALER_UNIT_FILES_DIR / "nexus.env", "w") - nexus_env.write(f"LIBEUFIN_NEXUS_DB_CONNECTION=jdbc:sqlite:{NEXUS_DB_FILE}") - nexus_env.close() - - # Frontends - donations_unit = open(TALER_UNIT_FILES_DIR / "donations.service", "w") - donations_unit.write("[Unit]\n") - donations_unit.write("Description=Donation Website that accepts Taler payments.\n") - donations_unit.write("[Service]\n") - donations_unit.write( - f"ExecStart={TALER_PREFIX}/bin/taler-merchant-demos donations -c {CFG_OUTDIR / 'taler.conf'}\n" - ) - donations_unit.write(f"EnvironmentFile={systemd_user_dir / 'donations.env'}\n") - donations_unit.close() - donations_env = open(TALER_UNIT_FILES_DIR / "donations.env", "w") - donations_env.write(f"PATH={os.environ.get('PATH')}") - donations_env.close() - # Symlinking the unit (and env, for euFin) files into the canonical SystemD user directory. - if not os.path.islink(systemd_user_dir / "exchange.service"): - os.symlink(exchange_unit.name, systemd_user_dir / "exchange.service") - if not os.path.islink(systemd_user_dir / "merchant-backend.service"): - os.symlink(merchant_unit.name, systemd_user_dir / "merchant-backend.service") - if not os.path.islink(systemd_user_dir / "exchange-secmod-rsa.service"): - os.symlink(exchange_rsa_unit.name, systemd_user_dir / "exchange-secmod-rsa.service") - if not os.path.islink(systemd_user_dir / "exchange-secmod-eddsa.service"): - os.symlink(exchange_eddsa_unit.name, systemd_user_dir / "exchange-secmod-eddsa.service") - if not os.path.islink(systemd_user_dir / "sandbox.service"): - os.symlink(sandbox_unit.name, systemd_user_dir / "sandbox.service") - if not os.path.islink(systemd_user_dir / "sandbox.env"): - os.symlink(sandbox_env.name, systemd_user_dir / "sandbox.env") - if not os.path.islink(systemd_user_dir / "nexus.service"): - os.symlink(nexus_unit.name, systemd_user_dir / "nexus.service") - if not os.path.islink(systemd_user_dir / "nexus.env"): - os.symlink(nexus_env.name, systemd_user_dir / "nexus.env") - if not os.path.islink(systemd_user_dir / "donations.service"): - os.symlink(donations_unit.name, systemd_user_dir / "donations.service") - if not os.path.islink(systemd_user_dir / "donations.env"): - os.symlink(donations_env.name, systemd_user_dir / "donations.env") - + with open(TALER_UNIT_FILES_DIR / "libeufin-sandbox-local.env", "w") as sandbox_env: + sandbox_env.write(f"LIBEUFIN_SANDBOX_DB_CONNECTION=jdbc:sqlite:{SANDBOX_DB_FILE}\n") + sandbox_env.write(f"LIBEUFIN_SANDBOX_ADMIN_PASSWORD={SANDBOX_ADMIN_PASSWORD}") + with open(TALER_UNIT_FILES_DIR / "libeufin-nexus-local.env", "w") as nexus_env: + nexus_env.write(f"LIBEUFIN_NEXUS_DB_CONNECTION=jdbc:sqlite:{NEXUS_DB_FILE}\n") + + with open(TALER_UNIT_FILES_DIR / "taler-donations-local.service", "w") as donations_unit: + donations_unit.write(unit_file_content( + description = "Donation Website that accepts Taler payments.", + cmd = f"{TALER_PREFIX}/bin/taler-merchant-demos donations -c {CFG_OUTDIR / 'taler.conf'}", + env = TALER_UNIT_FILES_DIR / "taler-frontends-local.env" + )) + with open(TALER_UNIT_FILES_DIR / "taler-blog-local.service", "w") as blog_unit: + blog_unit.write(unit_file_content( + description = "Blog that accepts Taler payments.", + cmd = f"{TALER_PREFIX}/bin/taler-merchant-demos blog -c {CFG_OUTDIR / 'taler.conf'}", + env = TALER_UNIT_FILES_DIR / "taler-frontends-local.env" + )) + with open(TALER_UNIT_FILES_DIR / "taler-frontends-local.env", "w") as frontends_env: + frontends_env.write(f"PATH={os.environ.get('PATH')}\n") + frontends_env.write(f"TALER_CONFIG_FILE={CFG_OUTDIR / 'taler.conf'}\n") print(" OK") # more units here.. @@ -1713,13 +1722,14 @@ Logs: {rev_proxy.get_log_filename()}" @cli.command() def launch(): - subprocess.run(["systemctl", "--user", "start", "exchange.service"], check=True) - subprocess.run(["systemctl", "--user", "start", "exchange-secmod-rsa.service"], check=True) - subprocess.run(["systemctl", "--user", "start", "exchange-secmod-eddsa.service"], check=True) - subprocess.run(["systemctl", "--user", "start", "merchant-backend.service"], check=True) - subprocess.run(["systemctl", "--user", "start", "nexus.service"], check=True) - subprocess.run(["systemctl", "--user", "start", "sandbox.service"], check=True) - subprocess.run(["systemctl", "--user", "start", "donations.service"], check=True) + subprocess.run(["systemctl", "--user", "start", "taler-exchange-httpd-local.service"], check=True) + subprocess.run(["systemctl", "--user", "start", "taler-exchange-wirewatch-local.service"], check=True) + subprocess.run(["systemctl", "--user", "start", "taler-exchange-secmod-rsa-local.service"], check=True) + subprocess.run(["systemctl", "--user", "start", "taler-exchange-secmod-eddsa-local.service"], check=True) + subprocess.run(["systemctl", "--user", "start", "taler-merchant-httpd-local.service"], check=True) + subprocess.run(["systemctl", "--user", "start", "libeufin-nexus-local.service"], check=True) + subprocess.run(["systemctl", "--user", "start", "libeufin-sandbox-local.service"], check=True) + subprocess.run(["systemctl", "--user", "start", "taler-donations-local.service"], check=True) rev_proxy = TalerReverseProxy( LOG_DIR, @@ -1735,14 +1745,53 @@ def launch(): ) # Stop with CTRL+C print_nn("Stopping the services...") - subprocess.run(["systemctl", "--user", "stop", "donations.service"], check=True) - subprocess.run(["systemctl", "--user", "stop", "nexus.service"], check=True) - subprocess.run(["systemctl", "--user", "stop", "sandbox.service"], check=True) - subprocess.run(["systemctl", "--user", "stop", "merchant-backend.service"], check=True) - subprocess.run(["systemctl", "--user", "stop", "exchange.service"], check=True) - subprocess.run(["systemctl", "--user", "stop", "exchange-secmod-rsa.service"], check=True) - subprocess.run(["systemctl", "--user", "stop", "exchange-secmod-eddsa.service"], check=True) + subprocess.run(["systemctl", "--user", "stop", "taler-donations-local.service"], check=True) + subprocess.run(["systemctl", "--user", "stop", "libeufin-sandbox-local.service"], check=True) + subprocess.run(["systemctl", "--user", "stop", "libeufin-nexus-local.service"], check=True) + subprocess.run(["systemctl", "--user", "stop", "taler-merchant-httpd-local.service"], check=True) + subprocess.run(["systemctl", "--user", "stop", "taler-exchange-secmod-eddsa-local.service"], check=True) + subprocess.run(["systemctl", "--user", "stop", "taler-exchange-secmod-rsa-local.service"], check=True) + subprocess.run(["systemctl", "--user", "stop", "taler-exchange-wirewatch-local.service"], check=True) + subprocess.run(["systemctl", "--user", "stop", "taler-exchange-httpd-local.service"], check=True) + print(" OK") + +@cli.command() +def withdraw(): + print_nn("Create withdrawal operation...") + resp = requests.post(REV_PROXY_URL + + f"/sandbox/demobanks/default/access-api/accounts/{CUSTOMER_BANK_ACCOUNT}/withdrawals", + json = dict(amount=CURRENCY + ":5"), + auth = requests.auth.HTTPBasicAuth(SANDBOX_ADMIN_USERNAME, SANDBOX_ADMIN_PASSWORD) + ) + try: + resp.raise_for_status() + except Exception as error: + print("Could not create withdrawal") + print(error) + exit(1) + withdrawal_id = resp.json()["withdrawal_id"] + withdraw_uri = resp.json()["taler_withdraw_uri"] + print(" OK") + print("Let wallet specify the reserve public key at the bank...") + # Let wallet give the reserve public key to the bank. + subprocess.run(["taler-wallet-cli", "handle-uri", withdraw_uri], check=True) + # Let the user confirm the withdrawal operation and + # get the bank wire the funds. + print_nn("Confirm withdrawal operation at the bank...") + resp = requests.post(REV_PROXY_URL + + f"/sandbox/demobanks/default/access-api/accounts/{CUSTOMER_BANK_ACCOUNT}/withdrawals/{withdrawal_id}/confirm", + auth = requests.auth.HTTPBasicAuth(SANDBOX_ADMIN_USERNAME, SANDBOX_ADMIN_PASSWORD) + ) + try: + resp.raise_for_status() + except Exception as error: + print("Could not create withdrawal") + print(error) + exit(1) print(" OK") + print("Let wallet complete all pending operations") + subprocess.run(["taler-wallet-cli", "handle-uri", withdraw_uri], check=True) + subprocess.run(["taler-wallet-cli", "run-until-done"], check=True) if __name__ == "__main__": cli() |