shodan-python icon indicating copy to clipboard operation
shodan-python copied to clipboard

Add input validation to shodan convert command

Open rmhowe425 opened this issue 1 year ago • 4 comments

  • Closes out #204
  • Created validation.py where I stored 2 functions used as callback methods for the input file type and output format for the shodan convert command.
  • Functions used for input validation are passed in via the callback parameter for click.argument.

rmhowe425 avatar Dec 03 '23 04:12 rmhowe425

@achillean If you're okay with this PR and my method for adding input validation, I would he happy to open a new issue & PR to add similar input validation for all other CLI arguments.

This could help clean up and simplify the actual implementation for each command.

rmhowe425 avatar Dec 03 '23 04:12 rmhowe425

The validation of the filename looks good but I'm not sure what the validation of the output parameters adds. click already checks that the output format is one of the values specified in type:

$ shodan convert test.txt nonsense
Usage: shodan convert [OPTIONS] <input file> <output format>
Try 'shodan convert -h' for help.

Error: Invalid value for '<output format>': 'nonsense' is not one of 'kml', 'csv', 'geo.json', 'images', 'xlsx'.

Also I'm not a fan of having to maintain the list of supported output formats in different locations. It's fairly rare that they get changed but it would be nicer if everything (help text, error text, mapping of output format to class etc.) was automatically generated. However, the primary hesitation for me in adding the callback for the output format is that I'm not sure why it needs to exist.

achillean avatar Dec 03 '23 17:12 achillean

Ah yep I see what you mean! I'll remove the callback input validation for the output format 😄

rmhowe425 avatar Dec 03 '23 18:12 rmhowe425

@achillean I updated the implementation to only include filename input validation.

rmhowe425 avatar Jan 01 '24 14:01 rmhowe425