foreman_rh_cloud 1.0.7 → 1.0.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (199) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +33 -0
  3. data/app/controllers/foreman_inventory_upload/accounts_controller.rb +2 -0
  4. data/app/controllers/foreman_inventory_upload/tasks_controller.rb +25 -0
  5. data/app/controllers/foreman_inventory_upload/uploads_controller.rb +22 -3
  6. data/app/controllers/foreman_rh_cloud/react_controller.rb +3 -0
  7. data/app/controllers/insights_cloud/hits_controller.rb +17 -0
  8. data/app/controllers/insights_cloud/settings_controller.rb +24 -0
  9. data/app/controllers/insights_cloud/tasks_controller.rb +7 -0
  10. data/app/helpers/foreman_inventory_upload_host_helper.rb +20 -0
  11. data/app/models/concerns/rh_cloud_host.rb +12 -0
  12. data/app/models/insights_facet.rb +7 -0
  13. data/app/models/insights_hit.rb +6 -0
  14. data/app/models/inventory_sync/inventory_status.rb +30 -0
  15. data/app/models/setting/rh_cloud.rb +3 -1
  16. data/app/overrides/hosts_list.rb +13 -0
  17. data/app/views/foreman_rh_cloud/react/insights_cloud.html.erb +6 -0
  18. data/app/views/foreman_rh_cloud/react/inventory_upload.html.erb +1 -1
  19. data/app/views/hosts/_insights_tab.html.erb +15 -0
  20. data/config/routes.rb +11 -0
  21. data/db/migrate/20191215104806_create_insights_hits.foreman_inventory_upload.rb +14 -0
  22. data/db/migrate/20191216062008_create_insights_facets.foreman_inventory_upload.rb +7 -0
  23. data/db/migrate/20200727111529_add_uuid_column_to_insights_facets.foreman_rh_cloud.rb +5 -0
  24. data/lib/foreman_inventory_upload.rb +4 -0
  25. data/lib/foreman_inventory_upload/async/generate_report_job.rb +1 -1
  26. data/lib/foreman_inventory_upload/async/shell_process.rb +15 -9
  27. data/lib/foreman_inventory_upload/async/upload_report_job.rb +21 -9
  28. data/lib/foreman_inventory_upload/generators/fact_helpers.rb +1 -1
  29. data/lib/foreman_inventory_upload/generators/json_stream.rb +10 -0
  30. data/lib/foreman_inventory_upload/generators/metadata.rb +3 -0
  31. data/lib/foreman_inventory_upload/generators/queries.rb +2 -4
  32. data/lib/foreman_inventory_upload/generators/slice.rb +40 -13
  33. data/lib/foreman_inventory_upload/notifications/manifest_import_success_notification_override.rb +19 -0
  34. data/lib/foreman_rh_cloud.rb +67 -0
  35. data/lib/foreman_rh_cloud/engine.rb +36 -9
  36. data/lib/foreman_rh_cloud/version.rb +1 -1
  37. data/lib/insights_cloud.rb +15 -0
  38. data/lib/insights_cloud/async/insights_full_sync.rb +105 -0
  39. data/lib/insights_cloud/async/insights_scheduled_sync.rb +23 -0
  40. data/lib/inventory_sync/async/host_result.rb +50 -0
  41. data/lib/inventory_sync/async/inventory_full_sync.rb +101 -0
  42. data/lib/tasks/insights.rake +15 -0
  43. data/lib/tasks/rh_cloud_inventory.rake +37 -0
  44. data/package.json +3 -1
  45. data/test/controllers/insights_sync/settings_controller_test.rb +30 -0
  46. data/test/factories/insights_factories.rb +31 -0
  47. data/test/jobs/insights_full_sync_test.rb +94 -0
  48. data/test/jobs/inventory_full_sync_test.rb +91 -0
  49. data/test/jobs/upload_report_job_test.rb +34 -0
  50. data/test/unit/insights_facet_test.rb +16 -0
  51. data/test/unit/metadata_generator_test.rb +2 -0
  52. data/test/unit/rh_cloud_http_proxy_test.rb +65 -0
  53. data/test/unit/slice_generator_test.rb +73 -10
  54. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountList.fixtures.js +8 -0
  55. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListActions.js +3 -1
  56. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListReducer.js +11 -1
  57. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListSelectors.js +9 -0
  58. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListActions.test.js +8 -1
  59. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListReducer.test.js +13 -0
  60. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListSelectors.test.js +7 -2
  61. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListActions.test.js.snap +21 -2
  62. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListReducer.test.js.snap +11 -0
  63. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListSelectors.test.js.snap +3 -0
  64. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/AutoUploadSwitcher.js +6 -6
  65. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/__tests__/__snapshots__/AutoUploadSwitcher.test.js.snap +9 -9
  66. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/autoUploadSwitcher.scss +1 -1
  67. data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/DashboardActions.test.js +2 -2
  68. data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/DashboardSelectors.test.js +2 -2
  69. data/webpack/ForemanInventoryUpload/Components/FullScreenModal/FullScreenModal.js +5 -1
  70. data/webpack/ForemanInventoryUpload/Components/FullScreenModal/__tests__/__snapshots__/FullScreenModal.test.js.snap +1 -0
  71. data/webpack/ForemanInventoryUpload/Components/FullScreenModal/fullScreenModal.scss +15 -13
  72. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/HostObfuscationSwitcher.fixtures.js +1 -0
  73. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/HostObfuscationSwitcher.js +29 -0
  74. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/HostObfuscationSwitcherActions.js +30 -0
  75. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/HostObfuscationSwitcherConstants.js +3 -0
  76. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/__tests__/HostObfuscationSwitcher.test.js +14 -0
  77. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/__tests__/HostObfuscationSwitcherActions.test.js +14 -0
  78. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/__tests__/__snapshots__/HostObfuscationSwitcher.test.js.snap +38 -0
  79. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/__tests__/__snapshots__/HostObfuscationSwitcherActions.test.js.snap +14 -0
  80. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/hostObfuscationSwitcher.scss +0 -0
  81. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/index.js +20 -0
  82. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/InventoryFilterSelectors.test.js +2 -2
  83. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/__snapshots__/integration.test.js.snap +9 -0
  84. data/webpack/ForemanInventoryUpload/Components/InventorySettings/InventorySettings.js +15 -0
  85. data/webpack/ForemanInventoryUpload/Components/InventorySettings/__tests__/InventorySettings.test.js +13 -0
  86. data/webpack/ForemanInventoryUpload/Components/InventorySettings/__tests__/__snapshots__/InventorySettings.test.js.snap +13 -0
  87. data/webpack/ForemanInventoryUpload/Components/InventorySettings/index.js +1 -0
  88. data/webpack/ForemanInventoryUpload/Components/InventorySettings/inventorySettings.scss +15 -0
  89. data/webpack/ForemanInventoryUpload/Components/PageHeader/PageHeader.js +14 -4
  90. data/webpack/ForemanInventoryUpload/Components/PageHeader/__tests__/__snapshots__/PageHeader.test.js.snap +24 -5
  91. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/DocsButton/DocsButton.js +18 -0
  92. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/DocsButton/__tests__/DocsButton.test.js +13 -0
  93. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/DocsButton/__tests__/__snapshots__/DocsButton.test.js.snap +21 -0
  94. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/DocsButton/index.js +1 -0
  95. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/HistoryButton/HistoryButton.js +19 -0
  96. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/HistoryButton/__tests__/HistoryButton.test.js +14 -0
  97. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/HistoryButton/__tests__/__snapshots__/HistoryButton.test.js.snap +22 -0
  98. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/HistoryButton/index.js +1 -0
  99. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/PageDescription.js +24 -0
  100. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/__tests__/PageDescription.test.js +11 -0
  101. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/__tests__/__snapshots__/PageDescription.test.js.snap +17 -0
  102. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/index.js +1 -0
  103. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButton.js +52 -0
  104. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js +59 -0
  105. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonConstants.js +3 -0
  106. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonReducer.js +36 -0
  107. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonSelectors.js +13 -0
  108. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/SyncButton.test.js +13 -0
  109. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/SyncButtonActions.test.js +13 -0
  110. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/SyncButtonFixtures.js +9 -0
  111. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/SyncButtonReducer.test.js +33 -0
  112. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/SyncButtonSelectors.test.js +36 -0
  113. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/SyncButton.test.js.snap +26 -0
  114. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/SyncButtonActions.test.js.snap +36 -0
  115. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/SyncButtonReducer.test.js.snap +25 -0
  116. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/SyncButtonSelectors.test.js.snap +18 -0
  117. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/components/Modal.js +63 -0
  118. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/components/Toast.js +41 -0
  119. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/components/modal.scss +20 -0
  120. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/index.js +22 -0
  121. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/ToolbarButtons.js +15 -0
  122. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/__tests__/ToolbarButtons.test.js +12 -0
  123. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/__tests__/__snapshots__/ToolbarButtons.test.js.snap +11 -0
  124. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/index.js +1 -0
  125. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/toolbarButtons.scss +12 -0
  126. data/webpack/ForemanInventoryUpload/Components/StatusChart/StatusChart.js +1 -1
  127. data/webpack/ForemanInventoryUpload/Components/StatusChart/__tests__/__snapshots__/StatusChart.test.js.snap +1 -1
  128. data/webpack/ForemanInventoryUpload/Components/TabContainer/tabContainer.scss +1 -1
  129. data/webpack/ForemanInventoryUpload/ForemanInventoryConstants.js +7 -1
  130. data/webpack/ForemanInventoryUpload/ForemanInventoryHelpers.js +8 -0
  131. data/webpack/ForemanInventoryUpload/ForemanInventoryUploadReducers.js +2 -0
  132. data/webpack/ForemanInventoryUpload/SubscriptionsPageExtension/SubscriptionsPageExtensionActions.js +34 -0
  133. data/webpack/ForemanInventoryUpload/__tests__/ForemanInventoryHelpers.test.js +2 -1
  134. data/webpack/ForemanInventoryUpload/__tests__/__snapshots__/ForemanInventoryHelpers.test.js.snap +2 -0
  135. data/webpack/ForemanRhCloudPages.js +9 -0
  136. data/webpack/ForemanRhCloudReducers.js +4 -0
  137. data/webpack/ForemanRhCloudSelectors.js +7 -0
  138. data/webpack/ForemanRhCloudTestHelpers.js +17 -2
  139. data/webpack/InsightsCloudSync/Components/InsightsSettings/InsightsSettings.js +33 -0
  140. data/webpack/InsightsCloudSync/Components/InsightsSettings/InsightsSettingsActions.js +60 -0
  141. data/webpack/InsightsCloudSync/Components/InsightsSettings/InsightsSettingsConstants.js +10 -0
  142. data/webpack/InsightsCloudSync/Components/InsightsSettings/InsightsSettingsReducer.js +28 -0
  143. data/webpack/InsightsCloudSync/Components/InsightsSettings/InsightsSettingsSelectors.js +6 -0
  144. data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettings.test.js +18 -0
  145. data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsActions.test.js +46 -0
  146. data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsReducer.test.js +56 -0
  147. data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsSelectors.test.js +21 -0
  148. data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/__snapshots__/InsightsSettings.test.js.snap +15 -0
  149. data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/__snapshots__/InsightsSettingsActions.test.js.snap +31 -0
  150. data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/__snapshots__/InsightsSettingsReducer.test.js.snap +33 -0
  151. data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/__snapshots__/InsightsSettingsSelectors.test.js.snap +9 -0
  152. data/webpack/InsightsCloudSync/Components/InsightsSettings/index.js +21 -0
  153. data/webpack/InsightsCloudSync/Components/InsightsSettings/insightsSettings.scss +16 -0
  154. data/webpack/InsightsCloudSync/Components/InsightsSyncSwitcher/InsightsSyncSwitcher.fixtures.js +1 -0
  155. data/webpack/InsightsCloudSync/Components/InsightsSyncSwitcher/InsightsSyncSwitcher.js +45 -0
  156. data/webpack/InsightsCloudSync/Components/InsightsSyncSwitcher/__tests__/InsightsSyncSwitcher.test.js +17 -0
  157. data/webpack/InsightsCloudSync/Components/InsightsSyncSwitcher/__tests__/__snapshots__/InsightsSyncSwitcher.test.js.snap +38 -0
  158. data/webpack/InsightsCloudSync/Components/InsightsSyncSwitcher/index.js +1 -0
  159. data/webpack/InsightsCloudSync/Components/InsightsSyncSwitcher/insightsSyncSwitcher.scss +3 -0
  160. data/webpack/InsightsCloudSync/InsightsCloudSync.js +59 -0
  161. data/webpack/InsightsCloudSync/InsightsCloudSync.test.js +16 -0
  162. data/webpack/InsightsCloudSync/InsightsCloudSyncActions.js +23 -0
  163. data/webpack/InsightsCloudSync/InsightsCloudSyncConstants.js +6 -0
  164. data/webpack/InsightsCloudSync/InsightsCloudSyncHelpers.js +3 -0
  165. data/webpack/InsightsCloudSync/InsightsCloudSyncReducers.js +8 -0
  166. data/webpack/InsightsCloudSync/__snapshots__/InsightsCloudSync.test.js.snap +67 -0
  167. data/webpack/InsightsCloudSync/__tests__/InsightsCloudSyncHelpers.test.js +11 -0
  168. data/webpack/InsightsCloudSync/__tests__/__snapshots__/InsightsCloudSyncHelpers.test.js.snap +3 -0
  169. data/webpack/InsightsCloudSync/index.js +18 -0
  170. data/webpack/InsightsHostDetailsTab/InsightsTab.js +64 -0
  171. data/webpack/InsightsHostDetailsTab/InsightsTab.scss +86 -0
  172. data/webpack/InsightsHostDetailsTab/InsightsTabActions.js +30 -0
  173. data/webpack/InsightsHostDetailsTab/InsightsTabConstants.js +3 -0
  174. data/webpack/InsightsHostDetailsTab/InsightsTabReducer.js +26 -0
  175. data/webpack/InsightsHostDetailsTab/InsightsTabSelectors.js +3 -0
  176. data/webpack/InsightsHostDetailsTab/__tests__/InsightsTab.fixtures.js +25 -0
  177. data/webpack/InsightsHostDetailsTab/__tests__/InsightsTab.test.js +13 -0
  178. data/webpack/InsightsHostDetailsTab/__tests__/InsightsTabActions.test.js +13 -0
  179. data/webpack/InsightsHostDetailsTab/__tests__/InsightsTabIntegration.test.js +17 -0
  180. data/webpack/InsightsHostDetailsTab/__tests__/InsightsTabReducer.test.js +35 -0
  181. data/webpack/InsightsHostDetailsTab/__tests__/InsightsTabSelectors.test.js +13 -0
  182. data/webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTab.test.js.snap +30 -0
  183. data/webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTabActions.test.js.snap +20 -0
  184. data/webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTabReducer.test.js.snap +41 -0
  185. data/webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTabSelectors.test.js.snap +20 -0
  186. data/webpack/InsightsHostDetailsTab/components/ListItem/ListItem.js +69 -0
  187. data/webpack/InsightsHostDetailsTab/components/ListItem/index.js +1 -0
  188. data/webpack/InsightsHostDetailsTab/index.js +20 -0
  189. data/webpack/__mocks__/foremanReact/constants.js +5 -0
  190. data/webpack/__mocks__/foremanReact/redux/actions/toasts.js +8 -0
  191. data/webpack/__tests__/ForemanRhCloudSelectors.test.js +7 -2
  192. data/webpack/__tests__/ForemanRhCloudTestHelpers.test.js +12 -2
  193. data/webpack/__tests__/__snapshots__/ForemanRhCloudSelectors.test.js.snap +12 -2
  194. data/webpack/__tests__/__snapshots__/ForemanRhCloudTestHelpers.test.js.snap +29 -1
  195. data/webpack/index.js +2 -5
  196. data/webpack/stories/decorators/withCardsDecorator.js +1 -1
  197. data/webpack/subscriptions_extension_index.js +8 -0
  198. metadata +144 -3
  199. data/lib/tasks/generator.rake +0 -29
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cf631b63f0110a4a5d39aa664905fef695e8b402d458fe20704db84880bdf33f
4
- data.tar.gz: ac49f7073bf0e2828964587434f84275029ca0aef285f963d00ddc7e569b8197
3
+ metadata.gz: d2b83d27b99fc0f9f0a7b522230231712da3f1e96560b46e47db9d492640bb7c
4
+ data.tar.gz: 8ba8a7d0d5c08b73c313edf7f384015a98ed84e293d6f56e171d426d6f5b079e
5
5
  SHA512:
6
- metadata.gz: 9d9015a4931ab563c5d56cc38c1ea9ba54df04ebf9305f4077d5b88284b84b78da02f9dfed267192a8ce7ed49e98bf4b89e884eda8eae08a68fe8699771a9f69
7
- data.tar.gz: 45a135ff52da1cedacb37b84a70b3f73347d741e62beb95a96e0fed7cf022928649ca470b6d9242c9bfe55b790e28f2fb734f76fa0524f6548351fcc81d7b580
6
+ metadata.gz: 4115f3514b17c89258d375fdd2d14cf6919e915c1520741e2d23e4e4459652124b686493511d43c04e4f0a492e8223ee1f1333f1d52f5288fc7e76621d27ddc6
7
+ data.tar.gz: d11b69c3becd476ae2a914f8101bdf6c82904a9af0242571a8755dee930d27b264ea153d2e3f24cfb5d07826728e9dfe955a582a9ed6c1de6977d69143f137ae
data/README.md CHANGED
@@ -11,6 +11,39 @@ for how to install Foreman plugins
11
11
 
12
12
  *Usage here*
13
13
 
14
+ ### In Satellite
15
+
16
+ #### Inventory upload
17
+
18
+ In UI: Configure -> Inventory Upload -> Restart
19
+
20
+ From command-line:
21
+
22
+ export organization_id=1
23
+ export target=/var/lib/foreman/red_hat_inventory/generated_reports/
24
+ /usr/sbin/foreman-rake rh_cloud_inventory:report:generate
25
+
26
+ #### Fetch hosts remediation data
27
+
28
+ In UI: Configure -> Insights -> Sync now
29
+
30
+ From command-line:
31
+
32
+ /usr/sbin/foreman-rake rh_cloud_inventory:sync
33
+
34
+ #### Synchronize inventory status
35
+
36
+ In UI: Configure -> Inventory Upload -> Sync inventory status
37
+
38
+ From command-line:
39
+
40
+ # all organizations
41
+ /usr/sbin/foreman-rake rh_cloud_insights:sync
42
+
43
+ # specific organization with id 1
44
+ export organization_id=1
45
+ /usr/sbin/foreman-rake rh_cloud_insights:sync
46
+
14
47
  ## TODO
15
48
 
16
49
  *Todo list here*
@@ -22,6 +22,8 @@ module ForemanInventoryUpload
22
22
 
23
23
  render json: {
24
24
  autoUploadEnabled: Setting[:allow_auto_inventory_upload],
25
+ hostObfuscationEnabled: Setting[:obfuscate_inventory_hostnames],
26
+ cloudToken: Setting[:rh_cloud_token],
25
27
  accounts: accounts,
26
28
  }, status: :ok
27
29
  end
@@ -0,0 +1,25 @@
1
+ module ForemanInventoryUpload
2
+ class TasksController < ::ApplicationController
3
+ def create
4
+ selected_org = Organization.current
5
+ subscribed_hosts_ids = Set.new(
6
+ ForemanInventoryUpload::Generators::Queries.for_slice(
7
+ Host.unscoped.where(organization: selected_org)
8
+ ).pluck(:id)
9
+ )
10
+
11
+ if subscribed_hosts_ids.empty?
12
+ return render json: {
13
+ message: N_('Nothing to sync, there are no hosts with subscription for this organization.'),
14
+ }, status: :method_not_allowed
15
+ else
16
+ host_statuses = InventorySync::Async::InventoryFullSync.perform_now(selected_org)
17
+ end
18
+
19
+ render json: {
20
+ syncHosts: host_statuses[:sync],
21
+ disconnectHosts: host_statuses[:disconnect],
22
+ }, status: :ok
23
+ end
24
+ end
25
+ end
@@ -26,13 +26,32 @@ module ForemanInventoryUpload
26
26
 
27
27
  def auto_upload
28
28
  Setting[:allow_auto_inventory_upload] = auto_upload_params
29
- render json: {
30
- autoUploadEnabled: Setting[:allow_auto_inventory_upload],
31
- }
29
+ render_setting(:autoUploadEnabled, :allow_auto_inventory_upload)
30
+ end
31
+
32
+ def show_auto_upload
33
+ render_setting(:autoUploadEnabled, :allow_auto_inventory_upload)
32
34
  end
33
35
 
34
36
  def auto_upload_params
35
37
  ActiveModel::Type::Boolean.new.cast(params.require(:value))
36
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
37
56
  end
38
57
  end
@@ -4,5 +4,8 @@ module ForemanRhCloud
4
4
 
5
5
  def inventory_upload
6
6
  end
7
+
8
+ def insights_cloud
9
+ end
7
10
  end
8
11
  end
@@ -0,0 +1,17 @@
1
+ module InsightsCloud
2
+ class HitsController < ::ApplicationController
3
+ def index
4
+ host = Host.where(id: host_id_param).first
5
+
6
+ render json: {
7
+ hits: host.insights.hits,
8
+ }, status: :ok
9
+ end
10
+
11
+ private
12
+
13
+ def host_id_param
14
+ params.require(:host_id)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,24 @@
1
+ module InsightsCloud
2
+ class SettingsController < ::ApplicationController
3
+ def show
4
+ render_setting(:insightsSyncEnabled, :allow_auto_insights_sync)
5
+ end
6
+
7
+ def update
8
+ Setting[:allow_auto_insights_sync] = settings_params
9
+ render_setting(:insightsSyncEnabled, :allow_auto_insights_sync)
10
+ end
11
+
12
+ private
13
+
14
+ def render_setting(node_name, setting)
15
+ render json: {
16
+ node_name => Setting[setting],
17
+ }
18
+ end
19
+
20
+ def settings_params
21
+ ActiveModel::Type::Boolean.new.cast(params.require(:insightsSyncEnabled))
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,7 @@
1
+ module InsightsCloud
2
+ class TasksController < ::ApplicationController
3
+ def create
4
+ InsightsCloud::Async::InsightsFullSync.perform_now
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,20 @@
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 class: ['hidden-xs', 'ellipsis'] do
10
+ if host_hits
11
+ link_to(
12
+ content,
13
+ InsightsCloud::WebUi.system_url(InsightsCloud::WebUi::ADVISOR, host.insights.uuid),
14
+ :rel => 'external noopener noreferrer',
15
+ :target => '_blank'
16
+ )
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,12 @@
1
+ module RhCloudHost
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ has_many(
6
+ :inventory_upload_facts,
7
+ -> { where(fact_name_id: ForemanInventoryUpload::Generators::Queries.fact_names.values) },
8
+ class_name: 'FactValue',
9
+ :foreign_key => :host_id
10
+ )
11
+ end
12
+ end
@@ -0,0 +1,7 @@
1
+ class InsightsFacet < HostFacets::Base
2
+ has_many :hits,
3
+ foreign_key: :host_id,
4
+ primary_key: :host_id,
5
+ class_name: 'InsightsHit',
6
+ dependent: :destroy
7
+ 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,30 @@
1
+ module InventorySync
2
+ class InventoryStatus < HostStatus::Status
3
+ DISCONNECT = 0
4
+ SYNC = 1
5
+
6
+ def self.status_name
7
+ N_('Inventory')
8
+ end
9
+
10
+ def to_global(_options = {})
11
+ case status
12
+ when DISCONNECT
13
+ ::HostStatus::Global::WARN
14
+ when SYNC
15
+ ::HostStatus::Global::OK
16
+ else
17
+ ::HostStatus::Global::WARN
18
+ end
19
+ end
20
+
21
+ def to_label
22
+ case status
23
+ when DISCONNECT
24
+ N_('Host was not uploaded to your RH cloud inventory')
25
+ when SYNC
26
+ N_('Successfully uploaded to your RH cloud inventory')
27
+ end
28
+ end
29
+ end
30
+ end
@@ -3,8 +3,10 @@ class Setting::RhCloud < Setting
3
3
  return unless ActiveRecord::Base.connection.table_exists?('settings')
4
4
  return unless super
5
5
  [
6
- set('allow_auto_inventory_upload', N_('Allow automatic upload of the host inventory to the Red Hat cloud'), true),
6
+ set('allow_auto_inventory_upload', N_('Allow automatic upload of the host inventory to the Red Hat cloud'), false),
7
+ set('allow_auto_insights_sync', N_('Allow recommendations synchronization from Red Hat cloud'), false),
7
8
  set('obfuscate_inventory_hostnames', N_('Obfuscate host names sent to Red Hat cloud'), false),
9
+ 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),
8
10
  ]
9
11
  end
10
12
 
@@ -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,6 @@
1
+ <%= mount_react_component(
2
+ 'InsightsCloudSync',
3
+ '#ForemanRhCloudReactRoot',
4
+ {
5
+ settingsUrl: settings_url(search: 'name = rh_cloud_token')
6
+ }.to_json) %>
@@ -1 +1 @@
1
- <%= mount_react_component("ForemanInventoryUpload", '#ForemanRhCloudReactRoot') %>
1
+ <%= mount_react_component('ForemanInventoryUpload', '#ForemanRhCloudReactRoot') %>
@@ -0,0 +1,15 @@
1
+ <% content_for(:javascripts) do %>
2
+ <%= webpacked_plugins_js_for :'foreman_rh_cloud' %>
3
+ <% end %>
4
+
5
+ <% content_for(:stylesheets) do %>
6
+ <%= webpacked_plugins_css_for :'foreman_rh_cloud' %>
7
+ <% end %>
8
+
9
+ <div id="host_details_insights_react_container"></div>
10
+ <%= mount_react_component(
11
+ 'InsightsHostDetailsTab',
12
+ '#host_details_insights_react_container',
13
+ { hostID: host.id }.to_json,
14
+ flatten_data: true
15
+ ) %>
@@ -5,10 +5,21 @@ Rails.application.routes.draw do
5
5
  get ':organization_id/uploads/last', to: 'uploads#last', constraints: { organization_id: %r{[^\/]+} }
6
6
  get ':organization_id/uploads/file', to: 'uploads#download_file', constraints: { organization_id: %r{[^\/]+} }
7
7
  get 'accounts', to: 'accounts#index'
8
+ get 'auto_upload', to: 'uploads#show_auto_upload'
8
9
  post 'auto_upload', to: 'uploads#auto_upload'
10
+ post 'host_obfuscation', to: 'uploads#host_obfuscation'
11
+
12
+ resources :tasks, only: [:create]
13
+ end
14
+
15
+ namespace :insights_cloud do
16
+ resources :tasks, only: [:create]
17
+ resource :settings, only: [:show, :update]
18
+ get 'hits/:host_id', to: 'hits#index'
9
19
  end
10
20
 
11
21
  namespace :foreman_rh_cloud do
12
22
  get 'inventory_upload', to: 'react#inventory_upload'
23
+ get 'insights_cloud', to: 'react#insights_cloud'
13
24
  end
14
25
  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
@@ -0,0 +1,5 @@
1
+ class AddUuidColumnToInsightsFacets < ActiveRecord::Migration[5.2]
2
+ def change
3
+ add_column :insights_facets, :uuid, :string
4
+ end
5
+ end
@@ -60,4 +60,8 @@ module ForemanInventoryUpload
60
60
  FileUtils.mkdir_p(folder)
61
61
  folder
62
62
  end
63
+
64
+ def self.inventory_export_url
65
+ ForemanRhCloud.base_url + '/api/inventory/v1/hosts'
66
+ end
63
67
  end
@@ -23,7 +23,7 @@ module ForemanInventoryUpload
23
23
  end
24
24
 
25
25
  def command
26
- "#{rake_prefix}rake foreman_inventory_upload:report:generate"
26
+ "#{rake_prefix}rake rh_cloud_inventory:report:generate"
27
27
  end
28
28
 
29
29
  def env
@@ -8,24 +8,30 @@ module ForemanInventoryUpload
8
8
  def perform(instance_label)
9
9
  klass_name = self.class.name
10
10
  logger.debug("Starting #{klass_name} with label #{instance_label}")
11
- progress_output = ProgressOutput.register(instance_label)
12
- Open3.popen2e(hash_to_s(env), command) do |_stdin, stdout_stderr, wait_thread|
13
- progress_output.status = "Running in pid #{wait_thread.pid}"
11
+ progress_output_for(instance_label) do |progress_output|
12
+ Open3.popen2e(hash_to_s(env), command) do |_stdin, stdout_stderr, wait_thread|
13
+ progress_output.status = "Running in pid #{wait_thread.pid}"
14
14
 
15
- stdout_stderr.each do |out_line|
16
- progress_output.write_line(out_line)
17
- end
15
+ stdout_stderr.each do |out_line|
16
+ progress_output.write_line(out_line)
17
+ end
18
18
 
19
- progress_output.status = wait_thread.value.to_s
19
+ progress_output.status = wait_thread.value.to_s
20
+ end
20
21
  end
21
22
  logger.debug("Finished job #{klass_name} with label #{instance_label}")
22
- ensure
23
- progress_output.close
24
23
  end
25
24
 
26
25
  def command
27
26
  end
28
27
 
28
+ def progress_output_for(instance_label)
29
+ progress_output = ProgressOutput.register(instance_label)
30
+ yield(progress_output)
31
+ ensure
32
+ progress_output.close
33
+ end
34
+
29
35
  def env
30
36
  {}
31
37
  end
@@ -8,15 +8,33 @@ module ForemanInventoryUpload
8
8
  end
9
9
 
10
10
  def perform(filename, organization_id)
11
+ label = UploadReportJob.output_label(organization_id)
11
12
  @filename = filename
12
13
  @organization = Organization.find(organization_id)
13
14
 
15
+ if Setting[:content_disconnected]
16
+ progress_output_for(label) do |progress_output|
17
+ progress_output.write_line('Upload was stopped since disconnected mode setting is enabled for content on this instance.')
18
+ progress_output.status = "Task aborted, exit 1"
19
+ end
20
+ return
21
+ end
22
+
23
+ unless @organization.owner_details&.fetch('upstreamConsumer')&.fetch('idCert')
24
+ logger.info("Skipping organization '#{@organization}', no candlepin certificate defined.")
25
+ progress_output_for(label) do |progress_output|
26
+ progress_output.write_line("Skipping organization #{@organization}, no candlepin certificate defined.")
27
+ progress_output.status = "Task aborted, exit 1"
28
+ end
29
+ return
30
+ end
31
+
14
32
  Tempfile.create([@organization.name, '.pem']) do |cer_file|
15
33
  cer_file.write(rh_credentials[:cert])
16
34
  cer_file.write(rh_credentials[:key])
17
35
  cer_file.flush
18
36
  @cer_path = cer_file.path
19
- super(UploadReportJob.output_label(organization_id))
37
+ super(label)
20
38
  end
21
39
  end
22
40
 
@@ -29,6 +47,8 @@ module ForemanInventoryUpload
29
47
  'FILES' => @filename,
30
48
  'CER_PATH' => @cer_path
31
49
  )
50
+
51
+ http_proxy_string = ForemanRhCloud.http_proxy_string(logger: logger)
32
52
  if http_proxy_string
33
53
  env_vars['http_proxy'] = http_proxy_string
34
54
  env_vars['https_proxy'] = http_proxy_string
@@ -36,14 +56,6 @@ module ForemanInventoryUpload
36
56
  env_vars
37
57
  end
38
58
 
39
- def http_proxy_string
40
- @http_proxy_string ||= begin
41
- if Setting[:content_default_http_proxy]
42
- HttpProxy.unscoped.find_by(name: Setting[:content_default_http_proxy])&.full_url
43
- end
44
- end
45
- end
46
-
47
59
  def rh_credentials
48
60
  @rh_credentials ||= begin
49
61
  candlepin_id_certificate = @organization.owner_details['upstreamConsumer']['idCert']