def load_data(contents, org_name = 'chef')
%w(clients environments nodes roles users).each do |data_type|
if contents[data_type]
dejsonize_children(contents[data_type]).each_pair do |name, data|
data_store.set(['organizations', org_name, data_type, name], data, :create)
end
end
end
if contents['data']
contents['data'].each_pair do |key, data_bag|
data_store.create_dir(['organizations', org_name, 'data'], key, :recursive)
dejsonize_children(data_bag).each do |item_name, item|
data_store.set(['organizations', org_name, 'data', key, item_name], item, :create)
end
end
end
if contents['cookbooks']
contents['cookbooks'].each_pair do |name_version, cookbook|
if name_version =~ /(.+)-(\d+\.\d+\.\d+)$/
cookbook_data = CookbookData.to_hash(cookbook, $1, $2)
else
cookbook_data = CookbookData.to_hash(cookbook, name_version)
end
raise "No version specified" if !cookbook_data[:version]
data_store.create_dir(['organizations', org_name, 'cookbooks'], cookbook_data[:cookbook_name], :recursive)
data_store.set(['organizations', org_name, 'cookbooks', cookbook_data[:cookbook_name], cookbook_data[:version]], FFI_Yajl::Encoder.encode(cookbook_data, :pretty => true), :create)
cookbook_data.values.each do |files|
next unless files.is_a? Array
files.each do |file|
data_store.set(['organizations', org_name, 'file_store', 'checksums', file[:checksum]], get_file(cookbook, file[:path]), :create)
end
end
end
end
end