diff options
author | Thien-Thi Nguyen <ttn@gnuvola.org> | 2022-02-02 00:17:13 -0500 |
---|---|---|
committer | Thien-Thi Nguyen <ttn@gnuvola.org> | 2022-02-02 04:35:49 -0500 |
commit | d87965f2b3166a5a627e0ac4daa9ea70c6cc5c1c (patch) | |
tree | 2fa86857955bc184d81bd8c546ec968fdd02fbc6 /cli | |
parent | 97f26f5237135973a31d569969880845a9fb7448 (diff) | |
download | libeufin-d87965f2b3166a5a627e0ac4daa9ea70c6cc5c1c.tar.gz libeufin-d87965f2b3166a5a627e0ac4daa9ea70c6cc5c1c.tar.bz2 libeufin-d87965f2b3166a5a627e0ac4daa9ea70c6cc5c1c.zip |
Add abstraction: SandboxContext.access_api_url
This function constructs a proper URL for the Acesss API endpoints.
There are currently three of them that have been modified to use it:
- sandbox demobank register
- sandbox demobank info
- sandbox demobank new-transaction
Note that their functionality has not changed.
The change merely centralizes the URL construction, and
(in comments) documents the assumptions re Access API base URL.
Diffstat (limited to 'cli')
-rwxr-xr-x | cli/bin/libeufin-cli | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/cli/bin/libeufin-cli b/cli/bin/libeufin-cli index 3f6f9cca..956859ff 100755 --- a/cli/bin/libeufin-cli +++ b/cli/bin/libeufin-cli @@ -299,6 +299,17 @@ not found in the environment, assuming tests are being run...""" ) return sandbox_base_url + # For the Access-API endpoints, the user must choose exactly *one* bank + # and include that in ‘LIBEUFIN_SANDBOX_URL’ (or ‘--sandbox-url’). + def access_api_url(self, upath): + # NB: We expect that ‘base’ ends w/ f"demobanks/{bank}". + # This means that base for non-Access-API endpoints + # is incompatible w/ that for Access-API endpoints. + # (Using one for the other will result in 404.) But that's + # OK because the non-Access-API endspoints are going away. + base = self.require_sandbox_base_url () + return urljoin_nodrop (base, "/access-api" + upath) + class NexusContext: def __init__(self): @@ -1216,9 +1227,7 @@ def sandbox_demobank(ctx): ) @click.pass_obj def sandbox_demobank_new_transaction(obj, bank_account, payto_with_subject, amount): - # expected to include the demobank name. - sandbox_base_url = obj.require_sandbox_base_url() - url = urljoin_nodrop(sandbox_base_url, f"/access-api/accounts/{bank_account}/transactions") + url = obj.access_api_url (f"/accounts/{bank_account}/transactions") try: body = dict(paytoUri=payto_with_subject, amount=amount) resp = post( @@ -1241,8 +1250,7 @@ def sandbox_demobank_new_transaction(obj, bank_account, payto_with_subject, amou ) @click.pass_obj def sandbox_demobank_info(obj, bank_account): - sandbox_base_url = obj.require_sandbox_base_url() - url = urljoin_nodrop(sandbox_base_url, f"/access-api/accounts/{bank_account}") + url = obj.access_api_url (f"/accounts/{bank_account}") try: resp = get( url, @@ -1267,8 +1275,7 @@ def sandbox_demobank_info(obj, bank_account): ) @click.pass_obj def sandbox_demobank_register(obj, public): - sandbox_base_url = obj.require_sandbox_base_url() - url = urljoin_nodrop(sandbox_base_url, f"/access-api/testing/register") + url = obj.access_api_url ("/testing/register") try: resp = post( url, |