-
Notifications
You must be signed in to change notification settings - Fork 208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor CLI Interface, Add Scan fail-on-warnings #197
Conversation
lib/cfn-nag/cfn_nag_executor.rb
Outdated
end | ||
end | ||
|
||
def make_config(opts) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'd just call this method what it is without the verb: cfn_nag_config(opts)
lib/cfn-nag/read_cli_options.rb
Outdated
# rubocop:disable Metrics/BlockLength | ||
# rubocop:disable Metrics/AbcSize | ||
# rubocop:disable Metrics/MethodLength | ||
def read_cli_options(require_input_path: false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'd just name this: cli_options()
[Finishes #165899506]; [Finishes #165899494]; factors out command line arguments reading; adds fail-on-warnings support to cfn_nag_scan; removes repeated code across cfn_nag_scan and cfn_nag by refactoring into an executor. Post-refactor, rubocop and testing required the following included supplmental changes: CfnNagExecutor is too large if read_cli_options is included, so factors that function out to its own file; CfnNag class is too large with the added fail_on_warnings option, refactors initialize parameters as a separate CfnNagConfig class; refactors the cfn_nag integration tests to use the new signatures
Fixes a missing call to validate_options in the executor; refactors to stay within the 15 line per function bounds of rubocop
Adds naming corrections per @erickascic 's review; adds tests for CfnNagExecutor class at 88%
Adds additional tests to get cfn_nag_executor and other introduced files to 100% coverage
Updates cli_options to be backwards compatible -- removes alphabetical ordering, splits into two options categories for cfn_nag and cfn_nag_scan
f9ad74f
to
087337d
Compare
lib/cfn-nag/cfn_nag_executor.rb
Outdated
end | ||
|
||
def scan(aggregate_output: true, | ||
cli_supplier: cli_options(cfn_nag_scan: @require_input_path), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if i follow the code, cli_supplier and arg_supplier are exposed here to improve testability? imho this is a tradeoff for complicating the interface - i.e. anybody who calls this might scratch their head and likely never change the defaults. another approach i can suggest is to have "factory methods" for these two arguments, and then in your testing do a partial mock to replace the factory methods. easy on the testing side, and nothing exposed to the consumer
lib/cfn-nag/cfn_nag_executor.rb
Outdated
@parameter_values_string = nil | ||
end | ||
|
||
def scan(aggregate_output: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the require_input_path and aggregate_output are giving me a little trouble. i know what they're there for.... but i'm wondering if you turn the other scan args into factory methods.... er do you need both? or could you have them both be on the scan() instead of split between the constructor and scan()? there are basically two outcomes - single or aggregate, and only one of them requires the input path?
lib/cfn-nag/cli_options.rb
Outdated
# rubocop:disable Metrics/AbcSize | ||
# rubocop:disable Metrics/MethodLength | ||
def cli_options(cfn_nag_scan: false) | ||
options_message = '[options] <cloudformation template path ...>|' \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: move the messages into the "scope" where they are relevant and have the shared stuff up here only
lib/cfn-nag/cli_options.rb
Outdated
if cfn_nag_scan | ||
Trollop.options do | ||
version version | ||
opt :input_path, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we do one set of Trollop.options, but use the "cfn_nag_scan" flag to determine which short arg to force per opt for backward compat?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also break the options into common vs. divergent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comments inline
Refactors cli_options and argf_supplier into a factory-pattern from lambdas; changes the CfnNagExecutor to have no initializer arguments and scan to properly have a cfn_nag_scan argument instead, for clarity
Raises Argf and Options test coverage to 100%
Incorporates Eric's changeset from Slack; removes a test that is both no longer necessary and not working under the new changes; resolves rubocop issues
Removes @ items used in Trollop.options block -- those are unsupported and cause nil class exceptions
An extraneous puts options call in cfn_nag_executor was causing failures in the e2e tests; removes
Complies with Jesse's PR #215, adding output format option to cfn_nag
lib/cfn-nag/argf.rb
Outdated
@@ -0,0 +1,36 @@ | |||
# frozen_string_literal: true | |||
|
|||
class Argf |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be able to drop this whole file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry to beat the dead horse on this one - it looks good, i just have three final nitpicks around naming:
- i believe argf wrapper class is dead code in light of the argf_* wrapper methods?
- i know this came from my code so mea culpa, but i'm not sure i like the options_type value "cli" (scan is cool). it's all cli after all. I'm not sure what a better word is.... explicit? singular? hold that thought
- the name execute_single_scan() doesn't quite capture what is going on. ARGF will iterate through a list of file paths and process them. like for options_type.... i'm not sure what a better name is though - execute_scan_against_explicit_files() perhaps?
Per Eric Kascic's review, removes the Argf class (which was unused after prior changes); renames execute_single_scan execute_file_or_piped_scan since the argument can be an explicit file or piped input; changes the options type value for file/piped scans to 'file' from 'cli'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
woohoo!
[Finishes #165899506]; [Finishes #165899494]; factors out command line arguments reading; adds fail-on-warnings support to cfn_nag_scan; removes repeated code across cfn_nag_scan and cfn_nag by refactoring into an executor. Post-refactor, rubocop and testing required the following included supplmental changes: CfnNagExecutor is too large if read_cli_options is included, so factors that function out to its own file; CfnNag class is too large with the added fail_on_warnings option, refactors initialize parameters as a separate CfnNagConfig class; refactors the cfn_nag integration tests to use the new signatures