harness: helper to provision merchant instances
This commit is contained in:
parent
a45f45b61b
commit
1e10586322
@ -1652,9 +1652,6 @@ export class MerchantService implements MerchantServiceInterface {
|
|||||||
|
|
||||||
const body: MerchantInstanceConfig = {
|
const body: MerchantInstanceConfig = {
|
||||||
auth,
|
auth,
|
||||||
accounts: instanceConfig.paytoUris.map((x) => ({
|
|
||||||
payto_uri: x,
|
|
||||||
})),
|
|
||||||
id: instanceConfig.id,
|
id: instanceConfig.id,
|
||||||
name: instanceConfig.name,
|
name: instanceConfig.name,
|
||||||
address: instanceConfig.address ?? {},
|
address: instanceConfig.address ?? {},
|
||||||
|
@ -30,6 +30,9 @@ import {
|
|||||||
setGlobalLogLevelFromString,
|
setGlobalLogLevelFromString,
|
||||||
RegisterAccountRequest,
|
RegisterAccountRequest,
|
||||||
HttpStatusCode,
|
HttpStatusCode,
|
||||||
|
MerchantInstanceConfig,
|
||||||
|
Duration,
|
||||||
|
generateIban,
|
||||||
} 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 {
|
||||||
@ -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
|
deploymentCli
|
||||||
.subcommand("provisionBankAccount", "provision-bank-account", {
|
.subcommand("provisionBankAccount", "provision-bank-account", {
|
||||||
help: "Provision a corebank account.",
|
help: "Provision a corebank account.",
|
||||||
|
@ -72,11 +72,6 @@ export async function runMerchantInstancesUrlsTest(t: GlobalTestState) {
|
|||||||
),
|
),
|
||||||
jurisdiction: {},
|
jurisdiction: {},
|
||||||
name: "My Default Instance",
|
name: "My Default Instance",
|
||||||
accounts: [
|
|
||||||
{
|
|
||||||
payto_uri: generateRandomPayto("bar"),
|
|
||||||
},
|
|
||||||
],
|
|
||||||
auth: {
|
auth: {
|
||||||
method: "token",
|
method: "token",
|
||||||
token: "secret-token:i-am-default",
|
token: "secret-token:i-am-default",
|
||||||
@ -95,11 +90,6 @@ export async function runMerchantInstancesUrlsTest(t: GlobalTestState) {
|
|||||||
),
|
),
|
||||||
jurisdiction: {},
|
jurisdiction: {},
|
||||||
name: "My Second Instance",
|
name: "My Second Instance",
|
||||||
accounts: [
|
|
||||||
{
|
|
||||||
payto_uri: generateRandomPayto("bar"),
|
|
||||||
},
|
|
||||||
],
|
|
||||||
auth: {
|
auth: {
|
||||||
method: "token",
|
method: "token",
|
||||||
token: "secret-token:i-am-myinst",
|
token: "secret-token:i-am-myinst",
|
||||||
|
@ -74,18 +74,6 @@ export interface DeleteTippingReserveArgs {
|
|||||||
purge?: boolean;
|
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 {
|
interface MerchantBankAccount {
|
||||||
// The payto:// URI where the wallet will send coins.
|
// The payto:// URI where the wallet will send coins.
|
||||||
payto_uri: string;
|
payto_uri: string;
|
||||||
@ -102,7 +90,6 @@ interface MerchantBankAccount {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface MerchantInstanceConfig {
|
export interface MerchantInstanceConfig {
|
||||||
accounts: MerchantBankAccount[];
|
|
||||||
auth: MerchantAuthConfiguration;
|
auth: MerchantAuthConfiguration;
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
|
Loading…
Reference in New Issue
Block a user