summaryrefslogtreecommitdiff
path: root/lib/chef/data_bag.rb
diff options
context:
space:
mode:
authorIvan Larionov <ivan.larionov@skype.net>2013-12-02 18:22:17 +0400
committerIvan Larionov <ivan.larionov@skype.net>2014-05-31 03:21:59 +0400
commit91f15aa6d965b746a6a9598d8a9f78c536743842 (patch)
treecf4aab6e5e1f6a49a336c5ebe83224169475109d /lib/chef/data_bag.rb
parent7588211ecb83c9592065359622ff6cef98d773af (diff)
downloadchef-91f15aa6d965b746a6a9598d8a9f78c536743842.tar.gz
[CHEF-3399] Make data_bag_path an array like cookbook_path
Diffstat (limited to 'lib/chef/data_bag.rb')
-rw-r--r--lib/chef/data_bag.rb32
1 files changed, 21 insertions, 11 deletions
diff --git a/lib/chef/data_bag.rb b/lib/chef/data_bag.rb
index 639d71a74d..e940e6452b 100644
--- a/lib/chef/data_bag.rb
+++ b/lib/chef/data_bag.rb
@@ -83,11 +83,15 @@ class Chef
def self.list(inflate=false)
if Chef::Config[:solo]
- unless File.directory?(Chef::Config[:data_bag_path])
- raise Chef::Exceptions::InvalidDataBagPath, "Data bag path '#{Chef::Config[:data_bag_path]}' is invalid"
- end
+ paths = Array(Chef::Config[:data_bag_path])
+ names = []
+ paths.each do |path|
+ unless File.directory?(path)
+ raise Chef::Exceptions::InvalidDataBagPath, "Data bag path '#{path}' is invalid"
+ end
- names = Dir.glob(File.join(Chef::Config[:data_bag_path], "*")).map{|f|File.basename(f)}.sort
+ names += Dir.glob(File.join(path, "*")).map{|f|File.basename(f)}.sort
+ end
names.inject({}) {|h, n| h[n] = n; h}
else
if inflate
@@ -105,15 +109,21 @@ class Chef
# Load a Data Bag by name via either the RESTful API or local data_bag_path if run in solo mode
def self.load(name)
if Chef::Config[:solo]
- unless File.directory?(Chef::Config[:data_bag_path])
- raise Chef::Exceptions::InvalidDataBagPath, "Data bag path '#{Chef::Config[:data_bag_path]}' is invalid"
- end
+ paths = Array(Chef::Config[:data_bag_path])
+ data_bag = {}
+ paths.each do |path|
+ unless File.directory?(path)
+ raise Chef::Exceptions::InvalidDataBagPath, "Data bag path '#{path}' is invalid"
+ end
- Dir.glob(File.join(Chef::Config[:data_bag_path], "#{name}", "*.json")).inject({}) do |bag, f|
- item = Chef::JSONCompat.from_json(IO.read(f))
- bag[item['id']] = item
- bag
+ data = Dir.glob(File.join(path, name.to_s, "*.json")).inject({}) do |bag, f|
+ item = Chef::JSONCompat.from_json(IO.read(f))
+ bag[item['id']] = item
+ bag
+ end
+ data_bag.merge! data
end
+ return data_bag
else
Chef::REST.new(Chef::Config[:chef_server_url]).get_rest("data/#{name}")
end