diff options
author | Florian Dold <florian@dold.me> | 2024-05-02 17:09:17 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2024-05-02 17:09:17 +0200 |
commit | 9e3fc09bb056948d0706386edf52cd3a27b184ba (patch) | |
tree | 30a00582b695a6ebc877797428bce973063f4437 /packages/taler-harness | |
parent | 8e1ccefedd48f0076a53a14ecc2e2d5d094b90a9 (diff) | |
download | wallet-core-9e3fc09bb056948d0706386edf52cd3a27b184ba.tar.xz |
harness,util: implement writing changed config back to the file system, support multiple projects
Diffstat (limited to 'packages/taler-harness')
-rw-r--r-- | packages/taler-harness/src/harness/harness.ts | 26 | ||||
-rw-r--r-- | packages/taler-harness/src/harness/sync.ts | 2 | ||||
-rw-r--r-- | packages/taler-harness/src/index.ts | 94 |
3 files changed, 76 insertions, 46 deletions
diff --git a/packages/taler-harness/src/harness/harness.ts b/packages/taler-harness/src/harness/harness.ts index 68c0744fc..b27eaa371 100644 --- a/packages/taler-harness/src/harness/harness.ts +++ b/packages/taler-harness/src/harness/harness.ts @@ -651,7 +651,7 @@ export class FakebankService config.setString("bank", "max_debt", bc.maxDebt ?? `${bc.currency}:100`); config.setString("bank", "ram_limit", `${1024}`); const cfgFilename = testDir + "/bank.conf"; - config.write(cfgFilename, { excludeDefaults: true }); + config.writeTo(cfgFilename, { excludeDefaults: true }); return new FakebankService(gc, bc, cfgFilename); } @@ -680,7 +680,7 @@ export class FakebankService } const config = Configuration.load(this.configFile); config.setString("bank", "suggested_exchange", e.baseUrl); - config.write(this.configFile, { excludeDefaults: true }); + config.writeTo(this.configFile, { excludeDefaults: true }); } get baseUrl(): string { @@ -790,7 +790,7 @@ export class LibeufinBankService `${bc.currency}:100`, ); const cfgFilename = testDir + "/bank.conf"; - config.write(cfgFilename, { excludeDefaults: true }); + config.writeTo(cfgFilename, { excludeDefaults: true }); return new LibeufinBankService(gc, bc, cfgFilename); } @@ -828,7 +828,7 @@ export class LibeufinBankService "suggested_withdrawal_exchange", e.baseUrl, ); - config.write(this.configFile, { excludeDefaults: true }); + config.writeTo(this.configFile, { excludeDefaults: true }); } get baseUrl(): string { @@ -1052,7 +1052,7 @@ export class ExchangeService implements ExchangeServiceInterface { changeConfig(f: (config: Configuration) => void) { const config = Configuration.load(this.configFilename); f(config); - config.write(this.configFilename, { excludeDefaults: true }); + config.writeTo(this.configFilename, { excludeDefaults: true }); } static create(gc: GlobalTestState, e: ExchangeConfig) { @@ -1118,7 +1118,7 @@ export class ExchangeService implements ExchangeServiceInterface { fs.writeFileSync(masterPrivFile, Buffer.from(exchangeMasterKey.eddsaPriv)); const cfgFilename = testDir + `/exchange-${e.name}.conf`; - config.write(cfgFilename, { excludeDefaults: true }); + config.writeTo(cfgFilename, { excludeDefaults: true }); return new ExchangeService(gc, e, cfgFilename, exchangeMasterKey); } @@ -1127,13 +1127,13 @@ export class ExchangeService implements ExchangeServiceInterface { offeredCoins.forEach((cc) => setCoin(config, cc(this.exchangeConfig.currency)), ); - config.write(this.configFilename, { excludeDefaults: true }); + config.writeTo(this.configFilename, { excludeDefaults: true }); } addCoinConfigList(ccs: CoinConfig[]) { const config = Configuration.load(this.configFilename); ccs.forEach((cc) => setCoin(config, cc)); - config.write(this.configFilename, { excludeDefaults: true }); + config.writeTo(this.configFilename, { excludeDefaults: true }); } enableAgeRestrictions(maskStr: string) { @@ -1144,7 +1144,7 @@ export class ExchangeService implements ExchangeServiceInterface { "age_groups", maskStr, ); - config.write(this.configFilename, { excludeDefaults: true }); + config.writeTo(this.configFilename, { excludeDefaults: true }); } get masterPub() { @@ -1165,7 +1165,7 @@ export class ExchangeService implements ExchangeServiceInterface { ): Promise<void> { const config = Configuration.load(this.configFilename); await f(config); - config.write(this.configFilename, { excludeDefaults: true }); + config.writeTo(this.configFilename, { excludeDefaults: true }); } async addBankAccount( @@ -1206,7 +1206,7 @@ export class ExchangeService implements ExchangeServiceInterface { "password", exchangeBankAccount.accountPassword, ); - config.write(this.configFilename, { excludeDefaults: true }); + config.writeTo(this.configFilename, { excludeDefaults: true }); } exchangeHttpProc: ProcessWrapper | undefined; @@ -1701,7 +1701,7 @@ export class MerchantService implements MerchantServiceInterface { config.setString("merchantdb-postgres", "config", mc.database); // Do not contact demo.taler.net exchange in tests config.setString("merchant-exchange-kudos", "disabled", "yes"); - config.write(cfgFilename, { excludeDefaults: true }); + config.writeTo(cfgFilename, { excludeDefaults: true }); return new MerchantService(gc, mc, cfgFilename); } @@ -1719,7 +1719,7 @@ export class MerchantService implements MerchantServiceInterface { this.merchantConfig.currency, ); config.setString(`merchant-exchange-${e.name}`, "master_key", e.masterPub); - config.write(this.configFilename, { excludeDefaults: true }); + config.writeTo(this.configFilename, { excludeDefaults: true }); } async addDefaultInstance(): Promise<void> { diff --git a/packages/taler-harness/src/harness/sync.ts b/packages/taler-harness/src/harness/sync.ts index 64c9acaef..567a2e92d 100644 --- a/packages/taler-harness/src/harness/sync.ts +++ b/packages/taler-harness/src/harness/sync.ts @@ -85,7 +85,7 @@ export class SyncService { config.setString("syncdb-postgres", "config", sc.database); config.setString("sync", "payment_backend_url", sc.paymentBackendUrl); config.setString("sync", "upload_limit_mb", `${sc.uploadLimitMb}`); - config.write(cfgFilename); + config.writeTo(cfgFilename); return new SyncService(gc, sc, cfgFilename); } diff --git a/packages/taler-harness/src/index.ts b/packages/taler-harness/src/index.ts index 0f282e123..2b1fd9a0d 100644 --- a/packages/taler-harness/src/index.ts +++ b/packages/taler-harness/src/index.ts @@ -30,7 +30,6 @@ import { TalerAuthenticationHttpClient, TalerBankConversionHttpClient, TalerCoreBankHttpClient, - TalerErrorCode, TalerMerchantInstanceHttpClient, TalerMerchantManagementHttpClient, TransactionsResponse, @@ -42,7 +41,6 @@ import { randomBytes, rsaBlind, setGlobalLogLevelFromString, - setPrintHttpRequestAsCurl, stringifyPayTemplateUri, } from "@gnu-taler/taler-util"; import { clk } from "@gnu-taler/taler-util/clk"; @@ -80,7 +78,6 @@ import { } from "./harness/helpers.js"; import { getTestInfo, runTests } from "./integrationtests/testrunner.js"; import { lintExchangeDeployment } from "./lint.js"; -import { randomUUID } from "crypto"; const logger = new Logger("taler-harness:index.ts"); @@ -356,25 +353,46 @@ advancedCli ); }); -const configCli = testingCli.subcommand("configArgs", "config", { - help: "Subcommands for handling the Taler configuration.", -}); +const configCli = testingCli + .subcommand("configArgs", "config", { + help: "Subcommands for handling the Taler configuration.", + }) + .maybeOption("configEntryFile", ["-c", "--config"], clk.STRING, { + help: "Configuration file to use.", + }) + .maybeOption("project", ["--project"], clk.STRING, { + help: `Selection of the project to inspect/change the config (default: taler).`, + }); -configCli.subcommand("show", "show").action(async (args) => { - const config = Configuration.load(); - const cfgStr = config.stringify({ - diagnostics: true, +configCli + .subcommand("show", "show", { + help: "Show the current configuration.", + }) + .action(async (args) => { + const config = Configuration.load( + args.configArgs.configEntryFile, + args.configArgs.project, + ); + const cfgStr = config.stringify({ + diagnostics: true, + }); + console.log(cfgStr); }); - console.log(cfgStr); -}); configCli - .subcommand("get", "get") + .subcommand("get", "get", { + help: "Get a configuration option.", + }) .requiredArgument("section", clk.STRING) .requiredArgument("option", clk.STRING) - .flag("file", ["-f"]) + .flag("file", ["-f"], { + help: "Treat the value as a filename, expanding placeholders.", + }) .action(async (args) => { - const config = Configuration.load(); + const config = Configuration.load( + args.configArgs.configEntryFile, + args.configArgs.project, + ); let res; if (args.get.file) { res = config.getPath(args.get.section, args.get.option); @@ -389,6 +407,35 @@ configCli } }); +configCli + .subcommand("set", "set", { + help: "Set a configuration option.", + }) + .requiredArgument("section", clk.STRING) + .requiredArgument("option", clk.STRING) + .requiredArgument("value", clk.STRING) + .flag("dry", ["--dry"], { + help: "Do not write the changed config to disk, only write it to stdout.", + }) + .action(async (args) => { + const config = Configuration.load( + args.configArgs.configEntryFile, + args.configArgs.project, + ); + config.setString(args.set.section, args.set.option, args.set.value); + if (args.set.dry) { + console.log( + config.stringify({ + excludeDefaults: true, + }), + ); + } else { + config.write({ + excludeDefaults: true, + }); + } + }); + const deploymentCli = testingCli.subcommand("deploymentArgs", "deployment", { help: "Subcommands for handling GNU Taler deployments.", }); @@ -1147,23 +1194,6 @@ deploymentCli console.log(out); }); -const deploymentConfigCli = deploymentCli.subcommand("configArgs", "config", { - help: "Subcommands the Taler configuration.", -}); - -deploymentConfigCli - .subcommand("show", "show") - .flag("diagnostics", ["-d", "--diagnostics"]) - .maybeArgument("cfgfile", clk.STRING, {}) - .action(async (args) => { - const cfg = Configuration.load(args.show.cfgfile); - console.log( - cfg.stringify({ - diagnostics: args.show.diagnostics, - }), - ); - }); - testingCli.subcommand("logtest", "logtest").action(async (args) => { logger.trace("This is a trace message."); logger.info("This is an info message."); |