(commandArray: string[])
| 190 | * removes potentially sensitive information from the command array (argv strings) |
| 191 | */ |
| 192 | export const redactCommandArray = (commandArray: string[]): string[] => { |
| 193 | const REDACTED_TAG = '[redacted]' |
| 194 | |
| 195 | for (let i = 0; i < commandArray.length; i++) { |
| 196 | const arg = commandArray[i] |
| 197 | // redact --option arguments |
| 198 | SENSITIVE_CLI_OPTIONS.forEach((option: string) => { |
| 199 | // --url file:./dev.db |
| 200 | // arg is `--url` and a complete match |
| 201 | const argIndexCompleteMatch = arg === option |
| 202 | // --url=file:./dev.db |
| 203 | // arg value is `--url=file:./dev.db` and a partial match |
| 204 | const argIndexPartialMatch = arg.indexOf(option) |
| 205 | |
| 206 | // First check for complete match and redact the value |
| 207 | if (argIndexCompleteMatch) { |
| 208 | commandArray[i + 1] = REDACTED_TAG |
| 209 | } |
| 210 | // else check for partial match and redact the value |
| 211 | else if (argIndexPartialMatch !== -1) { |
| 212 | commandArray[i] = `${option}=${REDACTED_TAG}` |
| 213 | } |
| 214 | }) |
| 215 | } |
| 216 | |
| 217 | return commandArray |
| 218 | } |
no test coverage detected