Class: Chef::AttributeAllowlist

Inherits:
Object
  • Object
show all
Defined in:
lib/chef/attribute_allowlist.rb

Class Method Summary collapse

Class Method Details

.filter(data, allowlist = nil) ⇒ Object

filter takes two arguments - the data you want to filter, and an array of keys you want included. You can capture a subtree of the data to filter by providing a "/"-delimited string of keys. If some key includes "/"-characters, you must provide an array of keys instead.

AttributeAllowlist.filter( { "filesystem" => { "/dev/disk" => { "size" => "10mb" }, "map - autohome" => { "size" => "10mb" } }, "network" => { "interfaces" => { "eth0" => ..., "eth1" => ... } } }, ["network/interfaces/eth0", ["filesystem", "/dev/disk"]]) will capture the eth0 and /dev/disk subtrees.



30
31
32
33
34
35
36
37
38
# File 'lib/chef/attribute_allowlist.rb', line 30

def self.filter(data, allowlist = nil)
  return data if allowlist.nil?

  new_data = {}
  allowlist.each do |item|
    add_data(data, new_data, item)
  end
  new_data
end