summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoah Kantrowitz <noah@coderanger.net>2018-05-04 17:22:58 -0700
committerNoah Kantrowitz <noah@coderanger.net>2018-06-05 20:25:11 -0700
commit435ccd59e3d21c0fa247cbae9eaaff20901580e3 (patch)
tree900fc8ac801d9b066b280e124580e807ee3c009b
parent8e7800ab9c51e256d85722fd58c1cf8e27bb5a96 (diff)
downloadchef-435ccd59e3d21c0fa247cbae9eaaff20901580e3.tar.gz
Add in version ranges too.
Signed-off-by: Noah Kantrowitz <noah@coderanger.net>
-rw-r--r--lib/chef/node_map.rb14
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/chef/node_map.rb b/lib/chef/node_map.rb
index 448e695ca9..b6ef008ce1 100644
--- a/lib/chef/node_map.rb
+++ b/lib/chef/node_map.rb
@@ -45,8 +45,10 @@ class Chef
# @param key [Object] Key to store
# @param value [Object] Value associated with the key
# @param filters [Hash] Node filter options to apply to key retrieval
- # @param allow_cookbook_override [Boolean] Allow a cookbook to add to this
- # key even in locked mode.
+ # @param allow_cookbook_override [Boolean, String] Allow a cookbook to add
+ # to this key even in locked mode. If a string is given, it should be a
+ # Gem::Requirement-compatible value indicating for which Chef versions an
+ # override from cookbooks is allowed.
# @param __core_override__ [Boolean] Advanced-mode override to add to a key
# even in locked mode.
#
@@ -67,7 +69,13 @@ class Chef
new_matcher[:core_override] = __core_override__
# Check if the key is already present and locked, unless the override is allowed.
- if !__core_override__ && map[key] && map[key].any? {|matcher| matcher[:locked] } && !map[key].any? {|matcher| matcher[:cookbook_override] }
+ # The checks to see if we should reject, in order:
+ # 1. Core overide mode is not set.
+ # 2. The key exists.
+ # 3. At least one previous `provides` is now locked.
+ # 4. No previous `provides` had `allow_cookbook_override`, either set to
+ # true or with a string version matcher that still matches Chef::VERSION
+ if !__core_override__ && map[key] && map[key].any? {|matcher| matcher[:locked] } && !map[key].any? {|matcher| matcher[:cookbook_override].is_a?(String) ? Chef::VERSION =~ matcher[:cookbook_override] : matcher[:cookbook_override] }
type_of_thing = klass.is_a?(Chef::Resource) ? 'resource' : 'provider'
# For now, only log the warning.
Chef.log_deprecation("Trying to register #{type_of_thing} #{key} on top of existing Chef core #{type_of_thing}. Check if a new version of the cookbook is available.")