foreman_rh_cloud 1.0.10 → 1.0.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) 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/uploads_controller.rb +18 -0
  5. data/app/controllers/insights_cloud/hits_controller.rb +17 -0
  6. data/app/helpers/foreman_inventory_upload_host_helper.rb +2 -3
  7. data/app/models/concerns/rh_cloud_host.rb +15 -0
  8. data/app/models/insights_hit.rb +1 -1
  9. data/app/models/setting/rh_cloud.rb +2 -0
  10. data/app/overrides/hosts_list.rb +1 -1
  11. data/app/services/foreman_rh_cloud/cloud_auth.rb +28 -0
  12. data/app/views/hosts/_insights_tab.html.erb +15 -0
  13. data/config/routes.rb +3 -0
  14. data/db/migrate/20201007115752_add_hits_count_to_insights_facets_table.foreman_rh_cloud.rb +5 -0
  15. data/db/migrate/20201007121540_setup_hits_count_cache.foreman_rh_cloud.rb +10 -0
  16. data/lib/foreman_inventory_upload/async/generate_report_job.rb +1 -1
  17. data/lib/foreman_inventory_upload/async/shell_process.rb +15 -9
  18. data/lib/foreman_inventory_upload/async/upload_report_job.rb +21 -9
  19. data/lib/foreman_inventory_upload/generators/fact_helpers.rb +35 -0
  20. data/lib/foreman_inventory_upload/generators/json_stream.rb +7 -2
  21. data/lib/foreman_inventory_upload/generators/metadata.rb +3 -0
  22. data/lib/foreman_inventory_upload/generators/queries.rb +4 -4
  23. data/lib/foreman_inventory_upload/generators/slice.rb +27 -25
  24. data/lib/foreman_rh_cloud.rb +55 -0
  25. data/lib/foreman_rh_cloud/engine.rb +13 -2
  26. data/lib/foreman_rh_cloud/version.rb +1 -1
  27. data/lib/insights_cloud/async/insights_full_sync.rb +5 -24
  28. data/lib/inventory_sync/async/inventory_full_sync.rb +3 -22
  29. data/lib/tasks/insights.rake +15 -0
  30. data/lib/tasks/rh_cloud_inventory.rake +37 -0
  31. data/package.json +3 -1
  32. data/test/jobs/upload_report_job_test.rb +34 -0
  33. data/test/unit/fact_helpers_test.rb +22 -0
  34. data/test/unit/insights_facet_test.rb +7 -0
  35. data/test/unit/metadata_generator_test.rb +2 -0
  36. data/test/unit/rh_cloud_http_proxy_test.rb +65 -0
  37. data/test/unit/slice_generator_test.rb +167 -2
  38. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountList.fixtures.js +14 -1
  39. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListActions.js +22 -18
  40. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListReducer.js +16 -0
  41. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListSelectors.js +6 -0
  42. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListActions.test.js +7 -0
  43. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListReducer.test.js +12 -8
  44. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListSelectors.test.js +9 -0
  45. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListActions.test.js.snap +19 -0
  46. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListReducer.test.js.snap +11 -0
  47. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListSelectors.test.js.snap +6 -0
  48. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/AutoUploadSwitcher.fixtures.js +2 -0
  49. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/AutoUploadSwitcherActions.js +10 -11
  50. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/AutoUploadSwitcherConstants.js +0 -1
  51. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/__tests__/AutoUploadSwitcherActions.test.js +12 -2
  52. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/__tests__/__snapshots__/AutoUploadSwitcherActions.test.js.snap +17 -0
  53. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/ExcludePackagesSwitcher.fixtures.js +1 -0
  54. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/ExcludePackagesSwitcher.js +30 -0
  55. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/ExcludePackagesSwitcherActions.js +29 -0
  56. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/ExcludePackagesSwitcherConstants.js +1 -0
  57. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/__tests__/ExcludePackagesSwitcher.test.js +13 -0
  58. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/__tests__/ExcludePackagesSwitcherActions.test.js +21 -0
  59. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/__tests__/__snapshots__/ExcludePackagesSwitcher.test.js.snap +38 -0
  60. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/__tests__/__snapshots__/ExcludePackagesSwitcherActions.test.js.snap +31 -0
  61. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/__tests__/__snapshots__/integration.test.js.snap +41 -0
  62. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/__tests__/integration.test.js +38 -0
  63. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/excludePackagesSwitcher.scss +3 -0
  64. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/index.js +20 -0
  65. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/HostObfuscationSwitcher.fixtures.js +2 -1
  66. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/HostObfuscationSwitcher.js +1 -0
  67. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/HostObfuscationSwitcher.scss +3 -0
  68. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/HostObfuscationSwitcherActions.js +10 -11
  69. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/HostObfuscationSwitcherConstants.js +0 -2
  70. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/__tests__/HostObfuscationSwitcherActions.test.js +12 -2
  71. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/__tests__/__snapshots__/HostObfuscationSwitcherActions.test.js.snap +18 -1
  72. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/__snapshots__/integration.test.js.snap +3 -0
  73. data/webpack/ForemanInventoryUpload/Components/InventorySettings/InventorySettings.js +4 -0
  74. data/webpack/ForemanInventoryUpload/Components/InventorySettings/__tests__/__snapshots__/InventorySettings.test.js.snap +2 -0
  75. data/webpack/ForemanInventoryUpload/Components/IpsObfuscationSwitcher/IpsObfuscationSwitcher.fixtures.js +1 -0
  76. data/webpack/ForemanInventoryUpload/Components/IpsObfuscationSwitcher/IpsObfuscationSwitcher.js +29 -0
  77. data/webpack/ForemanInventoryUpload/Components/IpsObfuscationSwitcher/IpsObfuscationSwitcherActions.js +29 -0
  78. data/webpack/ForemanInventoryUpload/Components/IpsObfuscationSwitcher/IpsObfuscationSwitcherConstants.js +1 -0
  79. data/webpack/ForemanInventoryUpload/Components/IpsObfuscationSwitcher/__tests__/IpsObfuscationSwitcher.test.js +13 -0
  80. data/webpack/ForemanInventoryUpload/Components/IpsObfuscationSwitcher/__tests__/IpsObfuscationSwitcherActions.test.js +21 -0
  81. data/webpack/ForemanInventoryUpload/Components/IpsObfuscationSwitcher/__tests__/__snapshots__/IpsObfuscationSwitcher.test.js.snap +38 -0
  82. data/webpack/ForemanInventoryUpload/Components/IpsObfuscationSwitcher/__tests__/__snapshots__/IpsObfuscationSwitcherActions.test.js.snap +31 -0
  83. data/webpack/ForemanInventoryUpload/Components/IpsObfuscationSwitcher/index.js +20 -0
  84. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButton.js +8 -2
  85. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js +9 -11
  86. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonConstants.js +1 -1
  87. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonReducer.js +2 -2
  88. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/SyncButtonActions.test.js +18 -0
  89. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/SyncButtonReducer.test.js +1 -8
  90. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/SyncButtonActions.test.js.snap +62 -0
  91. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/SyncButtonReducer.test.js.snap +0 -7
  92. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/components/Modal.js +2 -2
  93. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/components/Toast.js +1 -1
  94. data/webpack/ForemanInventoryUpload/Components/StatusChart/StatusChart.js +1 -1
  95. data/webpack/ForemanInventoryUpload/Components/StatusChart/__tests__/__snapshots__/StatusChart.test.js.snap +1 -1
  96. data/webpack/ForemanInventoryUpload/Components/TabContainer/tabContainer.scss +1 -1
  97. data/webpack/ForemanInventoryUpload/Components/TabHeader/TabHeader.js +6 -1
  98. data/webpack/ForemanInventoryUpload/Components/Terminal/Terminal.js +2 -4
  99. data/webpack/ForemanInventoryUpload/ForemanInventoryHelpers.js +8 -0
  100. data/webpack/ForemanRhCloudPages.js +2 -0
  101. data/webpack/ForemanRhCloudReducers.js +2 -0
  102. data/webpack/ForemanRhCloudSelectors.js +5 -0
  103. data/webpack/ForemanRhCloudTestHelpers.js +6 -1
  104. data/webpack/InsightsCloudSync/Components/InsightsSettings/InsightsSettingsActions.js +17 -20
  105. data/webpack/InsightsCloudSync/Components/InsightsSettings/InsightsSettingsConstants.js +0 -6
  106. data/webpack/InsightsCloudSync/Components/InsightsSettings/InsightsSettingsReducer.js +0 -4
  107. data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsActions.test.js +16 -0
  108. data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsReducer.test.js +1 -24
  109. data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/__snapshots__/InsightsSettingsActions.test.js.snap +38 -4
  110. data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/__snapshots__/InsightsSettingsReducer.test.js.snap +0 -14
  111. data/webpack/InsightsCloudSync/InsightsCloudSync.js +1 -1
  112. data/webpack/InsightsCloudSync/InsightsCloudSyncActions.js +10 -11
  113. data/webpack/InsightsCloudSync/InsightsCloudSyncConstants.js +0 -2
  114. data/webpack/InsightsCloudSync/__snapshots__/InsightsCloudSync.test.js.snap +1 -1
  115. data/webpack/InsightsHostDetailsTab/InsightsTab.js +64 -0
  116. data/webpack/InsightsHostDetailsTab/InsightsTab.scss +86 -0
  117. data/webpack/InsightsHostDetailsTab/InsightsTabActions.js +31 -0
  118. data/webpack/InsightsHostDetailsTab/InsightsTabConstants.js +2 -0
  119. data/webpack/InsightsHostDetailsTab/InsightsTabReducer.js +19 -0
  120. data/webpack/InsightsHostDetailsTab/InsightsTabSelectors.js +3 -0
  121. data/webpack/InsightsHostDetailsTab/__tests__/InsightsTab.fixtures.js +25 -0
  122. data/webpack/InsightsHostDetailsTab/__tests__/InsightsTab.test.js +13 -0
  123. data/webpack/InsightsHostDetailsTab/__tests__/InsightsTabActions.test.js +19 -0
  124. data/webpack/InsightsHostDetailsTab/__tests__/InsightsTabIntegration.test.js +17 -0
  125. data/webpack/InsightsHostDetailsTab/__tests__/InsightsTabReducer.test.js +26 -0
  126. data/webpack/InsightsHostDetailsTab/__tests__/InsightsTabSelectors.test.js +13 -0
  127. data/webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTab.test.js.snap +30 -0
  128. data/webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTabActions.test.js.snap +58 -0
  129. data/webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTabReducer.test.js.snap +34 -0
  130. data/webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTabSelectors.test.js.snap +20 -0
  131. data/webpack/InsightsHostDetailsTab/components/ListItem/ListItem.js +69 -0
  132. data/webpack/InsightsHostDetailsTab/components/ListItem/index.js +1 -0
  133. data/webpack/InsightsHostDetailsTab/index.js +20 -0
  134. data/webpack/__tests__/__snapshots__/ForemanRhCloudSelectors.test.js.snap +1 -0
  135. data/webpack/__tests__/__snapshots__/ForemanRhCloudTestHelpers.test.js.snap +3 -0
  136. data/webpack/stories/decorators/withCardsDecorator.js +1 -1
  137. metadata +67 -16
  138. data/lib/tasks/generator.rake +0 -29
  139. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/hostObfuscationSwitcher.scss +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fb457584e95614e52c7026cb963409b2a2ea645b082315c0004b787db6ecf028
4
- data.tar.gz: 6352df86d12f35dbdc4d90538c1604aa00e1c4710f09c6deb0066efce8a48277
3
+ metadata.gz: 830861dcfd46371108e610046d742960ace76310a79bf3fde268de4230de0ccb
4
+ data.tar.gz: a42767333df5769a37bcd9e28ebb9e7eab815a13933bdd38cb678c77602eb5b0
5
5
  SHA512:
6
- metadata.gz: 1299b5836e5bf30151c690e5c222c67d34f351b0e5ffbd4e3ffeead0109457adce46279a1ddb550f3468aac4439c1050e366bf831dfb3c84b3e021e5cc2d9dd3
7
- data.tar.gz: edc7f560cd4ed663a07535bc247b0d5baf7e5755a50f002e9c752116cda93b729a15cc7b4452c12a95d9cee542d7201f900142f408abfa43a8e308d390305aa2
6
+ metadata.gz: bc3f5e9f3f5dff9c8198bc10d131c42f6b2cd8ef5409711182af631effda0b0b99a2c12f9e0b0e1cf4d30a821f58d28fef94edc2341a2938693ba773832a8a27
7
+ data.tar.gz: 87731548c51473f8f88d20f9036d3709135734795c950ffb70fe86b302d18c209a3825fa720b1227ffbe3cc4a51960f7386a6cbfce0d91494f94afb0d2de4745
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*
@@ -23,7 +23,9 @@ module ForemanInventoryUpload
23
23
  render json: {
24
24
  autoUploadEnabled: Setting[:allow_auto_inventory_upload],
25
25
  hostObfuscationEnabled: Setting[:obfuscate_inventory_hostnames],
26
+ ipsObfuscationEnabled: Setting[:obfuscate_inventory_ips],
26
27
  cloudToken: Setting[:rh_cloud_token],
28
+ excludePackages: Setting[:exclude_installed_packages],
27
29
  accounts: accounts,
28
30
  }, status: :ok
29
31
  end
@@ -46,6 +46,24 @@ module ForemanInventoryUpload
46
46
  ActiveModel::Type::Boolean.new.cast(params.require(:value))
47
47
  end
48
48
 
49
+ def installed_packages_inclusion
50
+ Setting[:exclude_installed_packages] = host_obfuscation_params
51
+ render_setting(:excludePackages, :exclude_installed_packages)
52
+ end
53
+
54
+ def installed_packages_inclusion_params
55
+ ActiveModel::Type::Boolean.new.cast(params.require(:value))
56
+ end
57
+
58
+ def ips_obfuscation
59
+ Setting[:obfuscate_inventory_ips] = ips_obfuscation_params
60
+ render_setting(:ipsObfuscationEnabled, :obfuscate_inventory_ips)
61
+ end
62
+
63
+ def ips_obfuscation_params
64
+ ActiveModel::Type::Boolean.new.cast(params.require(:value))
65
+ end
66
+
49
67
  private
50
68
 
51
69
  def render_setting(node_name, setting)
@@ -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
@@ -5,11 +5,10 @@ module ForemanInventoryUploadHostHelper
5
5
 
6
6
  def hits_counts_cell(host)
7
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
8
+ tag.td class: ['hidden-xs', 'ellipsis', 'text-center'] do
10
9
  if host_hits
11
10
  link_to(
12
- content,
11
+ host_hits,
13
12
  InsightsCloud::WebUi.system_url(InsightsCloud::WebUi::ADVISOR, host.insights.uuid),
14
13
  :rel => 'external noopener noreferrer',
15
14
  :target => '_blank'
@@ -0,0 +1,15 @@
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
+
12
+ has_many :insights_hits, through: :insights, source: :hits
13
+ scoped_search :relation => :insights, :on => :hits_count, :only_explicit => true, :rename => :insights_recommendations_count
14
+ end
15
+ end
@@ -2,5 +2,5 @@ class InsightsHit < ApplicationRecord
2
2
  has_one :host
3
3
  # since the facet is one-to-one association with a host, we can connect
4
4
  # through host_id column on both this model and facet.
5
- has_one :insights_facet, foreign_key: 'host_id', primary_key: 'host_id'
5
+ belongs_to :insights_facet, foreign_key: 'host_id', primary_key: 'host_id', counter_cache: :hits_count
6
6
  end
@@ -6,7 +6,9 @@ class Setting::RhCloud < Setting
6
6
  set('allow_auto_inventory_upload', N_('Allow automatic upload of the host inventory to the Red Hat cloud'), false),
7
7
  set('allow_auto_insights_sync', N_('Allow recommendations synchronization from Red Hat cloud'), false),
8
8
  set('obfuscate_inventory_hostnames', N_('Obfuscate host names sent to Red Hat cloud'), false),
9
+ set('obfuscate_inventory_ips', N_('Obfuscate ip addresses sent to Red Hat cloud'), false),
9
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),
11
+ set('exclude_installed_packages', N_('Exclude installed packages from Red Hat cloud inventory report'), false),
10
12
  ]
11
13
  end
12
14
 
@@ -2,7 +2,7 @@ Deface::Override.new(
2
2
  virtual_path: 'hosts/_list',
3
3
  name: 'insights_hits_header',
4
4
  insert_before: 'thead tr th.hidden-xs:first-of-type',
5
- text: '<th class="hidden-xs" width="10%"><%= _("Insights")%></th>'
5
+ text: '<th class="hidden-xs ellipsis" width="12%"><%= sort :insights_recommendations_count, :as => _("Recommendations")%></th>'
6
6
  )
7
7
 
8
8
  Deface::Override.new(
@@ -0,0 +1,28 @@
1
+ module ForemanRhCloud
2
+ module CloudAuth
3
+ extend ActiveSupport::Concern
4
+
5
+ def rh_credentials
6
+ @rh_credentials ||= query_refresh_token
7
+ end
8
+
9
+ def query_refresh_token
10
+ token_response = RestClient::Request.execute(
11
+ method: :post,
12
+ url: ForemanRhCloud.authentication_url,
13
+ verify_ssl: ForemanRhCloud.verify_ssl_method,
14
+ proxy: ForemanRhCloud.transformed_http_proxy_string(logger: logger),
15
+ payload: {
16
+ grant_type: 'refresh_token',
17
+ client_id: 'rhsm-api',
18
+ refresh_token: Setting[:rh_cloud_token],
19
+ }
20
+ )
21
+
22
+ JSON.parse(token_response)['access_token']
23
+ rescue RestClient::ExceptionWithResponse => e
24
+ Foreman::Logging.exception('Unable to authenticate using rh_cloud_token setting', e)
25
+ raise ::Foreman::WrappedException.new(e, N_('Unable to authenticate using rh_cloud_token setting'))
26
+ end
27
+ end
28
+ end
@@ -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
+ ) %>
@@ -8,6 +8,8 @@ Rails.application.routes.draw do
8
8
  get 'auto_upload', to: 'uploads#show_auto_upload'
9
9
  post 'auto_upload', to: 'uploads#auto_upload'
10
10
  post 'host_obfuscation', to: 'uploads#host_obfuscation'
11
+ post 'installed_packages_inclusion', to: 'uploads#installed_packages_inclusion'
12
+ post 'ips_obfuscation', to: 'uploads#ips_obfuscation'
11
13
 
12
14
  resources :tasks, only: [:create]
13
15
  end
@@ -15,6 +17,7 @@ Rails.application.routes.draw do
15
17
  namespace :insights_cloud do
16
18
  resources :tasks, only: [:create]
17
19
  resource :settings, only: [:show, :update]
20
+ get 'hits/:host_id', to: 'hits#index'
18
21
  end
19
22
 
20
23
  namespace :foreman_rh_cloud do
@@ -0,0 +1,5 @@
1
+ class AddHitsCountToInsightsFacetsTable < ActiveRecord::Migration[5.0]
2
+ def change
3
+ add_column :insights_facets, :hits_count, :integer
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ class SetupHitsCountCache < ActiveRecord::Migration[5.0]
2
+ def up
3
+ ActiveRecord::Base.connection.execute <<-SQL.squish
4
+ UPDATE insights_facets
5
+ SET hits_count = (SELECT count(1)
6
+ FROM insights_hits
7
+ WHERE insights_hits.host_id = insights_facets.host_id)
8
+ SQL
9
+ end
10
+ 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']
@@ -1,3 +1,5 @@
1
+ require 'json'
2
+
1
3
  module ForemanInventoryUpload
2
4
  module Generators
3
5
  module FactHelpers
@@ -69,6 +71,39 @@ module ForemanInventoryUpload
69
71
  def obfuscate_fqdn(fqdn)
70
72
  "#{Digest::SHA1.hexdigest(fqdn)}.example.com"
71
73
  end
74
+
75
+ def obfuscate_ips?(host)
76
+ insights_client_setting = fact_value(host, 'insights_client::obfuscate_ip_enabled')
77
+ insights_client_setting = ActiveModel::Type::Boolean.new.cast(insights_client_setting)
78
+ return insights_client_setting unless insights_client_setting.nil?
79
+
80
+ Setting[:obfuscate_inventory_ips]
81
+ end
82
+
83
+ def host_ips(host)
84
+ return obfuscated_ips(host) if obfuscate_ips?(host)
85
+
86
+ # return a pass through proxy hash in case no obfuscation needed
87
+ Hash.new { |h, k| k }
88
+ end
89
+
90
+ def obfuscated_ips(host)
91
+ insights_client_ips = JSON.parse(fact_value(host, 'insights_client::ips') || '[]')
92
+
93
+ obfuscated_ips = Hash[
94
+ insights_client_ips.map { |ip_record| [ip_record['original'], ip_record['obfuscated']] }
95
+ ]
96
+
97
+ obfuscated_ips.default_proc = proc do |hash, key|
98
+ hash[key] = obfuscate_ip(key, hash)
99
+ end
100
+
101
+ obfuscated_ips
102
+ end
103
+
104
+ def obfuscate_ip(ip, ips_dict)
105
+ "10.230.230.#{ips_dict.count + 1}"
106
+ end
72
107
  end
73
108
  end
74
109
  end
@@ -26,8 +26,13 @@ module ForemanInventoryUpload
26
26
  @out << string
27
27
  end
28
28
 
29
- def simple_field(name, value, last = false)
30
- @out << "\"#{name}\": #{stringify_value(value)}#{last ? '' : ','}" unless value.nil?
29
+ def simple_field(name, value, last = false, &block)
30
+ return if value.nil? || value.try(:empty?)
31
+ return if value.kind_of?(Array) && value.compact.empty?
32
+
33
+ block ||= ->(value) { value }
34
+
35
+ @out << "\"#{name}\": #{stringify_value(block.call(value))}#{last ? '' : ','}"
31
36
  end
32
37
 
33
38
  def array_field(name, last = false, &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')
@@ -24,29 +24,29 @@ module ForemanInventoryUpload
24
24
  'dmi::system::product_name',
25
25
  'dmi::chassis::asset_tag',
26
26
  'insights_client::obfuscate_hostname_enabled',
27
+ 'insights_client::obfuscate_ip_enabled',
27
28
  'insights_client::hostname',
29
+ 'insights_client::ips',
28
30
  ]).pluck(:name, :id)
29
31
  ]
30
32
  end
31
33
 
32
34
  def self.for_slice(base)
33
- fact_values = FactValue.where(fact_name_id: fact_names.values)
34
35
  base
35
36
  .joins(:subscription_facet)
36
- .eager_load(:fact_values)
37
37
  .preload(
38
38
  :interfaces,
39
39
  :installed_packages,
40
40
  :content_facet,
41
41
  :host_statuses,
42
+ :inventory_upload_facts,
42
43
  subscription_facet: [:pools, :installed_products, :hypervisor_host]
43
44
  )
44
- .merge(fact_values)
45
45
  end
46
46
 
47
47
  def self.for_report(portal_user)
48
48
  org_ids = organizations_for_user(portal_user).pluck(:id)
49
- for_slice(Host.unscoped.where(organization_id: org_ids)).in_batches(of: 1_000)
49
+ for_org(org_ids)
50
50
  end
51
51
 
52
52
  def self.for_org(organization_id)