summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2020-04-02 19:52:21 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2020-04-02 19:52:21 -0700
commit8dcf5be92642700ee3f2aedb83484bcf0e2c159c (patch)
tree3f44abd8bef8e75f05f57cd1213f14418aabed7a /lib
parent333e0695117f8a518b8f2729bc3f97a5bd6560e4 (diff)
downloadchef-8dcf5be92642700ee3f2aedb83484bcf0e2c159c.tar.gz
Change name_property to be identity and not desired_state by default
If no other property is an identity property then the name_property is the default identity property. The name_property is also marked as not being desired state by default (the 'name' should never change). Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/chef/mixin/properties.rb14
-rw-r--r--lib/chef/property.rb6
-rw-r--r--lib/chef/resource.rb13
-rw-r--r--lib/chef/resource_reporter.rb2
4 files changed, 31 insertions, 4 deletions
diff --git a/lib/chef/mixin/properties.rb b/lib/chef/mixin/properties.rb
index ecb589e015..94afa4640b 100644
--- a/lib/chef/mixin/properties.rb
+++ b/lib/chef/mixin/properties.rb
@@ -264,10 +264,22 @@ class Chef
end
result = properties.values.select(&:identity?)
- result = [ properties[:name] ] if result.empty?
+ # if there are no other identity properites set, then the name_property becomes the identity, or
+ # failing that we use the actual name.
+ if result.empty?
+ result = name_property ? [ properties[name_property] ] : [ properties[:name] ]
+ end
result
end
+ # Returns the name of the name property. Returns nil if there is no name property.
+ #
+ # @return [Symbol] the name property for this resource
+ def name_property
+ p = properties.find { |n, p| p.name_property? }
+ p ? p.first : nil
+ end
+
def included(other)
other.extend ClassMethods
end
diff --git a/lib/chef/property.rb b/lib/chef/property.rb
index 336331b59f..a29286c21b 100644
--- a/lib/chef/property.rb
+++ b/lib/chef/property.rb
@@ -1,7 +1,7 @@
#
# Author:: John Keiser <jkeiser@chef.io>
# Copyright:: Copyright 2015-2016, John Keiser
-# Copyright:: Copyright 2015-2020, Chef Software, Inc.
+# Copyright:: Copyright 2015-2020, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -141,6 +141,10 @@ class Chef
raise ArgumentError, "A property cannot be both a name_property/name_attribute and have a default value. Use one or the other on property #{self}"
end
+ if options[:name_property]
+ options[:desired_state] = false unless options.key?(:desired_state)
+ end
+
# Recursively freeze the default if it isn't a lazy value.
unless default.is_a?(DelayedEvaluator)
visitor = lambda do |obj|
diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb
index 5153dd4910..e6a33dc71a 100644
--- a/lib/chef/resource.rb
+++ b/lib/chef/resource.rb
@@ -497,11 +497,22 @@ class Chef
def state_for_resource_reporter
state = {}
state_properties = self.class.state_properties
+# p = state_properties.find { |p| p.name_property? }
+# if p
+# pp p
+# raise "boom"
+# end
+
state_properties.each do |property|
- if property.identity? || property.is_set?(self)
+ if property.is_set?(self)
state[property.name] = property.sensitive? ? "*sensitive value suppressed*" : send(property.name)
end
end
+# identity_properties = self.class.identity_properties
+# pp identity_properties
+# identity_properties.each do |property|
+# state[property.name] = property.sensitive? ? "*sensitive value suppressed*" : send(property.name)
+# end
state
end
diff --git a/lib/chef/resource_reporter.rb b/lib/chef/resource_reporter.rb
index 246b2d5500..c8517dfc83 100644
--- a/lib/chef/resource_reporter.rb
+++ b/lib/chef/resource_reporter.rb
@@ -3,7 +3,7 @@
# Author:: Prajakta Purohit (prajakta@chef.io>)
# Auther:: Tyler Cloke (<tyler@opscode.com>)
#
-# Copyright:: Copyright 2012-2019, Chef Software Inc.
+# Copyright:: Copyright 2012-2020, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");