Permalink
Browse files

Add support for chef older than 0.9.16.

  • Loading branch information...
1 parent ba6ce49 commit 36e94f5b4089ba47085ec7f7ca9e7a3267876551 @fnichol committed Sep 19, 2011
Showing with 16 additions and 2 deletions.
  1. +16 −2 libraries/solo_data_bags.rb
@@ -34,6 +34,12 @@ def self.load_local(name)
end
class DataBagItem
+ def self.from_hash(h)
+ item = new
+ item.raw_data = h
+ item
+ end
+
##
# Load a Data Bag Item by name via local data_bag_path if run in solo
# mode.
@@ -63,8 +69,16 @@ def data_bag(bag)
end
def data_bag_item(bag, item)
- DataBag.validate_name!(bag.to_s)
- DataBagItem.validate_id!(item)
+ # Chef::DataBag.validate_name! and
+ # Chef::DataBagItem.validate_name! were introduced in v0.9.16 so
+ # they may not exist
+ if DataBag.respond_to?("validate_name!")
+ DataBag.validate_name!(bag.to_s)
+ end
+ if DataBagItem.respond_to?("validate_name!")
+ DataBagItem.validate_id!(item)
+ end
+
DataBagItem.load_local(bag, item)
rescue Exception
Log.error("Failed to load data bag item: #{bag.inspect} #{item.inspect}")

0 comments on commit 36e94f5

Please sign in to comment.