foreman_rh_cloud 2.0.9 → 2.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/foreman_inventory_upload/accounts_controller.rb +1 -0
  3. data/app/controllers/foreman_inventory_upload/tasks_controller.rb +25 -0
  4. data/app/controllers/insights_cloud/settings_controller.rb +24 -0
  5. data/app/controllers/insights_cloud/tasks_controller.rb +1 -2
  6. data/app/helpers/foreman_inventory_upload_host_helper.rb +10 -1
  7. data/app/models/insights_facet.rb +5 -1
  8. data/app/models/inventory_sync/inventory_status.rb +30 -0
  9. data/app/models/setting/rh_cloud.rb +1 -0
  10. data/app/views/foreman_rh_cloud/react/inventory_upload.html.erb +1 -1
  11. data/config/routes.rb +3 -0
  12. data/db/migrate/20200727111529_add_uuid_column_to_insights_facets.foreman_rh_cloud.rb +5 -0
  13. data/lib/foreman_inventory_upload.rb +4 -0
  14. data/lib/foreman_inventory_upload/async/upload_report_job.rb +29 -1
  15. data/lib/foreman_inventory_upload/generators/fact_helpers.rb +1 -1
  16. data/lib/foreman_inventory_upload/generators/slice.rb +25 -3
  17. data/lib/foreman_rh_cloud.rb +13 -0
  18. data/lib/foreman_rh_cloud/engine.rb +6 -1
  19. data/lib/foreman_rh_cloud/version.rb +1 -1
  20. data/lib/insights_cloud.rb +8 -8
  21. data/lib/insights_cloud/async/insights_full_sync.rb +17 -10
  22. data/lib/insights_cloud/async/insights_scheduled_sync.rb +23 -0
  23. data/lib/inventory_sync/async/host_result.rb +50 -0
  24. data/lib/inventory_sync/async/inventory_full_sync.rb +99 -0
  25. data/test/controllers/insights_sync/settings_controller_test.rb +30 -0
  26. data/test/factories/insights_factories.rb +31 -0
  27. data/test/jobs/insights_full_sync_test.rb +4 -2
  28. data/test/jobs/inventory_full_sync_test.rb +91 -0
  29. data/test/unit/insights_facet_test.rb +16 -0
  30. data/test/unit/slice_generator_test.rb +15 -7
  31. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountList.fixtures.js +3 -1
  32. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListActions.js +2 -1
  33. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListReducer.js +2 -0
  34. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListSelectors.js +2 -0
  35. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListReducer.test.js +2 -0
  36. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListActions.test.js.snap +1 -0
  37. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListReducer.test.js.snap +1 -0
  38. data/webpack/ForemanInventoryUpload/Components/FullScreenModal/FullScreenModal.js +5 -1
  39. data/webpack/ForemanInventoryUpload/Components/FullScreenModal/__tests__/__snapshots__/FullScreenModal.test.js.snap +1 -0
  40. data/webpack/ForemanInventoryUpload/Components/FullScreenModal/fullScreenModal.scss +15 -13
  41. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/__snapshots__/integration.test.js.snap +6 -0
  42. data/webpack/ForemanInventoryUpload/Components/PageHeader/PageHeader.js +1 -1
  43. data/webpack/ForemanInventoryUpload/Components/PageHeader/__tests__/__snapshots__/PageHeader.test.js.snap +3 -3
  44. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/DocsButton/DocsButton.js +1 -0
  45. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/DocsButton/__tests__/__snapshots__/DocsButton.test.js.snap +1 -0
  46. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/HistoryButton/HistoryButton.js +1 -0
  47. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/HistoryButton/__tests__/__snapshots__/HistoryButton.test.js.snap +1 -0
  48. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButton.js +52 -0
  49. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js +59 -0
  50. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonConstants.js +3 -0
  51. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonReducer.js +36 -0
  52. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonSelectors.js +13 -0
  53. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/SyncButton.test.js +13 -0
  54. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/SyncButtonActions.test.js +13 -0
  55. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/SyncButtonFixtures.js +9 -0
  56. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/SyncButtonReducer.test.js +33 -0
  57. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/SyncButtonSelectors.test.js +36 -0
  58. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/SyncButton.test.js.snap +26 -0
  59. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/SyncButtonActions.test.js.snap +36 -0
  60. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/SyncButtonReducer.test.js.snap +25 -0
  61. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/SyncButtonSelectors.test.js.snap +18 -0
  62. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/components/Modal.js +63 -0
  63. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/components/Toast.js +41 -0
  64. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/components/modal.scss +20 -0
  65. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/index.js +22 -0
  66. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/ToolbarButtons.js +2 -0
  67. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/__tests__/__snapshots__/ToolbarButtons.test.js.snap +1 -0
  68. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/toolbarButtons.scss +6 -1
  69. data/webpack/ForemanInventoryUpload/ForemanInventoryConstants.js +3 -1
  70. data/webpack/ForemanInventoryUpload/ForemanInventoryUploadReducers.js +2 -0
  71. data/webpack/ForemanRhCloudPages.js +7 -0
  72. data/webpack/ForemanRhCloudTestHelpers.js +12 -3
  73. data/webpack/InsightsCloudSync/Components/InsightsSettings/InsightsSettings.js +33 -0
  74. data/webpack/InsightsCloudSync/Components/InsightsSettings/InsightsSettingsActions.js +60 -0
  75. data/webpack/InsightsCloudSync/Components/InsightsSettings/InsightsSettingsConstants.js +10 -0
  76. data/webpack/InsightsCloudSync/Components/InsightsSettings/InsightsSettingsReducer.js +28 -0
  77. data/webpack/InsightsCloudSync/Components/InsightsSettings/InsightsSettingsSelectors.js +6 -0
  78. data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettings.test.js +18 -0
  79. data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsActions.test.js +46 -0
  80. data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsReducer.test.js +56 -0
  81. data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsSelectors.test.js +21 -0
  82. data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/__snapshots__/InsightsSettings.test.js.snap +15 -0
  83. data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/__snapshots__/InsightsSettingsActions.test.js.snap +31 -0
  84. data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/__snapshots__/InsightsSettingsReducer.test.js.snap +33 -0
  85. data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/__snapshots__/InsightsSettingsSelectors.test.js.snap +9 -0
  86. data/webpack/InsightsCloudSync/Components/InsightsSettings/index.js +21 -0
  87. data/webpack/InsightsCloudSync/Components/InsightsSettings/insightsSettings.scss +16 -0
  88. data/webpack/InsightsCloudSync/Components/InsightsSyncSwitcher/InsightsSyncSwitcher.fixtures.js +1 -0
  89. data/webpack/InsightsCloudSync/Components/InsightsSyncSwitcher/InsightsSyncSwitcher.js +45 -0
  90. data/webpack/InsightsCloudSync/Components/InsightsSyncSwitcher/__tests__/InsightsSyncSwitcher.test.js +17 -0
  91. data/webpack/InsightsCloudSync/Components/InsightsSyncSwitcher/__tests__/__snapshots__/InsightsSyncSwitcher.test.js.snap +38 -0
  92. data/webpack/InsightsCloudSync/Components/InsightsSyncSwitcher/index.js +1 -0
  93. data/webpack/InsightsCloudSync/Components/InsightsSyncSwitcher/insightsSyncSwitcher.scss +3 -0
  94. data/webpack/InsightsCloudSync/InsightsCloudSync.js +32 -28
  95. data/webpack/InsightsCloudSync/InsightsCloudSyncReducers.js +7 -2
  96. data/webpack/InsightsCloudSync/__snapshots__/InsightsCloudSync.test.js.snap +51 -46
  97. data/webpack/InsightsCloudSync/index.js +2 -1
  98. data/webpack/__mocks__/foremanReact/constants.js +5 -0
  99. data/webpack/__mocks__/foremanReact/redux/actions/toasts.js +8 -0
  100. data/webpack/__tests__/ForemanRhCloudSelectors.test.js +4 -1
  101. data/webpack/__tests__/ForemanRhCloudTestHelpers.test.js +12 -2
  102. data/webpack/__tests__/__snapshots__/ForemanRhCloudSelectors.test.js.snap +9 -9
  103. data/webpack/__tests__/__snapshots__/ForemanRhCloudTestHelpers.test.js.snap +24 -2
  104. data/webpack/index.js +2 -12
  105. metadata +59 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c164b990c325cd1f5e90004585c0074c558ee29ece8b687d37115d88f278274d
4
- data.tar.gz: 01f04d99170a49224c7687949acff8d7171ce73d0d620343ce348c324b2b6040
3
+ metadata.gz: a340f8085bfc6d4d08048369230ab9b90a392cc460b86d53c30bbe8a90ed3c86
4
+ data.tar.gz: dd76bc695e8d183ac9b9afd05e84ca8650730584919243f9b99d10da522dd707
5
5
  SHA512:
6
- metadata.gz: dc211d399ff2f518b47ccfe76e8a569cac8b3356bab5dc6f2dabfc8c0a3de2926dd8fe99f2a84ea8dba9e4dea3b871cdd3380dfebb48e51cdcb1198dbac16bc8
7
- data.tar.gz: 622e9894c0bef62e38f25b687d2acb0c5db74cf8e299e5a327f102052704324e2aafaee71fa30b595de66a29124789a815899e3f324000c559e3c75ce2ce401c
6
+ metadata.gz: dbd457318e1c1b23db3e5d2e9a71974f30f6d089fa7df5af02d4b6fbce6487c8b3cedd0749da05d76b32aa5af22a2a1cc99ffaef3d141c77a1edffd838d8bc70
7
+ data.tar.gz: 7269c01c4e2599456f4d340425ad60b56a9f65749642d0e5cbda9c2217fd792b8cf1d61808a787c36a644d0f785e7c623a22d47b58af83e693530acbb77824fd
@@ -23,6 +23,7 @@ module ForemanInventoryUpload
23
23
  render json: {
24
24
  autoUploadEnabled: Setting[:allow_auto_inventory_upload],
25
25
  hostObfuscationEnabled: Setting[:obfuscate_inventory_hostnames],
26
+ cloudToken: Setting[:rh_cloud_token],
26
27
  accounts: accounts,
27
28
  }, status: :ok
28
29
  end
@@ -0,0 +1,25 @@
1
+ module ForemanInventoryUpload
2
+ class TasksController < ::ApplicationController
3
+ def create
4
+ selected_org = Organization.current
5
+ subscribed_hosts_ids = Set.new(
6
+ ForemanInventoryUpload::Generators::Queries.for_slice(
7
+ Host.unscoped.where(organization: selected_org)
8
+ ).pluck(:id)
9
+ )
10
+
11
+ if subscribed_hosts_ids.empty?
12
+ return render json: {
13
+ message: N_('Nothing to sync, there are no hosts with subscription for this organization.'),
14
+ }, status: :method_not_allowed
15
+ else
16
+ host_statuses = InventorySync::Async::InventoryFullSync.perform_now(selected_org)
17
+ end
18
+
19
+ render json: {
20
+ syncHosts: host_statuses[:sync],
21
+ disconnectHosts: host_statuses[:disconnect],
22
+ }, status: :ok
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,24 @@
1
+ module InsightsCloud
2
+ class SettingsController < ::ApplicationController
3
+ def show
4
+ render_setting(:insightsSyncEnabled, :allow_auto_insights_sync)
5
+ end
6
+
7
+ def update
8
+ Setting[:allow_auto_insights_sync] = settings_params
9
+ render_setting(:insightsSyncEnabled, :allow_auto_insights_sync)
10
+ end
11
+
12
+ private
13
+
14
+ def render_setting(node_name, setting)
15
+ render json: {
16
+ node_name => Setting[setting],
17
+ }
18
+ end
19
+
20
+ def settings_params
21
+ ActiveModel::Type::Boolean.new.cast(params.require(:insightsSyncEnabled))
22
+ end
23
+ end
24
+ end
@@ -1,8 +1,7 @@
1
1
  module InsightsCloud
2
2
  class TasksController < ::ApplicationController
3
3
  def create
4
- selected_org = Organization.current
5
- InsightsCloud::Async::InsightsFullSync.perform_now(selected_org)
4
+ InsightsCloud::Async::InsightsFullSync.perform_now
6
5
  end
7
6
  end
8
7
  end
@@ -6,6 +6,15 @@ module ForemanInventoryUploadHostHelper
6
6
  def hits_counts_cell(host)
7
7
  host_hits = hits_counts[host.id]
8
8
  content = n_('One recommendation', '%{hits} recommendations', host_hits) % { hits: host_hits } if host_hits
9
- tag.td content, class: ['hidden-xs', 'ellipsis']
9
+ tag.td class: ['hidden-xs', 'ellipsis'] do
10
+ if host_hits
11
+ link_to(
12
+ content,
13
+ InsightsCloud::WebUi.system_url(InsightsCloud::WebUi::ADVISOR, host.insights.uuid),
14
+ :rel => 'external noopener noreferrer',
15
+ :target => '_blank'
16
+ )
17
+ end
18
+ end
10
19
  end
11
20
  end
@@ -1,3 +1,7 @@
1
1
  class InsightsFacet < HostFacets::Base
2
- has_many :hits, foreign_key: :host_id, primary_key: :host_id, class_name: 'InsightsHit'
2
+ has_many :hits,
3
+ foreign_key: :host_id,
4
+ primary_key: :host_id,
5
+ class_name: 'InsightsHit',
6
+ dependent: :destroy
3
7
  end
@@ -0,0 +1,30 @@
1
+ module InventorySync
2
+ class InventoryStatus < HostStatus::Status
3
+ DISCONNECT = 0
4
+ SYNC = 1
5
+
6
+ def self.status_name
7
+ N_('Inventory')
8
+ end
9
+
10
+ def to_global(_options = {})
11
+ case status
12
+ when DISCONNECT
13
+ ::HostStatus::Global::WARN
14
+ when SYNC
15
+ ::HostStatus::Global::OK
16
+ else
17
+ ::HostStatus::Global::WARN
18
+ end
19
+ end
20
+
21
+ def to_label
22
+ case status
23
+ when DISCONNECT
24
+ N_('Host was not uploaded to your RH cloud inventory')
25
+ when SYNC
26
+ N_('Successfully uploaded to your RH cloud inventory')
27
+ end
28
+ end
29
+ end
30
+ end
@@ -4,6 +4,7 @@ class Setting::RhCloud < Setting
4
4
  return unless super
5
5
  [
6
6
  set('allow_auto_inventory_upload', N_('Allow automatic upload of the host inventory to the Red Hat cloud'), false),
7
+ set('allow_auto_insights_sync', N_('Allow recommendations synchronization from Red Hat cloud'), false),
7
8
  set('obfuscate_inventory_hostnames', N_('Obfuscate host names sent to Red Hat cloud'), false),
8
9
  set('rh_cloud_token', N_('Authentication token to Red Hat cloud services. Used to authenticate requests to cloud APIs'), 'DEFAULT', N_('Red Hat Cloud token'), nil, encrypted: true),
9
10
  ]
@@ -1 +1 @@
1
- <%= mount_react_component("ForemanInventoryUpload", '#ForemanRhCloudReactRoot') %>
1
+ <%= mount_react_component('ForemanInventoryUpload', '#ForemanRhCloudReactRoot') %>
@@ -8,10 +8,13 @@ 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
+
12
+ resources :tasks, only: [:create]
11
13
  end
12
14
 
13
15
  namespace :insights_cloud do
14
16
  resources :tasks, only: [:create]
17
+ resource :settings, only: [:show, :update]
15
18
  end
16
19
 
17
20
  namespace :foreman_rh_cloud do
@@ -0,0 +1,5 @@
1
+ class AddUuidColumnToInsightsFacets < ActiveRecord::Migration[5.2]
2
+ def change
3
+ add_column :insights_facets, :uuid, :string
4
+ end
5
+ end
@@ -60,4 +60,8 @@ module ForemanInventoryUpload
60
60
  FileUtils.mkdir_p(folder)
61
61
  folder
62
62
  end
63
+
64
+ def self.inventory_export_url
65
+ ForemanRhCloud.base_url + '/api/inventory/v1/hosts'
66
+ end
63
67
  end
@@ -37,7 +37,10 @@ module ForemanInventoryUpload
37
37
  end
38
38
 
39
39
  def http_proxy_string
40
- @http_proxy_string ||= HttpProxy.default_global_content_proxy&.full_url
40
+ @http_proxy_string ||=
41
+ HttpProxy.default_global_content_proxy&.full_url ||
42
+ cdn_proxy ||
43
+ global_foreman_proxy
41
44
  end
42
45
 
43
46
  def rh_credentials
@@ -49,6 +52,31 @@ module ForemanInventoryUpload
49
52
  }
50
53
  end
51
54
  end
55
+
56
+ def cdn_proxy
57
+ cdn_settings = SETTINGS[:katello][:cdn_proxy] || {}
58
+
59
+ return nil unless cdn_settings[:host]
60
+
61
+ proxy_uri = URI('')
62
+
63
+ original_uri = URI.parse(cdn_settings[:host])
64
+
65
+ proxy_uri.scheme = original_uri.scheme || 'http'
66
+ proxy_uri.host = original_uri.host || original_uri.path
67
+ proxy_uri.port = cdn_settings[:port]
68
+ proxy_uri.user = cdn_settings[:user]
69
+ proxy_uri.password = cdn_settings[:password]
70
+
71
+ proxy_uri.to_s
72
+ rescue URI::Error => e
73
+ logger.warn("cdn_proxy parsing failed: #{e}")
74
+ nil
75
+ end
76
+
77
+ def global_foreman_proxy
78
+ Setting[:http_proxy]
79
+ end
52
80
  end
53
81
  end
54
82
  end
@@ -67,7 +67,7 @@ module ForemanInventoryUpload
67
67
  end
68
68
 
69
69
  def obfuscate_fqdn(fqdn)
70
- Digest::SHA1.hexdigest(fqdn)
70
+ "#{Digest::SHA1.hexdigest(fqdn)}.example.com"
71
71
  end
72
72
  end
73
73
  end
@@ -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
 
@@ -52,7 +54,7 @@ module ForemanInventoryUpload
52
54
  end
53
55
  @stream.array_field('facts') do
54
56
  @stream.object do
55
- @stream.simple_field('namespace', 'satellite')
57
+ @stream.simple_field('namespace', SATELLITE_NAMESPACE)
56
58
  @stream.object_field('facts', :last) do
57
59
  report_satellite_facts(host)
58
60
  end
@@ -60,8 +62,15 @@ module ForemanInventoryUpload
60
62
  end
61
63
 
62
64
  @stream.array_field('tags', :last) do
63
- report_tag('satellite', 'satellite_instance_id', Foreman.instance_id) if Foreman.respond_to?(:instance_id)
64
- 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)
65
74
  end
66
75
  end
67
76
  end
@@ -75,6 +84,18 @@ module ForemanInventoryUpload
75
84
  @stream.comma unless last
76
85
  end
77
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
+
78
99
  def report_system_profile(host)
79
100
  @stream.simple_field('number_of_cpus', fact_value(host, 'cpu::cpu(s)').to_i)
80
101
  @stream.simple_field('number_of_sockets', fact_value(host, 'cpu::cpu_socket(s)').to_i)
@@ -146,6 +167,7 @@ module ForemanInventoryUpload
146
167
  end
147
168
  @stream.simple_field('system_purpose_usage', host.subscription_facet.purpose_usage)
148
169
  @stream.simple_field('system_purpose_role', host.subscription_facet.purpose_role)
170
+ @stream.simple_field('system_purpose_sla', host.subscription_facet.service_level)
149
171
  @stream.simple_field('distribution_version', fact_value(host, 'distribution::version'))
150
172
  @stream.simple_field('satellite_instance_id', Foreman.try(:instance_id))
151
173
  @stream.simple_field('is_simple_content_access', golden_ticket?(host.organization))
@@ -1,4 +1,17 @@
1
1
  require 'foreman_rh_cloud/engine.rb'
2
2
 
3
3
  module ForemanRhCloud
4
+ def self.base_url
5
+ # for testing set ENV to 'https://ci.cloud.redhat.com'
6
+ @base_url ||= ENV['SATELLITE_RH_CLOUD_URL'] || 'https://cloud.redhat.com'
7
+ end
8
+
9
+ def self.authentication_url
10
+ # https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/token
11
+ @authentication_url ||= ENV['SATELLITE_RH_CLOUD_SSO_URL'] || 'https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/token'
12
+ end
13
+
14
+ def self.verify_ssl_method
15
+ @verify_ssl_method ||= ENV['SATELLITE_RH_CLOUD_URL'] ? OpenSSL::SSL::VERIFY_NONE : OpenSSL::SSL::VERIFY_PEER
16
+ end
4
17
  end
@@ -58,10 +58,14 @@ module ForemanRhCloud
58
58
  menu :top_menu, :insights_hits_import, :caption => N_('Insights'), :url_hash => { controller: :'foreman_rh_cloud/react', :action => :insights_cloud }, parent: :configure_menu
59
59
 
60
60
  register_facet InsightsFacet, :insights do
61
- configure_host
61
+ configure_host do
62
+ set_dependent_action :destroy
63
+ end
62
64
  end
63
65
 
64
66
  register_global_js_file 'subscriptions_extension'
67
+
68
+ register_custom_status(InventorySync::InventoryStatus)
65
69
  end
66
70
 
67
71
  ::Katello::UINotifications::Subscriptions::ManifestImportSuccess.include ForemanInventoryUpload::Notifications::ManifestImportSuccessNotificationOverride if defined?(Katello)
@@ -71,6 +75,7 @@ module ForemanRhCloud
71
75
  unless Rails.env.test?
72
76
  ForemanTasks.dynflow.config.on_init do |world|
73
77
  ForemanInventoryUpload::Async::GenerateAllReportsJob.spawn_if_missing(world)
78
+ InsightsCloud::Async::InsightsScheduledSync.spawn_if_missing(world)
74
79
  end
75
80
  end
76
81
  end
@@ -1,3 +1,3 @@
1
1
  module ForemanRhCloud
2
- VERSION = '2.0.9'.freeze
2
+ VERSION = '2.0.10'.freeze
3
3
  end
@@ -1,15 +1,15 @@
1
1
  module InsightsCloud
2
- def self.base_url
3
- # for testing set ENV to 'https://ci.cloud.redhat.com'
4
- @base_url ||= ENV['SATELLITE_INSIGHTS_CLOUD_URL'] || 'https://cloud.redhat.com'
5
- end
2
+ module WebUi
3
+ ADVISOR = 'advisor'
4
+ VULNERABILITY = 'vulnerability'
5
+ PATCH = 'patch'
6
6
 
7
- def self.authentication_url
8
- # https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/token
9
- @authentication_url ||= ENV['SATELLITE_INSIGHTS_CLOUD_SSO_URL'] || 'https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/token'
7
+ def self.system_url(subsystem, host_uuid)
8
+ ForemanRhCloud.base_url + "/insights/#{subsystem}/systems/#{host_uuid}"
9
+ end
10
10
  end
11
11
 
12
12
  def self.hits_export_url
13
- base_url + '/api/insights/v1/export/hits/'
13
+ ForemanRhCloud.base_url + '/api/insights/v1/export/hits/'
14
14
  end
15
15
  end
@@ -3,13 +3,11 @@ require 'rest-client'
3
3
  module InsightsCloud
4
4
  module Async
5
5
  class InsightsFullSync < ::ApplicationJob
6
- def perform(organization)
7
- @organization = organization
8
-
6
+ def perform
9
7
  hits = query_insights_hits
10
8
 
11
- host_names = hits.map { |hit| hit['hostname'] }.uniq
12
- setup_host_names(host_names)
9
+ @hits_host_names = Hash[hits.map { |hit| [hit['hostname'], hit['uuid']] }]
10
+ setup_host_names(@hits_host_names.keys)
13
11
 
14
12
  replace_hits_data(hits)
15
13
  end
@@ -28,7 +26,7 @@ module InsightsCloud
28
26
  hits_response = RestClient::Request.execute(
29
27
  method: :get,
30
28
  url: InsightsCloud.hits_export_url,
31
- verify_ssl: ENV['SATELLITE_INSIGHTS_CLOUD_URL'] ? OpenSSL::SSL::VERIFY_NONE : OpenSSL::SSL::VERIFY_PEER,
29
+ verify_ssl: ForemanRhCloud.verify_ssl_method,
32
30
  headers: {
33
31
  Authorization: "Bearer #{rh_credentials}",
34
32
  }
@@ -40,8 +38,8 @@ module InsightsCloud
40
38
  def query_refresh_token
41
39
  token_response = RestClient::Request.execute(
42
40
  method: :post,
43
- url: InsightsCloud.authentication_url,
44
- verify_ssl: ENV['SATELLITE_INSIGHTS_CLOUD_URL'] ? OpenSSL::SSL::VERIFY_NONE : OpenSSL::SSL::VERIFY_PEER,
41
+ url: ForemanRhCloud.authentication_url,
42
+ verify_ssl: ForemanRhCloud.verify_ssl_method,
45
43
  payload: {
46
44
  grant_type: 'refresh_token',
47
45
  client_id: 'rhsm-api',
@@ -57,7 +55,7 @@ module InsightsCloud
57
55
 
58
56
  def setup_host_names(host_names)
59
57
  @host_ids = Hash[
60
- Host.where(name: host_names).pluck(:name, :id)
58
+ Host.unscoped.where(name: host_names).pluck(:name, :id)
61
59
  ]
62
60
  end
63
61
 
@@ -71,7 +69,16 @@ module InsightsCloud
71
69
  InsightsHit.create(hits.map { |hits_hash| to_model_hash(hits_hash) }.compact)
72
70
  # create new facets for hosts that are missing one
73
71
  hosts_with_existing_facets = InsightsFacet.where(host_id: @host_ids.values).pluck(:host_id)
74
- InsightsFacet.create((@host_ids.values - hosts_with_existing_facets).map { |id| {host_id: id} })
72
+ InsightsFacet.create(
73
+ @host_ids.map do |host_name, host_id|
74
+ unless hosts_with_existing_facets.include?(host_id)
75
+ {
76
+ host_id: host_id,
77
+ uuid: @hits_host_names[host_name],
78
+ }
79
+ end
80
+ end.compact
81
+ )
75
82
  end
76
83
  end
77
84
 
@@ -0,0 +1,23 @@
1
+ module InsightsCloud
2
+ module Async
3
+ class InsightsScheduledSync < ::ApplicationJob
4
+ def perform
5
+ unless Setting[:allow_auto_insights_sync]
6
+ logger.debug(
7
+ 'The scheduled process is disabled due to the "allow_auto_insights_sync"
8
+ setting being set to false.'
9
+ )
10
+ return
11
+ end
12
+
13
+ InsightsFullSync.perform_later()
14
+ ensure
15
+ self.class.set(:wait => 24.hours).perform_later
16
+ end
17
+
18
+ def self.singleton_job_name
19
+ name
20
+ end
21
+ end
22
+ end
23
+ end