Class: ForemanInventoryUpload::UploadsSettingsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/foreman_inventory_upload/uploads_settings_controller.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.cloud_connector_statusObject



20
21
22
23
24
25
# File 'app/controllers/foreman_inventory_upload/uploads_settings_controller.rb', line 20

def self.cloud_connector_status
  cloud_connector = ForemanRhCloud::CloudConnector.new
  job = cloud_connector&.latest_job
  return nil unless job
  { id: job.id, task: ForemanTasks::Task.where(:id => job.task_id).first }
end

Instance Method Details

#indexObject



3
4
5
6
7
8
9
10
11
12
13
# File 'app/controllers/foreman_inventory_upload/uploads_settings_controller.rb', line 3

def index
  render json: {
    autoUploadEnabled: Setting[:allow_auto_inventory_upload],
    hostObfuscationEnabled: Setting[:obfuscate_inventory_hostnames],
    ipsObfuscationEnabled: Setting[:obfuscate_inventory_ips],
    excludePackagesEnabled: Setting[:exclude_installed_packages],
    allowAutoInsightsMismatchDelete: Setting[:allow_auto_insights_mismatch_delete],
    CloudConnectorStatus: ForemanInventoryUpload::UploadsSettingsController.cloud_connector_status,
    lastSyncTask: last_successful_inventory_sync_task,
  }, status: :ok
end

#last_successful_inventory_sync_taskObject



27
28
29
30
31
32
# File 'app/controllers/foreman_inventory_upload/uploads_settings_controller.rb', line 27

def last_successful_inventory_sync_task
  task = ForemanTasks::Task.where(label: 'InventorySync::Async::InventoryFullSync', result: 'success')
                    .reorder('ended_at desc').first
  return nil unless task
  { output: task.output, endedAt: task.ended_at }
end

#set_advanced_settingObject



15
16
17
18
# File 'app/controllers/foreman_inventory_upload/uploads_settings_controller.rb', line 15

def set_advanced_setting
  Setting[params.require(:setting)] = ActiveModel::Type::Boolean.new.cast(params.require(:value))
  index
end