From 1e8867d9a3c149d4f00c3e05f60fdf67863184a4 Mon Sep 17 00:00:00 2001 From: Martin Povolny Date: Mon, 20 Jan 2020 17:54:37 +0100 Subject: [PATCH] Add payload download action to the UI worker. --- .../migration_analytics_controller.rb | 25 +++++++++++++++++++ config/routes.rb | 1 + 2 files changed, 26 insertions(+) diff --git a/app/controllers/migration_analytics_controller.rb b/app/controllers/migration_analytics_controller.rb index 0428491..ea65038 100644 --- a/app/controllers/migration_analytics_controller.rb +++ b/app/controllers/migration_analytics_controller.rb @@ -13,5 +13,30 @@ def layout_full_center end end + def payload + check_feature_enabled + task_id = params['task_id'] + raise "Must specify a task id via \"task_id\"" if task_id.blank? + + begin + task = MiqTask.find(task_id) + path = task&.context_data&.payload_path + if path && File.exist?(path) + send_file(path, :type => 'application/binary', :filename => 'analytics_payload.bin') + else + raise "Payload not found." + end + rescue ActiveRecord::RecordNotFound => e + action_result(false, e.to_s) + end + end + menu_section :migration + + private + def check_feature_enabled + unless Settings.prototype.migration_analytics.enabled + raise ActionController::RoutingError, 'Feature Not Enabled' + end + end end diff --git a/config/routes.rb b/config/routes.rb index 92f97b8..b7a8650 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,6 @@ Rails.application.routes.draw do if Settings.prototype.migration_analytics.enabled get "/migration_analytics", to: "migration_analytics#index" + get "/migration_analytics/payload", to: "migration_analytics#payload" end end