diff options
author | Florian Dold <florian@dold.me> | 2023-10-09 23:49:40 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2023-10-09 23:49:40 +0200 |
commit | 1e105863221ca01d7bc94613dfbf0604ad51b4fe (patch) | |
tree | e35784daf4d3702970f2ffad6495f47d0e042530 | |
parent | a45f45b61bf0e70c04695f5de0c9b799fa96d2d6 (diff) |
harness: helper to provision merchant instancesv0.9.3-dev.32
-rw-r--r-- | packages/taler-harness/src/harness/harness.ts | 3 | ||||
-rw-r--r-- | packages/taler-harness/src/index.ts | 87 | ||||
-rw-r--r-- | packages/taler-harness/src/integrationtests/test-merchant-instances-urls.ts | 10 | ||||
-rw-r--r-- | packages/taler-util/src/MerchantApiClient.ts | 13 |
4 files changed, 87 insertions, 26 deletions
diff --git a/packages/taler-harness/src/harness/harness.ts b/packages/taler-harness/src/harness/harness.ts index e30cbcb54..65a19959a 100644 --- a/packages/taler-harness/src/harness/harness.ts +++ b/packages/taler-harness/src/harness/harness.ts @@ -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 ?? {}, diff --git a/packages/taler-harness/src/index.ts b/packages/taler-harness/src/index.ts index b8e0cfca1..4ee89518a 100644 --- a/packages/taler-harness/src/index.ts +++ b/packages/taler-harness/src/index.ts @@ -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 { @@ -522,6 +525,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.", }) diff --git a/packages/taler-harness/src/integrationtests/test-merchant-instances-urls.ts b/packages/taler-harness/src/integrationtests/test-merchant-instances-urls.ts index a037a01c5..7236436ac 100644 --- a/packages/taler-harness/src/integrationtests/test-merchant-instances-urls.ts +++ b/packages/taler-harness/src/integrationtests/test-merchant-instances-urls.ts @@ -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", diff --git a/packages/taler-util/src/MerchantApiClient.ts b/packages/taler-util/src/MerchantApiClient.ts index 988872ae7..2e10e394a 100644 --- a/packages/taler-util/src/MerchantApiClient.ts +++ b/packages/taler-util/src/MerchantApiClient.ts @@ -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; |