From c5076cb7000861c48b41871aa6c04feca9ec7216 Mon Sep 17 00:00:00 2001 From: Robert Schweikert Date: Fri, 17 Jan 2025 13:36:27 -0500 Subject: [PATCH] Export engine adjustments - Provide a description for use of the data export engine and how to use it - Rename the update_info interface of the export engine to export_rmt_data --- engines/data_export/README.md | 10 ++++++++-- engines/data_export/lib/data_export/engine.rb | 12 ++++++------ .../data_export/lib/data_export/handlers/example.rb | 2 +- .../v3/subscriptions/systems_controller_spec.rb | 8 ++++---- .../connect/v3/systems/systems_controller_spec.rb | 8 ++++---- 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/engines/data_export/README.md b/engines/data_export/README.md index 0a661a23b..a0ee33843 100644 --- a/engines/data_export/README.md +++ b/engines/data_export/README.md @@ -1,5 +1,11 @@ # DataExport -Short description and motivation. +The data export engine supports exporting of data from RMT whenever a +client visits the RMT server to received updates or an initial registration +is performed. + +With this implementation the implementer can decide to forward all client +data or specific data to some external service for data analysis for example. ## Usage -How to use my plugin. +Place you implementation into /usr/share/rmt/engines/data_export/lib/data_export/handlers/ and implement the export_rmt_data function. The function takes no +arguments. Data to be exported is extracted from the RMT data base. diff --git a/engines/data_export/lib/data_export/engine.rb b/engines/data_export/lib/data_export/engine.rb index d129e10be..4137caf59 100644 --- a/engines/data_export/lib/data_export/engine.rb +++ b/engines/data_export/lib/data_export/engine.rb @@ -4,9 +4,9 @@ class Engine < ::Rails::Engine config.after_initialize do # replaces RMT registration for SCC registration Api::Connect::V3::Subscriptions::SystemsController.class_eval do - after_action :update_info, only: %i[announce_system], if: -> { response.successful? } + after_action :export_rmt_data, only: %i[announce_system], if: -> { response.successful? } - def update_info + def export_rmt_data # no need to check if system is nil # as the response is successful return if @system.byos? @@ -17,7 +17,7 @@ def update_info params, logger ) - data_export_handler.update_info + data_export_handler.export_rmt_data logger.info "System #{@system.login} info updated by data export handler after announcing the system" rescue StandardError => e logger.error('Unexpected data export error has occurred:') @@ -29,16 +29,16 @@ def update_info end Api::Connect::V3::Systems::SystemsController.class_eval do - after_action :update_info, only: %i[update], if: -> { response.successful? } + after_action :export_rmt_data, only: %i[update], if: -> { response.successful? } - def update_info + def export_rmt_data data_export_handler = DataExport.handler.new( @system, request, params, logger ) - data_export_handler.update_info + data_export_handler.export_rmt_data logger.info "System #{@system.login} info updated by data export handler after updating the system" rescue StandardError => e logger.error('Unexpected data export error has occurred:') diff --git a/engines/data_export/lib/data_export/handlers/example.rb b/engines/data_export/lib/data_export/handlers/example.rb index d230ad353..c9f00db6a 100644 --- a/engines/data_export/lib/data_export/handlers/example.rb +++ b/engines/data_export/lib/data_export/handlers/example.rb @@ -1,5 +1,5 @@ class DataExport::Handlers::Example < DataExport::HandlerBase - def update_info + def export_rmt_data true end end diff --git a/engines/data_export/spec/requests/api/connect/v3/subscriptions/systems_controller_spec.rb b/engines/data_export/spec/requests/api/connect/v3/subscriptions/systems_controller_spec.rb index 16ff00a96..a73dd41a5 100644 --- a/engines/data_export/spec/requests/api/connect/v3/subscriptions/systems_controller_spec.rb +++ b/engines/data_export/spec/requests/api/connect/v3/subscriptions/systems_controller_spec.rb @@ -38,7 +38,7 @@ before do allow(DataExport::Handlers::Example).to receive(:new).and_return(plugin_double) - allow(plugin_double).to receive(:update_info) + allow(plugin_double).to receive(:export_rmt_data) stub_request(:post, scc_register_system_url) .to_return( status: 201, @@ -48,7 +48,7 @@ end it 'saves the data' do - expect(plugin_double).to receive(:update_info) + expect(plugin_double).to receive(:export_rmt_data) post '/connect/subscriptions/systems', params: params, headers: { HTTP_AUTHORIZATION: 'Token token=' } end @@ -57,7 +57,7 @@ before do allow(DataExport::Handlers::Example).to receive(:new).and_return(plugin_double) - allow(plugin_double).to receive(:update_info).and_raise('foo') + allow(plugin_double).to receive(:export_rmt_data).and_raise('foo') allow(Rails.logger).to receive(:error) stub_request(:post, scc_register_system_url) .to_return( @@ -68,7 +68,7 @@ end it 'does not save the data and log error' do - expect(plugin_double).to receive(:update_info) + expect(plugin_double).to receive(:export_rmt_data) expect(Rails.logger).to receive(:error) post '/connect/subscriptions/systems', params: params, headers: { HTTP_AUTHORIZATION: 'Token token=' } end diff --git a/engines/data_export/spec/requests/api/connect/v3/systems/systems_controller_spec.rb b/engines/data_export/spec/requests/api/connect/v3/systems/systems_controller_spec.rb index 8507f5a07..27e72b5c9 100644 --- a/engines/data_export/spec/requests/api/connect/v3/systems/systems_controller_spec.rb +++ b/engines/data_export/spec/requests/api/connect/v3/systems/systems_controller_spec.rb @@ -30,22 +30,22 @@ before { allow(DataExport::Handlers::Example).to receive(:new).and_return(plugin_double) } context 'when data export success' do - before { allow(plugin_double).to receive(:update_info) } + before { allow(plugin_double).to receive(:export_rmt_data) } it do - expect(plugin_double).to receive(:update_info) + expect(plugin_double).to receive(:export_rmt_data) expect { update_action }.to change { system.reload.hostname }.from('initial').to(payload[:hostname]) end end context 'when data export fails' do before do - allow(plugin_double).to receive(:update_info).and_raise('foo') + allow(plugin_double).to receive(:export_rmt_data).and_raise('foo') allow(Rails.logger).to receive(:error) end it do - expect(plugin_double).to receive(:update_info) + expect(plugin_double).to receive(:export_rmt_data) expect(Rails.logger).to receive(:error) update_action end