Skip to content

Commit

Permalink
Argument Validator updates (#729)
Browse files Browse the repository at this point in the history
* Reengineer validators

* Updats to docstrings

* Linter appeasement
  • Loading branch information
ramo-j authored Feb 19, 2023
1 parent e15964b commit cf351bd
Show file tree
Hide file tree
Showing 4 changed files with 367 additions and 230 deletions.
2 changes: 1 addition & 1 deletion data/recipes/upload_turbinia.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
["files", "Paths to process.", null],
["--turbinia_recipe", "The Turbinia recipe name to use for evidence processing.", null],
["--destination_turbinia_dir", "Destination path in Turbinia host to write the files to.", null],
["--hostname", "Remote host.", null, {"format": "fqdn"}],
["--hostname", "Remote host.", null, {"format": "hostname"}],
["--directory", "Directory in which to copy and compress files.", null],
["--turbinia_config", "Turbinia config file to use.", null],
["--local_turbinia_results", "Directory where Turbinia results will be downloaded to.", null],
Expand Down
11 changes: 9 additions & 2 deletions dftimewolf/cli/dftimewolf_recipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,15 +295,22 @@ def ValidateArguments(self) -> None:
switch = arg.switch.replace('--', '')
if (switch == arg.switch or # Ignore optional args, unless present
self.state.command_line_options[switch] is not None):
self._args_validator.Validate(self.state.command_line_options[switch],
arg.format)
value, message = self._args_validator.Validate(
self.state.command_line_options[switch], arg.format)
if not value:
error_messages.append(
f'Argument validation error: "{arg.switch}" with value '
f'"{self.state.command_line_options[switch]}" gave error: '
f'{str(message)}')
except errors.RecipeArgsValidatorError as exception:
error_messages.append(f'Argument validation error: "{arg.switch}" with '
f'value "{self.state.command_line_options[switch]}" gave error: '
f'{str(exception)}')

if error_messages:
for message in error_messages:
if self.cdm:
self.cdm.EnqueueMessage('dftimewolf', message, True)
logger.critical(message)
raise errors.RecipeArgsValidatorError(
'At least one argument failed validation')
Expand Down
Loading

0 comments on commit cf351bd

Please sign in to comment.