diff options
-rw-r--r-- | packages/taler-harness/src/index.ts | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/packages/taler-harness/src/index.ts b/packages/taler-harness/src/index.ts index 8ed67b162..b8e0cfca1 100644 --- a/packages/taler-harness/src/index.ts +++ b/packages/taler-harness/src/index.ts @@ -28,6 +28,8 @@ import { MerchantApiClient, rsaBlind, setGlobalLogLevelFromString, + RegisterAccountRequest, + HttpStatusCode, } from "@gnu-taler/taler-util"; import { clk } from "@gnu-taler/taler-util/clk"; import { @@ -520,6 +522,48 @@ deploymentCli }); deploymentCli + .subcommand("provisionBankAccount", "provision-bank-account", { + help: "Provision a corebank account.", + }) + .requiredArgument("corebankApiBaseUrl", clk.STRING) + .flag("exchange", ["--exchange"]) + .flag("public", ["--public"]) + .requiredOption("login", ["--login"], clk.STRING) + .requiredOption("name", ["--name"], clk.STRING) + .requiredOption("password", ["--password"], clk.STRING) + .maybeOption("internalPayto", ["--payto"], clk.STRING) + .action(async (args) => { + const httpLib = createPlatformHttpLib(); + const corebankApiBaseUrl = args.provisionBankAccount.corebankApiBaseUrl; + const url = new URL("accounts", corebankApiBaseUrl); + const accountLogin = args.provisionBankAccount.login; + const body: RegisterAccountRequest = { + name: args.provisionBankAccount.name, + password: args.provisionBankAccount.password, + username: accountLogin, + is_public: !!args.provisionBankAccount.public, + is_taler_exchange: !!args.provisionBankAccount.exchange, + internal_payto_uri: args.provisionBankAccount.internalPayto, + }; + const resp = await httpLib.fetch(url.href, { + method: "POST", + body, + }); + if (resp.status >= 200 && resp.status <= 299) { + logger.info(`account ${accountLogin} successfully provisioned`); + return; + } + if (resp.status === HttpStatusCode.Conflict) { + logger.info(`account ${accountLogin} already provisioned`); + return; + } + logger.error( + `unable to provision bank account, HTTP response status ${resp.status}`, + ); + process.exit(2); + }); + +deploymentCli .subcommand("coincfg", "gen-coin-config", { help: "Generate a coin/denomination configuration for the exchange.", }) |