Class: Chef::Audit::AuditReporter

Inherits:
EventDispatch::Base show all
Defined in:
lib/chef/audit/audit_reporter.rb

Constant Summary collapse

PROTOCOL_VERSION =
"0.1.1"

Instance Method Summary collapse

Methods inherited from EventDispatch::Base

#attribute_changed, #attribute_file_load_failed, #attribute_file_loaded, #attribute_load_complete, #attribute_load_start, #converge_complete, #converge_failed, #converge_start, #cookbook_clean_complete, #cookbook_clean_start, #cookbook_gem_failed, #cookbook_gem_finished, #cookbook_gem_installing, #cookbook_gem_start, #cookbook_gem_using, #cookbook_resolution_complete, #cookbook_resolution_failed, #cookbook_resolution_start, #cookbook_sync_complete, #cookbook_sync_failed, #cookbook_sync_start, #definition_file_load_failed, #definition_file_loaded, #definition_load_complete, #definition_load_start, #deprecation, #handler_executed, #handlers_completed, #handlers_start, #library_file_load_failed, #library_file_loaded, #library_load_complete, #library_load_start, #lwrp_file_load_failed, #lwrp_file_loaded, #lwrp_load_complete, #lwrp_load_start, #msg, #node_load_completed, #node_load_failed, #node_load_start, #ohai_completed, #ohai_plugin_file_load_failed, #ohai_plugin_file_loaded, #ohai_plugin_load_complete, #ohai_plugin_load_start, #policyfile_loaded, #provider_requirement_failed, #recipe_file_load_failed, #recipe_file_loaded, #recipe_load_complete, #recipe_load_start, #recipe_not_found, #registration_completed, #registration_failed, #registration_start, #removed_cookbook_file, #resource_action_start, #resource_bypassed, #resource_completed, #resource_current_state_load_bypassed, #resource_current_state_loaded, #resource_failed, #resource_failed_retriable, #resource_skipped, #resource_up_to_date, #resource_update_applied, #resource_update_progress, #resource_updated, #run_list_expand_failed, #run_list_expanded, #run_start, #run_started, #skipping_registration, #stream_closed, #stream_opened, #stream_output, #synchronized_cookbook, #updated_cookbook_file, #whyrun_assumption

Constructor Details

#initialize(rest_client) ⇒ AuditReporter

Returns a new instance of AuditReporter


33
34
35
36
37
38
# File 'lib/chef/audit/audit_reporter.rb', line 33

def initialize(rest_client)
  @rest_client = rest_client
  # Ruby 1.9.3 and above "enumerate their values in the order that the corresponding keys were inserted."
  @ordered_control_groups = Hash.new
  @audit_phase_error = nil
end

Instance Method Details

#audit_phase_complete(audit_output) ⇒ Object


50
51
52
53
54
55
# File 'lib/chef/audit/audit_reporter.rb', line 50

def audit_phase_complete(audit_output)
  Chef::Log.debug("Audit Reporter completed successfully without errors.")
  ordered_control_groups.each do |name, control_group|
    audit_data.add_control_group(control_group)
  end
end

#audit_phase_failed(error, audit_output) ⇒ Object

If the audit phase failed, its because there was some kind of error in the framework that runs tests - normal errors are interpreted as EXAMPLE failures and captured. We still want to send available audit information to the server so we process the known control groups.


61
62
63
64
65
66
67
68
# File 'lib/chef/audit/audit_reporter.rb', line 61

def audit_phase_failed(error, audit_output)
  # The stacktrace information has already been logged elsewhere
  @audit_phase_error = error
  Chef::Log.debug("Audit Reporter failed.")
  ordered_control_groups.each do |name, control_group|
    audit_data.add_control_group(control_group)
  end
end

#audit_phase_start(run_status) ⇒ Object


44
45
46
47
48
# File 'lib/chef/audit/audit_reporter.rb', line 44

def audit_phase_start(run_status)
  Chef::Log.debug("Audit Reporter starting")
  @audit_data = AuditData.new(run_status.node.name, run_status.run_id)
  @run_status = run_status
end

#auditing_enabled?Boolean

If @audit_enabled is nil or true, we want to run audits

Returns:

  • (Boolean)

99
100
101
# File 'lib/chef/audit/audit_reporter.rb', line 99

def auditing_enabled?
  Chef::Config[:audit_mode] != :disabled
end

#control_example_failure(control_group_name, example_data, error) ⇒ Object


93
94
95
96
# File 'lib/chef/audit/audit_reporter.rb', line 93

def control_example_failure(control_group_name, example_data, error)
  control_group = ordered_control_groups[control_group_name]
  control_group.example_failure(example_data, error.message)
end

#control_example_success(control_group_name, example_data) ⇒ Object


88
89
90
91
# File 'lib/chef/audit/audit_reporter.rb', line 88

def control_example_success(control_group_name, example_data)
  control_group = ordered_control_groups[control_group_name]
  control_group.example_success(example_data)
end

#control_group_started(name) ⇒ Object


80
81
82
83
84
85
86
# File 'lib/chef/audit/audit_reporter.rb', line 80

def control_group_started(name)
  if ordered_control_groups.has_key?(name)
    raise Chef::Exceptions::AuditControlGroupDuplicate.new(name)
  end
   = run_context.audits[name].
  ordered_control_groups.store(name, ControlGroupData.new(name, ))
end

#run_completed(node) ⇒ Object


70
71
72
# File 'lib/chef/audit/audit_reporter.rb', line 70

def run_completed(node)
  post_auditing_data
end

#run_contextObject


40
41
42
# File 'lib/chef/audit/audit_reporter.rb', line 40

def run_context
  run_status.run_context
end

#run_failed(error) ⇒ Object


74
75
76
77
78
# File 'lib/chef/audit/audit_reporter.rb', line 74

def run_failed(error)
  # Audit phase errors are captured when audit_phase_failed gets called.
  # The error passed here isn't relevant to auditing, so we ignore it.
  post_auditing_data
end