summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorVasu1105 <vasundhara.jagdale@msystechnologies.com>2019-12-20 14:16:29 +0530
committerVasu1105 <vasundhara.jagdale@msystechnologies.com>2019-12-20 14:16:29 +0530
commite57e97eb4c72a4a7213eecce8fbb15ce74159848 (patch)
tree741c06b2d234cefb975efbe65c67b52444868591 /lib
parente78d3e46ec1c449e48435755811fa47f8ea1e0c9 (diff)
downloadchef-e57e97eb4c72a4a7213eecce8fbb15ce74159848.tar.gz
Added client side validation to validate presence of metadata files and validate name field
Signed-off-by: Vasu1105 <vasundhara.jagdale@msystechnologies.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/chef/chef_fs/file_system/chef_server/cookbooks_dir.rb1
-rw-r--r--lib/chef/cookbook_version.rb4
-rw-r--r--lib/chef/knife/cookbook_upload.rb9
3 files changed, 13 insertions, 1 deletions
diff --git a/lib/chef/chef_fs/file_system/chef_server/cookbooks_dir.rb b/lib/chef/chef_fs/file_system/chef_server/cookbooks_dir.rb
index 3c13bca3a3..52fc708552 100644
--- a/lib/chef/chef_fs/file_system/chef_server/cookbooks_dir.rb
+++ b/lib/chef/chef_fs/file_system/chef_server/cookbooks_dir.rb
@@ -73,6 +73,7 @@ class Chef
def upload_cookbook(other, options)
cookbook = other.chef_object if other.chef_object
+ raise Chef::Exceptions::MetadataNotFound.new(cookbook.root_paths[0], cookbook.name) unless cookbook.has_metadata_file?
if cookbook
begin
diff --git a/lib/chef/cookbook_version.rb b/lib/chef/cookbook_version.rb
index 8de9ee0d17..4989fb8d91 100644
--- a/lib/chef/cookbook_version.rb
+++ b/lib/chef/cookbook_version.rb
@@ -445,6 +445,10 @@ class Chef
end
end
+ def has_metadata_file?
+ all_files.include?(metadata_json_file) || all_files.include?(metadata_rb_file)
+ end
+
##
# REST API
##
diff --git a/lib/chef/knife/cookbook_upload.rb b/lib/chef/knife/cookbook_upload.rb
index 0243b0cf12..c8c9067800 100644
--- a/lib/chef/knife/cookbook_upload.rb
+++ b/lib/chef/knife/cookbook_upload.rb
@@ -99,8 +99,16 @@ class Chef
cookbooks = []
cookbooks_to_upload.each do |cookbook_name, cookbook|
+ raise Chef::Exceptions::MetadataNotFound.new(cookbook.root_paths[0], cookbook_name) unless cookbook.has_metadata_file?
+
+ if cookbook.metadata.name.nil?
+ message = "Cookbook loaded at path [#{cookbook.root_paths[0]}] has invalid metadata: #{cookbook.metadata.errors.join("; ")}"
+ raise Chef::Exceptions::MetadataNotValid, message
+ end
+
cookbooks << cookbook
end
+
if cookbooks.empty?
cookbook_path = config[:cookbook_path].respond_to?(:join) ? config[:cookbook_path].join(", ") : config[:cookbook_path]
ui.warn("Could not find any cookbooks in your cookbook path: #{cookbook_path}. Use --cookbook-path to specify the desired path.")
@@ -164,7 +172,6 @@ class Chef
unless version_constraints_to_update.empty?
update_version_constraints(version_constraints_to_update) if config[:environment]
end
-
ensure
tmp_cl.unlink!
end