foreman_rh_cloud 1.0.4 → 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (171) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/foreman_inventory_upload/accounts_controller.rb +4 -6
  3. data/app/controllers/foreman_inventory_upload/uploads_controller.rb +33 -7
  4. data/app/controllers/foreman_rh_cloud/react_controller.rb +11 -0
  5. data/app/controllers/insights_cloud/tasks_controller.rb +8 -0
  6. data/app/helpers/foreman_inventory_upload_host_helper.rb +11 -0
  7. data/app/models/insights_facet.rb +3 -0
  8. data/app/models/insights_hit.rb +6 -0
  9. data/app/models/setting/rh_cloud.rb +15 -0
  10. data/app/overrides/hosts_list.rb +13 -0
  11. data/app/views/foreman_rh_cloud/react/insights_cloud.html.erb +1 -0
  12. data/app/views/foreman_rh_cloud/react/inventory_upload.html.erb +1 -0
  13. data/app/views/{foreman_inventory_upload/layouts/react.html.erb → layouts/foreman_rh_cloud/application.html.erb} +2 -2
  14. data/config/routes.rb +12 -1
  15. data/db/migrate/20191215104806_create_insights_hits.foreman_inventory_upload.rb +14 -0
  16. data/db/migrate/20191216062008_create_insights_facets.foreman_inventory_upload.rb +7 -0
  17. data/lib/foreman_inventory_upload.rb +12 -0
  18. data/lib/foreman_inventory_upload/async/async_helpers.rb +13 -0
  19. data/lib/foreman_inventory_upload/async/generate_all_reports_job.rb +8 -0
  20. data/lib/foreman_inventory_upload/async/shell_process.rb +3 -1
  21. data/lib/foreman_inventory_upload/generators/archived_report.rb +6 -3
  22. data/lib/foreman_inventory_upload/generators/fact_helpers.rb +56 -0
  23. data/lib/foreman_inventory_upload/generators/queries.rb +7 -0
  24. data/lib/foreman_inventory_upload/generators/slice.rb +34 -12
  25. data/lib/foreman_inventory_upload/notifications/manifest_import_success_notification_override.rb +19 -0
  26. data/lib/foreman_rh_cloud/engine.rb +33 -5
  27. data/lib/foreman_rh_cloud/version.rb +1 -1
  28. data/lib/insights_cloud.rb +15 -0
  29. data/lib/insights_cloud/async/insights_full_sync.rb +92 -0
  30. data/test/controllers/accounts_controller_test.rb +8 -3
  31. data/test/controllers/uploads_controller_test.rb +13 -0
  32. data/test/jobs/insights_full_sync_test.rb +62 -0
  33. data/test/unit/archived_report_generator_test.rb +1 -0
  34. data/test/unit/fact_helpers_test.rb +29 -0
  35. data/test/unit/slice_generator_test.rb +249 -13
  36. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountList.fixtures.js +14 -2
  37. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountList.js +13 -10
  38. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListActions.js +6 -3
  39. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListHelper.js +10 -0
  40. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListReducer.js +16 -0
  41. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListSelectors.js +10 -1
  42. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyResults/EmptyResults.js +15 -0
  43. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyResults/__tests__/EmptyResults.test.js +13 -0
  44. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyResults/__tests__/__snapshots__/EmptyResults.test.js.snap +18 -0
  45. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyResults/emptyResults.scss +7 -0
  46. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyResults/index.js +1 -0
  47. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItem/ListItem.js +1 -4
  48. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountList.test.js +1 -0
  49. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListActions.test.js +8 -1
  50. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListHelper.test.js +12 -0
  51. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListIntegration.test.js +1 -1
  52. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListReducer.test.js +22 -0
  53. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListSelectors.test.js +20 -8
  54. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountList.test.js.snap +2 -3
  55. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListActions.test.js.snap +20 -2
  56. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListReducer.test.js.snap +20 -0
  57. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListSelectors.test.js.snap +8 -2
  58. data/webpack/ForemanInventoryUpload/Components/AccountList/index.js +2 -0
  59. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/AutoUploadSwitcher.fixtures.js +1 -0
  60. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/AutoUploadSwitcher.js +32 -0
  61. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/AutoUploadSwitcherActions.js +30 -0
  62. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/AutoUploadSwitcherConstants.js +2 -0
  63. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/__tests__/AutoUploadSwitcher.test.js +14 -0
  64. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/__tests__/AutoUploadSwitcherActions.test.js +14 -0
  65. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/__tests__/__snapshots__/AutoUploadSwitcher.test.js.snap +38 -0
  66. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/__tests__/__snapshots__/AutoUploadSwitcherActions.test.js.snap +14 -0
  67. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/autoUploadSwitcher.scss +3 -0
  68. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/index.js +17 -0
  69. data/webpack/ForemanInventoryUpload/Components/Dashboard/DashboardActions.js +4 -3
  70. data/webpack/ForemanInventoryUpload/Components/Dashboard/DashboardSelectors.js +1 -1
  71. data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/DashboardActions.test.js +2 -3
  72. data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/DashboardIntegration.test.js +2 -1
  73. data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/DashboardSelectors.test.js +3 -2
  74. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/HostObfuscationSwitcher.fixtures.js +1 -0
  75. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/HostObfuscationSwitcher.js +29 -0
  76. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/HostObfuscationSwitcherActions.js +30 -0
  77. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/HostObfuscationSwitcherConstants.js +3 -0
  78. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/__tests__/HostObfuscationSwitcher.test.js +14 -0
  79. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/__tests__/HostObfuscationSwitcherActions.test.js +14 -0
  80. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/__tests__/__snapshots__/HostObfuscationSwitcher.test.js.snap +38 -0
  81. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/__tests__/__snapshots__/HostObfuscationSwitcherActions.test.js.snap +14 -0
  82. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/hostObfuscationSwitcher.scss +0 -0
  83. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/index.js +20 -0
  84. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/Components/ClearButton/ClearButton.js +26 -0
  85. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/Components/ClearButton/index.js +1 -0
  86. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/InventoryFilter.fixtures.js +2 -0
  87. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/InventoryFilter.js +39 -0
  88. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/InventoryFilterActions.js +16 -0
  89. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/InventoryFilterConstants.js +3 -0
  90. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/InventoryFilterReducer.js +36 -0
  91. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/InventoryFilterSelectors.js +7 -0
  92. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/InventoryFilter.test.js +14 -0
  93. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/InventoryFilterActions.test.js +14 -0
  94. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/InventoryFilterReducer.test.js +35 -0
  95. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/InventoryFilterSelectors.test.js +21 -0
  96. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/__snapshots__/InventoryFilter.test.js.snap +25 -0
  97. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/__snapshots__/InventoryFilterActions.test.js.snap +17 -0
  98. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/__snapshots__/InventoryFilterReducer.test.js.snap +25 -0
  99. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/__snapshots__/InventoryFilterSelectors.test.js.snap +9 -0
  100. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/__snapshots__/integration.test.js.snap +31 -0
  101. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/integration.test.js +18 -0
  102. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/index.js +17 -0
  103. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/inventoryFilter.scss +28 -0
  104. data/webpack/ForemanInventoryUpload/Components/InventorySettings/InventorySettings.js +15 -0
  105. data/webpack/ForemanInventoryUpload/Components/InventorySettings/__tests__/InventorySettings.test.js +13 -0
  106. data/webpack/ForemanInventoryUpload/Components/InventorySettings/__tests__/__snapshots__/InventorySettings.test.js.snap +13 -0
  107. data/webpack/ForemanInventoryUpload/Components/InventorySettings/index.js +1 -0
  108. data/webpack/ForemanInventoryUpload/Components/InventorySettings/inventorySettings.scss +15 -0
  109. data/webpack/ForemanInventoryUpload/Components/PageHeader/PageHeader.js +40 -0
  110. data/webpack/ForemanInventoryUpload/Components/PageHeader/__tests__/PageHeader.test.js +13 -0
  111. data/webpack/ForemanInventoryUpload/Components/PageHeader/__tests__/__snapshots__/PageHeader.test.js.snap +61 -0
  112. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/DocsButton/DocsButton.js +17 -0
  113. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/DocsButton/__tests__/DocsButton.test.js +13 -0
  114. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/DocsButton/__tests__/__snapshots__/DocsButton.test.js.snap +20 -0
  115. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/DocsButton/index.js +1 -0
  116. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/HistoryButton/HistoryButton.js +18 -0
  117. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/HistoryButton/__tests__/HistoryButton.test.js +14 -0
  118. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/HistoryButton/__tests__/__snapshots__/HistoryButton.test.js.snap +21 -0
  119. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/HistoryButton/index.js +1 -0
  120. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/PageDescription.js +24 -0
  121. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/__tests__/PageDescription.test.js +11 -0
  122. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/__tests__/__snapshots__/PageDescription.test.js.snap +17 -0
  123. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/index.js +1 -0
  124. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/ToolbarButtons.js +13 -0
  125. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/__tests__/ToolbarButtons.test.js +12 -0
  126. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/__tests__/__snapshots__/ToolbarButtons.test.js.snap +10 -0
  127. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/index.js +1 -0
  128. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/toolbarButtons.scss +7 -0
  129. data/webpack/ForemanInventoryUpload/Components/PageHeader/index.js +1 -0
  130. data/webpack/ForemanInventoryUpload/Components/PageHeader/pageHeader.scss +3 -0
  131. data/webpack/ForemanInventoryUpload/Components/ScheduledRun/ScheduledRun.fixtures.js +1 -0
  132. data/webpack/ForemanInventoryUpload/Components/ScheduledRun/ScheduledRun.js +4 -2
  133. data/webpack/ForemanInventoryUpload/Components/ScheduledRun/__tests__/ScheduledRun.test.js +0 -1
  134. data/webpack/ForemanInventoryUpload/Components/ScheduledRun/__tests__/__snapshots__/ScheduledRun.test.js.snap +0 -2
  135. data/webpack/ForemanInventoryUpload/Components/ScheduledRun/index.js +12 -1
  136. data/webpack/ForemanInventoryUpload/Components/TabBody/__tests__/__snapshots__/TabBody.test.js.snap +1 -1
  137. data/webpack/ForemanInventoryUpload/ForemanInventoryConstants.js +7 -0
  138. data/webpack/ForemanInventoryUpload/ForemanInventoryHelpers.js +12 -0
  139. data/webpack/ForemanInventoryUpload/ForemanInventoryUpload.js +18 -9
  140. data/webpack/ForemanInventoryUpload/ForemanInventoryUploadReducers.js +4 -4
  141. data/webpack/ForemanInventoryUpload/SubscriptionsPageExtension/SubscriptionsPageExtensionActions.js +34 -0
  142. data/webpack/ForemanInventoryUpload/__tests__/ForemanInventoryHelpers.test.js +12 -0
  143. data/webpack/ForemanInventoryUpload/{ForemanInventoryUpload.test.js → __tests__/ForemanInventoryUpload.test.js} +1 -1
  144. data/webpack/ForemanInventoryUpload/__tests__/__snapshots__/ForemanInventoryHelpers.test.js.snap +5 -0
  145. data/webpack/ForemanInventoryUpload/{__snapshots__ → __tests__/__snapshots__}/ForemanInventoryUpload.test.js.snap +6 -5
  146. data/webpack/ForemanRhCloudHelpers.js +6 -0
  147. data/webpack/ForemanRhCloudReducers.js +10 -0
  148. data/webpack/ForemanRhCloudSelectors.js +5 -0
  149. data/webpack/ForemanRhCloudTestHelpers.js +6 -0
  150. data/webpack/InsightsCloudSync/InsightsCloudSync.js +26 -0
  151. data/webpack/InsightsCloudSync/InsightsCloudSync.test.js +13 -0
  152. data/webpack/InsightsCloudSync/InsightsCloudSyncActions.js +23 -0
  153. data/webpack/InsightsCloudSync/InsightsCloudSyncConstants.js +6 -0
  154. data/webpack/InsightsCloudSync/InsightsCloudSyncHelpers.js +3 -0
  155. data/webpack/InsightsCloudSync/InsightsCloudSyncReducers.js +3 -0
  156. data/webpack/InsightsCloudSync/__snapshots__/InsightsCloudSync.test.js.snap +25 -0
  157. data/webpack/InsightsCloudSync/__tests__/InsightsCloudSyncHelpers.test.js +11 -0
  158. data/webpack/InsightsCloudSync/__tests__/__snapshots__/InsightsCloudSyncHelpers.test.js.snap +3 -0
  159. data/webpack/InsightsCloudSync/index.js +17 -0
  160. data/webpack/__mocks__/foremanReact/components/Layout/LayoutConstants.js +1 -0
  161. data/webpack/__tests__/ForemanRhCloudHelpers.test.js +11 -0
  162. data/webpack/__tests__/ForemanRhCloudSelectors.test.js +19 -0
  163. data/webpack/__tests__/ForemanRhCloudTestHelpers.test.js +10 -0
  164. data/webpack/__tests__/__snapshots__/ForemanRhCloudHelpers.test.js.snap +3 -0
  165. data/webpack/__tests__/__snapshots__/ForemanRhCloudSelectors.test.js.snap +24 -0
  166. data/webpack/__tests__/__snapshots__/ForemanRhCloudTestHelpers.test.js.snap +14 -0
  167. data/webpack/index.js +8 -1
  168. data/webpack/subscriptions_extension_index.js +8 -0
  169. metadata +124 -7
  170. data/app/controllers/foreman_inventory_upload/react_controller.rb +0 -7
  171. data/webpack/ForemanInventoryUpload/ForemanInventoryUploadSelectors.js +0 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 74f7aec361b1006ae16a1e49f3c1bbf0ce5916a48849638bebc68b3b4dacde5b
4
- data.tar.gz: 2e5f90b72fbd9759f97418d13936b8e0a49d2c9add73b0f8ad5780fb860f5dce
3
+ metadata.gz: 90a809c493cd6f251d29d9e126c7e2ee3e9bf2b63cd6f9e723da166764f47502
4
+ data.tar.gz: 13118ce2cc5c2580485b148842b2d972445ad2f1032bfb1bc27e5ecaeac29a54
5
5
  SHA512:
6
- metadata.gz: feec26a018a4b92c0d9d1777d9ba4633d142c6cb8f7bf109058c222af18d06ab8ab8ce52e1998739539fb4bcece3d5fb893e872b48f2c227b0714005cb2b2ff9
7
- data.tar.gz: 4cfeacaaf11a06f0d2b15840bb1fd01738a2101b5f2d9045ae9f7d58af52a14da009edfebcfd40c77079c17daffb2955e4d548cd2c4ff3879eae1f9ca7ce1191
6
+ metadata.gz: 63a34e66722cb135b56609eb61897c0ac567eb036e0cc7ef8515b0439876b300ecac26835bb881033b22dd18885357a89e743bdf4e9fb50331611b866f483749
7
+ data.tar.gz: f6a402750f8bf71ecdedecb5a2548fd74048e8a1c83a6d31e4ca094e3d034546d6d598c7901396cca8a0c690abf5cf9c947e7aa60ef14d6c6dc4c616bb70e6a7
@@ -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
- labels = Organization.all.pluck(:id, :name)
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
- path = Rails.root.join(ForemanInventoryUpload.uploads_folder, filename)
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 path, disposition: 'attachment', filename: filename
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 ForemanRhCloud
2
+ class ReactController < ::ApplicationController
3
+ layout "foreman_rh_cloud/application"
4
+
5
+ def inventory_upload
6
+ end
7
+
8
+ def insights_cloud
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,8 @@
1
+ module InsightsCloud
2
+ class TasksController < ::ApplicationController
3
+ def create
4
+ selected_org = Organization.current
5
+ InsightsCloud::Async::InsightsFullSync.perform_now(selected_org)
6
+ end
7
+ end
8
+ 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,3 @@
1
+ class InsightsFacet < HostFacets::Base
2
+ has_many :hits, foreign_key: :host_id, primary_key: :host_id, class_name: 'InsightsHit'
3
+ end
@@ -0,0 +1,6 @@
1
+ class InsightsHit < ApplicationRecord
2
+ has_one :host
3
+ # since the facet is one-to-one association with a host, we can connect
4
+ # through host_id column on both this model and facet.
5
+ has_one :insights_facet, foreign_key: 'host_id', primary_key: 'host_id'
6
+ 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'), true),
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('InsightsCloudSync', '#ForemanRhCloudReactRoot') %>
@@ -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="ForemanInventoryUploadReactRoot"></div>
13
+ <div id="ForemanRhCloudReactRoot"></div>
14
+ <%= yield %>
14
15
  <% end %>
15
16
  <%= render file: "layouts/base" %>
16
- <%= mount_react_component('ForemanInventoryUpload', '#ForemanInventoryUploadReactRoot') %>
@@ -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
@@ -0,0 +1,7 @@
1
+ class CreateInsightsFacets < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table :insights_facets do |t|
4
+ t.references :host, foreign_key: true, null: false
5
+ end
6
+ end
7
+ 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(
@@ -0,0 +1,13 @@
1
+ module ForemanInventoryUpload
2
+ module Async
3
+ module AsyncHelpers
4
+ extend ActiveSupport::Concern
5
+
6
+ def hash_to_s(hash)
7
+ hash.each_with_object({}) do |(k, v), a|
8
+ a[k.to_s] = v.to_s
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -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
- hosts_count = hosts_batch.count
20
- @logger.info "Adding slice #{slice_id} with #{hosts_count} hosts"
21
- generate_slice(tmpdir, slice_id, hosts_batch)
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
@@ -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&.pools&.first
29
+ next unless host&.subscription_facet
28
30
  @stream.comma unless first
29
- first = false if report_host(host)
31
+ if report_host(host)
32
+ first = false
33
+ @hosts_count += 1
34
+ end
30
35
  end
31
36
  end
32
37
  end
@@ -34,11 +39,10 @@ module ForemanInventoryUpload
34
39
 
35
40
  def report_host(host)
36
41
  @stream.object do
37
- @stream.simple_field('display_name', host.name)
38
- @stream.simple_field('fqdn', host.fqdn)
39
- @stream.simple_field('account', host.subscription_facet.pools.first.account_number.to_s)
40
- @stream.simple_field('subscription_manager_id', host.subscription_facet.uuid)
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
48
  @stream.array_field('ip_addresses') do
@@ -65,7 +69,7 @@ module ForemanInventoryUpload
65
69
 
66
70
  @stream.array_field('tags', :last) do
67
71
  report_tag('satellite', 'satellite_instance_id', Foreman.instance_id) if Foreman.respond_to?(:instance_id)
68
- report_tag('satellite', 'organization_id', host.organization_id, :last)
72
+ report_tag('satellite', 'organization_id', host.organization_id.to_s, :last)
69
73
  end
70
74
  end
71
75
  end
@@ -105,12 +109,24 @@ module ForemanInventoryUpload
105
109
  end.join(', '))
106
110
  end
107
111
  end
108
- @stream.simple_field('os_release', fact_value(host, 'distribution::name'))
112
+ @stream.simple_field(
113
+ 'os_release',
114
+ os_release_value(
115
+ name: fact_value(host, 'distribution::name'),
116
+ version: fact_value(host, 'distribution::version'),
117
+ codename: fact_value(host, 'distribution::id')
118
+ )
119
+ )
109
120
  @stream.simple_field('os_kernel_version', fact_value(host, 'uname::release'))
110
121
  @stream.simple_field('arch', host.architecture&.name)
111
122
  @stream.simple_field('subscription_status', host.subscription_status_label)
112
123
  @stream.simple_field('katello_agent_running', host.content_facet&.katello_agent_installed?)
113
124
  @stream.simple_field('satellite_managed', true)
125
+ @stream.simple_field(
126
+ 'infrastructure_type',
127
+ ActiveModel::Type::Boolean.new.cast(fact_value(host, 'virt::is_guest')) ? 'virtual' : 'physical'
128
+ )
129
+ @stream.simple_field('cloud_provider', cloud_provider(host))
114
130
  unless (installed_products = host.subscription_facet&.installed_products).empty?
115
131
  @stream.array_field('installed_products') do
116
132
  @stream.raw(installed_products.map do |product|
@@ -131,17 +147,23 @@ module ForemanInventoryUpload
131
147
  end
132
148
 
133
149
  def report_satellite_facts(host)
134
- @stream.simple_field('virtual_host_name', host.subscription_facet.hypervisor_host&.name)
135
- @stream.simple_field('virtual_host_uuid', host.subscription_facet.hypervisor_host&.subscription_facet&.uuid)
150
+ @stream.simple_field('virtual_host_name', host.subscription_facet&.hypervisor_host&.name)
151
+ @stream.simple_field('virtual_host_uuid', host.subscription_facet&.hypervisor_host&.subscription_facet&.uuid)
136
152
  if defined?(ForemanThemeSatellite)
137
153
  @stream.simple_field('satellite_version', ForemanThemeSatellite::SATELLITE_VERSION)
138
154
  end
139
155
  @stream.simple_field('system_purpose_usage', host.subscription_facet.purpose_usage)
140
156
  @stream.simple_field('system_purpose_role', host.subscription_facet.purpose_role)
141
157
  @stream.simple_field('distribution_version', fact_value(host, 'distribution::version'))
142
- @stream.simple_field('satellite_instance_id', Foreman.respond_to?(:instance_id) ? Foreman.instance_id : nil)
158
+ @stream.simple_field('satellite_instance_id', Foreman.try(:instance_id))
159
+ @stream.simple_field('is_simple_content_access', golden_ticket?(host.organization))
160
+ @stream.simple_field('is_hostname_obfuscated', !!obfuscate_hostname?(host))
143
161
  @stream.simple_field('organization_id', host.organization_id, :last)
144
162
  end
163
+
164
+ def os_release_value(name:, version:, codename:)
165
+ "#{name} #{version} (#{codename})"
166
+ end
145
167
  end
146
168
  end
147
169
  end