Skip to content

Commit

Permalink
feat: response timeout is configurable from environment (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matte22 authored Jun 10, 2024
1 parent 9a63d8b commit ed5f8c3
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async function apiRequest({method = 'GET', endpoint, json, authorize = true, ful
url: `${options.api}${endpoint}`,
responseType: 'json',
timeout: {
request: CONSTANTS.REQUEST_TIMEOUT
response: options.responseTimeout
}
}

Expand Down
1 change: 1 addition & 0 deletions lib/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ program
.option('--no-ignore-dot', 'Do not ignore dotfiles in the path (`WATCHER_IGNORE_DOT=0`).')
.option('--strict-revision-check', 'For CKL, ignore checklist of uninstalled STIG revision (`WATCHER_STRICT_REVISION_CHECK=1`). Negate with `--no-strict-revision-check`.', getBoolean('WATCHER_STRICT_REVISION_CHECK', false))
.option('--no-strict-revision-check', 'For CKL, allow checklist of uninstalled STIG revision (`WATCHER_STRICT_REVISION_CHECK=0`). This is the default behavior.')
.option('--response-timeout <ms>', 'Specify the timeout duration in milliseconds for an API response to begin. If a response takes longer than this time, an error will be thrown.', parseIntegerArg, parseIntegerEnv(pe.WATCHER_RESPONSE_TIMEOUT) ?? 20000) // 20 secs

// Parse ARGV and get the parsed options object
// Options properties are created as camelCase versions of the long option name
Expand Down
6 changes: 3 additions & 3 deletions lib/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async function getOpenIDConfiguration () {
const requestOptions = {
responseType: 'json',
timeout: {
request: CONSTANTS.REQUEST_TIMEOUT
response: options.responseTimeout
}
}
let response
Expand Down Expand Up @@ -122,7 +122,7 @@ async function authenticateClientSecret () {
password: options.clientSecret,
responseType: 'json',
timeout: {
request: CONSTANTS.REQUEST_TIMEOUT
response: options.responseTimeout
}
}

Expand Down Expand Up @@ -180,7 +180,7 @@ async function authenticateSignedJwt () {
},
responseType: 'json',
timeout: {
request: CONSTANTS.REQUEST_TIMEOUT
response: options.responseTimeout
}
}
logger.debug({
Expand Down
3 changes: 1 addition & 2 deletions lib/consts.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ export const ERR_AUTHOFFLINE = 2
export const ERR_NOTOKEN = 3
export const ERR_NOGRANT = 4
export const ERR_UNKNOWN = 5
export const ERR_FAILINIT = 6
export const REQUEST_TIMEOUT = 5000
export const ERR_FAILINIT = 6

0 comments on commit ed5f8c3

Please sign in to comment.