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
@@ -67,7 +67,7 @@ module ForemanInventoryUpload
67
67
  end
68
68
 
69
69
  def obfuscate_fqdn(fqdn)
70
- Base64.urlsafe_encode64(Digest::SHA1.digest(fqdn), padding: false)
70
+ "#{Digest::SHA1.hexdigest(fqdn)}.example.com"
71
71
  end
72
72
  end
73
73
  end
@@ -36,6 +36,16 @@ module ForemanInventoryUpload
36
36
  @out << ',' unless last
37
37
  end
38
38
 
39
+ def string_array_value(name, value, last = false)
40
+ return if value.empty?
41
+
42
+ string_value = value.map { |v| stringify_value(v) }
43
+
44
+ array_field(name, last) do
45
+ raw(string_value.join(', '))
46
+ end
47
+ end
48
+
39
49
  def object_field(name, last = false, &block)
40
50
  @out << "\"#{name}\": "
41
51
  object(&block)
@@ -21,6 +21,9 @@ module ForemanInventoryUpload
21
21
  private
22
22
 
23
23
  def render_report(metadata)
24
+ metadata ||= {}
25
+ metadata['foreman_rh_cloud_version'] = ForemanRhCloud::VERSION
26
+
24
27
  @stream.object do
25
28
  @stream.simple_field('report_id', Foreman.uuid)
26
29
  @stream.simple_field('host_inventory_api_version', '1.0')
@@ -30,23 +30,21 @@ module ForemanInventoryUpload
30
30
  end
31
31
 
32
32
  def self.for_slice(base)
33
- fact_values = FactValue.where(fact_name_id: fact_names.values)
34
33
  base
35
34
  .joins(:subscription_facet)
36
- .eager_load(:fact_values)
37
35
  .preload(
38
36
  :interfaces,
39
37
  :installed_packages,
40
38
  :content_facet,
41
39
  :host_statuses,
40
+ :inventory_upload_facts,
42
41
  subscription_facet: [:pools, :installed_products, :hypervisor_host]
43
42
  )
44
- .merge(fact_values)
45
43
  end
46
44
 
47
45
  def self.for_report(portal_user)
48
46
  org_ids = organizations_for_user(portal_user).pluck(:id)
49
- for_slice(Host.unscoped.where(organization_id: org_ids)).in_batches(of: 1_000)
47
+ for_org(org_ids)
50
48
  end
51
49
 
52
50
  def self.for_org(organization_id)
@@ -3,6 +3,8 @@ module ForemanInventoryUpload
3
3
  class Slice
4
4
  include FactHelpers
5
5
 
6
+ SATELLITE_NAMESPACE = 'satellite'
7
+
6
8
  attr_accessor :slice_id
7
9
  attr_reader :hosts_count
8
10
 
@@ -45,22 +47,14 @@ module ForemanInventoryUpload
45
47
  @stream.simple_field('satellite_id', host.subscription_facet&.uuid)
46
48
  @stream.simple_field('bios_uuid', fact_value(host, 'dmi::system::uuid'))
47
49
  @stream.simple_field('vm_uuid', fact_value(host, 'virt::uuid'))
48
- @stream.array_field('ip_addresses') do
49
- @stream.raw(host.interfaces.map do |nic|
50
- @stream.stringify_value(nic.ip) if nic.ip
51
- end.compact.join(', '))
52
- end
53
- @stream.array_field('mac_addresses') do
54
- @stream.raw(host.interfaces.map do |nic|
55
- @stream.stringify_value(nic.mac) if nic.mac
56
- end.compact.join(', '))
57
- end
50
+ report_ip_addresses(host)
51
+ report_mac_addresses(host)
58
52
  @stream.object_field('system_profile') do
59
53
  report_system_profile(host)
60
54
  end
61
55
  @stream.array_field('facts') do
62
56
  @stream.object do
63
- @stream.simple_field('namespace', 'satellite')
57
+ @stream.simple_field('namespace', SATELLITE_NAMESPACE)
64
58
  @stream.object_field('facts', :last) do
65
59
  report_satellite_facts(host)
66
60
  end
@@ -68,8 +62,15 @@ module ForemanInventoryUpload
68
62
  end
69
63
 
70
64
  @stream.array_field('tags', :last) do
71
- report_tag('satellite', 'satellite_instance_id', Foreman.instance_id) if Foreman.respond_to?(:instance_id)
72
- report_tag('satellite', 'organization_id', host.organization_id.to_s, :last)
65
+ report_satellite_tag('satellite_instance_id', Foreman.instance_id) if Foreman.respond_to?(:instance_id)
66
+ report_satellite_tag('lifecycle_environment', host.lifecycle_environment&.name)
67
+ report_satellite_tag('content_view', host.content_view&.name)
68
+ report_satellite_tag('activation_key', host.activation_keys) { |key| key.name }
69
+ report_satellite_tag('host_collection', host.host_collections) { |collection| collection.name }
70
+ report_satellite_tag('location', host.location.name)
71
+ report_satellite_tag('organization', host.organization.name)
72
+ report_satellite_tag('hostgroup', host.hostgroup&.name)
73
+ report_satellite_tag('organization_id', host.organization_id.to_s, :last)
73
74
  end
74
75
  end
75
76
  end
@@ -83,6 +84,18 @@ module ForemanInventoryUpload
83
84
  @stream.comma unless last
84
85
  end
85
86
 
87
+ def report_satellite_tag(key, value, last = nil)
88
+ return if value.nil?
89
+
90
+ array_value = Array(value)
91
+ last_index = array_value.count - 1
92
+
93
+ array_value.each_with_index do |value, index|
94
+ value = yield(value) if block_given?
95
+ report_tag(SATELLITE_NAMESPACE, key, value, last && index == last_index)
96
+ end
97
+ end
98
+
86
99
  def report_system_profile(host)
87
100
  @stream.simple_field('number_of_cpus', fact_value(host, 'cpu::cpu(s)').to_i)
88
101
  @stream.simple_field('number_of_sockets', fact_value(host, 'cpu::cpu_socket(s)').to_i)
@@ -154,12 +167,26 @@ module ForemanInventoryUpload
154
167
  end
155
168
  @stream.simple_field('system_purpose_usage', host.subscription_facet.purpose_usage)
156
169
  @stream.simple_field('system_purpose_role', host.subscription_facet.purpose_role)
170
+ @stream.simple_field('system_purpose_sla', host.subscription_facet.service_level)
157
171
  @stream.simple_field('distribution_version', fact_value(host, 'distribution::version'))
158
172
  @stream.simple_field('satellite_instance_id', Foreman.try(:instance_id))
159
173
  @stream.simple_field('is_simple_content_access', golden_ticket?(host.organization))
174
+ @stream.simple_field('is_hostname_obfuscated', !!obfuscate_hostname?(host))
160
175
  @stream.simple_field('organization_id', host.organization_id, :last)
161
176
  end
162
177
 
178
+ def report_ip_addresses(host)
179
+ ip_addresses = host.interfaces.map { |nic| nic.ip }.compact
180
+
181
+ @stream.string_array_value('ip_addresses', ip_addresses)
182
+ end
183
+
184
+ def report_mac_addresses(host)
185
+ macs = host.interfaces.map { |nic| nic.mac }.compact
186
+
187
+ @stream.string_array_value('mac_addresses', macs)
188
+ end
189
+
163
190
  def os_release_value(name:, version:, codename:)
164
191
  "#{name} #{version} (#{codename})"
165
192
  end
@@ -0,0 +1,19 @@
1
+ module ForemanInventoryUpload
2
+ module Notifications
3
+ module ManifestImportSuccessNotificationOverride
4
+ extend ActiveSupport::Concern
5
+
6
+ def actions
7
+ {
8
+ :links => [
9
+ {
10
+ :href => Rails.application.routes.url_helpers.foreman_rh_cloud_inventory_upload_path,
11
+ :title => _('Enable inventory upload'),
12
+ :external => false,
13
+ },
14
+ ],
15
+ }
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,4 +1,71 @@
1
1
  require 'foreman_rh_cloud/engine.rb'
2
+ require 'cgi'
3
+ require 'uri'
2
4
 
3
5
  module ForemanRhCloud
6
+ def self.base_url
7
+ # for testing set ENV to 'https://ci.cloud.redhat.com'
8
+ @base_url ||= ENV['SATELLITE_RH_CLOUD_URL'] || 'https://cloud.redhat.com'
9
+ end
10
+
11
+ def self.authentication_url
12
+ # https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/token
13
+ @authentication_url ||= ENV['SATELLITE_RH_CLOUD_SSO_URL'] || 'https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/token'
14
+ end
15
+
16
+ def self.verify_ssl_method
17
+ @verify_ssl_method ||= ENV['SATELLITE_RH_CLOUD_URL'] ? OpenSSL::SSL::VERIFY_NONE : OpenSSL::SSL::VERIFY_PEER
18
+ end
19
+
20
+ def self.http_proxy_string(logger: Foreman::Logging.logger('background'))
21
+ ForemanRhCloud.proxy_setting(logger: logger)
22
+ end
23
+
24
+ def self.transformed_http_proxy_string(logger: Foreman::Logging.logger('background'))
25
+ ForemanRhCloud.transform_scheme(ForemanRhCloud.proxy_setting(logger: logger))
26
+ end
27
+
28
+ def self.proxy_setting(logger: Foreman::Logging.logger('background'))
29
+ HttpProxy.default_global_content_proxy&.full_url ||
30
+ ForemanRhCloud.cdn_proxy(logger: logger) ||
31
+ ForemanRhCloud.global_foreman_proxy
32
+ end
33
+
34
+ def self.cdn_proxy(logger: Foreman::Logging.logger('app'))
35
+ proxy_config = SETTINGS[:katello][:cdn_proxy]
36
+ return nil unless proxy_config
37
+
38
+ uri = URI('')
39
+ uri.host = proxy_config[:host]
40
+ uri.port = proxy_config[:port]
41
+ uri.scheme = proxy_config[:scheme] || 'http'
42
+
43
+ if proxy_config[:user]
44
+ uri.user = CGI.escape(proxy_config[:user])
45
+ uri.password = CGI.escape(proxy_config[:password])
46
+ end
47
+ uri.to_s
48
+ rescue URI::Error => e
49
+ logger.warn("cdn_proxy parsing failed: #{e}")
50
+ nil
51
+ end
52
+
53
+ def self.global_foreman_proxy
54
+ Setting[:http_proxy]
55
+ end
56
+
57
+ # This method assumes uri_string contains uri-encoded username and p@$$word:
58
+ # http://user:p%40%24%24word@localhost:8888
59
+ def self.transform_scheme(uri_string)
60
+ transformed_uri = URI.parse(uri_string)
61
+
62
+ case transformed_uri.scheme
63
+ when "http"
64
+ transformed_uri.scheme = 'proxy'
65
+ when "https"
66
+ transformed_uri.scheme = 'proxys'
67
+ end
68
+
69
+ transformed_uri.to_s
70
+ end
4
71
  end
@@ -30,13 +30,17 @@ module ForemanRhCloud
30
30
 
31
31
  # Add permissions
32
32
  security_block :foreman_rh_cloud do
33
- permission(:generate_foreman_rh_cloud, :'foreman_inventory_upload/reports' => [:generate])
34
- permission(:view_foreman_rh_cloud,
35
- 'foreman_inventory_upload/accounts': [:index],
36
- 'foreman_inventory_upload/reports': [:last],
37
- 'foreman_inventory_upload/uploads': [:auto_upload, :download_file, :last],
38
- 'foreman_rh_cloud/react': [:inventory_upload]
39
- )
33
+ permission(
34
+ :generate_foreman_rh_cloud,
35
+ 'foreman_inventory_upload/reports': [:generate]
36
+ )
37
+ permission(
38
+ :view_foreman_rh_cloud,
39
+ 'foreman_inventory_upload/accounts': [:index],
40
+ 'foreman_inventory_upload/reports': [:last],
41
+ 'foreman_inventory_upload/uploads': [:auto_upload, :download_file, :last],
42
+ 'foreman_rh_cloud/react': [:inventory_upload]
43
+ )
40
44
  end
41
45
 
42
46
  plugin_permissions = [:view_foreman_rh_cloud, :generate_foreman_rh_cloud]
@@ -49,16 +53,39 @@ module ForemanRhCloud
49
53
  Role::SYSTEM_ADMIN => plugin_permissions
50
54
 
51
55
  # Adding a sub menu after hosts menu
52
- sub_menu :top_menu, :foreman_rh_cloud, :caption => N_('RH Cloud'), :icon => 'fa fa-cloud-upload' do
53
- menu :top_menu, :level1, :caption => N_('Inventory Upload'), :url_hash => { controller: :'foreman_rh_cloud/react', :action => :inventory_upload}
56
+ divider :top_menu, caption: N_('RH Cloud'), parent: :configure_menu
57
+ menu :top_menu, :inventory_upload, :caption => N_('Inventory Upload'), :url_hash => { controller: :'foreman_rh_cloud/react', :action => :inventory_upload}, parent: :configure_menu
58
+ menu :top_menu, :insights_hits_import, :caption => N_('Insights'), :url_hash => { controller: :'foreman_rh_cloud/react', :action => :insights_cloud }, parent: :configure_menu
59
+
60
+ register_facet InsightsFacet, :insights do
61
+ configure_host do
62
+ set_dependent_action :destroy
63
+ end
64
+ end
65
+
66
+ register_global_js_file 'subscriptions_extension'
67
+
68
+ register_custom_status(InventorySync::InventoryStatus)
69
+
70
+ extend_page 'hosts/show' do |context|
71
+ context.add_pagelet :main_tabs,
72
+ partial: 'hosts/insights_tab',
73
+ name: _('Insights'),
74
+ onlyif: proc { |host| host.insights }
54
75
  end
55
76
  end
77
+
78
+ ::Katello::UINotifications::Subscriptions::ManifestImportSuccess.include ForemanInventoryUpload::Notifications::ManifestImportSuccessNotificationOverride if defined?(Katello)
79
+
80
+ ::Host::Managed.include RhCloudHost
81
+ ::Host::Base.include RhCloudHost
56
82
  end
57
83
 
58
84
  initializer "foreman_rh_cloud.set_dynflow.config.on_init", :before => :finisher_hook do |_app|
59
85
  unless Rails.env.test?
60
86
  ForemanTasks.dynflow.config.on_init do |world|
61
87
  ForemanInventoryUpload::Async::GenerateAllReportsJob.spawn_if_missing(world)
88
+ InsightsCloud::Async::InsightsScheduledSync.spawn_if_missing(world)
62
89
  end
63
90
  end
64
91
  end
@@ -1,3 +1,3 @@
1
1
  module ForemanRhCloud
2
- VERSION = '1.0.7'.freeze
2
+ VERSION = '1.0.12'.freeze
3
3
  end
@@ -0,0 +1,15 @@
1
+ module InsightsCloud
2
+ module WebUi
3
+ ADVISOR = 'advisor'
4
+ VULNERABILITY = 'vulnerability'
5
+ PATCH = 'patch'
6
+
7
+ def self.system_url(subsystem, host_uuid)
8
+ ForemanRhCloud.base_url + "/insights/#{subsystem}/systems/#{host_uuid}"
9
+ end
10
+ end
11
+
12
+ def self.hits_export_url
13
+ ForemanRhCloud.base_url + '/api/insights/v1/export/hits/'
14
+ end
15
+ end
@@ -0,0 +1,105 @@
1
+ require 'rest-client'
2
+
3
+ module InsightsCloud
4
+ module Async
5
+ class InsightsFullSync < ::ApplicationJob
6
+ def perform
7
+ hits = query_insights_hits
8
+
9
+ @hits_host_names = Hash[hits.map { |hit| [hit['hostname'], hit['uuid']] }]
10
+ setup_host_names(@hits_host_names.keys)
11
+
12
+ replace_hits_data(hits)
13
+ end
14
+
15
+ def logger
16
+ Foreman::Logging.logger('background')
17
+ end
18
+
19
+ def rh_credentials
20
+ @rh_credentials ||= query_refresh_token
21
+ end
22
+
23
+ private
24
+
25
+ def query_insights_hits
26
+ hits_response = RestClient::Request.execute(
27
+ method: :get,
28
+ url: InsightsCloud.hits_export_url,
29
+ verify_ssl: ForemanRhCloud.verify_ssl_method,
30
+ proxy: ForemanRhCloud.transformed_http_proxy_string(logger: logger),
31
+ headers: {
32
+ Authorization: "Bearer #{rh_credentials}",
33
+ }
34
+ )
35
+
36
+ JSON.parse(hits_response)
37
+ end
38
+
39
+ def query_refresh_token
40
+ token_response = RestClient::Request.execute(
41
+ method: :post,
42
+ url: ForemanRhCloud.authentication_url,
43
+ verify_ssl: ForemanRhCloud.verify_ssl_method,
44
+ proxy: ForemanRhCloud.transformed_http_proxy_string(logger: logger),
45
+ payload: {
46
+ grant_type: 'refresh_token',
47
+ client_id: 'rhsm-api',
48
+ refresh_token: Setting[:rh_cloud_token],
49
+ }
50
+ )
51
+
52
+ JSON.parse(token_response)['access_token']
53
+ rescue RestClient::ExceptionWithResponse => e
54
+ Foreman::Logging.exception('Unable to authenticate using rh_cloud_token setting', e)
55
+ raise ::Foreman::WrappedException.new(e, N_('Unable to authenticate using rh_cloud_token setting'))
56
+ end
57
+
58
+ def setup_host_names(host_names)
59
+ @host_ids = Hash[
60
+ Host.unscoped.where(name: host_names).pluck(:name, :id)
61
+ ]
62
+ end
63
+
64
+ def host_id(host_name)
65
+ @host_ids[host_name]
66
+ end
67
+
68
+ def replace_hits_data(hits)
69
+ InsightsHit.transaction do
70
+ InsightsHit.delete_all
71
+ InsightsHit.create(hits.map { |hits_hash| to_model_hash(hits_hash) }.compact)
72
+ # create new facets for hosts that are missing one
73
+ hosts_with_existing_facets = InsightsFacet.where(host_id: @host_ids.values).pluck(:host_id)
74
+ InsightsFacet.create(
75
+ @host_ids.map do |host_name, host_id|
76
+ unless hosts_with_existing_facets.include?(host_id)
77
+ {
78
+ host_id: host_id,
79
+ uuid: @hits_host_names[host_name],
80
+ }
81
+ end
82
+ end.compact
83
+ )
84
+ end
85
+ end
86
+
87
+ def to_model_hash(hit_hash)
88
+ hit_host_id = host_id(hit_hash['hostname'])
89
+
90
+ return unless hit_host_id
91
+
92
+ {
93
+ host_id: hit_host_id,
94
+ last_seen: DateTime.parse(hit_hash['last_seen']),
95
+ publish_date: DateTime.parse(hit_hash['publish_date']),
96
+ title: hit_hash['title'],
97
+ solution_url: hit_hash['solution_url'],
98
+ total_risk: hit_hash['total_risk'].to_i,
99
+ likelihood: hit_hash['likelihood'].to_i,
100
+ results_url: hit_hash['results_url'],
101
+ }
102
+ end
103
+ end
104
+ end
105
+ end