diff options
author | MS <ms@taler.net> | 2023-01-20 14:23:55 +0100 |
---|---|---|
committer | MS <ms@taler.net> | 2023-01-20 16:39:57 +0100 |
commit | c32c2a00f53adf223b51f2bb2e73a237f3bba7e9 (patch) | |
tree | 12641e5961d7c584038a5ebc1e8a790498256301 /cli | |
parent | 048e0ada98b551e89c7ae410fb00a07289e9d332 (diff) | |
download | libeufin-c32c2a00f53adf223b51f2bb2e73a237f3bba7e9.tar.gz libeufin-c32c2a00f53adf223b51f2bb2e73a237f3bba7e9.tar.bz2 libeufin-c32c2a00f53adf223b51f2bb2e73a237f3bba7e9.zip |
CLI.
Adding the command to call "GET /cashouts" and
remove any status code check from tell_user().
Diffstat (limited to 'cli')
-rwxr-xr-x | cli/bin/libeufin-cli | 149 |
1 files changed, 95 insertions, 54 deletions
diff --git a/cli/bin/libeufin-cli b/cli/bin/libeufin-cli index de5377f4..8fd3a7e4 100755 --- a/cli/bin/libeufin-cli +++ b/cli/bin/libeufin-cli @@ -25,6 +25,14 @@ def maybe_auth(sandbox_ctx): ) return dict() + +# Gets the account name to use in a request. It gives +# precedence to the account name passed along the CLI options, +# and falls back to the account name found in the environment. +# It returns None if no account was found, or that was 'admin'. +# Admin is excluded because it isn't modeled like ordinary +# customers and would therefore very likely hit != 2xx response +# statuses. def get_account_name(accountNameCli, usernameEnv): maybeUsername = accountNameCli if not maybeUsername: @@ -45,14 +53,9 @@ def check_response_status(resp, expected_status_code=200): print("Response: {}".format(resp.text), file=sys.stderr) sys.exit(1) -# Prints unexpected responses without exiting -# and optionally prints expected respones. -def tell_user(resp, expected_status_code=200, withsuccess=False): - if resp.status_code != expected_status_code: - print(resp.content.decode("utf-8"), file=sys.stderr) - return - if withsuccess: - print(resp.content.decode("utf-8")) +# Prints the response body. +def tell_user(resp): + print(resp.content.decode("utf-8")) # Normalize the two components to "x/" and "y" and pass them # to urljoin(). This avoids drop-policies from plain urljoin(). @@ -127,8 +130,8 @@ def users_self(obj): print("Could not reach nexus at " + url) exit(1) - tell_user(resp, withsuccess=True) check_response_status(resp) + tell_user(resp) @users.command("list", help="List users") @click.pass_obj @@ -141,8 +144,8 @@ def list_users(obj): print("Could not reach nexus at " + url) exit(1) - tell_user(resp, withsuccess=True) check_response_status(resp) + tell_user(resp) @users.command(help="Change user's password (as superuser)") @@ -169,8 +172,8 @@ def change_password(obj, username, new_password): print("Could not reach nexus at " + url) exit(1) - tell_user(resp, withsuccess=True) check_response_status(resp) + tell_user(resp) @users.command("create", help="Create a new user without superuser privileges") @@ -404,14 +407,12 @@ def get_key_letter(obj, connection_name, output_file): print("Could not reach nexus at " + url) exit(1) - tell_user(resp) check_response_status(resp) output = open(output_file, "wb") output.write(resp.content) output.close() - @connections.command(help="export backup") @click.option("--passphrase", help="Passphrase for locking the backup", required=True) @click.option("--output-file", help="Where to store the backup", required=True) @@ -459,7 +460,6 @@ def delete_connection(obj, connection_name): print("Could not reach nexus at " + url) exit(1) - tell_user(resp) check_response_status(resp) @@ -495,7 +495,6 @@ def restore_backup(obj, backup_file, passphrase, connection_name): print("Could not reach nexus at " + url) exit(1) - tell_user(resp) check_response_status(resp) @@ -528,7 +527,6 @@ def new_ebics_connection( print(f"Could not reach nexus at {url}") exit(1) - tell_user(resp) check_response_status(resp) @@ -545,9 +543,9 @@ def connect(obj, connection_name): print(e) print(f"Could not reach nexus at {url}") exit(1) - tell_user(resp, withsuccess=True) - check_response_status(resp) + check_response_status(resp) + tell_user(resp) @connections.command(help="Import one bank account, chosen from the downloaded ones.") @click.option( @@ -580,7 +578,6 @@ def import_bank_account( print(f"Could not reach nexus at {url}: {e}") exit(1) - tell_user(resp) check_response_status(resp) @@ -603,7 +600,6 @@ def download_bank_accounts(obj, connection_name): print("Could not reach nexus at " + url) exit(1) - tell_user(resp) check_response_status(resp) @@ -620,8 +616,8 @@ def list_connections(obj): print("Could not reach nexus at " + url) exit(1) - tell_user(resp, withsuccess=True) check_response_status(resp) + tell_user(resp) @connections.command(help="Show the status of a bank connection.") @@ -638,8 +634,8 @@ def show_connection(obj, connection_name): print("Could not reach nexus at " + url) exit(1) - tell_user(resp, withsuccess=True) check_response_status(resp) + tell_user(resp) @connections.command(help="list bank accounts hosted at one connection") @@ -658,8 +654,8 @@ def list_offered_bank_accounts(obj, connection_name): print("Could not reach nexus at " + url) exit(1) - tell_user(resp, withsuccess=True) check_response_status(resp) + tell_user(resp) @accounts.command(help="Schedules a new task") @@ -708,7 +704,6 @@ def task_schedule( print("Could not reach nexus at " + url) exit(1) - tell_user(resp) check_response_status(resp) @@ -728,8 +723,8 @@ def task_status(obj, account_name, task_name): print("Could not reach nexus " + url) exit(1) - tell_user(resp, withsuccess=True) check_response_status(resp) + tell_user(resp) @accounts.command(help="Delete a task") @@ -748,7 +743,6 @@ def task_delete(obj, account_name, task_name): print("Could not reach nexus " + url) exit(1) - tell_user(resp) check_response_status(resp) @@ -764,8 +758,8 @@ def tasks_show(obj, account_name): print("Could not reach nexus " + url) exit(1) - tell_user(resp, withsuccess=True) check_response_status(resp) + tell_user(resp) @accounts.command(help="Show accounts belonging to calling user") @@ -778,8 +772,8 @@ def show(obj): print(f"Could not reach nexus at {url}, error: {e}") exit(1) - tell_user(resp, withsuccess=True) check_response_status(resp) + tell_user(resp) @accounts.command(help="Prepare payment initiation debiting the account.") @@ -825,7 +819,6 @@ def prepare_payment( print("Could not reach nexus at " + url) exit(1) - tell_user(resp) check_response_status(resp) @@ -857,7 +850,6 @@ def submit_payments(obj, account_name, payment_uuid): print("Could not reach nexus at" + url) exit(1) - tell_user(resp) check_response_status(resp) @@ -877,8 +869,8 @@ def show_payment(obj, account_name, payment_uuid): print("Could not reach nexus at" + url) exit(1) - tell_user(resp, withsuccess=True) check_response_status(resp) + tell_user(resp) @accounts.command(help="List payment initiations") @@ -895,10 +887,8 @@ def list_payments(obj, account_name): print("Could not reach nexus at" + url) exit(1) - tell_user( - resp, withsuccess=True, - ) check_response_status(resp) + tell_user(resp) @accounts.command(help="Delete a payment initiation") @@ -917,7 +907,6 @@ def delete_payment(obj, account_name, payment_uuid): print("Could not reach nexus at" + url) exit(1) - tell_user(resp) check_response_status(resp) @@ -945,8 +934,8 @@ def fetch_transactions(obj, account_name, range_type, level): print("Could not reach nexus " + url) exit(1) - tell_user(resp, withsuccess=True) check_response_status(resp) + tell_user(resp) @accounts.command(help="Get transactions from the simplified nexus JSON API") @@ -982,7 +971,7 @@ def transactions(obj, compact, account_name): ) ) else: - tell_user(resp, withsuccess=True) + tell_user(resp) check_response_status(resp) @@ -996,8 +985,8 @@ def list_facades(obj): print(f"Could not reach nexus (at {obj.nexus_base_url}): {e}") exit(1) - tell_user(resp, withsuccess=True) check_response_status(resp) + tell_user(resp) @facades.command( @@ -1030,7 +1019,6 @@ def new_anastasis_facade(obj, facade_name, connection_name, account_name, curren print(f"Could not reach nexus (at {obj.nexus_base_url}): {e}") exit(1) - tell_user(resp) check_response_status(resp) @@ -1064,7 +1052,6 @@ def new_twg_facade(obj, facade_name, connection_name, account_name, currency): print(f"Could not reach nexus (at {obj.nexus_base_url}): {e}") exit(1) - tell_user(resp) check_response_status(resp) @@ -1086,8 +1073,8 @@ def check_sandbox_status(obj): print("Could not reach sandbox") exit(1) - tell_user(resp, withsuccess=True) check_response_status(resp) + tell_user(resp) @sandbox_ebicshost.command("create", help="Create an EBICS host") @@ -1107,7 +1094,6 @@ def make_ebics_host(obj, host_id): print("Could not reach sandbox") exit(1) - tell_user(resp) check_response_status(resp) @@ -1123,8 +1109,8 @@ def list_ebics_host(obj): print("Could not reach sandbox") exit(1) - tell_user(resp, withsuccess=True) check_response_status(resp) + tell_user(resp) @sandbox.group("ebicssubscriber", help="manage EBICS subscribers") @@ -1152,7 +1138,6 @@ def create_ebics_subscriber(obj, host_id, partner_id, user_id): print("Could not reach sandbox") exit(1) - tell_user(resp) check_response_status(resp) @@ -1168,8 +1153,8 @@ def list_ebics_subscriber(obj): print("Could not reach sandbox") exit(1) - tell_user(resp, withsuccess=True) check_response_status(resp) + tell_user(resp) @sandbox.group("ebicsbankaccount", help="manage EBICS bank accounts") @@ -1223,7 +1208,6 @@ def associate_bank_account( print("Could not reach sandbox") exit(1) - tell_user(resp) check_response_status(resp) @@ -1266,7 +1250,8 @@ def sandbox_demobank_list_transactions(obj, bank_account): print("Could not reach sandbox at " + url) exit(1) - tell_user(resp, withsuccess=True) + check_response_status(resp) + tell_user(resp) @sandbox_demobank.command("new-transaction", help="Initiate a new transaction.") @@ -1320,8 +1305,9 @@ def sandbox_demobank_info(obj, bank_account): print(e) print("Could not reach sandbox") exit(1) - tell_user(resp, withsuccess=True) + check_response_status(resp) + tell_user(resp) @sandbox_demobank.command( "debug-url", @@ -1432,8 +1418,8 @@ def bankaccount_list(obj): print("Could not reach sandbox") exit(1) - tell_user(resp, withsuccess=True) check_response_status(resp) + tell_user(resp) @sandbox_bankaccount.command("transactions", help="List transactions") @@ -1451,8 +1437,8 @@ def transactions_list(obj, account_label): print("Could not reach sandbox") exit(1) - tell_user(resp, withsuccess=True) check_response_status(resp) + tell_user(resp) @sandbox_bankaccount.command("generate-transactions", help="Generate test transactions") @@ -1471,7 +1457,6 @@ def bankaccount_generate_transactions(obj, account_label): print("Could not reach sandbox") exit(1) - tell_user(resp) check_response_status(resp) @@ -1517,7 +1502,6 @@ def simulate_incoming_transaction( print("Could not reach sandbox") exit(1) - tell_user(resp) check_response_status(resp) @@ -1606,7 +1590,7 @@ def circuit_cashout_info(obj, uuid): exit(1) check_response_status(resp) - tell_user(resp, withsuccess=True) + tell_user(resp) @sandbox_demobank.command( "circuit-delete-account", @@ -1885,6 +1869,63 @@ def circuit_cashout(obj, subject, amount_debit, amount_credit, tan_channel): exit(1) check_response_status(resp, expected_status_code=202) - tell_user(resp, 202, withsuccess=True) # Communicates back the operation UUID. + tell_user(resp) # Communicates back the operation UUID. + +@sandbox_demobank.command( + "circuit-account-info", + help="Retrieve Circuit information about one account. Useful to get cash-out address and contact details." +) +@click.option( + "--username", + help="Username of the account to retrieve. It defaults to LIBEUFIN_SANDBOX_USERNAME and doesn't accept 'admin'.", +) +@click.pass_obj +def circuit_account_info(obj, username): + resource_name = get_account_name(username, obj.username) + if not resource_name: + print( + "Couldn't find the username whose account is being retrieved.", + file=sys.stderr + ) + exit(1) + # resource_name != admin + account_info_endpoint = obj.circuit_api_url(f"accounts/{resource_name}") + try: + resp = get( + account_info_endpoint, + **maybe_auth(obj) + ) + except Exception as e: + print(e) + print("Could not reach the bank at " + account_info_endpoint) + exit(1) + + check_response_status(resp) + tell_user(resp) + + +@sandbox_demobank.command( + "circuit-accounts", + help="Gets the list of all the accounts managed by the Circuit. Only 'admin' allowed" +) +@click.pass_obj +def circuit_accounts(obj): + # Check admin is requesting. + if (obj.username != "admin"): + print("Not running as 'admin'. Won't request", file=sys.stderr) + exit(1) + accounts_endpoint = obj.circuit_api_url(f"accounts") + try: + resp = get( + accounts_endpoint, + **maybe_auth(obj) + ) + except Exception as e: + print(e) + print("Could not reach the bank at " + accounts_endpoint) + exit(1) + + check_response_status(resp) + tell_user(resp) cli() |