foreman_rh_cloud 1.0.4.1 → 1.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/foreman_inventory_upload/accounts_controller.rb +4 -6
- data/app/controllers/foreman_inventory_upload/uploads_controller.rb +33 -7
- data/app/controllers/foreman_rh_cloud/react_controller.rb +11 -0
- data/app/controllers/insights_cloud/tasks_controller.rb +8 -0
- data/app/helpers/foreman_inventory_upload_host_helper.rb +11 -0
- data/app/models/insights_facet.rb +3 -0
- data/app/models/insights_hit.rb +6 -0
- data/app/models/setting/rh_cloud.rb +15 -0
- data/app/overrides/hosts_list.rb +13 -0
- data/app/views/foreman_rh_cloud/react/insights_cloud.html.erb +6 -0
- data/app/views/foreman_rh_cloud/react/inventory_upload.html.erb +1 -0
- data/app/views/{foreman_inventory_upload/layouts/react.html.erb → layouts/foreman_rh_cloud/application.html.erb} +2 -2
- data/config/routes.rb +12 -1
- data/db/migrate/20191215104806_create_insights_hits.foreman_inventory_upload.rb +14 -0
- data/db/migrate/20191216062008_create_insights_facets.foreman_inventory_upload.rb +7 -0
- data/lib/foreman_inventory_upload.rb +12 -0
- data/lib/foreman_inventory_upload/async/async_helpers.rb +13 -0
- data/lib/foreman_inventory_upload/async/generate_all_reports_job.rb +8 -0
- data/lib/foreman_inventory_upload/async/shell_process.rb +3 -1
- data/lib/foreman_inventory_upload/generators/archived_report.rb +6 -3
- data/lib/foreman_inventory_upload/generators/fact_helpers.rb +56 -0
- data/lib/foreman_inventory_upload/generators/json_stream.rb +10 -0
- data/lib/foreman_inventory_upload/generators/queries.rb +7 -0
- data/lib/foreman_inventory_upload/generators/slice.rb +47 -21
- data/lib/foreman_inventory_upload/notifications/manifest_import_success_notification_override.rb +19 -0
- data/lib/foreman_rh_cloud/engine.rb +33 -5
- data/lib/foreman_rh_cloud/version.rb +1 -1
- data/lib/insights_cloud.rb +15 -0
- data/lib/insights_cloud/async/insights_full_sync.rb +96 -0
- data/test/controllers/accounts_controller_test.rb +8 -3
- data/test/controllers/uploads_controller_test.rb +13 -0
- data/test/jobs/insights_full_sync_test.rb +92 -0
- data/test/unit/archived_report_generator_test.rb +1 -0
- data/test/unit/fact_helpers_test.rb +29 -0
- data/test/unit/slice_generator_test.rb +274 -12
- data/webpack/ForemanInventoryUpload/Components/AccountList/AccountList.fixtures.js +14 -2
- data/webpack/ForemanInventoryUpload/Components/AccountList/AccountList.js +13 -10
- data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListActions.js +6 -3
- data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListHelper.js +10 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListReducer.js +16 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListSelectors.js +10 -1
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyResults/EmptyResults.js +15 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyResults/__tests__/EmptyResults.test.js +13 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyResults/__tests__/__snapshots__/EmptyResults.test.js.snap +18 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyResults/emptyResults.scss +7 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyResults/index.js +1 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItem/ListItem.js +1 -4
- data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountList.test.js +1 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListActions.test.js +8 -1
- data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListHelper.test.js +12 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListIntegration.test.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListReducer.test.js +22 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListSelectors.test.js +20 -8
- data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountList.test.js.snap +2 -3
- data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListActions.test.js.snap +20 -2
- data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListReducer.test.js.snap +20 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListSelectors.test.js.snap +8 -2
- data/webpack/ForemanInventoryUpload/Components/AccountList/index.js +2 -0
- data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/AutoUploadSwitcher.fixtures.js +1 -0
- data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/AutoUploadSwitcher.js +32 -0
- data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/AutoUploadSwitcherActions.js +30 -0
- data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/AutoUploadSwitcherConstants.js +2 -0
- data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/__tests__/AutoUploadSwitcher.test.js +14 -0
- data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/__tests__/AutoUploadSwitcherActions.test.js +14 -0
- data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/__tests__/__snapshots__/AutoUploadSwitcher.test.js.snap +38 -0
- data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/__tests__/__snapshots__/AutoUploadSwitcherActions.test.js.snap +14 -0
- data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/autoUploadSwitcher.scss +3 -0
- data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/index.js +17 -0
- data/webpack/ForemanInventoryUpload/Components/Dashboard/DashboardActions.js +4 -3
- data/webpack/ForemanInventoryUpload/Components/Dashboard/DashboardSelectors.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/DashboardActions.test.js +2 -3
- data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/DashboardIntegration.test.js +2 -1
- data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/DashboardSelectors.test.js +3 -2
- data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/HostObfuscationSwitcher.fixtures.js +1 -0
- data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/HostObfuscationSwitcher.js +29 -0
- data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/HostObfuscationSwitcherActions.js +30 -0
- data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/HostObfuscationSwitcherConstants.js +3 -0
- data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/__tests__/HostObfuscationSwitcher.test.js +14 -0
- data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/__tests__/HostObfuscationSwitcherActions.test.js +14 -0
- data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/__tests__/__snapshots__/HostObfuscationSwitcher.test.js.snap +38 -0
- data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/__tests__/__snapshots__/HostObfuscationSwitcherActions.test.js.snap +14 -0
- data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/hostObfuscationSwitcher.scss +0 -0
- data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/index.js +20 -0
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/Components/ClearButton/ClearButton.js +26 -0
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/Components/ClearButton/index.js +1 -0
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/InventoryFilter.fixtures.js +2 -0
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/InventoryFilter.js +39 -0
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/InventoryFilterActions.js +16 -0
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/InventoryFilterConstants.js +3 -0
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/InventoryFilterReducer.js +36 -0
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/InventoryFilterSelectors.js +7 -0
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/InventoryFilter.test.js +14 -0
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/InventoryFilterActions.test.js +14 -0
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/InventoryFilterReducer.test.js +35 -0
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/InventoryFilterSelectors.test.js +21 -0
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/__snapshots__/InventoryFilter.test.js.snap +25 -0
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/__snapshots__/InventoryFilterActions.test.js.snap +17 -0
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/__snapshots__/InventoryFilterReducer.test.js.snap +25 -0
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/__snapshots__/InventoryFilterSelectors.test.js.snap +9 -0
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/__snapshots__/integration.test.js.snap +31 -0
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/integration.test.js +18 -0
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/index.js +17 -0
- data/webpack/ForemanInventoryUpload/Components/InventoryFilter/inventoryFilter.scss +28 -0
- data/webpack/ForemanInventoryUpload/Components/InventorySettings/InventorySettings.js +15 -0
- data/webpack/ForemanInventoryUpload/Components/InventorySettings/__tests__/InventorySettings.test.js +13 -0
- data/webpack/ForemanInventoryUpload/Components/InventorySettings/__tests__/__snapshots__/InventorySettings.test.js.snap +13 -0
- data/webpack/ForemanInventoryUpload/Components/InventorySettings/index.js +1 -0
- data/webpack/ForemanInventoryUpload/Components/InventorySettings/inventorySettings.scss +15 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/PageHeader.js +40 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/__tests__/PageHeader.test.js +13 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/__tests__/__snapshots__/PageHeader.test.js.snap +61 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/DocsButton/DocsButton.js +17 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/DocsButton/__tests__/DocsButton.test.js +13 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/DocsButton/__tests__/__snapshots__/DocsButton.test.js.snap +20 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/DocsButton/index.js +1 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/HistoryButton/HistoryButton.js +18 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/HistoryButton/__tests__/HistoryButton.test.js +14 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/HistoryButton/__tests__/__snapshots__/HistoryButton.test.js.snap +21 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/HistoryButton/index.js +1 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/PageDescription.js +24 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/__tests__/PageDescription.test.js +11 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/__tests__/__snapshots__/PageDescription.test.js.snap +17 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/index.js +1 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/ToolbarButtons.js +13 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/__tests__/ToolbarButtons.test.js +12 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/__tests__/__snapshots__/ToolbarButtons.test.js.snap +10 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/index.js +1 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/toolbarButtons.scss +7 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/index.js +1 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/pageHeader.scss +3 -0
- data/webpack/ForemanInventoryUpload/Components/ScheduledRun/ScheduledRun.fixtures.js +1 -0
- data/webpack/ForemanInventoryUpload/Components/ScheduledRun/ScheduledRun.js +4 -2
- data/webpack/ForemanInventoryUpload/Components/ScheduledRun/__tests__/ScheduledRun.test.js +0 -1
- data/webpack/ForemanInventoryUpload/Components/ScheduledRun/__tests__/__snapshots__/ScheduledRun.test.js.snap +0 -2
- data/webpack/ForemanInventoryUpload/Components/ScheduledRun/index.js +12 -1
- data/webpack/ForemanInventoryUpload/Components/TabBody/__tests__/__snapshots__/TabBody.test.js.snap +1 -1
- data/webpack/ForemanInventoryUpload/ForemanInventoryConstants.js +7 -0
- data/webpack/ForemanInventoryUpload/ForemanInventoryHelpers.js +12 -0
- data/webpack/ForemanInventoryUpload/ForemanInventoryUpload.js +18 -9
- data/webpack/ForemanInventoryUpload/ForemanInventoryUploadReducers.js +4 -4
- data/webpack/ForemanInventoryUpload/SubscriptionsPageExtension/SubscriptionsPageExtensionActions.js +34 -0
- data/webpack/ForemanInventoryUpload/__tests__/ForemanInventoryHelpers.test.js +12 -0
- data/webpack/ForemanInventoryUpload/{ForemanInventoryUpload.test.js → __tests__/ForemanInventoryUpload.test.js} +1 -1
- data/webpack/ForemanInventoryUpload/__tests__/__snapshots__/ForemanInventoryHelpers.test.js.snap +5 -0
- data/webpack/ForemanInventoryUpload/{__snapshots__ → __tests__/__snapshots__}/ForemanInventoryUpload.test.js.snap +6 -5
- data/webpack/ForemanRhCloudHelpers.js +6 -0
- data/webpack/ForemanRhCloudReducers.js +10 -0
- data/webpack/ForemanRhCloudSelectors.js +5 -0
- data/webpack/ForemanRhCloudTestHelpers.js +6 -0
- data/webpack/InsightsCloudSync/InsightsCloudSync.js +55 -0
- data/webpack/InsightsCloudSync/InsightsCloudSync.test.js +16 -0
- data/webpack/InsightsCloudSync/InsightsCloudSyncActions.js +23 -0
- data/webpack/InsightsCloudSync/InsightsCloudSyncConstants.js +6 -0
- data/webpack/InsightsCloudSync/InsightsCloudSyncHelpers.js +3 -0
- data/webpack/InsightsCloudSync/InsightsCloudSyncReducers.js +3 -0
- data/webpack/InsightsCloudSync/__snapshots__/InsightsCloudSync.test.js.snap +62 -0
- data/webpack/InsightsCloudSync/__tests__/InsightsCloudSyncHelpers.test.js +11 -0
- data/webpack/InsightsCloudSync/__tests__/__snapshots__/InsightsCloudSyncHelpers.test.js.snap +3 -0
- data/webpack/InsightsCloudSync/index.js +17 -0
- data/webpack/__mocks__/foremanReact/components/Layout/LayoutConstants.js +1 -0
- data/webpack/__tests__/ForemanRhCloudHelpers.test.js +11 -0
- data/webpack/__tests__/ForemanRhCloudSelectors.test.js +19 -0
- data/webpack/__tests__/ForemanRhCloudTestHelpers.test.js +10 -0
- data/webpack/__tests__/__snapshots__/ForemanRhCloudHelpers.test.js.snap +3 -0
- data/webpack/__tests__/__snapshots__/ForemanRhCloudSelectors.test.js.snap +24 -0
- data/webpack/__tests__/__snapshots__/ForemanRhCloudTestHelpers.test.js.snap +14 -0
- data/webpack/index.js +8 -1
- data/webpack/subscriptions_extension_index.js +8 -0
- metadata +124 -7
- data/app/controllers/foreman_inventory_upload/react_controller.rb +0 -7
- data/webpack/ForemanInventoryUpload/ForemanInventoryUploadSelectors.js +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e4b8f3297e5f7e0279d18de6ee94ae4607eb94e9df9fd3976881af75314c93a
|
4
|
+
data.tar.gz: 5673e003e78a64e4127ceb313899792161392387b0398a6b966e5da98821f036
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d42c544257f0db44fa5d0d9dc7dc778f5a630cad2ba88667660aa1a9bf257192ab7df8645611cedd1aa988b64f84449adcd4337376e22ac0ab4ea6fd21c4cac0
|
7
|
+
data.tar.gz: 82968701d406c36012ab10043c95448f86d6723808b99009861a54132e8e372b78978b86a5477eeeb5b4c2c6176fd72bef204dd77680432174daa9ab07af35fc
|
@@ -1,12 +1,8 @@
|
|
1
1
|
module ForemanInventoryUpload
|
2
2
|
class AccountsController < ::ApplicationController
|
3
|
-
# override default "welcome screen behavior, since we don't have a model"
|
4
|
-
def welcome
|
5
|
-
true
|
6
|
-
end
|
7
|
-
|
8
3
|
def index
|
9
|
-
|
4
|
+
organizations = User.current.my_organizations
|
5
|
+
labels = organizations.pluck(:id, :name)
|
10
6
|
|
11
7
|
accounts = Hash[
|
12
8
|
labels.map do |id, label|
|
@@ -25,6 +21,8 @@ module ForemanInventoryUpload
|
|
25
21
|
]
|
26
22
|
|
27
23
|
render json: {
|
24
|
+
autoUploadEnabled: Setting[:allow_auto_inventory_upload],
|
25
|
+
hostObfuscationEnabled: Setting[:obfuscate_inventory_hostnames],
|
28
26
|
accounts: accounts,
|
29
27
|
}, status: :ok
|
30
28
|
end
|
@@ -11,14 +11,10 @@ module ForemanInventoryUpload
|
|
11
11
|
|
12
12
|
def download_file
|
13
13
|
filename = ForemanInventoryUpload.facts_archive_name(params[:organization_id])
|
14
|
-
|
15
|
-
unless File.exist? path
|
16
|
-
return throw_flash_error(
|
17
|
-
"Path doesn't exist: #{path}"
|
18
|
-
)
|
19
|
-
end
|
14
|
+
files = Dir["{#{ForemanInventoryUpload.uploads_file_path(filename)},#{ForemanInventoryUpload.done_file_path(filename)}}"]
|
20
15
|
|
21
|
-
send_file
|
16
|
+
return send_file files.first, disposition: 'attachment', filename: filename unless files.empty?
|
17
|
+
throw_flash_error "File doesn't exist"
|
22
18
|
end
|
23
19
|
|
24
20
|
def throw_flash_error(message)
|
@@ -27,5 +23,35 @@ module ForemanInventoryUpload
|
|
27
23
|
:error_msg => message
|
28
24
|
)
|
29
25
|
end
|
26
|
+
|
27
|
+
def auto_upload
|
28
|
+
Setting[:allow_auto_inventory_upload] = auto_upload_params
|
29
|
+
render_setting(:autoUploadEnabled, :allow_auto_inventory_upload)
|
30
|
+
end
|
31
|
+
|
32
|
+
def show_auto_upload
|
33
|
+
render_setting(:autoUploadEnabled, :allow_auto_inventory_upload)
|
34
|
+
end
|
35
|
+
|
36
|
+
def auto_upload_params
|
37
|
+
ActiveModel::Type::Boolean.new.cast(params.require(:value))
|
38
|
+
end
|
39
|
+
|
40
|
+
def host_obfuscation
|
41
|
+
Setting[:obfuscate_inventory_hostnames] = host_obfuscation_params
|
42
|
+
render_setting(:hostObfuscationEnabled, :obfuscate_inventory_hostnames)
|
43
|
+
end
|
44
|
+
|
45
|
+
def host_obfuscation_params
|
46
|
+
ActiveModel::Type::Boolean.new.cast(params.require(:value))
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def render_setting(node_name, setting)
|
52
|
+
render json: {
|
53
|
+
node_name => Setting[setting],
|
54
|
+
}
|
55
|
+
end
|
30
56
|
end
|
31
57
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module ForemanInventoryUploadHostHelper
|
2
|
+
def hits_counts
|
3
|
+
@hits_counts ||= InsightsHit.where(host_id: @hosts).group(:host_id).count
|
4
|
+
end
|
5
|
+
|
6
|
+
def hits_counts_cell(host)
|
7
|
+
host_hits = hits_counts[host.id]
|
8
|
+
content = n_('One recommendation', '%{hits} recommendations', host_hits) % { hits: host_hits } if host_hits
|
9
|
+
tag.td content, class: ['hidden-xs', 'ellipsis']
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class Setting::RhCloud < Setting
|
2
|
+
def self.default_settings
|
3
|
+
return unless ActiveRecord::Base.connection.table_exists?('settings')
|
4
|
+
return unless super
|
5
|
+
[
|
6
|
+
set('allow_auto_inventory_upload', N_('Allow automatic upload of the host inventory to the Red Hat cloud'), false),
|
7
|
+
set('obfuscate_inventory_hostnames', N_('Obfuscate host names sent to Red Hat cloud'), false),
|
8
|
+
set('rh_cloud_token', N_('Authentication token to Red Hat cloud services. Used to authenticate requests to cloud APIs'), 'DEFAULT', N_('Red Hat Cloud token'), nil, encrypted: true),
|
9
|
+
]
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.humanized_category
|
13
|
+
N_('RH Cloud')
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Deface::Override.new(
|
2
|
+
virtual_path: 'hosts/_list',
|
3
|
+
name: 'insights_hits_header',
|
4
|
+
insert_before: 'thead tr th.hidden-xs:first-of-type',
|
5
|
+
text: '<th class="hidden-xs" width="10%"><%= _("Insights")%></th>'
|
6
|
+
)
|
7
|
+
|
8
|
+
Deface::Override.new(
|
9
|
+
virtual_path: 'hosts/_list',
|
10
|
+
name: 'insights_hits_cells',
|
11
|
+
insert_before: 'tbody tr td.hidden-xs:first-of-type',
|
12
|
+
text: '<%= hits_counts_cell(host) %>'
|
13
|
+
)
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= mount_react_component("ForemanInventoryUpload", '#ForemanRhCloudReactRoot') %>
|
@@ -10,7 +10,7 @@
|
|
10
10
|
<%= notifications %>
|
11
11
|
<div id="organization-id" data-id="<%= Organization.current.id if Organization.current %>" ></div>
|
12
12
|
<div id="user-id" data-id="<%= User.current.id if User.current %>" ></div>
|
13
|
-
<div id="
|
13
|
+
<div id="ForemanRhCloudReactRoot"></div>
|
14
|
+
<%= yield %>
|
14
15
|
<% end %>
|
15
16
|
<%= render file: "layouts/base" %>
|
16
|
-
<%= mount_react_component('ForemanInventoryUpload', '#ForemanInventoryUploadReactRoot') %>
|
data/config/routes.rb
CHANGED
@@ -1,10 +1,21 @@
|
|
1
1
|
Rails.application.routes.draw do
|
2
2
|
namespace :foreman_inventory_upload do
|
3
|
-
get 'index', to: 'react#index'
|
4
3
|
get ':organization_id/reports/last', to: 'reports#last', constraints: { organization_id: %r{[^\/]+} }
|
5
4
|
post ':organization_id/reports', to: 'reports#generate', constraints: { organization_id: %r{[^\/]+} }
|
6
5
|
get ':organization_id/uploads/last', to: 'uploads#last', constraints: { organization_id: %r{[^\/]+} }
|
7
6
|
get ':organization_id/uploads/file', to: 'uploads#download_file', constraints: { organization_id: %r{[^\/]+} }
|
8
7
|
get 'accounts', to: 'accounts#index'
|
8
|
+
get 'auto_upload', to: 'uploads#show_auto_upload'
|
9
|
+
post 'auto_upload', to: 'uploads#auto_upload'
|
10
|
+
post 'host_obfuscation', to: 'uploads#host_obfuscation'
|
11
|
+
end
|
12
|
+
|
13
|
+
namespace :insights_cloud do
|
14
|
+
resources :tasks, only: [:create]
|
15
|
+
end
|
16
|
+
|
17
|
+
namespace :foreman_rh_cloud do
|
18
|
+
get 'inventory_upload', to: 'react#inventory_upload'
|
19
|
+
get 'insights_cloud', to: 'react#insights_cloud'
|
9
20
|
end
|
10
21
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class CreateInsightsHits < ActiveRecord::Migration[5.2]
|
2
|
+
def change
|
3
|
+
create_table :insights_hits do |t|
|
4
|
+
t.references :host, foreign_key: true, null: false
|
5
|
+
t.datetime :last_seen
|
6
|
+
t.string :title
|
7
|
+
t.string :solution_url
|
8
|
+
t.integer :total_risk
|
9
|
+
t.integer :likelihood
|
10
|
+
t.datetime :publish_date
|
11
|
+
t.string :results_url
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -18,6 +18,18 @@ module ForemanInventoryUpload
|
|
18
18
|
)
|
19
19
|
end
|
20
20
|
|
21
|
+
def self.uploads_file_path(filename)
|
22
|
+
File.join(ForemanInventoryUpload.uploads_folder, filename)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.done_folder
|
26
|
+
File.join(ForemanInventoryUpload.uploads_folder, 'done/')
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.done_file_path(filename)
|
30
|
+
File.join(ForemanInventoryUpload.done_folder, filename)
|
31
|
+
end
|
32
|
+
|
21
33
|
def self.generated_reports_folder
|
22
34
|
@generated_reports_folder ||= ensure_folder(
|
23
35
|
File.join(
|
@@ -2,6 +2,14 @@ module ForemanInventoryUpload
|
|
2
2
|
module Async
|
3
3
|
class GenerateAllReportsJob < ::ApplicationJob
|
4
4
|
def perform
|
5
|
+
unless Setting[:allow_auto_inventory_upload]
|
6
|
+
logger.debug(
|
7
|
+
'The scheduled process is disabled due to the "allow_auto_inventory_upload"
|
8
|
+
setting being set to false.'
|
9
|
+
)
|
10
|
+
return
|
11
|
+
end
|
12
|
+
|
5
13
|
organizations = Organization.unscoped.all
|
6
14
|
|
7
15
|
organizations.map do |organization|
|
@@ -3,11 +3,13 @@ require 'open3'
|
|
3
3
|
module ForemanInventoryUpload
|
4
4
|
module Async
|
5
5
|
class ShellProcess < ::ApplicationJob
|
6
|
+
include AsyncHelpers
|
7
|
+
|
6
8
|
def perform(instance_label)
|
7
9
|
klass_name = self.class.name
|
8
10
|
logger.debug("Starting #{klass_name} with label #{instance_label}")
|
9
11
|
progress_output = ProgressOutput.register(instance_label)
|
10
|
-
Open3.popen2e(env, command) do |_stdin, stdout_stderr, wait_thread|
|
12
|
+
Open3.popen2e(hash_to_s(env), command) do |_stdin, stdout_stderr, wait_thread|
|
11
13
|
progress_output.status = "Running in pid #{wait_thread.pid}"
|
12
14
|
|
13
15
|
stdout_stderr.each do |out_line|
|
@@ -16,9 +16,9 @@ module ForemanInventoryUpload
|
|
16
16
|
first = true
|
17
17
|
host_batches.each do |hosts_batch|
|
18
18
|
slice_id = Foreman.uuid
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
@logger.info "Adding slice #{slice_id}"
|
20
|
+
hosts_count = generate_slice(tmpdir, slice_id, hosts_batch)
|
21
|
+
@logger.info "slice #{slice_id} was created with #{hosts_count} hosts"
|
22
22
|
inner_generator.add_slice(slice_id, hosts_count, first)
|
23
23
|
first = false
|
24
24
|
end
|
@@ -43,10 +43,13 @@ module ForemanInventoryUpload
|
|
43
43
|
private
|
44
44
|
|
45
45
|
def generate_slice(tmpdir, slice_id, hosts_batch)
|
46
|
+
hosts_count = 0
|
46
47
|
File.open(File.join(tmpdir, "#{slice_id}.json"), 'w') do |slice_out|
|
47
48
|
slice_generator = ForemanInventoryUpload::Generators::Slice.new(hosts_batch, slice_out, slice_id)
|
48
49
|
slice_generator.render
|
50
|
+
hosts_count = slice_generator.hosts_count
|
49
51
|
end
|
52
|
+
hosts_count
|
50
53
|
end
|
51
54
|
end
|
52
55
|
end
|
@@ -3,6 +3,11 @@ module ForemanInventoryUpload
|
|
3
3
|
module FactHelpers
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
|
+
CLOUD_AMAZON = 'aws'
|
7
|
+
CLOUD_GOOGLE = 'google'
|
8
|
+
CLOUD_AZURE = 'azure'
|
9
|
+
CLOUD_ALIBABA = 'alibaba'
|
10
|
+
|
6
11
|
def fact_value(host, fact_name)
|
7
12
|
value_record = host.fact_values.find do |fact_value|
|
8
13
|
fact_value.fact_name_id == ForemanInventoryUpload::Generators::Queries.fact_names[fact_name]
|
@@ -13,6 +18,57 @@ module ForemanInventoryUpload
|
|
13
18
|
def kilobytes_to_bytes(kilobytes)
|
14
19
|
kilobytes * 1024
|
15
20
|
end
|
21
|
+
|
22
|
+
def account_id(organization)
|
23
|
+
@organization_accounts ||= {}
|
24
|
+
@organization_accounts[organization.id] ||= organization.pools.where.not(account_number: nil).pluck(:account_number).first
|
25
|
+
end
|
26
|
+
|
27
|
+
def golden_ticket?(organization)
|
28
|
+
result = organization.try(:golden_ticket?)
|
29
|
+
result = organization.content_access_mode == 'org_environment' if result.nil?
|
30
|
+
|
31
|
+
@organization_golden_tickets ||= {}
|
32
|
+
@organization_golden_tickets[organization.id] ||= result
|
33
|
+
end
|
34
|
+
|
35
|
+
def cloud_provider(host)
|
36
|
+
bios_version = fact_value(host, 'dmi::bios::version')
|
37
|
+
|
38
|
+
if bios_version
|
39
|
+
return CLOUD_AMAZON if bios_version.downcase['amazon']
|
40
|
+
return CLOUD_GOOGLE if bios_version.downcase['google']
|
41
|
+
end
|
42
|
+
|
43
|
+
chassis_asset_tag = fact_value(host, 'dmi::chassis::asset_tag')
|
44
|
+
return CLOUD_AZURE if chassis_asset_tag && chassis_asset_tag['7783-7084-3265-9085-8269-3286-77']
|
45
|
+
|
46
|
+
system_manufacturer = fact_value(host, 'dmi::system::manufacturer')
|
47
|
+
return CLOUD_ALIBABA if system_manufacturer && system_manufacturer.downcase['alibaba cloud']
|
48
|
+
|
49
|
+
product_name = fact_value(host, 'dmi::system::product_name')
|
50
|
+
return CLOUD_ALIBABA if product_name && product_name.downcase['alibaba cloud ecs']
|
51
|
+
|
52
|
+
nil
|
53
|
+
end
|
54
|
+
|
55
|
+
def obfuscate_hostname?(host)
|
56
|
+
insights_client_setting = fact_value(host, 'insights_client::obfuscate_hostname_enabled')
|
57
|
+
insights_client_setting = ActiveModel::Type::Boolean.new.cast(insights_client_setting)
|
58
|
+
return insights_client_setting unless insights_client_setting.nil?
|
59
|
+
|
60
|
+
Setting[:obfuscate_inventory_hostnames]
|
61
|
+
end
|
62
|
+
|
63
|
+
def fqdn(host)
|
64
|
+
return host.fqdn unless obfuscate_hostname?(host)
|
65
|
+
|
66
|
+
fact_value(host, 'insights_client::hostname') || obfuscate_fqdn(host.fqdn)
|
67
|
+
end
|
68
|
+
|
69
|
+
def obfuscate_fqdn(fqdn)
|
70
|
+
Digest::SHA1.hexdigest(fqdn)
|
71
|
+
end
|
16
72
|
end
|
17
73
|
end
|
18
74
|
end
|
@@ -36,6 +36,16 @@ module ForemanInventoryUpload
|
|
36
36
|
@out << ',' unless last
|
37
37
|
end
|
38
38
|
|
39
|
+
def string_array_value(name, value, last = false)
|
40
|
+
return if value.empty?
|
41
|
+
|
42
|
+
string_value = value.map { |v| stringify_value(v) }
|
43
|
+
|
44
|
+
array_field(name, last) do
|
45
|
+
raw(string_value.join(', '))
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
39
49
|
def object_field(name, last = false, &block)
|
40
50
|
@out << "\"#{name}\": "
|
41
51
|
object(&block)
|
@@ -18,6 +18,13 @@ module ForemanInventoryUpload
|
|
18
18
|
'uname::release',
|
19
19
|
'lscpu::flags',
|
20
20
|
'distribution::version',
|
21
|
+
'distribution::id',
|
22
|
+
'virt::is_guest',
|
23
|
+
'dmi::system::manufacturer',
|
24
|
+
'dmi::system::product_name',
|
25
|
+
'dmi::chassis::asset_tag',
|
26
|
+
'insights_client::obfuscate_hostname_enabled',
|
27
|
+
'insights_client::hostname',
|
21
28
|
]).pluck(:name, :id)
|
22
29
|
]
|
23
30
|
end
|
@@ -4,11 +4,13 @@ module ForemanInventoryUpload
|
|
4
4
|
include FactHelpers
|
5
5
|
|
6
6
|
attr_accessor :slice_id
|
7
|
+
attr_reader :hosts_count
|
7
8
|
|
8
9
|
def initialize(hosts, output = [], slice_id = Foreman.uuid)
|
9
10
|
@stream = JsonStream.new(output)
|
10
11
|
@hosts = hosts
|
11
12
|
@slice_id = slice_id
|
13
|
+
@hosts_count = 0
|
12
14
|
end
|
13
15
|
|
14
16
|
def render
|
@@ -24,9 +26,12 @@ module ForemanInventoryUpload
|
|
24
26
|
@stream.array_field('hosts', :last) do
|
25
27
|
first = true
|
26
28
|
hosts_batch.each do |host|
|
27
|
-
next unless host&.subscription_facet
|
29
|
+
next unless host&.subscription_facet
|
28
30
|
@stream.comma unless first
|
29
|
-
|
31
|
+
if report_host(host)
|
32
|
+
first = false
|
33
|
+
@hosts_count += 1
|
34
|
+
end
|
30
35
|
end
|
31
36
|
end
|
32
37
|
end
|
@@ -34,23 +39,14 @@ module ForemanInventoryUpload
|
|
34
39
|
|
35
40
|
def report_host(host)
|
36
41
|
@stream.object do
|
37
|
-
@stream.simple_field('
|
38
|
-
@stream.simple_field('
|
39
|
-
@stream.simple_field('
|
40
|
-
@stream.simple_field('
|
41
|
-
@stream.simple_field('satellite_id', host.subscription_facet.uuid)
|
42
|
+
@stream.simple_field('fqdn', fqdn(host))
|
43
|
+
@stream.simple_field('account', account_id(host.organization).to_s)
|
44
|
+
@stream.simple_field('subscription_manager_id', host.subscription_facet&.uuid)
|
45
|
+
@stream.simple_field('satellite_id', host.subscription_facet&.uuid)
|
42
46
|
@stream.simple_field('bios_uuid', fact_value(host, 'dmi::system::uuid'))
|
43
47
|
@stream.simple_field('vm_uuid', fact_value(host, 'virt::uuid'))
|
44
|
-
|
45
|
-
|
46
|
-
@stream.stringify_value(nic.ip) if nic.ip
|
47
|
-
end.compact.join(', '))
|
48
|
-
end
|
49
|
-
@stream.array_field('mac_addresses') do
|
50
|
-
@stream.raw(host.interfaces.map do |nic|
|
51
|
-
@stream.stringify_value(nic.mac) if nic.mac
|
52
|
-
end.compact.join(', '))
|
53
|
-
end
|
48
|
+
report_ip_addresses(host)
|
49
|
+
report_mac_addresses(host)
|
54
50
|
@stream.object_field('system_profile') do
|
55
51
|
report_system_profile(host)
|
56
52
|
end
|
@@ -105,12 +101,24 @@ module ForemanInventoryUpload
|
|
105
101
|
end.join(', '))
|
106
102
|
end
|
107
103
|
end
|
108
|
-
@stream.simple_field(
|
104
|
+
@stream.simple_field(
|
105
|
+
'os_release',
|
106
|
+
os_release_value(
|
107
|
+
name: fact_value(host, 'distribution::name'),
|
108
|
+
version: fact_value(host, 'distribution::version'),
|
109
|
+
codename: fact_value(host, 'distribution::id')
|
110
|
+
)
|
111
|
+
)
|
109
112
|
@stream.simple_field('os_kernel_version', fact_value(host, 'uname::release'))
|
110
113
|
@stream.simple_field('arch', host.architecture&.name)
|
111
114
|
@stream.simple_field('subscription_status', host.subscription_status_label)
|
112
115
|
@stream.simple_field('katello_agent_running', host.content_facet&.katello_agent_installed?)
|
113
116
|
@stream.simple_field('satellite_managed', true)
|
117
|
+
@stream.simple_field(
|
118
|
+
'infrastructure_type',
|
119
|
+
ActiveModel::Type::Boolean.new.cast(fact_value(host, 'virt::is_guest')) ? 'virtual' : 'physical'
|
120
|
+
)
|
121
|
+
@stream.simple_field('cloud_provider', cloud_provider(host))
|
114
122
|
unless (installed_products = host.subscription_facet&.installed_products).empty?
|
115
123
|
@stream.array_field('installed_products') do
|
116
124
|
@stream.raw(installed_products.map do |product|
|
@@ -131,17 +139,35 @@ module ForemanInventoryUpload
|
|
131
139
|
end
|
132
140
|
|
133
141
|
def report_satellite_facts(host)
|
134
|
-
@stream.simple_field('virtual_host_name', host.subscription_facet
|
135
|
-
@stream.simple_field('virtual_host_uuid', host.subscription_facet
|
142
|
+
@stream.simple_field('virtual_host_name', host.subscription_facet&.hypervisor_host&.name)
|
143
|
+
@stream.simple_field('virtual_host_uuid', host.subscription_facet&.hypervisor_host&.subscription_facet&.uuid)
|
136
144
|
if defined?(ForemanThemeSatellite)
|
137
145
|
@stream.simple_field('satellite_version', ForemanThemeSatellite::SATELLITE_VERSION)
|
138
146
|
end
|
139
147
|
@stream.simple_field('system_purpose_usage', host.subscription_facet.purpose_usage)
|
140
148
|
@stream.simple_field('system_purpose_role', host.subscription_facet.purpose_role)
|
141
149
|
@stream.simple_field('distribution_version', fact_value(host, 'distribution::version'))
|
142
|
-
@stream.simple_field('satellite_instance_id', Foreman.
|
150
|
+
@stream.simple_field('satellite_instance_id', Foreman.try(:instance_id))
|
151
|
+
@stream.simple_field('is_simple_content_access', golden_ticket?(host.organization))
|
152
|
+
@stream.simple_field('is_hostname_obfuscated', !!obfuscate_hostname?(host))
|
143
153
|
@stream.simple_field('organization_id', host.organization_id, :last)
|
144
154
|
end
|
155
|
+
|
156
|
+
def report_ip_addresses(host)
|
157
|
+
ip_addresses = host.interfaces.map { |nic| nic.ip }.compact
|
158
|
+
|
159
|
+
@stream.string_array_value('ip_addresses', ip_addresses)
|
160
|
+
end
|
161
|
+
|
162
|
+
def report_mac_addresses(host)
|
163
|
+
macs = host.interfaces.map { |nic| nic.mac }.compact
|
164
|
+
|
165
|
+
@stream.string_array_value('mac_addresses', macs)
|
166
|
+
end
|
167
|
+
|
168
|
+
def os_release_value(name:, version:, codename:)
|
169
|
+
"#{name} #{version} (#{codename})"
|
170
|
+
end
|
145
171
|
end
|
146
172
|
end
|
147
173
|
end
|