From 0b3213605b6d76780d1ecc29eefeeef16b94bfa4 Mon Sep 17 00:00:00 2001 From: Alex Pop <107378+alexpop@users.noreply.github.com> Date: Fri, 31 May 2019 20:09:58 +0100 Subject: [PATCH] Make entity_uuid work for Chef Infra 15 (#371) Signed-off-by: Alex Pop --- files/default/handler/audit_report.rb | 2 ++ libraries/helper.rb | 8 ++------ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/files/default/handler/audit_report.rb b/files/default/handler/audit_report.rb index 9018c514..28d217ae 100644 --- a/files/default/handler/audit_report.rb +++ b/files/default/handler/audit_report.rb @@ -229,6 +229,7 @@ def send_report(reporter, server, user, source_location, report) # TODO: harmonize reporter interface if reporter == 'chef-visibility' || reporter == 'chef-automate' + # `run_status.entity_uuid` is calling the `entity_uuid` method in libraries/helper.rb opts = { entity_uuid: run_status.entity_uuid, run_id: run_status.run_id, @@ -242,6 +243,7 @@ def send_report(reporter, server, user, source_location, report) chef_org = Chef::Config[:chef_server_url].split('/').last if chef_url url = construct_url(chef_url, File.join('organizations', chef_org, 'data-collector')) + # `run_status.entity_uuid` is calling the `entity_uuid` method in libraries/helper.rb opts = { entity_uuid: run_status.entity_uuid, run_id: run_status.run_id, diff --git a/libraries/helper.rb b/libraries/helper.rb index d86e7c2c..dbf1430e 100644 --- a/libraries/helper.rb +++ b/libraries/helper.rb @@ -16,12 +16,8 @@ def run_id # Returns the node's uuid def entity_uuid - if defined?(Chef) && - defined?(Chef::DataCollector) && - defined?(Chef::DataCollector::Messages) && - defined?(Chef::DataCollector::Messages.node_uuid) - Chef::DataCollector::Messages.node_uuid - end + # the Chef::DataCollector::Messages API here is Chef < 15.0 backcompat and can be removed when Chef 14.x is no longer supported + node[:chef_guid] || defined?(Chef::DataCollector::Messages) && Chef::DataCollector::Messages.node_uuid end # Convert the strings in the profile definitions into symbols for handling