From 24593b3cad7878ba9e169dc076a2dbf0ab27dbd0 Mon Sep 17 00:00:00 2001 From: maartenvandenbrande Date: Wed, 28 Jan 2026 12:02:57 +0100 Subject: [PATCH 1/2] feat: add cli arguments for the uma server --- packages/uma/bin/main.js | 35 ++++++++++++++++++++------ packages/uma/package.json | 3 ++- yarn.lock | 53 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 82 insertions(+), 9 deletions(-) diff --git a/packages/uma/bin/main.js b/packages/uma/bin/main.js index 503552d..a845791 100644 --- a/packages/uma/bin/main.js +++ b/packages/uma/bin/main.js @@ -1,12 +1,33 @@ const path = require('path'); +const yargs = require('yargs/yargs'); +const { hideBin } = require('yargs/helpers'); const { ComponentsManager } = require('componentsjs'); const { setGlobalLoggerFactory, WinstonLoggerFactory } = require('global-logger-factory'); -const protocol = 'http'; -const host = 'localhost'; -const port = 4000; - -const baseUrl = `${protocol}://${host}:${port}/uma`; +const argv = yargs(hideBin(process.argv)) + .option('port', { + alias: 'p', + type: 'number', + description: 'Port number for the UMA server', + default: 4000 + }) + .option('baseUrl', { + alias: 'b', + type: 'string', + description: 'Base URL for the UMA server', + }) + .option('loggingLevel', { + alias: 'l', + type: 'string', + description: 'Log level for the UMA server', + default: 'info' + }) + .help() + .alias('help', 'h') + .argv; + +const port = argv.port; +const baseUrl = argv.baseUrl || `http://localhost:${port}/uma`; const rootDir = path.join(__dirname, '../'); const launch = async () => { @@ -22,11 +43,11 @@ const launch = async () => { const configPath = path.join(rootDir, './config/default.json'); - setGlobalLoggerFactory(new WinstonLoggerFactory('info')); + setGlobalLoggerFactory(new WinstonLoggerFactory(argv.logLevel || 'info')); const manager = await ComponentsManager.build({ mainModulePath: rootDir, - logLevel: 'silly', + logLevel: argv.logLevel || 'silly', typeChecking: false, }); diff --git a/packages/uma/package.json b/packages/uma/package.json index e0b4b99..51241ac 100644 --- a/packages/uma/package.json +++ b/packages/uma/package.json @@ -76,7 +76,8 @@ "odrl-evaluator": "^0.5.0", "rdf-vocabulary": "^1.0.1", "uri-template-lite": "^23.4.0", - "winston": "^3.11.0" + "winston": "^3.11.0", + "yargs": "^18.0.0" }, "lsd:module": "https://linkedsoftwaredependencies.org/bundles/npm/@solidlab/uma", "lsd:components": "dist/components/components.jsonld", diff --git a/yarn.lock b/yarn.lock index 970d544..ba0fd52 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5660,6 +5660,7 @@ __metadata: rdf-vocabulary: "npm:^1.0.1" uri-template-lite: "npm:^23.4.0" winston: "npm:^3.11.0" + yargs: "npm:^18.0.0" languageName: unknown linkType: soft @@ -6823,6 +6824,13 @@ __metadata: languageName: node linkType: hard +"ansi-styles@npm:^6.2.1": + version: 6.2.3 + resolution: "ansi-styles@npm:6.2.3" + checksum: 10c0/23b8a4ce14e18fb854693b95351e286b771d23d8844057ed2e7d083cd3e708376c3323707ec6a24365f7d7eda3ca00327fe04092e29e551499ec4c8b7bfac868 + languageName: node + linkType: hard + "arg@npm:^4.1.0": version: 4.1.3 resolution: "arg@npm:4.1.3" @@ -7231,6 +7239,17 @@ __metadata: languageName: node linkType: hard +"cliui@npm:^9.0.1": + version: 9.0.1 + resolution: "cliui@npm:9.0.1" + dependencies: + string-width: "npm:^7.2.0" + strip-ansi: "npm:^7.1.0" + wrap-ansi: "npm:^9.0.0" + checksum: 10c0/13441832e9efe7c7a76bd2b8e683555c478d461a9f249dc5db9b17fe8d4b47fa9277b503914b90bd00e4a151abb6b9b02b2288972ffe2e5e3ca40bcb1c2330d3 + languageName: node + linkType: hard + "clownface@npm:^1.4.0": version: 1.5.1 resolution: "clownface@npm:1.5.1" @@ -12841,7 +12860,7 @@ __metadata: languageName: node linkType: hard -"string-width@npm:^7.2.0": +"string-width@npm:^7.0.0, string-width@npm:^7.2.0": version: 7.2.0 resolution: "string-width@npm:7.2.0" dependencies: @@ -13909,6 +13928,17 @@ __metadata: languageName: node linkType: hard +"wrap-ansi@npm:^9.0.0": + version: 9.0.2 + resolution: "wrap-ansi@npm:9.0.2" + dependencies: + ansi-styles: "npm:^6.2.1" + string-width: "npm:^7.0.0" + strip-ansi: "npm:^7.1.0" + checksum: 10c0/3305839b9a0d6fb930cb63a52f34d3936013d8b0682ff3ec133c9826512620f213800ffa19ea22904876d5b7e9a3c1f40682f03597d986a4ca881fa7b033688c + languageName: node + linkType: hard + "wrappy@npm:1": version: 1.0.2 resolution: "wrappy@npm:1.0.2" @@ -14011,6 +14041,13 @@ __metadata: languageName: node linkType: hard +"yargs-parser@npm:^22.0.0": + version: 22.0.0 + resolution: "yargs-parser@npm:22.0.0" + checksum: 10c0/cb7ef81759c4271cb1d96b9351dbbc9a9ce35d3e1122d2b739bf6c432603824fa02c67cc12dcef6ea80283379d63495686e8f41cc7b06c6576e792aba4d33e1c + languageName: node + linkType: hard + "yargs@npm:^16.2.0": version: 16.2.0 resolution: "yargs@npm:16.2.0" @@ -14041,6 +14078,20 @@ __metadata: languageName: node linkType: hard +"yargs@npm:^18.0.0": + version: 18.0.0 + resolution: "yargs@npm:18.0.0" + dependencies: + cliui: "npm:^9.0.1" + escalade: "npm:^3.1.1" + get-caller-file: "npm:^2.0.5" + string-width: "npm:^7.2.0" + y18n: "npm:^5.0.5" + yargs-parser: "npm:^22.0.0" + checksum: 10c0/bf290e4723876ea9c638c786a5c42ac28e03c9ca2325e1424bf43b94e5876456292d3ed905b853ebbba6daf43ed29e772ac2a6b3c5fb1b16533245d6211778f3 + languageName: node + linkType: hard + "yn@npm:3.1.1": version: 3.1.1 resolution: "yn@npm:3.1.1" From ecddd9e11b2f20d91368748b85c1f3a2537f587a Mon Sep 17 00:00:00 2001 From: maartenvandenbrande Date: Fri, 30 Jan 2026 10:00:01 +0100 Subject: [PATCH 2/2] feat: cleanup defaults + add backupFilePath option --- packages/uma/bin/main.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/packages/uma/bin/main.js b/packages/uma/bin/main.js index a845791..517815a 100644 --- a/packages/uma/bin/main.js +++ b/packages/uma/bin/main.js @@ -15,6 +15,7 @@ const argv = yargs(hideBin(process.argv)) alias: 'b', type: 'string', description: 'Base URL for the UMA server', + default: `http://localhost:${argv.port}/uma` }) .option('loggingLevel', { alias: 'l', @@ -22,32 +23,33 @@ const argv = yargs(hideBin(process.argv)) description: 'Log level for the UMA server', default: 'info' }) + .option('backupFilePath', { + alias: 'f', + type: 'string', + description: 'Backup file path for the UMA server', + default: '' + }) .help() .alias('help', 'h') .argv; -const port = argv.port; -const baseUrl = argv.baseUrl || `http://localhost:${port}/uma`; const rootDir = path.join(__dirname, '../'); const launch = async () => { const variables = {}; - variables['urn:uma:variables:port'] = port; - variables['urn:uma:variables:baseUrl'] = baseUrl; - - variables['urn:uma:variables:policyBaseIRI'] = 'http://localhost:3000/'; - variables['urn:uma:variables:policyDir'] = path.join(rootDir, './config/rules/policy'); + variables['urn:uma:variables:port'] = argv.port; + variables['urn:uma:variables:baseUrl'] = argv.baseUrl; variables['urn:uma:variables:eyePath'] = 'eye'; - variables['urn:uma:variables:backupFilePath'] = 'backup.ttl'; + variables['urn:uma:variables:backupFilePath'] = argv.backupFilePath; const configPath = path.join(rootDir, './config/default.json'); - setGlobalLoggerFactory(new WinstonLoggerFactory(argv.logLevel || 'info')); + setGlobalLoggerFactory(new WinstonLoggerFactory(argv.loggingLevel)); const manager = await ComponentsManager.build({ mainModulePath: rootDir, - logLevel: argv.logLevel || 'silly', + logLevel: argv.loggingLevel, typeChecking: false, });