diff options
author | Tom Duffield <tom@chef.io> | 2017-02-10 14:19:37 -0600 |
---|---|---|
committer | Tom Duffield <tom@chef.io> | 2017-02-10 14:19:37 -0600 |
commit | 9a22ebad6a82c703a012721c19f7a5e9ffffc344 (patch) | |
tree | 63d5dd291b9835da0a22b547c3e4bdf0e99977e1 | |
parent | 346ee33c99bb630ea60d59833f74c5c2c05bed97 (diff) | |
download | chef-9a22ebad6a82c703a012721c19f7a5e9ffffc344.tar.gz |
Keep variable in initial order when sorting propertiestduffield/suppress-sensitive-properties
Signed-off-by: Tom Duffield <tom@chef.io>
-rw-r--r-- | lib/chef/resource.rb | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb index 3ed0cda825..0335b6f903 100644 --- a/lib/chef/resource.rb +++ b/lib/chef/resource.rb @@ -670,16 +670,18 @@ class Chef text = "# Declared in #{@source_line}\n\n" text << "#{resource_name}(\"#{name}\") do\n" - props = [] - self.class.state_properties.each do |p| - props << "@#{p.name}".to_sym - text << " #{p.name} #{p.sensitive? ? "\"*sensitive value suppressed*\"\n": "#{p.get(self).inspect}\n"}" + all_props = {} + self.class.state_properties.map do |p| + all_props[p.name.to_s] = p.sensitive? ? '"*sensitive value suppressed*"' : value_to_text(p.get(self)) end - ivars = instance_variables.map { |ivar| ivar.to_sym } - HIDDEN_IVARS - props - ivars.map { |i| i.to_s.sub(/^@/, "") }.each do |ivar| - if (value = instance_variable_get("@#{ivar}".to_sym)) && !(value.respond_to?(:empty?) && value.empty?) - text << " #{ivar.to_s.sub(/^@/, '')} #{value.respond_to?(:to_text) ? value.to_text : value.inspect}\n" + ivars = instance_variables.map { |ivar| ivar.to_sym } - HIDDEN_IVARS + ivars.each do |ivar| + iv = ivar.to_s.sub(/^@/, "") + if all_props.keys.include?(iv) + text << " #{iv} #{all_props[iv]}\n" + elsif (value = instance_variable_get(ivar)) && !(value.respond_to?(:empty?) && value.empty?) + text << " #{iv} #{value_to_text(value)}\n" end end @@ -689,6 +691,10 @@ class Chef text << "end\n" end + def value_to_text(value) + value.respond_to?(:to_text) ? value.to_text : value.inspect + end + def inspect ivars = instance_variables.map { |ivar| ivar.to_sym } - FORBIDDEN_IVARS ivars.inject("<#{self}") do |str, ivar| |