harness: helper to provision merchant instances

This commit is contained in:
Florian Dold 2023-10-09 23:49:40 +02:00
parent a45f45b61b
commit 1e10586322
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
4 changed files with 87 additions and 26 deletions

View File

@ -1652,9 +1652,6 @@ export class MerchantService implements MerchantServiceInterface {
const body: MerchantInstanceConfig = {
auth,
accounts: instanceConfig.paytoUris.map((x) => ({
payto_uri: x,
})),
id: instanceConfig.id,
name: instanceConfig.name,
address: instanceConfig.address ?? {},

View File

@ -30,6 +30,9 @@ import {
setGlobalLogLevelFromString,
RegisterAccountRequest,
HttpStatusCode,
MerchantInstanceConfig,
Duration,
generateIban,
} from "@gnu-taler/taler-util";
import { clk } from "@gnu-taler/taler-util/clk";
import {
@ -521,6 +524,90 @@ deploymentCli
}
});
deploymentCli
.subcommand("genIban", "gen-iban", {
help: "Generate a random IBAN.",
})
.requiredArgument("countryCode", clk.STRING)
.requiredArgument("length", clk.INT)
.action(async (args) => {
console.log(generateIban(args.genIban.countryCode, args.genIban.length));
});
deploymentCli
.subcommand("provisionMerchantInstance", "provision-merchant-instance", {
help: "Provision a merchant backend instance.",
})
.requiredArgument("merchantApiBaseUrl", clk.STRING)
.requiredOption("managementToken", ["--management-token"], clk.STRING)
.requiredOption("instanceToken", ["--instance-token"], clk.STRING)
.requiredOption("name", ["--name"], clk.STRING)
.requiredOption("id", ["--id"], clk.STRING)
.requiredOption("payto", ["--payto"], clk.STRING)
.action(async (args) => {
const httpLib = createPlatformHttpLib();
const baseUrl = args.provisionMerchantInstance.merchantApiBaseUrl;
const managementToken = args.provisionMerchantInstance.managementToken;
const instanceToken = args.provisionMerchantInstance.instanceToken;
const instanceId = args.provisionMerchantInstance.id;
const body: MerchantInstanceConfig = {
address: {},
auth: {
method: "token",
token: args.provisionMerchantInstance.instanceToken,
},
default_pay_delay: Duration.toTalerProtocolDuration(
Duration.fromSpec({ hours: 1 }),
),
default_wire_transfer_delay: { d_us: 1 },
id: instanceId,
jurisdiction: {},
name: args.provisionMerchantInstance.name,
use_stefan: true,
};
const url = new URL("management/instances", baseUrl);
const createResp = await httpLib.fetch(url.href, {
method: "POST",
body,
headers: {
Authorization: `Bearer ${managementToken}`,
},
});
if (createResp.status >= 200 && createResp.status <= 299) {
logger.info(`instance ${instanceId} created successfully`);
} else if (createResp.status === HttpStatusCode.Conflict) {
logger.info(`instance ${instanceId} already exists`);
} else {
logger.error(
`unable to create instance ${instanceId}, HTTP status ${createResp.status}`,
);
}
const accountsUrl = new URL(
`instances/${instanceId}/private/accounts`,
baseUrl,
);
const accountBody = {
payto_uri: args.provisionMerchantInstance.payto,
};
const createAccountResp = await httpLib.fetch(accountsUrl.href, {
method: "POST",
body: accountBody,
headers: {
Authorization: `Bearer ${instanceToken}`,
},
});
if (createAccountResp.status != 200) {
console.error(
`unable to configure bank account for instance ${instanceId}, status ${createAccountResp.status}`,
);
const resp = await createAccountResp.json();
console.error(j2s(resp));
process.exit(2);
}
logger.info(`successfully configured bank account for ${instanceId}`);
});
deploymentCli
.subcommand("provisionBankAccount", "provision-bank-account", {
help: "Provision a corebank account.",

View File

@ -72,11 +72,6 @@ export async function runMerchantInstancesUrlsTest(t: GlobalTestState) {
),
jurisdiction: {},
name: "My Default Instance",
accounts: [
{
payto_uri: generateRandomPayto("bar"),
},
],
auth: {
method: "token",
token: "secret-token:i-am-default",
@ -95,11 +90,6 @@ export async function runMerchantInstancesUrlsTest(t: GlobalTestState) {
),
jurisdiction: {},
name: "My Second Instance",
accounts: [
{
payto_uri: generateRandomPayto("bar"),
},
],
auth: {
method: "token",
token: "secret-token:i-am-myinst",

View File

@ -74,18 +74,6 @@ export interface DeleteTippingReserveArgs {
purge?: boolean;
}
export interface MerchantInstanceConfig {
accounts: MerchantBankAccount[];
auth: MerchantAuthConfiguration;
id: string;
name: string;
address: unknown;
jurisdiction: unknown;
use_stefan: boolean;
default_wire_transfer_delay: TalerProtocolDuration;
default_pay_delay: TalerProtocolDuration;
}
interface MerchantBankAccount {
// The payto:// URI where the wallet will send coins.
payto_uri: string;
@ -102,7 +90,6 @@ interface MerchantBankAccount {
}
export interface MerchantInstanceConfig {
accounts: MerchantBankAccount[];
auth: MerchantAuthConfiguration;
id: string;
name: string;