diff options
author | tyler-ball <tyleraball@gmail.com> | 2014-12-02 16:09:35 -0800 |
---|---|---|
committer | tyler-ball <tyleraball@gmail.com> | 2014-12-17 18:52:21 -0800 |
commit | b079e015f4ebb8c5db600bd49641699cbbacdb10 (patch) | |
tree | fd7d81f983998b228aa8e63875f03c895716fa7a /lib/chef/audit | |
parent | 19f2c6e437642db0c03b193349b13d04636cb8ee (diff) | |
download | chef-b079e015f4ebb8c5db600bd49641699cbbacdb10.tar.gz |
Adding cookbook and recipe information per analytics request
Diffstat (limited to 'lib/chef/audit')
-rw-r--r-- | lib/chef/audit/audit_event_proxy.rb | 2 | ||||
-rw-r--r-- | lib/chef/audit/audit_reporter.rb | 9 | ||||
-rw-r--r-- | lib/chef/audit/control_group_data.rb | 27 | ||||
-rw-r--r-- | lib/chef/audit/runner.rb | 2 |
4 files changed, 19 insertions, 21 deletions
diff --git a/lib/chef/audit/audit_event_proxy.rb b/lib/chef/audit/audit_event_proxy.rb index 6d5591d943..36160db9bb 100644 --- a/lib/chef/audit/audit_event_proxy.rb +++ b/lib/chef/audit/audit_event_proxy.rb @@ -43,7 +43,7 @@ class Chef described_class = example.metadata[:described_class] if described_class resource_type = described_class.class.name.split(':')[-1] - # TODO submit github PR to expose this + # TODO https://github.com/serverspec/serverspec/pull/493 resource_name = described_class.instance_variable_get(:@name) end diff --git a/lib/chef/audit/audit_reporter.rb b/lib/chef/audit/audit_reporter.rb index 21ffb62829..d022ac0c47 100644 --- a/lib/chef/audit/audit_reporter.rb +++ b/lib/chef/audit/audit_reporter.rb @@ -28,7 +28,7 @@ class Chef attr_reader :rest_client, :audit_data, :ordered_control_groups, :run_status private :rest_client, :audit_data, :ordered_control_groups, :run_status - PROTOCOL_VERSION = '0.1.0' + PROTOCOL_VERSION = '0.1.1' def initialize(rest_client) @rest_client = rest_client @@ -36,6 +36,10 @@ class Chef @ordered_control_groups = Hash.new end + def run_context + run_status.run_context + end + def audit_phase_start(run_status) Chef::Log.debug("Audit Reporter starting") @audit_data = AuditData.new(run_status.node.name, run_status.run_id) @@ -71,7 +75,8 @@ class Chef if ordered_control_groups.has_key?(name) raise Chef::Exceptions::AuditControlGroupDuplicate.new(name) end - ordered_control_groups.store(name, ControlGroupData.new(name)) + metadata = run_context.audits[name].metadata + ordered_control_groups.store(name, ControlGroupData.new(name, metadata)) end def control_example_success(control_group_name, example_data) diff --git a/lib/chef/audit/control_group_data.rb b/lib/chef/audit/control_group_data.rb index 969d128c1b..42a91ef5a7 100644 --- a/lib/chef/audit/control_group_data.rb +++ b/lib/chef/audit/control_group_data.rb @@ -28,14 +28,15 @@ class Chef end class ControlGroupData - attr_reader :name, :status, :number_succeeded, :number_failed, :controls + attr_reader :name, :status, :number_succeeded, :number_failed, :controls, :metadata - def initialize(name) + def initialize(name, metadata={}) @status = "success" @controls = [] @number_succeeded = 0 @number_failed = 0 @name = name + @metadata = metadata end @@ -68,20 +69,14 @@ class Chef :number_failed => number_failed, :controls => controls.collect { |c| c.to_hash } } - add_display_only_data(h) + # If there is a duplicate key, metadata will overwrite it + add_display_only_data(h).merge(metadata) end private def create_control(control_data) - name = control_data[:name] - resource_type = control_data[:resource_type] - resource_name = control_data[:resource_name] - context = control_data[:context] - line_number = control_data[:line_number] - # TODO make this smarter with splat arguments so if we start passing in more control_data - # I don't have to modify code in multiple places - ControlData.new(name, resource_type, resource_name, context, line_number) + ControlData.new(control_data) end # The id and control sequence number are ephemeral data - they are not needed @@ -103,12 +98,10 @@ class Chef attr_reader :name, :resource_type, :resource_name, :context, :line_number attr_accessor :status, :details - def initialize(name, resource_type, resource_name, context, line_number) - @context = context - @name = name - @resource_type = resource_type - @resource_name = resource_name - @line_number = line_number + def initialize(control_data={}) + control_data.each do |k, v| + self.instance_variable_set("@#{k}", v) + end end def to_hash diff --git a/lib/chef/audit/runner.rb b/lib/chef/audit/runner.rb index df6b6d682f..2fd33ac0de 100644 --- a/lib/chef/audit/runner.rb +++ b/lib/chef/audit/runner.rb @@ -144,7 +144,7 @@ class Chef def register_controls add_example_group_methods run_context.audits.each do |name, group| - ctl_grp = RSpec::Core::ExampleGroup.__controls__(*group[:args], &group[:block]) + ctl_grp = RSpec::Core::ExampleGroup.__controls__(*group.args, &group.block) RSpec.world.register(ctl_grp) end end |