diff options
author | Florian Dold <florian@dold.me> | 2023-08-25 14:11:23 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2023-08-25 14:11:23 +0200 |
commit | c95740f1e845d1bb14b5e255b1d217dd30b3a7da (patch) | |
tree | 9e2a27875b0a83c9fe3228de9a4f6350bc0944a0 /packages/taler-util/src/talerconfig.ts | |
parent | 896841aec5dc3594d83cc300349d20ec2270f88e (diff) | |
download | wallet-core-c95740f1e845d1bb14b5e255b1d217dd30b3a7da.tar.xz |
taler-util: make config parsing more compliant with spec
Diffstat (limited to 'packages/taler-util/src/talerconfig.ts')
-rw-r--r-- | packages/taler-util/src/talerconfig.ts | 36 |
1 files changed, 29 insertions, 7 deletions
diff --git a/packages/taler-util/src/talerconfig.ts b/packages/taler-util/src/talerconfig.ts index d86c58678..098f5f9a4 100644 --- a/packages/taler-util/src/talerconfig.ts +++ b/packages/taler-util/src/talerconfig.ts @@ -25,11 +25,14 @@ */ import { AmountJson } from "./amounts.js"; import { Amounts } from "./amounts.js"; +import { Logger } from "./logging.js"; import nodejs_path from "path"; import nodejs_os from "os"; import nodejs_fs from "fs"; +const logger = new Logger("talerconfig.ts"); + export class ConfigError extends Error { constructor(message: string) { super(); @@ -77,7 +80,7 @@ export class ConfigValue<T> { constructor( private sectionName: string, private optionName: string, - public value: string | undefined, + private value: string | undefined, private converter: (x: string) => T, ) {} @@ -138,7 +141,7 @@ export function pathsub( lookup: (s: string, depth: number) => string | undefined, depth = 0, ): string { - if (depth >= 10) { + if (depth >= 128) { throw Error("recursion in path substitution"); } let s = x; @@ -624,15 +627,18 @@ export class Configuration { lookupVariable(x: string, depth: number = 0): string | undefined { // We loop up options in PATHS in upper case, as option names // are case insensitive - let val = this.findEntry("PATHS", x)?.value; + const val = this.findEntry("PATHS", x)?.value; if (val !== undefined) { return pathsub(val, (v, d) => this.lookupVariable(v, d), depth); } + // Environment variables can be case sensitive, respect that. const envVal = process.env[x]; if (envVal !== undefined) { return envVal; } + + logger.warn(`unable to resolve variable '${x}'`); return; } @@ -692,12 +698,28 @@ export class Configuration { "DOCDIR", `${installPrefix}/share/doc/taler/`, ); - this.setStringSystemDefault("PATHS", "ICONDIR", `${installPrefix}/share/icons/`); - this.setStringSystemDefault("PATHS", "LOCALEDIR", `${installPrefix}/share/locale/`); + this.setStringSystemDefault( + "PATHS", + "ICONDIR", + `${installPrefix}/share/icons/`, + ); + this.setStringSystemDefault( + "PATHS", + "LOCALEDIR", + `${installPrefix}/share/locale/`, + ); this.setStringSystemDefault("PATHS", "PREFIX", `${installPrefix}/`); this.setStringSystemDefault("PATHS", "BINDIR", `${installPrefix}/bin`); - this.setStringSystemDefault("PATHS", "LIBDIR", `${installPrefix}/lib/taler/`); - this.setStringSystemDefault("PATHS", "DATADIR", `${installPrefix}/share/taler/`); + this.setStringSystemDefault( + "PATHS", + "LIBDIR", + `${installPrefix}/lib/taler/`, + ); + this.setStringSystemDefault( + "PATHS", + "DATADIR", + `${installPrefix}/share/taler/`, + ); this.loadDefaultsFromDir(baseConfigDir); } |