diff --git a/lib/chef-dk/policyfile/uploader.rb b/lib/chef-dk/policyfile/uploader.rb index 770d2a87c..ec500071a 100644 --- a/lib/chef-dk/policyfile/uploader.rb +++ b/lib/chef-dk/policyfile/uploader.rb @@ -41,6 +41,7 @@ def initialize(policyfile_lock, policy_group, ui: nil, http_client: nil, policy_ @ui = ui || UI.null @policy_document_native_api = policy_document_native_api + @policy_lock_for_transport = nil @cookbook_versions_for_policy = nil end @@ -49,7 +50,7 @@ def policy_name end def upload - ui.msg("Uploading policy to policy group #{policy_group}") + ui.msg("Uploading policy #{policy_name} (#{short_revision_id}) to policy group #{policy_group}") if !using_policy_document_native_api? ui.msg(<<-DRAGONS) @@ -73,7 +74,7 @@ def upload_policy end def upload_policy_native - http_client.put("/policy_groups/#{policy_group}/policies/#{policy_name}", policyfile_lock.to_lock) + http_client.put("/policy_groups/#{policy_group}/policies/#{policy_name}", policy_lock_for_transport) end def data_bag_create @@ -84,7 +85,7 @@ def data_bag_create def data_bag_item_create policy_id = "#{policy_name}-#{policy_group}" - lock_data = policyfile_lock.to_lock.dup + lock_data = policy_lock_for_transport.dup lock_data["id"] = policy_id @@ -180,6 +181,14 @@ def using_policy_document_native_api? private + def short_revision_id + policy_lock_for_transport["revision_id"][0, 10] + end + + def policy_lock_for_transport + @policy_lock_for_transport ||= policyfile_lock.to_lock + end + def list_cookbooks_url if using_policy_document_native_api? "cookbook_artifacts?num_versions=all" diff --git a/spec/unit/policyfile/uploader_spec.rb b/spec/unit/policyfile/uploader_spec.rb index 2f5e2a322..ef18a5fab 100644 --- a/spec/unit/policyfile/uploader_spec.rb +++ b/spec/unit/policyfile/uploader_spec.rb @@ -28,6 +28,7 @@ { "name" => "example", "run_list" => [ "recipe[omnibus::default]" ], + "revision_id" => "f4b29d87c36de67cbfd9aa3147df77cebf9f719e8c884036b3cf34ba94773ca5", "cookbook_locks" => { "omnibus" => { "version" => "2.2.0",