summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Keiser <john@johnkeiser.com>2016-01-13 10:28:42 -0800
committerJohn Keiser <john@johnkeiser.com>2016-01-14 11:41:45 -0800
commite0263aeed7d18b22bb7bc5a3d217ff61e9f9e824 (patch)
tree560ce6685ac291a5a2e3e461cde3f33e4fe30756
parent0b8e829663122e09aaafcaf21615f9171225a057 (diff)
downloadchef-zero-jk/cookbook-artifact-rspec.tar.gz
Fix cookbook_artifactjk/cookbook-artifact-rspec
-rw-r--r--lib/chef_zero/rspec.rb15
-rw-r--r--lib/chef_zero/server.rb33
2 files changed, 30 insertions, 18 deletions
diff --git a/lib/chef_zero/rspec.rb b/lib/chef_zero/rspec.rb
index fa10f77..e3913cf 100644
--- a/lib/chef_zero/rspec.rb
+++ b/lib/chef_zero/rspec.rb
@@ -125,8 +125,8 @@ module ChefZero
end
end
- def cookbook_artifact(name, data, &block)
- before(chef_server_options[:server_scope]) { cookbook_artifact(name, data, &block) }
+ def cookbook_artifact(name, identifier, data = {}, &block)
+ before(chef_server_options[:server_scope]) { cookbook_artifact(name, identifier, data, &block) }
end
def data_bag(name, data, &block)
@@ -227,9 +227,16 @@ module ChefZero
end
end
- def cookbook_artifact(name, identifier, data, &block)
+ def cookbook_artifact(name, identifier, data = {}, &block)
with_object_path("cookbook_artifacts/#{name}") do
- ChefZero::RSpec.server.load_data({ 'cookbook_artifact' => { name => { identifier => data } } }, current_org)
+ if data.has_key?('metadata.rb')
+ if data['metadata.rb'].nil?
+ data.delete('metadata.rb')
+ end
+ else
+ data['metadata.rb'] = "name #{name.inspect}"
+ end
+ ChefZero::RSpec.server.load_data({ 'cookbook_artifacts' => { "#{name}-#{identifier}" => data } }, current_org)
instance_eval(&block) if block_given?
end
end
diff --git a/lib/chef_zero/server.rb b/lib/chef_zero/server.rb
index c96150e..3326420 100644
--- a/lib/chef_zero/server.rb
+++ b/lib/chef_zero/server.rb
@@ -473,20 +473,25 @@ module ChefZero
end
end
- if contents['cookbooks']
- contents['cookbooks'].each_pair do |name_version, cookbook|
- if name_version =~ /(.+)-(\d+\.\d+\.\d+)$/
- cookbook_data = ChefData::CookbookData.to_hash(cookbook, $1, $2)
- else
- cookbook_data = ChefData::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)
+ %w(cookbooks cookbook_artifacts).each do |cookbook_type|
+ if contents[cookbook_type]
+ contents[cookbook_type].each_pair do |name_version, cookbook|
+ if cookbook_type == 'cookbook_artifacts'
+ name, dash, identifier = name_version.rpartition('-')
+ cookbook_data = ChefData::CookbookData.to_hash(cookbook, name, identifier)
+ elsif name_version =~ /(.+)-(\d+\.\d+\.\d+)$/
+ cookbook_data = ChefData::CookbookData.to_hash(cookbook, $1, $2)
+ else
+ cookbook_data = ChefData::CookbookData.to_hash(cookbook, name_version)
+ end
+ raise "No version specified" if !cookbook_data[:version]
+ data_store.create_dir(['organizations', org_name, cookbook_type], cookbook_data[:cookbook_name], :recursive)
+ data_store.set(['organizations', org_name, cookbook_type, 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