From 2c06b6ddf27574e2e3962b45c5e79a97424c1fe0 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Mon, 23 Oct 2023 14:57:12 -0400 Subject: [PATCH] Add ability to generate report without uploading --- app/controllers/api/v2/rh_cloud/inventory_controller.rb | 4 +++- app/controllers/concerns/inventory_upload/report_actions.rb | 2 +- .../foreman_inventory_upload/reports_controller.rb | 3 ++- lib/foreman_inventory_upload/async/generate_report_job.rb | 6 ++++-- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/controllers/api/v2/rh_cloud/inventory_controller.rb b/app/controllers/api/v2/rh_cloud/inventory_controller.rb index 31563c9b..dd492ded 100644 --- a/app/controllers/api/v2/rh_cloud/inventory_controller.rb +++ b/app/controllers/api/v2/rh_cloud/inventory_controller.rb @@ -18,10 +18,12 @@ def download_file api :POST, "/organizations/:organization_id/rh_cloud/report", N_("Start report generation") param :organization_id, Integer, required: true, desc: N_("Set the current organization context for the request") + param :disconnected, Boolean, required: false, desc: N_('Generate the report, but do not upload') def generate_report organization_id = params[:organization_id] + disconnected = params[:disconnected] - start_report_generation(organization_id) + start_report_generation(organization_id, disconnected) render json: { action_status: 'success', diff --git a/app/controllers/concerns/inventory_upload/report_actions.rb b/app/controllers/concerns/inventory_upload/report_actions.rb index e40dd367..cc7d87e3 100644 --- a/app/controllers/concerns/inventory_upload/report_actions.rb +++ b/app/controllers/concerns/inventory_upload/report_actions.rb @@ -10,7 +10,7 @@ def initialize(**params) end end - def start_report_generation(organization_id) + def start_report_generation(organization_id, disconnected) ForemanTasks.async_task(ForemanInventoryUpload::Async::GenerateReportJob, ForemanInventoryUpload.generated_reports_folder, organization_id) end diff --git a/app/controllers/foreman_inventory_upload/reports_controller.rb b/app/controllers/foreman_inventory_upload/reports_controller.rb index 20bc72e6..37d7e35e 100644 --- a/app/controllers/foreman_inventory_upload/reports_controller.rb +++ b/app/controllers/foreman_inventory_upload/reports_controller.rb @@ -21,8 +21,9 @@ def last def generate organization_id = params[:organization_id] + disconnected = params[:disconnected] - start_report_generation(organization_id) + start_report_generation(organization_id, disconnected) render json: { action_status: 'success', diff --git a/lib/foreman_inventory_upload/async/generate_report_job.rb b/lib/foreman_inventory_upload/async/generate_report_job.rb index b0bef3fc..5f071538 100644 --- a/lib/foreman_inventory_upload/async/generate_report_job.rb +++ b/lib/foreman_inventory_upload/async/generate_report_job.rb @@ -5,7 +5,8 @@ def self.output_label(label) "report_for_#{label}" end - def plan(base_folder, organization_id) + def plan(base_folder, organization_id, disconnected) + # rubocop:disable Style/MultilineIfModifier sequence do super( GenerateReportJob.output_label(organization_id), @@ -18,8 +19,9 @@ def plan(base_folder, organization_id) base_folder, ForemanInventoryUpload.facts_archive_name(organization_id), organization_id - ) + ) unless disconnected end + # rubocop:enable Style/MultilineIfModifier end def rake_prefix