Skip to content

Commit

Permalink
Added code comments and rename control_list_exist? method to controls…
Browse files Browse the repository at this point in the history
…_list_exist?

Signed-off-by: Vasu1105 <vasundhara.jagdale@chef.io>
  • Loading branch information
Vasu1105 committed Mar 19, 2021
1 parent 58d256a commit 982ba44
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/inspec/control_eval_context.rb
Expand Up @@ -53,7 +53,7 @@ def profile_name

def control(id, opts = {}, &block)
opts[:skip_only_if_eval] = @skip_only_if_eval
if control_exist_in_controls_list?(id) || control_list_empty?
if control_exist_in_controls_list?(id) || controls_list_empty?
register_control(Inspec::Rule.new(id, profile_id, resources_dsl, opts, &block))
end
end
Expand All @@ -74,7 +74,7 @@ def describe(*args, &block)
res = describe(*args, &block)
end

if control_exist_in_controls_list?(id) || control_list_empty?
if control_exist_in_controls_list?(id) || controls_list_empty?
register_control(rule, &block)
end

Expand Down Expand Up @@ -182,14 +182,17 @@ def block_location(block, alternate_caller)
end
end

# Returns true if configuration hash is not empty and it contains the list of controls is not empty
def profile_config_exist?
!@conf.empty? && @conf.key?("profile") && !@conf["profile"].include_controls_list.empty?
end

def control_list_empty?
# Returns true if configuration hash is empty or configuration hash does not have the list of controls that needs to be included
def controls_list_empty?
!@conf.empty? && @conf.key?("profile") && @conf["profile"].include_controls_list.empty? || @conf.empty?
end

# Check if the given control exist in the --controls option
def control_exist_in_controls_list?(id)
if profile_config_exist?
id_exist_in_list = @conf["profile"].include_controls_list.any? do |inclusion|
Expand Down
2 changes: 2 additions & 0 deletions lib/inspec/profile.rb
Expand Up @@ -228,6 +228,8 @@ def collect_tests(include_list = @controls)
@runner_context.all_rules
end

# This creates the list of controls provided in the --controls options which need to be include
# for evaluation.
def include_controls_list
return [] if @controls.nil? || @controls.empty?

Expand Down

0 comments on commit 982ba44

Please sign in to comment.