Skip to content

Commit

Permalink
feat: scan mode history management (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matte22 authored Feb 19, 2024
1 parent 00f497f commit e398da9
Show file tree
Hide file tree
Showing 8 changed files with 2,128 additions and 86 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ watched/
.env
*.log
log.json
bundle.js
bundle.js
coverage/
2 changes: 1 addition & 1 deletion dist/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
*

# Except this file
!.gitignore
!.gitignore
13 changes: 11 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,27 @@ import startFsEventWatcher from './lib/events.js'
import { getOpenIDConfiguration, getToken } from './lib/auth.js'
import * as api from './lib/api.js'
import { serializeError } from 'serialize-error'
import startScanner from './lib/scan.js'
import { initScanner } from './lib/scan.js'
import semverGte from 'semver/functions/gte.js'

const minApiVersion = '1.2.7'

process.on('SIGINT', () => {
logger.info({
component: 'main',
message: 'received SIGINT, exiting'
})
process.exit(0)
})

run()

async function run() {
try {
logger.info({
component: 'main',
message: 'running',
pid: process.pid,
options: getObfuscatedConfig(options)
})

Expand All @@ -30,7 +39,7 @@ async function run() {
startFsEventWatcher()
}
else if (options.mode === 'scan') {
startScanner()
initScanner()
}
}
catch (e) {
Expand Down
21 changes: 11 additions & 10 deletions lib/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ const component = 'args'

function getVersion() {
try {
const packageJsonText = readFileSync('./package.json', 'utf8');
return JSON.parse(packageJsonText).version;
const packageJsonText = readFileSync('./package.json', 'utf8')
return JSON.parse(packageJsonText).version
}
catch (error) {
console.error('Error reading package.json:', error);
console.error('Error reading package.json:', error)
}
}

let configValid = true

const version = getVersion();
const version = getVersion()

// Use .env, if present, to setup the environment
config()
Expand Down Expand Up @@ -54,18 +54,18 @@ const getBoolean = (envvar, defaultState = true) => {
}
}
const parseIntegerArg = (value) => {
const parsedValue = parseInt(value, 10);
const parsedValue = parseInt(value, 10)
if (isNaN(parsedValue)) {
throw new InvalidOptionArgumentError('Not a number.');
throw new InvalidOptionArgumentError('Not a number.')
}
return parsedValue;
return parsedValue
}
const parseIntegerEnv = (value) => {
const parsedValue = parseInt(value, 10);
const parsedValue = parseInt(value, 10)
if (isNaN(parsedValue)) {
return undefined
}
return parsedValue;
return parsedValue
}

// Build the Command
Expand All @@ -92,7 +92,8 @@ program
.option('--add-existing', 'For `--mode events`, existing files in the path will generate an `add` event (`WATCHER_ADD_EXISTING=1`). Ignored if `--mode scan`, negate with `--no-add-existing`.', getBoolean('WATCHER_ADD_EXISTING', false))
.option('--no-add-existing', 'Ignore existing files in the watched path (`WATCHER_ADD_EXISTING=0`).')
.option('--cargo-delay <ms>', 'Milliseconds to delay processing the queue (`WATCHER_CARGO_DELAY`)', parseIntegerArg, parseIntegerEnv(pe.WATCHER_CARGO_DELAY) ?? 2000)
.option('--cargo-size <number>', 'Maximum queue size that triggers processing (`WATCHER_CARGO_SIZE`)', parseIntegerArg, parseIntegerEnv(pe.WATCHER_CARGO_SIZE) ?? 25)
.option('--history-write-interval <ms>', 'Interval in milliseconds for when to periodically sync history file(`WATCHER_HISTORY_WRITE_INTERVAL`)', parseIntegerArg, parseIntegerEnv(pe.WATCHER_HISTORY_WRITE_INTERVAL) ?? 15000)
.option('--cargo-size <number>', 'Maximum queue size that triggers processing (`WATCHER_CARGO_SIZE`)', parseIntegerArg, parseIntegerEnv(pe.WATCHER_CARGO_SIZE) ?? 10)
.option('--create-objects', 'Create Assets or STIG Assignments as needed (`WATCHER_CREATE_OBJECTS=1`). Negate with `--no-create-objects`.', getBoolean('WATCHER_CREATE_OBJECTS', true))
.option('--no-create-objects', 'Do not create Assets or STIG Assignments (`WATCHER_CREATE_OBJECTS=0`).')
.option('--ignore-dir [name...]', 'DEPRECATED, use --ignore-glob. Sub-directory name to ignore. Can be invoked multiple times.(`WATCHER_IGNORE_DIRS=<csv>`)', pe.WATCHER_IGNORE_DIRS?.split(','))
Expand Down
Loading

0 comments on commit e398da9

Please sign in to comment.