summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPete Higgins <pete@peterhiggins.org>2020-04-15 16:31:17 -0700
committerPete Higgins <pete@peterhiggins.org>2020-04-15 16:51:50 -0700
commit3c48e7a622150125f00345b03256efbd9efeacf7 (patch)
tree3f127acd6508b1ee8daddeccdf3b018ecbe8796e
parente000b3d74a7970fa71f71e9ceac8b4aeee521548 (diff)
downloadohai-3c48e7a622150125f00345b03256efbd9efeacf7.tar.gz
Filter out unnedded properties.
Signed-off-by: Pete Higgins <pete@peterhiggins.org>
-rw-r--r--lib/ohai/common/dmi.rb14
-rw-r--r--spec/unit/plugins/windows/dmi_spec.rb32
2 files changed, 43 insertions, 3 deletions
diff --git a/lib/ohai/common/dmi.rb b/lib/ohai/common/dmi.rb
index b5a139db..5cbc4fa3 100644
--- a/lib/ohai/common/dmi.rb
+++ b/lib/ohai/common/dmi.rb
@@ -111,6 +111,15 @@ module Ohai
id
end
+ SKIPPED_CONVENIENCE_KEYS = %w{
+ application_identifier
+ caption
+ creation_class_name
+ size
+ system_creation_class_name
+ record_id
+ }.freeze
+
# create simplified convenience access keys for each record type
# for single occurrences of one type, copy to top level all fields and values
# for multiple occurrences of same type, copy to top level all fields and values that are common to all records
@@ -123,11 +132,10 @@ module Ohai
records[:all_records].each do |record|
record.each do |field, value|
next unless value.is_a?(String)
- next if field.to_s == "application_identifier"
- next if field.to_s == "size"
- next if field.to_s == "record_id"
translated = field.downcase.gsub(/[^a-z0-9]/, "_")
+ next if SKIPPED_CONVENIENCE_KEYS.include?(translated.to_s)
+
value = value.strip
if in_common.key?(translated)
in_common[translated] = nil unless in_common[translated] == value
diff --git a/spec/unit/plugins/windows/dmi_spec.rb b/spec/unit/plugins/windows/dmi_spec.rb
index 3fa8ffc1..77ffd003 100644
--- a/spec/unit/plugins/windows/dmi_spec.rb
+++ b/spec/unit/plugins/windows/dmi_spec.rb
@@ -99,4 +99,36 @@ describe Ohai::System, "DMI", :windows_only do
expect(plugin[:dmi][:chassis]["shared_property"]).to eq("Taco Bell")
end
end
+
+ context "with extra information that should be filtered out" do
+ FILTERED_KEYS = [
+ %w{Caption caption aaa},
+ %w{CreationClassName creation_class_name bbb},
+ %w{SystemCreationClassName system_creation_class_name ccc},
+ ].freeze
+
+ before do
+ properties = FILTERED_KEYS.map { |name, _, _| double(name: name) }
+ wmi_ole_object = double properties_: properties
+
+ FILTERED_KEYS.each do |name, _, value|
+ allow(wmi_ole_object).to receive(:invoke).with(name).and_return(value)
+ end
+
+ wmi_object = WmiLite::Wmi::Instance.new(wmi_ole_object)
+ expect_any_instance_of(WmiLite::Wmi).to receive(:instances_of).with("Win32_SystemEnclosure").and_return([wmi_object])
+
+ plugin.run
+ end
+
+ FILTERED_KEYS.each do |name, transformed_name, value|
+ it "adds #{name} to :all_records" do
+ expect(plugin[:dmi][:chassis][:all_records].first[name]).to eq(value)
+ end
+
+ it "does not add #{transformed_name} to the root" do
+ expect(plugin[:dmi][:chassis]).not_to have_key(transformed_name)
+ end
+ end
+ end
end