38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/chef/knife/scrub_attributes.rb', line 38
def run
unless prefix = name_args.first
show_usage
ui.fatal 'You must specify a prefix of attributes to scrub'
exit 1
end
search = Chef::Search::Query.new
search.search('node', config[:query]) do |node|
parent, key = (node.normal, prefix)
unless parent && parent.component_has_key?(parent.normal, key)
ui.msg format(node, "unknown normal attribute #{prefix}")
next
end
value = parent.value_at_current_nesting(parent.normal, key).fetch(key)
unless ui.confirm format(node, "Do you want to delete #{value.inspect}")
next
end
if deleted = parent.delete_from_component(parent.normal, key)
node.save
ui.msg format(node, "deleted normal attribute #{deleted.inspect}")
else
ui.msg format(node, "could not delete normal attribute #{prefix}")
end
end
end
|