foreman_rh_cloud 2.0.15 → 3.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (202) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/concerns/insights_cloud/candlepin_cache.rb +28 -0
  3. data/app/controllers/concerns/insights_cloud/client_authentication.rb +23 -0
  4. data/app/controllers/foreman_inventory_upload/accounts_controller.rb +9 -1
  5. data/app/controllers/foreman_inventory_upload/uploads_controller.rb +4 -6
  6. data/app/controllers/insights_cloud/api/machine_telemetries_controller.rb +73 -0
  7. data/app/controllers/insights_cloud/hits_controller.rb +24 -0
  8. data/app/controllers/insights_cloud/settings_controller.rb +8 -0
  9. data/app/controllers/insights_cloud/tasks_controller.rb +6 -1
  10. data/app/helpers/foreman_inventory_upload_host_helper.rb +1 -8
  11. data/app/models/insights_hit.rb +20 -1
  12. data/app/models/insights_resolution.rb +3 -0
  13. data/app/models/insights_rule.rb +3 -0
  14. data/app/models/setting/rh_cloud.rb +15 -3
  15. data/app/overrides/layouts/base/styles.html.erb.deface +2 -0
  16. data/app/services/foreman_rh_cloud/branch_info.rb +57 -0
  17. data/app/services/foreman_rh_cloud/cloud_connector.rb +60 -0
  18. data/app/services/foreman_rh_cloud/cloud_request_forwarder.rb +102 -0
  19. data/app/views/layouts/foreman_rh_cloud/application.html.erb +0 -4
  20. data/config/Gemfile.lock.gh_test +116 -86
  21. data/config/package-lock.json.gh_test +3085 -3943
  22. data/config/routes.rb +21 -3
  23. data/db/migrate/20210214000001_create_rules_and_resolutions.foreman_rh_cloud.rb +24 -0
  24. data/db/migrate/20210214000002_add_rule_id_to_hits.foreman_rh_cloud.rb +5 -0
  25. data/lib/foreman_inventory_upload/generators/slice.rb +3 -3
  26. data/lib/foreman_rh_cloud.rb +9 -0
  27. data/lib/foreman_rh_cloud/engine.rb +19 -6
  28. data/lib/foreman_rh_cloud/version.rb +1 -1
  29. data/lib/insights_cloud.rb +4 -0
  30. data/lib/insights_cloud/async/insights_full_sync.rb +29 -0
  31. data/lib/insights_cloud/async/insights_rules_sync.rb +80 -0
  32. data/lib/insights_cloud/async/rules_result.rb +13 -0
  33. data/package.json +19 -18
  34. data/test/controllers/insights_cloud/api/machine_telemetries_controller_test.rb +107 -0
  35. data/test/factories/insights_factories.rb +2 -1
  36. data/test/factories/inventory_upload_factories.rb +12 -0
  37. data/test/jobs/insights_full_sync_test.rb +17 -0
  38. data/test/jobs/insights_rules_sync_test.rb +198 -0
  39. data/test/unit/services/foreman_rh_cloud/branch_info_test.rb +60 -0
  40. data/test/unit/services/foreman_rh_cloud/cloud_request_forwarder_test.rb +106 -0
  41. data/test/unit/slice_generator_test.rb +29 -3
  42. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountList.fixtures.js +7 -1
  43. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountList.js +3 -2
  44. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListActions.js +1 -1
  45. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListReducer.js +2 -0
  46. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItem/ListItem.js +33 -15
  47. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItem/__tests__/__snapshots__/ListItem.test.js.snap +43 -43
  48. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItemStatus/ListItemStatus.js +6 -7
  49. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItemStatus/ListItemStatusHelper.js +5 -4
  50. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItemStatus/__tests__/__snapshots__/ListItemStatus.test.js.snap +19 -34
  51. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListActions.test.js +2 -2
  52. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountList.test.js.snap +3 -3
  53. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListActions.test.js.snap +7 -1
  54. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListReducer.test.js.snap +7 -1
  55. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListSelectors.test.js.snap +2 -2
  56. data/webpack/ForemanInventoryUpload/Components/AccountList/accountList.scss +28 -5
  57. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/AutoUploadSwitcher.js +7 -10
  58. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/AutoUploadSwitcherActions.js +1 -1
  59. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/__tests__/AutoUploadSwitcherActions.test.js +2 -2
  60. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/__tests__/__snapshots__/AutoUploadSwitcher.test.js.snap +5 -28
  61. data/webpack/ForemanInventoryUpload/Components/Dashboard/DashboardActions.js +2 -2
  62. data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/DashboardActions.test.js +6 -6
  63. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/ExcludePackagesSwitcher.js +6 -9
  64. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/ExcludePackagesSwitcherActions.js +1 -1
  65. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/__tests__/ExcludePackagesSwitcherActions.test.js +2 -2
  66. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/__tests__/__snapshots__/ExcludePackagesSwitcher.test.js.snap +5 -28
  67. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/__tests__/__snapshots__/integration.test.js.snap +5 -0
  68. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/__tests__/integration.test.js +2 -2
  69. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/HostObfuscationSwitcher.js +6 -9
  70. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/HostObfuscationSwitcherActions.js +1 -1
  71. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/__tests__/HostObfuscationSwitcherActions.test.js +2 -2
  72. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/__tests__/__snapshots__/HostObfuscationSwitcher.test.js.snap +5 -28
  73. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/InventoryFilterReducer.js +6 -3
  74. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/__snapshots__/integration.test.js.snap +5 -0
  75. data/webpack/ForemanInventoryUpload/Components/InventorySettings/InventorySettings.js +2 -2
  76. data/webpack/ForemanInventoryUpload/Components/InventorySettings/{inventorySettings.scss → InventorySettings.scss} +2 -5
  77. data/webpack/ForemanInventoryUpload/Components/InventorySettings/__tests__/__snapshots__/InventorySettings.test.js.snap +1 -1
  78. data/webpack/ForemanInventoryUpload/Components/IpsObfuscationSwitcher/IpsObfuscationSwitcher.js +6 -8
  79. data/webpack/ForemanInventoryUpload/Components/IpsObfuscationSwitcher/IpsObfuscationSwitcherActions.js +1 -1
  80. data/webpack/ForemanInventoryUpload/Components/IpsObfuscationSwitcher/__tests__/IpsObfuscationSwitcherActions.test.js +2 -2
  81. data/webpack/ForemanInventoryUpload/Components/IpsObfuscationSwitcher/__tests__/__snapshots__/IpsObfuscationSwitcher.test.js.snap +5 -28
  82. data/webpack/ForemanInventoryUpload/Components/PageHeader/PageHeader.js +12 -18
  83. data/webpack/ForemanInventoryUpload/Components/PageHeader/PageHeader.scss +31 -0
  84. data/webpack/ForemanInventoryUpload/Components/PageHeader/PageTitle.js +53 -0
  85. data/webpack/ForemanInventoryUpload/Components/PageHeader/{components/DocsButton/__tests__/DocsButton.test.js → __tests__/PageTitle.test.js} +3 -3
  86. data/webpack/ForemanInventoryUpload/Components/PageHeader/__tests__/__snapshots__/PageHeader.test.js.snap +13 -38
  87. data/webpack/ForemanInventoryUpload/Components/PageHeader/__tests__/__snapshots__/PageTitle.test.js.snap +43 -0
  88. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/CloudConnectorButton/CloudConnectorActions.js +21 -0
  89. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/CloudConnectorButton/CloudConnectorButton.js +59 -0
  90. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/CloudConnectorButton/CloudConnectorConstants.js +6 -0
  91. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/CloudConnectorButton/CloudConnectorSelectors.js +19 -0
  92. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/CloudConnectorButton/__tests__/CloudConnectorActions.test.js +9 -0
  93. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/CloudConnectorButton/__tests__/CloudConnectorButton.test.js +22 -0
  94. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/CloudConnectorButton/__tests__/__snapshots__/CloudConnectorActions.test.js.snap +11 -0
  95. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/CloudConnectorButton/__tests__/__snapshots__/CloudConnectorButton.test.js.snap +56 -0
  96. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/CloudConnectorButton/index.js +21 -0
  97. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SettingsWarning/SettingsWarning.js +64 -0
  98. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SettingsWarning/SettingsWarning.test.js +18 -0
  99. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SettingsWarning/__snapshots__/SettingsWarning.test.js.snap +30 -0
  100. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SettingsWarning/index.js +25 -0
  101. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButton.js +9 -11
  102. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js +1 -1
  103. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/SyncButton.test.js +1 -1
  104. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/SyncButtonActions.test.js +2 -2
  105. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/SyncButton.test.js.snap +7 -9
  106. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/ToolbarButtons.js +2 -4
  107. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/__tests__/__snapshots__/ToolbarButtons.test.js.snap +1 -2
  108. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/toolbarButtons.scss +5 -2
  109. data/webpack/ForemanInventoryUpload/Components/Terminal/terminal.scss +1 -0
  110. data/webpack/ForemanInventoryUpload/ForemanInventoryConstants.js +2 -2
  111. data/webpack/ForemanInventoryUpload/ForemanInventoryUpload.js +8 -14
  112. data/webpack/ForemanInventoryUpload/SubscriptionsPageExtension/InventoryAutoUpload/InventoryAutoUpload.js +92 -0
  113. data/webpack/ForemanInventoryUpload/SubscriptionsPageExtension/InventoryAutoUpload/__tests__/InventoryAutoUpload.test.js +17 -0
  114. data/webpack/ForemanInventoryUpload/SubscriptionsPageExtension/InventoryAutoUpload/__tests__/__snapshots__/InventoryAutoUpload.test.js.snap +106 -0
  115. data/webpack/ForemanInventoryUpload/SubscriptionsPageExtension/InventoryAutoUpload/components/AdvancedSettings/AdvancedSettings.js +60 -0
  116. data/webpack/ForemanInventoryUpload/SubscriptionsPageExtension/InventoryAutoUpload/components/AdvancedSettings/index.js +28 -0
  117. data/webpack/ForemanInventoryUpload/SubscriptionsPageExtension/InventoryAutoUpload/index.js +22 -0
  118. data/webpack/ForemanInventoryUpload/__tests__/__snapshots__/ForemanInventoryUpload.test.js.snap +7 -10
  119. data/webpack/ForemanRhCloudFills.js +23 -0
  120. data/webpack/ForemanRhCloudPages.js +25 -1
  121. data/webpack/ForemanRhCloudReducers.js +10 -1
  122. data/webpack/InsightsCloudSync/Components/InsightsHeader/InsightsHeader.scss +4 -0
  123. data/webpack/InsightsCloudSync/Components/InsightsHeader/index.js +16 -0
  124. data/webpack/InsightsCloudSync/Components/InsightsSettings/InsightsSettingsActions.js +1 -1
  125. data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsActions.test.js +2 -2
  126. data/webpack/InsightsCloudSync/Components/InsightsSettings/insightsSettings.scss +1 -0
  127. data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTable.js +125 -0
  128. data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableActions.js +154 -0
  129. data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableConstants.js +56 -0
  130. data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableHelpers.js +39 -0
  131. data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableReducer.js +28 -0
  132. data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableSelectors.js +78 -0
  133. data/webpack/InsightsCloudSync/Components/InsightsTable/SelectAllAlert.js +59 -0
  134. data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/InsightsTable.test.js +13 -0
  135. data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/InsightsTableActions.test.js +48 -0
  136. data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/InsightsTableSelectors.test.js +58 -0
  137. data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/__snapshots__/InsightsTable.test.js.snap +155 -0
  138. data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/__snapshots__/InsightsTableActions.test.js.snap +132 -0
  139. data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/__snapshots__/InsightsTableSelectors.test.js.snap +89 -0
  140. data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/fixtures.js +104 -0
  141. data/webpack/InsightsCloudSync/Components/InsightsTable/components/EmptyState.js +53 -0
  142. data/webpack/InsightsCloudSync/Components/InsightsTable/index.js +45 -0
  143. data/webpack/InsightsCloudSync/Components/InsightsTable/table.scss +11 -0
  144. data/webpack/InsightsCloudSync/Components/NoTokenEmptyState.js +79 -0
  145. data/webpack/InsightsCloudSync/Components/__tests__/InsightsHeader.test.js +10 -0
  146. data/webpack/InsightsCloudSync/Components/__tests__/NoTokenEmptyState.test.js +19 -0
  147. data/webpack/InsightsCloudSync/Components/__tests__/__snapshots__/InsightsHeader.test.js.snap +13 -0
  148. data/webpack/InsightsCloudSync/Components/__tests__/__snapshots__/NoTokenEmptyState.test.js.snap +214 -0
  149. data/webpack/InsightsCloudSync/InsightsCloudSync.js +47 -44
  150. data/webpack/InsightsCloudSync/InsightsCloudSync.test.js +10 -2
  151. data/webpack/InsightsCloudSync/InsightsCloudSyncActions.js +23 -20
  152. data/webpack/InsightsCloudSync/InsightsCloudSyncConstants.js +16 -2
  153. data/webpack/InsightsCloudSync/InsightsCloudSyncHelpers.js +7 -0
  154. data/webpack/InsightsCloudSync/InsightsCloudSyncReducers.js +2 -0
  155. data/webpack/InsightsCloudSync/__snapshots__/InsightsCloudSync.test.js.snap +44 -61
  156. data/webpack/InsightsCloudSync/__tests__/InsightsCloudSyncActions.test.js +9 -0
  157. data/webpack/InsightsCloudSync/__tests__/__snapshots__/InsightsCloudSyncActions.test.js.snap +11 -0
  158. data/webpack/InsightsCloudSync/index.js +11 -3
  159. data/webpack/InsightsHostDetailsTab/InsightsTab.js +5 -7
  160. data/webpack/InsightsHostDetailsTab/InsightsTabActions.js +1 -1
  161. data/webpack/InsightsHostDetailsTab/__tests__/InsightsTab.fixtures.js +12 -14
  162. data/webpack/InsightsHostDetailsTab/__tests__/InsightsTabActions.test.js +2 -2
  163. data/webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTabActions.test.js.snap +10 -12
  164. data/webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTabReducer.test.js.snap +10 -12
  165. data/webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTabSelectors.test.js.snap +10 -12
  166. data/webpack/__mocks__/foremanReact/Root/Context/ForemanContext.js +1 -0
  167. data/webpack/__mocks__/foremanReact/common/MountingService.js +1 -0
  168. data/webpack/__mocks__/foremanReact/constants.js +19 -0
  169. data/webpack/__mocks__/foremanReact/redux/API/APISelectors.js +24 -0
  170. data/webpack/__mocks__/foremanReact/redux/API/index.js +12 -0
  171. data/webpack/__mocks__/foremanReact/routes/RouterSelector.js +2 -0
  172. data/webpack/__mocks__/foremanReact/routes/common/PageLayout/PageLayout.js +10 -0
  173. data/webpack/common/Switcher/HelpLabel.js +30 -0
  174. data/webpack/common/Switcher/SwitcherPF4.js +36 -0
  175. data/webpack/common/Switcher/SwitcherPF4.scss +10 -0
  176. data/webpack/common/Switcher/__tests__/HelpLabel.test.js +13 -0
  177. data/webpack/common/Switcher/__tests__/SwitcherPF4.test.js +14 -0
  178. data/webpack/common/Switcher/__tests__/__snapshots__/HelpLabel.test.js.snap +20 -0
  179. data/webpack/common/Switcher/__tests__/__snapshots__/SwitcherPF4.test.js.snap +22 -0
  180. data/webpack/common/Switcher/index.js +79 -0
  181. data/webpack/global_index.js +7 -0
  182. data/webpack/index.js +4 -14
  183. metadata +117 -23
  184. data/app/controllers/foreman_rh_cloud/react_controller.rb +0 -11
  185. data/app/views/foreman_rh_cloud/react/insights_cloud.html.erb +0 -1
  186. data/app/views/foreman_rh_cloud/react/inventory_upload.html.erb +0 -1
  187. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItem/listItem.scss +0 -0
  188. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItemStatus/listItemStatus.scss +0 -16
  189. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/autoUploadSwitcher.scss +0 -3
  190. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/excludePackagesSwitcher.scss +0 -3
  191. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/HostObfuscationSwitcher.scss +0 -3
  192. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/DocsButton/DocsButton.js +0 -18
  193. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/DocsButton/__tests__/__snapshots__/DocsButton.test.js.snap +0 -21
  194. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/DocsButton/index.js +0 -1
  195. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/HistoryButton/HistoryButton.js +0 -19
  196. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/HistoryButton/__tests__/HistoryButton.test.js +0 -12
  197. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/HistoryButton/__tests__/__snapshots__/HistoryButton.test.js.snap +0 -22
  198. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/HistoryButton/index.js +0 -1
  199. data/webpack/ForemanInventoryUpload/Components/PageHeader/pageHeader.scss +0 -3
  200. data/webpack/ForemanInventoryUpload/SubscriptionsPageExtension/SubscriptionsPageExtensionActions.js +0 -34
  201. data/webpack/__mocks__/foremanReact/API.js +0 -7
  202. data/webpack/subscriptions_extension_index.js +0 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f471a3f5124bd751cc9059d2eb0a4b25df07fc234928f1ec2c3f30a980bd0709
4
- data.tar.gz: 5080948b90534cc195661776fcfa71de4caa23e9589dfda3cbb9326927033766
3
+ metadata.gz: de4c573e51011ac6fd99707859fa86d659454b7f30183494ab5e240e773bec0a
4
+ data.tar.gz: f0510f09adf430834e01b9732a9cf6faedff0b18471e7b90fbca8a47fe867a13
5
5
  SHA512:
6
- metadata.gz: 24dd90a5e2f290c6d898b75840ba923f26e7ff95f1c6e99ef4f836c68874fc567bb02457b05d94b6136ec0723f4b72804c975a9aa32f3b06c8a717d1cd0ba593
7
- data.tar.gz: 8e74afc6e8d07b6505adbf268a0cc1705c3544ee87e369cd66806338671e585879500528485a3ed60f103c6d3394bdcaa99c65dae95add382b0d766d294438d7
6
+ metadata.gz: a5ef31993d25982136027082f9fb3d382133378627afd0f5da6eeb5eb24a971aa36cdb7f8995347b017ab438124219113e6b326a52f1821e0ccbdb0a6e402f52
7
+ data.tar.gz: e5da37635a059fadc6e6c62464aec98f75e803fddb1f8b1ca9b23ad27e42cffdb006bdd4ae5e59d10317d8599f6629ff8f4e08065a15947aff7f93133ec49e8a
@@ -0,0 +1,28 @@
1
+ module InsightsCloud
2
+ module CandlepinCache
3
+ extend ActiveSupport::Concern
4
+
5
+ def upstream_owner(org)
6
+ # We use a cache because owner_details is a call to Candlepin
7
+ Rails.cache.fetch("rh_cloud_upstream_owner_#{org.id}", expires_in: 1.minute) do
8
+ org.owner_details['upstreamConsumer']
9
+ end
10
+ end
11
+
12
+ def cp_owner_id(org)
13
+ owner = upstream_owner(org)
14
+ owner['uuid'] if owner
15
+ end
16
+
17
+ def candlepin_id_cert(org)
18
+ owner = upstream_owner(org)
19
+ return unless owner
20
+ id_cert = {
21
+ cert: owner.dig('idCert', 'cert'),
22
+ key: owner.dig('idCert', 'key'),
23
+ }
24
+ return unless id_cert.values.all?
25
+ id_cert
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,23 @@
1
+ module InsightsCloud
2
+ module ClientAuthentication
3
+ extend ActiveSupport::Concern
4
+
5
+ include ::Katello::Authentication::ClientAuthentication
6
+
7
+ def authorize
8
+ client_authorized? || super
9
+ end
10
+
11
+ def client_authorized?
12
+ authenticate_client && valid_machine_user?
13
+ end
14
+
15
+ def valid_machine_user?
16
+ subscribed_host_by_uuid(User.current.uuid).present?
17
+ end
18
+
19
+ def subscribed_host_by_uuid(uuid)
20
+ @host = Host.unscoped.joins(:subscription_facet).where(:katello_subscription_facets => {:uuid => uuid }).first
21
+ end
22
+ end
23
+ end
@@ -24,14 +24,22 @@ module ForemanInventoryUpload
24
24
  autoUploadEnabled: Setting[:allow_auto_inventory_upload],
25
25
  hostObfuscationEnabled: Setting[:obfuscate_inventory_hostnames],
26
26
  ipsObfuscationEnabled: Setting[:obfuscate_inventory_ips],
27
- cloudToken: Setting[:rh_cloud_token],
27
+ cloudToken: !Setting[:rh_cloud_token].empty?,
28
28
  excludePackages: Setting[:exclude_installed_packages],
29
29
  accounts: accounts,
30
+ CloudConnectorStatus: cloud_connector_status,
30
31
  }, status: :ok
31
32
  end
32
33
 
33
34
  private
34
35
 
36
+ def cloud_connector_status
37
+ cloud_connector = ForemanRhCloud::CloudConnector.new
38
+ job = cloud_connector&.latest_job
39
+ return nil unless job
40
+ { id: job.id, task: ForemanTasks::Task.where(:id => job.task_id).first }
41
+ end
42
+
35
43
  def status_for(label, job_class)
36
44
  label = job_class.output_label(label)
37
45
  ForemanInventoryUpload::Async::ProgressOutput.get(label)&.status
@@ -14,14 +14,12 @@ module ForemanInventoryUpload
14
14
  files = Dir["{#{ForemanInventoryUpload.uploads_file_path(filename)},#{ForemanInventoryUpload.done_file_path(filename)}}"]
15
15
 
16
16
  return send_file files.first, disposition: 'attachment', filename: filename unless files.empty?
17
- throw_flash_error "File doesn't exist"
17
+ raise ::Foreman::Exception.new("The report file doesn't exist")
18
18
  end
19
19
 
20
- def throw_flash_error(message)
21
- process_error(
22
- :redirect => foreman_inventory_upload_index_path,
23
- :error_msg => message
24
- )
20
+ def enable_cloud_connector
21
+ cloud_connector = ForemanRhCloud::CloudConnector.new
22
+ render json: cloud_connector.install.to_json
25
23
  end
26
24
 
27
25
  def auto_upload
@@ -0,0 +1,73 @@
1
+ module InsightsCloud::Api
2
+ class MachineTelemetriesController < ::Api::V2::BaseController
3
+ layout false
4
+
5
+ include ::InsightsCloud::ClientAuthentication
6
+ include ::InsightsCloud::CandlepinCache
7
+
8
+ before_action :cert_uuid, :ensure_org, :ensure_branch_id, :only => [:forward_request, :branch_info]
9
+ before_action :ensure_telemetry_enabled_for_consumer, :only => [:forward_request]
10
+
11
+ skip_after_action :log_response_body, :only => [:forward_request]
12
+ skip_before_action :check_media_type, :only => [:forward_request]
13
+
14
+ # The method that "proxies" requests over to Cloud
15
+ def forward_request
16
+ certs = candlepin_id_cert @organization
17
+ cloud_response = ::ForemanRhCloud::CloudRequestForwarder.new.forward_request(request, controller_name, @branch_id, certs)
18
+
19
+ if cloud_response.code == 401
20
+ return render json: {
21
+ :message => 'Authentication to the Insights Service failed.',
22
+ :headers => {},
23
+ }, status: :bad_gateway
24
+ end
25
+
26
+ if cloud_response.headers[:content_disposition]
27
+ return send_data cloud_response, disposition: cloud_response.headers[:content_disposition], type: cloud_response.headers[:content_type]
28
+ end
29
+
30
+ assign_header(response, cloud_response, :x_resource_count, true)
31
+ assign_header(response, cloud_response, :x_rh_insights_request_id, false)
32
+
33
+ render json: cloud_response, status: cloud_response.code
34
+ end
35
+
36
+ def branch_info
37
+ render :json => ForemanRhCloud::BranchInfo.new.generate(@uuid, @host, @branch_id, request.host).to_json
38
+ end
39
+
40
+ def assign_header(res, cloud_res, header, transform)
41
+ header_content = cloud_res.headers[header]
42
+ return unless header_content
43
+ new_header = transform ? header.to_s.tr('_', '-') : header.to_s
44
+ res.headers[new_header] = header_content
45
+ end
46
+
47
+ private
48
+
49
+ def ensure_telemetry_enabled_for_consumer
50
+ render_message 'Telemetry is not enabled for your organization', :status => 403 unless telemetry_config
51
+ end
52
+
53
+ def telemetry_config
54
+ ::RedhatAccess::TelemetryConfiguration.find_or_create_by(:organization_id => @organization.id) do |conf|
55
+ conf.enable_telemetry = true
56
+ end
57
+ end
58
+
59
+ def cert_uuid
60
+ @uuid ||= User.current.login
61
+ end
62
+
63
+ def ensure_org
64
+ @organization = @host.organization
65
+ return render_message 'Organization not found or invalid', :status => 400 unless @organization
66
+ end
67
+
68
+ def ensure_branch_id
69
+ @branch_id = cp_owner_id(@organization)
70
+ return render_message "Branch ID not found for organization #{@organization.title}", :status => 400 unless @branch_id
71
+ end
72
+ end
73
+ end
@@ -1,6 +1,18 @@
1
1
  module InsightsCloud
2
2
  class HitsController < ::ApplicationController
3
+ include Foreman::Controller::AutoCompleteSearch
4
+
3
5
  def index
6
+ hits = resource_base_search_and_page.preload(:host, :rule)
7
+
8
+ render json: {
9
+ hasToken: !Setting[:rh_cloud_token].empty?,
10
+ hits: hits.map { |hit| hit.attributes.merge(hostname: hit.host&.name, has_playbook: hit.has_playbook?) },
11
+ itemCount: hits.count,
12
+ }, status: :ok
13
+ end
14
+
15
+ def show
4
16
  host = Host.where(id: host_id_param).first
5
17
 
6
18
  render json: {
@@ -8,6 +20,18 @@ module InsightsCloud
8
20
  }, status: :ok
9
21
  end
10
22
 
23
+ def model_of_controller
24
+ ::InsightsHit
25
+ end
26
+
27
+ def resource_class
28
+ ::InsightsHit
29
+ end
30
+
31
+ def controller_permission
32
+ :insights_hits
33
+ end
34
+
11
35
  private
12
36
 
13
37
  def host_id_param
@@ -9,6 +9,14 @@ module InsightsCloud
9
9
  render_setting(:insightsSyncEnabled, :allow_auto_insights_sync)
10
10
  end
11
11
 
12
+ def save_token_and_sync
13
+ token = Setting::RhCloud.find_by_name("rh_cloud_token")
14
+ token.value = params.require(:value)
15
+ token.save!
16
+ InsightsCloud::Async::InsightsFullSync.perform_now
17
+ redirect_to(:controller => "hits", :action => 'index')
18
+ end
19
+
12
20
  private
13
21
 
14
22
  def render_setting(node_name, setting)
@@ -1,7 +1,12 @@
1
1
  module InsightsCloud
2
2
  class TasksController < ::ApplicationController
3
3
  def create
4
- InsightsCloud::Async::InsightsFullSync.perform_now
4
+ job = InsightsCloud::Async::InsightsFullSync.perform_later
5
+ task = ForemanTasks::Task.find_by(external_id: job.provider_job_id)
6
+
7
+ render json: {
8
+ task: task,
9
+ }, status: :ok
5
10
  end
6
11
  end
7
12
  end
@@ -6,14 +6,7 @@ module ForemanInventoryUploadHostHelper
6
6
  def hits_counts_cell(host)
7
7
  host_hits = hits_counts[host.id]
8
8
  tag.td class: ['hidden-xs', 'ellipsis', 'text-center'] do
9
- if host_hits
10
- link_to(
11
- host_hits,
12
- InsightsCloud::WebUi.system_url(InsightsCloud::WebUi::ADVISOR, host.insights.uuid),
13
- :rel => 'external noopener noreferrer',
14
- :target => '_blank'
15
- )
16
- end
9
+ link_to(host_hits, "#{host_path(host)}#insights") if host_hits
17
10
  end
18
11
  end
19
12
  end
@@ -1,6 +1,25 @@
1
1
  class InsightsHit < ApplicationRecord
2
- has_one :host
2
+ include ::Authorizable
3
+ belongs_to :host
3
4
  # since the facet is one-to-one association with a host, we can connect
4
5
  # through host_id column on both this model and facet.
5
6
  belongs_to :insights_facet, foreign_key: 'host_id', primary_key: 'host_id', counter_cache: :hits_count
7
+
8
+ has_one :rule, class_name: 'InsightsRule', foreign_key: 'rule_id', primary_key: 'rule_id'
9
+
10
+ scope :with_playbook, -> { joins(:rule) }
11
+
12
+ scoped_search on: :title, complete_value: true
13
+ scoped_search on: :total_risk, complete_value: true
14
+ scoped_search on: :rule_id, complete_value: true, only_explicit: true
15
+ scoped_search relation: :host, on: :name, rename: :hostname, complete_value: true
16
+ scoped_search on: :rule_id, rename: :with_playbook, only_explicit: true, complete_value: false, ext_method: :find_with_playbook
17
+
18
+ def self.find_with_playbook(key, operator, value)
19
+ { joins: :rule }
20
+ end
21
+
22
+ def has_playbook?
23
+ !rule.nil?
24
+ end
6
25
  end
@@ -0,0 +1,3 @@
1
+ class InsightsResolution < ApplicationRecord
2
+ belongs_to :rule, class_name: 'InsightsRule', foreign_key: 'rule_id', primary_key: 'rule_id', inverse_of: :resolutions
3
+ end
@@ -0,0 +1,3 @@
1
+ class InsightsRule < ApplicationRecord
2
+ has_many :resolutions, class_name: 'InsightsResolution', dependent: :destroy, foreign_key: 'rule_id', primary_key: 'rule_id', inverse_of: :rule
3
+ end
@@ -1,14 +1,26 @@
1
1
  class Setting::RhCloud < Setting
2
+ ::Setting::BLANK_ATTRS.concat %w{rh_cloud_token}
3
+
4
+ def self.load_defaults
5
+ return false unless table_exists?
6
+ transaction do
7
+ # If the user had auto_upload default setting, we will not surprise him, and force the value to false
8
+ # for new users, the default will be set to true and the value will remain nil
9
+ Setting.where(name: 'allow_auto_inventory_upload', value: nil).where("settings.default LIKE '%false%'").update_all(value: "--- false\n...")
10
+ super
11
+ end
12
+ end
13
+
2
14
  def self.default_settings
3
15
  return unless ActiveRecord::Base.connection.table_exists?('settings')
4
- return unless super
5
16
  [
6
- set('allow_auto_inventory_upload', N_('Allow automatic upload of the host inventory to the Red Hat cloud'), false, N_('Allow automatic inventory uploads')),
17
+ set('allow_auto_inventory_upload', N_('Allow automatic upload of the host inventory to the Red Hat cloud'), true, N_('Allow automatic inventory uploads')),
7
18
  set('allow_auto_insights_sync', N_('Allow recommendations synchronization from Red Hat cloud'), false, N_('Allow recommendations synchronization')),
8
19
  set('obfuscate_inventory_hostnames', N_('Obfuscate host names sent to Red Hat cloud'), false, N_('Obfuscate host names')),
9
20
  set('obfuscate_inventory_ips', N_('Obfuscate ip addresses sent to Red Hat cloud'), false, N_('Obfuscate IPs')),
10
- 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),
21
+ set('rh_cloud_token', N_('Authentication token to Red Hat cloud services. Used to authenticate requests to cloud APIs'), nil, N_('Red Hat Cloud token'), nil, encrypted: true),
11
22
  set('exclude_installed_packages', N_('Exclude installed packages from Red Hat cloud inventory report'), false, N_("Don't upload installed packages")),
23
+ set('include_parameter_tags', N_('Should import include parameter tags from Foreman?'), false, N_('Include parameters in insights-client reports')),
12
24
  ]
13
25
  end
14
26
 
@@ -0,0 +1,2 @@
1
+ <!-- insert_top 'head' -->
2
+ <%= css_tags_for([:foreman_rh_cloud]).first %>
@@ -0,0 +1,57 @@
1
+ module ForemanRhCloud
2
+ class BranchInfo
3
+ def generate(uuid, host, branch_id, request_hostname)
4
+ {
5
+ :remote_leaf => uuid,
6
+ :remote_branch => branch_id,
7
+ :display_name => host.organization.name,
8
+ :hostname => request_hostname,
9
+ :product => {
10
+ :type => core_app_name,
11
+ :major_version => core_app_version.major,
12
+ :minor_version => core_app_version.minor,
13
+ },
14
+ :organization_id => host.organization.id,
15
+ :satellite_instance_id => Foreman.instance_id,
16
+ :labels => host_labels(host),
17
+ }
18
+ end
19
+
20
+ def core_app_name
21
+ 'Foreman'
22
+ end
23
+
24
+ def core_app_version
25
+ Foreman::Version.new
26
+ end
27
+
28
+ def new_label(key, value, namespace)
29
+ {
30
+ :namespace => namespace,
31
+ :key => key,
32
+ :value => value,
33
+ }
34
+ end
35
+
36
+ def labels_from_items(items, label_namespace, label_lamb, label_value_method = :to_s)
37
+ items.map { |item| new_label(label_lamb.call(item), item.public_send(label_value_method), label_namespace) }
38
+ end
39
+
40
+ def host_labels(host)
41
+ labels = [new_label('Organization', host.organization.name, 'Satellite')]
42
+ labels += labels_from_items(host.location.title.split('/'), 'Satellite', ->(item) { 'Location' }) if host.location
43
+ labels += labels_from_items(host.hostgroup.title.split('/'), 'Satellite', ->(item) { 'Host Group' }) if host.hostgroup
44
+ labels += labels_from_items(host.host_collections, 'Satellite', ->(item) { 'Host Collection' }, :name)
45
+
46
+ if Setting[:include_parameter_tags]
47
+ labels += labels_from_items(
48
+ host.host_inherited_params_objects,
49
+ 'SatelliteParameter',
50
+ ->(item) { item.name },
51
+ :value)
52
+ end
53
+
54
+ labels
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,60 @@
1
+ require 'securerandom'
2
+
3
+ module ForemanRhCloud
4
+ class CloudConnector
5
+ CLOUD_CONNECTOR_USER = 'cloud_connector_user'.freeze
6
+ CLOUD_CONNECTOR_TOKEN_NAME = 'Cloud connector access token'.freeze
7
+ CLOUD_CONNECTOR_FEATURE = 'ansible_configure_cloud_connector'.freeze
8
+
9
+ def install
10
+ user = service_user
11
+ token_value = personal_access_token(user)
12
+
13
+ composer = ::JobInvocationComposer.for_feature(
14
+ CLOUD_CONNECTOR_FEATURE,
15
+ [foreman_host.id],
16
+ {:satellite_user => service_user.login, :satellite_password => token_value}
17
+ )
18
+ composer.trigger!
19
+ composer.job_invocation
20
+ end
21
+
22
+ def latest_job
23
+ feature_id = RemoteExecutionFeature.find_by_label(CLOUD_CONNECTOR_FEATURE)&.id
24
+ return nil unless feature_id
25
+ JobInvocation.where(:remote_execution_feature_id => feature_id).includes(:task).reorder('foreman_tasks_tasks.started_at DESC').first
26
+ end
27
+
28
+ def personal_access_token(user)
29
+ access_token = PersonalAccessToken.find_by_name(CLOUD_CONNECTOR_TOKEN_NAME)
30
+
31
+ access_token&.destroy! # destroy the old token if exists
32
+
33
+ personal_access_token = PersonalAccessToken.new(:name => CLOUD_CONNECTOR_TOKEN_NAME, :user => user)
34
+ token_value = personal_access_token.generate_token
35
+ personal_access_token.save!
36
+
37
+ token_value
38
+ end
39
+
40
+ def service_user
41
+ user = User.find_by_login(CLOUD_CONNECTOR_USER)
42
+
43
+ if user.nil?
44
+ user = User.create!(
45
+ :login => CLOUD_CONNECTOR_USER,
46
+ :password => SecureRandom.base64(255),
47
+ :description => "This is a service user used by cloud connector to talk to the Satellite API",
48
+ :auth_source => AuthSourceInternal.first,
49
+ :admin => true
50
+ )
51
+ end
52
+
53
+ user
54
+ end
55
+
56
+ def foreman_host
57
+ ::Host.friendly.find(::SmartProxy.default_capsule.name)
58
+ end
59
+ end
60
+ end