Skip to content

Commit

Permalink
don't check bounds for options that do not apply to specified mode
Browse files Browse the repository at this point in the history
  • Loading branch information
cd-rite committed Jun 10, 2024
1 parent bdc67e0 commit f01fdb5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ async function preflightServices () {
await hasMinApiVersion()
await auth.getOpenIDConfiguration()
await auth.getToken()
logger.info({ component, message: `preflight token request suceeded`})
logger.info({ component, message: `preflight token request succeeded`})
const promises = [
api.getCollection(options.collectionId),
api.getCollectionAssets(options.collectionId),
Expand All @@ -147,7 +147,7 @@ async function preflightServices () {
logger.warn({ component, message: `preflight user request failed; token may be missing scope 'stig-manager:user:read'? Watcher will not set {"status": "accepted"}`})
Alarm.noGrant(false)
}
logger.info({ component, message: `prefilght api requests suceeded`})
logger.info({ component, message: `preflight api requests succeeded`})
}

function getObfuscatedConfig (options) {
Expand Down
10 changes: 8 additions & 2 deletions lib/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ program
.option('--ignore-glob [glob...]', 'File or directory glob(s) to ignore. Can be invoked multiple times.(`WATCHER_IGNORE_GLOBS=<csv>`)', pe.WATCHER_IGNORE_GLOBS?.split(','))
.option('--event-polling', 'Use polling with `--mode events`, necessary for watching network files (`WATCHER_EVENT_POLLING=1`). Ignored if `--mode scan`, negate with `--no-event-polling`.', getBoolean('WATCHER_EVENT_POLLING', true))
.option('--no-event-polling', 'Don\'t use polling with `--mode events`, reduces CPU usage (`WATCHER_EVENT_POLLING=0`).')
.option('--stability-threshold <ms>', 'If `--mode events`, milliseconds to wait for file size to stabilize. May be helpful when watching network shares. (`WATCHER_STABILITY_THRESHOLD`). Igonred with `--mode scan`', parseIntegerArg, parseIntegerEnv(pe.WATCHER_STABILITY_THRESHOLD) ?? 0)
.option('--stability-threshold <ms>', 'If `--mode events`, milliseconds to wait for file size to stabilize. May be helpful when watching network shares. (`WATCHER_STABILITY_THRESHOLD`). Ignored with `--mode scan`', parseIntegerArg, parseIntegerEnv(pe.WATCHER_STABILITY_THRESHOLD) ?? 0)
.option('--one-shot', 'Process existing files in the path and exit. Sets `--add-existing`.', getBoolean('WATCHER_ONE_SHOT', false))
.option('--log-color', 'Colorize the console log output. Might confound downstream piped processes.', false)
.option('-d, --debug', 'Shortcut for `--log-level debug --log-file-level debug`', false)
Expand Down Expand Up @@ -142,11 +142,17 @@ logger.logger.log({

for (const key in CONSTANTS.configBounds) {
const bounds = CONSTANTS.configBounds[key]
//skip bounds checks for scanOnly and eventOnly options if not in that mode
if ((options.mode !== 'scan' && CONSTANTS.scanOnlyBounds.has(key))
|| (options.mode !== 'event' && CONSTANTS.eventOnlyBounds.has(key)))
{
continue
}
if (options[key] < bounds.min || options[key] > bounds.max) {
logger.logger.log({
level: 'error',
component: component,
message: `Config value out of bounds: ${key}=${options[key]}`
message: `Config value out of bounds: ${key}=${options[key]} must be between ${bounds.min} and ${bounds.max}`
})
configValid = false
}
Expand Down
2 changes: 2 additions & 0 deletions lib/consts.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,7 @@ export const configBounds = {
},
}

export const scanOnlyBounds = new Set(["scanInterval", "historyWriteInterval"])

export const eventOnlyBounds = new Set(["stabilityThreshold"])

0 comments on commit f01fdb5

Please sign in to comment.