summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authordanielsdeleo <dan@getchef.com>2015-03-24 17:53:56 -0700
committerdanielsdeleo <dan@getchef.com>2015-03-25 08:13:34 -0700
commita6fbf127d3eeb38d73fa4b9aec98ef34cf897f85 (patch)
treea0eeadd9ae0a6bb4887b1c8f80e28e25952c7d7e /lib
parent7ebb11ce0dbdec76562eb1008a8d85faad0cdaf4 (diff)
downloadchef-a6fbf127d3eeb38d73fa4b9aec98ef34cf897f85.tar.gz
Update policyfile URLs and cookbook artifact data format per RFC
Diffstat (limited to 'lib')
-rw-r--r--lib/chef/cookbook_manifest.rb20
-rw-r--r--lib/chef/cookbook_version.rb19
-rw-r--r--lib/chef/policy_builder/policyfile.rb8
3 files changed, 40 insertions, 7 deletions
diff --git a/lib/chef/cookbook_manifest.rb b/lib/chef/cookbook_manifest.rb
index 0d21e9725c..10654a4945 100644
--- a/lib/chef/cookbook_manifest.rb
+++ b/lib/chef/cookbook_manifest.rb
@@ -36,6 +36,7 @@ class Chef
def_delegator :@cookbook_version, :root_paths
def_delegator :@cookbook_version, :segment_filenames
def_delegator :@cookbook_version, :name
+ def_delegator :@cookbook_version, :identifier
def_delegator :@cookbook_version, :metadata
def_delegator :@cookbook_version, :full_name
def_delegator :@cookbook_version, :version
@@ -141,9 +142,16 @@ class Chef
# 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
- "#{cookbook_url_path}/#{name}/#{version}"
+ if policy_mode?
+ "#{named_cookbook_url}/#{identifier}"
+ else
+ "#{named_cookbook_url}/#{version}"
+ end
end
+ def named_cookbook_url
+ "#{cookbook_url_path}/#{name}"
+ 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).
@@ -214,10 +222,16 @@ class Chef
end
end
- manifest[:cookbook_name] = name.to_s
manifest[:metadata] = metadata
manifest[:version] = metadata.version
- manifest[:name] = full_name
+
+ if policy_mode?
+ manifest[:name] = name.to_s
+ manifest[:identifier] = identifier
+ else
+ manifest[:name] = full_name
+ manifest[:cookbook_name] = name.to_s
+ end
@manifest_records_by_path = extract_manifest_records_by_path(manifest)
@manifest = manifest
diff --git a/lib/chef/cookbook_version.rb b/lib/chef/cookbook_version.rb
index b8f32a61bb..8d302eeec2 100644
--- a/lib/chef/cookbook_version.rb
+++ b/lib/chef/cookbook_version.rb
@@ -78,6 +78,16 @@ class Chef
attr_accessor :chef_server_rest
+ # The `identifier` field is used for cookbook_artifacts, which are
+ # organized on the chef server according to their content. If the
+ # policy_mode option to CookbookManifest is set to true it will include
+ # this field in the manifest Hash and in the upload URL.
+ #
+ # This field may be removed or have different behavior in the future, don't
+ # use it in 3rd party code.
+ # @api private
+ attr_accessor :identifier
+
# The first root path is the primary cookbook dir, from which metadata is loaded
def root_dir
root_paths[0]
@@ -458,6 +468,15 @@ class Chef
cookbook_version
end
+ def self.from_cb_artifact_data(o)
+ cookbook_version = new(o["name"])
+ # We want the Chef::Cookbook::Metadata object to always be inflated
+ cookbook_version.metadata = Chef::Cookbook::Metadata.from_hash(o["metadata"])
+ cookbook_version.manifest = o
+ cookbook_version.identifier = o["identifier"]
+ cookbook_version
+ end
+
# @deprecated This method was used by the Ruby Chef Server and is no longer
# needed. There is no replacement.
def generate_manifest_with_urls(&url_generator)
diff --git a/lib/chef/policy_builder/policyfile.rb b/lib/chef/policy_builder/policyfile.rb
index d368b055f7..f85d72f121 100644
--- a/lib/chef/policy_builder/policyfile.rb
+++ b/lib/chef/policy_builder/policyfile.rb
@@ -239,7 +239,7 @@ class Chef
def policyfile_location
if Chef::Config[:policy_document_native_api]
validate_policy_config!
- "policies/#{policy_group}/#{policy_name}"
+ "policy_groups/#{policy_group}/policies/#{policy_name}"
else
"data/policyfiles/#{deployment_group}"
end
@@ -368,11 +368,11 @@ class Chef
end
def artifact_manifest_for(cookbook_name, lock_data)
- xyz_version = lock_data["dotted_decimal_identifier"]
- rel_url = "cookbook_artifacts/#{cookbook_name}/#{xyz_version}"
+ identifier = lock_data["identifier"]
+ rel_url = "cookbook_artifacts/#{cookbook_name}/#{identifier}"
http_api.get(rel_url)
rescue Exception => e
- message = "Error loading cookbook #{cookbook_name} at version #{xyz_version} from #{rel_url}: #{e.class} - #{e.message}"
+ message = "Error loading cookbook #{cookbook_name} with identifier #{identifier} from #{rel_url}: #{e.class} - #{e.message}"
err = Chef::Exceptions::CookbookNotFound.new(message)
err.set_backtrace(e.backtrace)
raise err