summaryrefslogtreecommitdiff
path: root/lib/chef/cookbook_manifest.rb
diff options
context:
space:
mode:
authordanielsdeleo <dan@getchef.com>2015-02-05 17:53:00 -0800
committerdanielsdeleo <dan@getchef.com>2015-02-11 10:52:49 -0800
commit677ca0d7e3366ea9b3b6a912c8c6c28d543e2046 (patch)
tree512473fe4a623586d86eee948efc43857d800d8e /lib/chef/cookbook_manifest.rb
parente3e9f1996131f287f0e6d8b344e658062003efe7 (diff)
downloadchef-677ca0d7e3366ea9b3b6a912c8c6c28d543e2046.tar.gz
Move remaining http relevant methods to CookbookManifest
Diffstat (limited to 'lib/chef/cookbook_manifest.rb')
-rw-r--r--lib/chef/cookbook_manifest.rb65
1 files changed, 47 insertions, 18 deletions
diff --git a/lib/chef/cookbook_manifest.rb b/lib/chef/cookbook_manifest.rb
index 82d4da7008..417afbd82c 100644
--- a/lib/chef/cookbook_manifest.rb
+++ b/lib/chef/cookbook_manifest.rb
@@ -36,6 +36,8 @@ class Chef
def_delegator :@cookbook_version, :name
def_delegator :@cookbook_version, :metadata
def_delegator :@cookbook_version, :full_name
+ def_delegator :@cookbook_version, :version
+ def_delegator :@cookbook_version, :frozen_version?
def initialize(cookbook_version)
@cookbook_version = cookbook_version
@@ -97,6 +99,51 @@ class Chef
@manifest_records_by_path
end
+ def to_hash
+ result = manifest.dup
+ result['frozen?'] = frozen_version?
+ result['chef_type'] = 'cookbook_version'
+ result.to_hash
+ end
+
+ def to_json(*a)
+ result = to_hash
+ result['json_class'] = "Chef::CookbookVersion"
+ Chef::JSONCompat.to_json(result, *a)
+ end
+
+ # Return the URL to save (PUT) this object to the server via the
+ # REST api. If there is an existing document on the server and it
+ # is marked frozen, a PUT will result in a 409 Conflict.
+ def save_url
+ "cookbooks/#{name}/#{version}"
+ end
+
+ # Adds the `force=true` parameter to the upload URL. This allows
+ # the user to overwrite a frozen cookbook (a PUT against the
+ # normal #save_url raises a 409 Conflict in this case).
+ def force_save_url
+ "cookbooks/#{name}/#{version}?force=true"
+ end
+
+ # TODO: This is kind of terrible. investigate removing it
+ def update_from(new_manifest)
+ @manifest = Mash.new new_manifest
+ @checksums = extract_checksums_from_manifest(@manifest)
+ @manifest_records_by_path = extract_manifest_records_by_path(@manifest)
+
+ # TODO: this part of this method is "feature envious" it only deals with
+ # mutating the CookbookVersion object.
+ COOKBOOK_SEGMENTS.each do |segment|
+ next unless @manifest.has_key?(segment)
+ filenames = @manifest[segment].map{|manifest_record| manifest_record['name']}
+
+ cookbook_version.replace_segment_filenames(segment, filenames)
+ end
+ end
+
+ private
+
# See #manifest for a description of the manifest return value.
# See #preferred_manifest_record for a description an individual manifest record.
def generate_manifest
@@ -147,24 +194,6 @@ class Chef
@manifest = manifest
end
- # TODO: This is kind of terrible. investigate removing it
- def update_from(new_manifest)
- @manifest = Mash.new new_manifest
- @checksums = extract_checksums_from_manifest(@manifest)
- @manifest_records_by_path = extract_manifest_records_by_path(@manifest)
-
- # TODO: this part of this method is "feature envious" it only deals with
- # mutating the CookbookVersion object.
- COOKBOOK_SEGMENTS.each do |segment|
- next unless @manifest.has_key?(segment)
- filenames = @manifest[segment].map{|manifest_record| manifest_record['name']}
-
- cookbook_version.replace_segment_filenames(segment, filenames)
- end
- end
-
- private
-
def parse_segment_file_from_root_paths(segment, segment_file)
root_paths.each do |root_path|
pathname = Chef::Util::PathHelper.relative_path_from(root_path, segment_file)