harness: helper to provision corebank account

This commit is contained in:
Florian Dold 2023-10-09 23:16:22 +02:00
parent 2ecdd6816d
commit a45f45b61b
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B

View File

@ -28,6 +28,8 @@ import {
MerchantApiClient, MerchantApiClient,
rsaBlind, rsaBlind,
setGlobalLogLevelFromString, setGlobalLogLevelFromString,
RegisterAccountRequest,
HttpStatusCode,
} from "@gnu-taler/taler-util"; } from "@gnu-taler/taler-util";
import { clk } from "@gnu-taler/taler-util/clk"; import { clk } from "@gnu-taler/taler-util/clk";
import { import {
@ -519,6 +521,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 deploymentCli
.subcommand("coincfg", "gen-coin-config", { .subcommand("coincfg", "gen-coin-config", {
help: "Generate a coin/denomination configuration for the exchange.", help: "Generate a coin/denomination configuration for the exchange.",