fortify / fcli

fcli is a command-line utility for interacting with various Fortify products
https://fortify.github.io/fcli/
Other
31 stars 18 forks source link

Generic max-results and order-by #120

Open MikeTheSnowman opened 1 year ago

MikeTheSnowman commented 1 year ago

With fcli SSC's list commands, if you try to limit the number of results being output by using the RESP APIs limit parameter, it won't work for two reasons:

Instead, we'd need to add a generic --max-results option, either in OutputMixin (so the option becomes available on all commands) or as a separate Mixin (so we can make this option available only on list commands for example). Alternatively, we could integrate this into the -q option, like -q maxResults=100, not sure whether that's a good idea though.

OutputMixin would then need to keep track of the number of filtered records actually written, and stop making requests for getting a next page once we've written the maximum number of results. Generic functionality in the SSC module would need to update the request to set the appropriate page size; if --max-results is not specified, this functionality adds limit=-1 to the request, or adds limit=<max-results> if --max-results is specified.

As for the --order-by option:

rsenden commented 1 year ago

Order-by functionality is already being discussed in #86

rsenden commented 1 year ago

Having an option to limit the number of results without the ability to provide a starting position probably doesn't make much sense. Potentially we could have a generic --records <start>-<end> output option:

rsenden commented 1 year ago

Although the comment above could potentially work for returning the first x records, it won't be performant when processing later pages, for example --records 100000-100005 as we'd still need to load the first 100000 or more records from the source system to be able to determine which ones are removed by client-side queries.

The only way to implement this in a performant way is to have a product-specific --records option, for example defined in a Mixin, and using this Mixin in all commands for which the primary endpoint supports paging. This means that paging will take place before applying client-side queries, so --records 0-1000 could potentially output 0 records if none of them match the given query.

As such, it may make sense to also have a generic --max-results option on all list commands (defined as a mixin referenced from either OutputHelperMixins::List or OutputWriterWithQueryFactoryMixin) that is applied after any client-side queries. This would allow users to simply see the first x matching records, without having to re-run the same command with different --records values to find the first x matching records. Obviously, once max results has been reached, no more pages should be loaded from the source system.