foreman_rh_cloud 12.2.0 → 12.2.2

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 (60) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/api/v2/rh_cloud/advisor_engine_config_controller.rb +1 -1
  3. data/app/controllers/api/v2/rh_cloud/cloud_request_controller.rb +3 -0
  4. data/app/controllers/api/v2/rh_cloud/inventory_controller.rb +3 -0
  5. data/app/controllers/concerns/foreman_rh_cloud/iop_smart_proxy_access.rb +28 -0
  6. data/app/controllers/concerns/insights_cloud/package_profile_upload_extensions.rb +1 -1
  7. data/app/controllers/foreman_inventory_upload/uploads_controller.rb +3 -0
  8. data/app/controllers/foreman_rh_cloud/foreman_rh_cloud_controller.rb +22 -0
  9. data/app/controllers/insights_cloud/api/machine_telemetries_controller.rb +19 -5
  10. data/app/controllers/insights_cloud/ui_requests_controller.rb +11 -0
  11. data/app/services/foreman_rh_cloud/cert_auth.rb +1 -1
  12. data/app/services/foreman_rh_cloud/cloud_request.rb +1 -1
  13. data/app/services/foreman_rh_cloud/cloud_request_forwarder.rb +1 -1
  14. data/app/services/foreman_rh_cloud/hit_remediations_retriever.rb +27 -10
  15. data/app/services/foreman_rh_cloud/url_remediations_retriever.rb +1 -1
  16. data/app/views/api/v2/hosts/insights/base.rabl +2 -2
  17. data/app/views/api/v2/hosts/insights/single.rabl +1 -1
  18. data/config/routes.rb +8 -14
  19. data/lib/foreman_inventory_upload/async/generate_all_reports_job.rb +2 -2
  20. data/lib/foreman_inventory_upload/async/upload_report_job.rb +1 -1
  21. data/lib/foreman_inventory_upload/generators/slice.rb +24 -0
  22. data/lib/foreman_rh_cloud/engine.rb +8 -131
  23. data/lib/foreman_rh_cloud/plugin.rb +150 -0
  24. data/lib/foreman_rh_cloud/version.rb +1 -1
  25. data/lib/foreman_rh_cloud.rb +5 -6
  26. data/lib/insights_cloud/async/insights_scheduled_sync.rb +2 -2
  27. data/lib/inventory_sync/async/inventory_hosts_sync.rb +1 -1
  28. data/lib/inventory_sync/async/inventory_scheduled_sync.rb +2 -2
  29. data/lib/tasks/insights.rake +1 -1
  30. data/lib/tasks/rh_cloud_inventory.rake +20 -2
  31. data/package.json +1 -1
  32. data/test/controllers/insights_cloud/api/machine_telemetries_controller_test.rb +20 -3
  33. data/test/controllers/insights_cloud/ui_requests_controller_test.rb +23 -0
  34. data/test/controllers/insights_sync/settings_controller_test.rb +1 -1
  35. data/test/factories/inventory_upload_factories.rb +4 -112
  36. data/test/jobs/inventory_scheduled_sync_test.rb +3 -3
  37. data/test/test_plugin_helper.rb +8 -2
  38. data/test/unit/rh_cloud_http_proxy_test.rb +3 -3
  39. data/test/unit/services/foreman_rh_cloud/cloud_request_forwarder_test.rb +4 -1
  40. data/test/unit/slice_generator_test.rb +33 -0
  41. data/test/unit/tags_generator_test.rb +4 -1
  42. data/webpack/CVEsHostDetailsTab/CVEsHostDetailsTab.js +2 -1
  43. data/webpack/CVEsHostDetailsTab/CVEsHostDetailsTab.scss +3 -0
  44. data/webpack/CveDetailsPage/CveDetailsPage.js +1 -1
  45. data/webpack/CveDetailsPage/CveDetailsPage.test.js +1 -3
  46. data/webpack/ForemanColumnExtensions/index.js +20 -15
  47. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/PageDescription.js +23 -0
  48. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/__tests__/PageDescription.test.js +2 -0
  49. data/webpack/ForemanRhCloudPages.js +1 -0
  50. data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationHelpers.js +26 -4
  51. data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationModal.js +85 -11
  52. data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationModalFooter.js +39 -5
  53. data/webpack/InsightsCloudSync/Components/RemediationModal/Resolutions.js +13 -0
  54. data/webpack/InsightsCloudSync/InsightsCloudSync.js +9 -7
  55. data/webpack/InsightsHostDetailsTab/NewHostDetailsTab.js +16 -15
  56. data/webpack/InsightsVulnerability/InsightsVulnerabilityListPage.js +1 -1
  57. data/webpack/IopRecommendationDetails/IopRecommendationDetails.js +1 -11
  58. data/webpack/common/Hooks/ConfigHooks.js +1 -2
  59. data/webpack/common/styles.scss +7 -0
  60. metadata +6 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 32fdc4ecba1d5949bce50e394de7cdd097697902c8ba47f47b14e26c96e44881
4
- data.tar.gz: 0de08119aa42cce06a73dd7bce46d730e023d40b7f54b621cb6a3cef50fb0b63
3
+ metadata.gz: b3bc2f9bf0700b7f22d4bee9c0b1f02b10d7b91a441bfa125f38cf2b3b00f655
4
+ data.tar.gz: 21a3c48d1720f8ffbea0dd00fbf3b660dc6adea2a097254fd4c9a6c85791f49b
5
5
  SHA512:
6
- metadata.gz: 03ad7ffd1b43db38bdd6762d01b1bd88e7404702a43cd7be626a72892e73f498c990eab3a4cc1037fe63393cdc87d460cd1b87fa7770749e87b9e9a2bf949418
7
- data.tar.gz: 403935258065a6cc0755b0d71ed9c3fa6a8652c59264c85da213aa21471d93af5efcde6a829f0e1606d949474b41ab6eaa7b9c573b0ecc74393dce786795f01f
6
+ metadata.gz: 12b3933a12e68f827cd1a3130be3c4f0907eaa2235c2ac7850a734c7b8fc9e89780d2c87287874d6067337a3679c331d151cf695b5d4e3ad24647434e0a96714
7
+ data.tar.gz: 278421740888ba600cfd295c43e8eefb649053a4153430f74ff8729e32312f18d93723db1193de8bdc7cb82c96e5c4307405455671035407c978b8d659ab136a
@@ -7,7 +7,7 @@ module Api
7
7
  api :GET, "/rh_cloud/advisor_engine_config", N_("Show if system is configured to use local iop-advisor-engine.")
8
8
  def show
9
9
  render json: {
10
- use_local_advisor_engine: ForemanRhCloud.with_local_advisor_engine?,
10
+ use_iop_mode: ForemanRhCloud.with_iop_smart_proxy?,
11
11
  }, status: :ok
12
12
  end
13
13
  end
@@ -1,7 +1,10 @@
1
1
  module Api::V2::RhCloud
2
2
  class CloudRequestController < ::Api::V2::BaseController
3
+ include ForemanRhCloud::IopSmartProxyAccess
3
4
  layout false
4
5
 
6
+ before_action :require_non_iop_smart_proxy, only: [:update]
7
+
5
8
  KNOWN_DIRECTIVES = {
6
9
  'playbook-sat' => :handle_run_playbook_request,
7
10
  'foreman_rh_cloud' => :handle_run_playbook_request,
@@ -5,6 +5,9 @@ module Api
5
5
  include ::Api::Version2
6
6
  include InventoryUpload::ReportActions
7
7
  include InventoryUpload::TaskActions
8
+ include ForemanRhCloud::IopSmartProxyAccess
9
+
10
+ before_action :require_non_iop_smart_proxy, only: [:enable_cloud_connector]
8
11
 
9
12
  api :GET, "/organizations/:organization_id/rh_cloud/report", N_("Download latest report")
10
13
  param :organization_id, Integer, required: true, desc: N_("Set the current organization context for the request")
@@ -0,0 +1,28 @@
1
+ module ForemanRhCloud
2
+ module IopSmartProxyAccess
3
+ extend ActiveSupport::Concern
4
+
5
+ private
6
+
7
+ def require_non_iop_smart_proxy
8
+ return unless ForemanRhCloud.with_iop_smart_proxy?
9
+
10
+ handle_iop_access_error('This feature is not available when using IoP Smart Proxy')
11
+ end
12
+
13
+ def require_iop_smart_proxy
14
+ return if ForemanRhCloud.with_iop_smart_proxy?
15
+
16
+ handle_iop_access_error('This feature is not available without IoP Smart Proxy')
17
+ end
18
+
19
+ def handle_iop_access_error(message)
20
+ if api_request?
21
+ not_found(message)
22
+ else
23
+ error(message)
24
+ redirect_back(fallback_location: main_app.root_path)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -10,7 +10,7 @@ module InsightsCloud
10
10
  end
11
11
 
12
12
  def generate_host_report
13
- return unless ForemanRhCloud.with_local_advisor_engine?
13
+ return unless ForemanRhCloud.with_iop_smart_proxy?
14
14
 
15
15
  logger.debug("Generating host-specific report for host #{@host.name}")
16
16
 
@@ -1,6 +1,9 @@
1
1
  module ForemanInventoryUpload
2
2
  class UploadsController < ::ApplicationController
3
3
  include InventoryUpload::ReportActions
4
+ include ForemanRhCloud::IopSmartProxyAccess
5
+
6
+ before_action :require_non_iop_smart_proxy, only: [:enable_cloud_connector]
4
7
 
5
8
  def last
6
9
  label = ForemanInventoryUpload::Async::UploadReportJob.output_label(params[:organization_id])
@@ -0,0 +1,22 @@
1
+ module ForemanRhCloud
2
+ class ForemanRhCloudController < ApplicationController
3
+ include ForemanRhCloud::IopSmartProxyAccess
4
+ layout 'layouts/react_application'
5
+ skip_before_action :authorize, :only => :index
6
+
7
+ before_action :require_iop_smart_proxy, only: [:recommendations]
8
+
9
+ def index
10
+ response.headers['X-Request-Path'] = request.path
11
+ render("react/index", formats: [:html])
12
+ end
13
+
14
+ def inventory_upload
15
+ index
16
+ end
17
+
18
+ def recommendations
19
+ index
20
+ end
21
+ end
22
+ end
@@ -12,6 +12,7 @@ module InsightsCloud::Api
12
12
  skip_after_action :log_response_body, :only => [:forward_request]
13
13
  skip_before_action :check_media_type, :only => [:forward_request]
14
14
  after_action :update_host_insights_status, only: [:forward_request]
15
+ after_action :update_host_facet, only: [:forward_request], if: -> { ForemanRhCloud.with_iop_smart_proxy? }
15
16
 
16
17
  # The method that "proxies" requests over to Cloud
17
18
  def forward_request
@@ -117,14 +118,27 @@ module InsightsCloud::Api
117
118
  end
118
119
 
119
120
  def update_host_insights_status
120
- return unless request.path == '/redhat_access/r/insights/platform/ingress/v1/upload' ||
121
- request.path.include?('/redhat_access/r/insights/uploads/')
122
-
123
- return unless @cloud_response.code.to_s.start_with?('2')
124
-
121
+ return unless upload_success?
125
122
  # create insights status if it wasn't there in the first place and refresh its reporting date
126
123
  @host.get_status(InsightsClientReportStatus).refresh!
127
124
  @host.refresh_global_status!
128
125
  end
126
+
127
+ def update_host_facet
128
+ return unless upload_success?
129
+
130
+ # in IoP case, the hosts are identified by the sub-man ID, and we can assume they already
131
+ # exist in the local inventory. This will also handle facet creation for new hosts.
132
+ return if @host.insights
133
+
134
+ insights_facet = @host.build_insights(uuid: @host.subscription_facet.uuid)
135
+ insights_facet.save
136
+ end
137
+
138
+ def upload_success?
139
+ @cloud_response&.code&.to_s&.start_with?('2') &&
140
+ (request.path == '/redhat_access/r/insights/platform/ingress/v1/upload' ||
141
+ request.path.include?('/redhat_access/r/insights/uploads/'))
142
+ end
129
143
  end
130
144
  end
@@ -75,6 +75,17 @@ module InsightsCloud
75
75
  res.headers[new_header] = header_content
76
76
  end
77
77
 
78
+ def translate_insights_host
79
+ facet = InsightsFacet.find_by(uuid: params[:uuid])
80
+ if facet.present?
81
+ Rails.logger.debug "Found InsightsFacet #{params[:uuid]}"
82
+ redirect_to host_details_page_path(facet.host_id)
83
+ else
84
+ Rails.logger.error "Could not find InsightsFacet for #{params[:uuid]}"
85
+ redirect_to '/page-not-found'
86
+ end
87
+ end
88
+
78
89
  private
79
90
 
80
91
  def ensure_org
@@ -11,7 +11,7 @@ module ForemanRhCloud
11
11
 
12
12
  def execute_cloud_request(params)
13
13
  organization = params.delete(:organization)
14
- certs = ForemanRhCloud.with_local_advisor_engine? ? foreman_certificate : candlepin_id_cert(organization)
14
+ certs = ForemanRhCloud.with_iop_smart_proxy? ? foreman_certificate : candlepin_id_cert(organization)
15
15
  final_params = {
16
16
  ssl_client_cert: OpenSSL::X509::Certificate.new(certs[:cert]),
17
17
  ssl_client_key: OpenSSL::PKey.read(certs[:key]),
@@ -8,7 +8,7 @@ module ForemanRhCloud
8
8
  proxy: ForemanRhCloud.transformed_http_proxy_string,
9
9
  }.deep_merge(params)
10
10
 
11
- if ForemanRhCloud.with_local_advisor_engine?
11
+ if ForemanRhCloud.with_iop_smart_proxy?
12
12
  final_params[:ssl_ca_file] ||= ForemanRhCloud.ca_cert
13
13
  end
14
14
 
@@ -37,7 +37,7 @@ module ForemanRhCloud
37
37
  requested_url = original_request.original_fullpath.end_with?('/') ? original_request.path + '/' : original_request.path
38
38
  params = path_params(requested_url)
39
39
 
40
- if ForemanRhCloud.with_local_advisor_engine?
40
+ if ForemanRhCloud.with_iop_smart_proxy?
41
41
  params[:ssl_ca_file] = ForemanRhCloud.ca_cert
42
42
  end
43
43
 
@@ -2,24 +2,34 @@ module ForemanRhCloud
2
2
  class HitRemediationsRetriever < RemediationsRetriever
3
3
  def initialize(hit_remediation_pairs, logger: Logger.new(IO::NULL))
4
4
  super(logger: logger)
5
- @hit_remediation_pairs = hit_remediation_pairs
5
+ @is_iop = ForemanRhCloud.with_iop_smart_proxy?
6
+ @hit_remediation_pairs = (hit_remediation_pairs || []).map(&:with_indifferent_access)
6
7
  logger.debug("Querying playbook for #{hit_remediation_pairs}")
7
8
  end
8
9
 
9
10
  private
10
11
 
11
12
  def hit_ids
13
+ # hit_ids are host ids
12
14
  @hit_remediation_pairs.map { |pair| pair["hit_id"] }
13
15
  end
14
16
 
15
17
  def remediation_ids
18
+ # In IoP, these are Insights rule IDs. For Hosted, they are Foreman database IDs
16
19
  @hit_remediation_pairs.map { |pair| pair["resolution_id"] }
17
20
  end
18
21
 
19
22
  def hits
20
- @hits ||= Hash[
21
- InsightsHit.joins(:insights_facet).where(id: hit_ids).pluck(:id, 'insights_facets.uuid')
22
- ]
23
+ if @is_iop
24
+ # Return the hit_id unaltered. With IoP, host ids are already translated
25
+ @hits = Hash[@hit_remediation_pairs.map { |pair| [pair[:hit_id], pair[:hit_id]] }]
26
+ else
27
+ # Return a hash which maps Foreman host ID to Insights-flavored ID
28
+ @hits ||= Hash[
29
+ InsightsHit.joins(:insights_facet).where(id: hit_ids).pluck(:id, 'insights_facets.uuid')
30
+ ]
31
+ end
32
+ @hits
23
33
  end
24
34
 
25
35
  def pairs_by_remediation_id
@@ -27,11 +37,18 @@ module ForemanRhCloud
27
37
  end
28
38
 
29
39
  def remediations
30
- @remediations ||= Hash[
31
- InsightsResolution.where(id: remediation_ids).pluck(:id, :resolution_type, :rule_id).map do |id, resolution_type, rule_id|
32
- [id, { resolution_type: resolution_type, rule_id: rule_id }]
33
- end
34
- ]
40
+ if @is_iop
41
+ @remediations = Hash[
42
+ @hit_remediation_pairs.map { |pair| [pair['resolution_id'], { resolution_type: pair['resolution_type'], rule_id: pair['rule_id'] }] }
43
+ ]
44
+ else
45
+ @remediations ||= Hash[
46
+ InsightsResolution.where(id: remediation_ids).pluck(:id, :resolution_type, :rule_id).map do |id, resolution_type, rule_id|
47
+ [id, { resolution_type: resolution_type, rule_id: rule_id }]
48
+ end
49
+ ]
50
+ end
51
+ @remediations
35
52
  end
36
53
 
37
54
  def playbook_request
@@ -65,7 +82,7 @@ module ForemanRhCloud
65
82
  end
66
83
 
67
84
  def organization
68
- InsightsHit.find(@hit_remediation_pairs.first['hit_id']).host.organization
85
+ @is_iop ? Organization.current : InsightsHit.find(@hit_remediation_pairs.first['hit_id']).host.organization
69
86
  end
70
87
  end
71
88
  end
@@ -28,7 +28,7 @@ module ForemanRhCloud
28
28
  end
29
29
 
30
30
  def payload
31
- @payload.to_json
31
+ @payload.present? ? @payload.to_json : @payload # don't run .to_json if @payload is ''
32
32
  end
33
33
 
34
34
  def method
@@ -6,6 +6,6 @@ end
6
6
  node :insights_hits_count do |facet|
7
7
  facet.hits&.count
8
8
  end
9
- node :use_local_advisor_engine do |_facet|
10
- ForemanRhCloud.with_local_advisor_engine?
9
+ node :use_iop_mode do |_facet|
10
+ ForemanRhCloud.with_iop_smart_proxy?
11
11
  end
@@ -1,5 +1,5 @@
1
1
  node :vulnerability do
2
2
  {
3
- enabled: ForemanRhCloud.with_local_advisor_engine?,
3
+ enabled: ForemanRhCloud.with_iop_smart_proxy?,
4
4
  }
5
5
  end
data/config/routes.rb CHANGED
@@ -9,9 +9,7 @@ Rails.application.routes.draw do
9
9
  get 'settings', to: 'uploads_settings#index'
10
10
  post 'setting', to: 'uploads_settings#set_advanced_setting'
11
11
 
12
- unless ForemanRhCloud.with_local_advisor_engine?
13
- post 'cloud_connector', to: 'uploads#enable_cloud_connector'
14
- end
12
+ post 'cloud_connector', to: 'uploads#enable_cloud_connector'
15
13
 
16
14
  resources :tasks, only: [:create, :show]
17
15
 
@@ -35,13 +33,9 @@ Rails.application.routes.draw do
35
33
  end
36
34
 
37
35
  namespace :foreman_rh_cloud do
38
- unless ForemanRhCloud.with_local_advisor_engine?
39
- get 'inventory_upload', to: '/react#index'
40
- end
41
- if ForemanRhCloud.with_local_advisor_engine?
42
- get 'recommendations', to: '/react#index'
43
- get 'recommendations/:rule_id', to: '/react#index'
44
- end
36
+ get 'inventory_upload', to: 'foreman_rh_cloud#inventory_upload'
37
+ get 'recommendations', to: 'foreman_rh_cloud#recommendations'
38
+ get 'recommendations/:rule_id', to: 'foreman_rh_cloud#recommendations'
45
39
  get 'insights_cloud', to: '/react#index' # Uses foreman's react controller
46
40
  get 'insights_vulnerability', to: '/react#index'
47
41
  get 'insights_vulnerability/:cve_id', to: '/react#index'
@@ -61,6 +55,8 @@ Rails.application.routes.draw do
61
55
  match '/api/lightspeed/*path', to: 'machine_telemetries#forward_request', via: :all
62
56
  end
63
57
 
58
+ get '/insights_hosts/:uuid', to: 'insights_cloud/ui_requests#translate_insights_host'
59
+
64
60
  # API routes
65
61
 
66
62
  namespace :api, :defaults => { :format => 'json' } do
@@ -77,10 +73,8 @@ Rails.application.routes.draw do
77
73
  end
78
74
 
79
75
  namespace 'rh_cloud' do
80
- unless ForemanRhCloud.with_local_advisor_engine?
81
- post 'enable_connector', to: 'inventory#enable_cloud_connector'
82
- post 'cloud_request', to: 'cloud_request#update'
83
- end
76
+ post 'enable_connector', to: 'inventory#enable_cloud_connector'
77
+ post 'cloud_request', to: 'cloud_request#update'
84
78
  get 'advisor_engine_config', to: 'advisor_engine_config#show'
85
79
  end
86
80
 
@@ -13,7 +13,7 @@ module ForemanInventoryUpload
13
13
  return
14
14
  end
15
15
 
16
- if ForemanRhCloud.with_local_advisor_engine?
16
+ if ForemanRhCloud.with_iop_smart_proxy?
17
17
  plan_self # so that 'run' runs
18
18
  else
19
19
  after_delay do
@@ -34,7 +34,7 @@ module ForemanInventoryUpload
34
34
  end
35
35
 
36
36
  def run
37
- output[:status] = _('The scheduled process is disabled because this Foreman is configured with the use_local_advisor_engine option.') if ForemanRhCloud.with_local_advisor_engine?
37
+ output[:status] = _('The scheduled process is disabled because this Foreman is configured with a local IoP Smart Proxy.') if ForemanRhCloud.with_iop_smart_proxy?
38
38
  end
39
39
 
40
40
  def rescue_strategy_for_self
@@ -60,7 +60,7 @@ module ForemanInventoryUpload
60
60
  end
61
61
 
62
62
  def certificate
63
- ForemanRhCloud.with_local_advisor_engine? ? foreman_certificate : manifest_certificate
63
+ ForemanRhCloud.with_iop_smart_proxy? ? foreman_certificate : manifest_certificate
64
64
  end
65
65
 
66
66
  def manifest_certificate
@@ -213,6 +213,8 @@ module ForemanInventoryUpload
213
213
  first = false
214
214
  end
215
215
  end
216
+
217
+ report_yum_repos(host)
216
218
  end
217
219
  @stream.simple_field('satellite_managed', true, :last)
218
220
  end
@@ -248,6 +250,28 @@ module ForemanInventoryUpload
248
250
  def os_release_value(name, version, codename)
249
251
  "#{name} #{version} (#{codename})"
250
252
  end
253
+
254
+ def report_yum_repos(host)
255
+ return unless host&.content_facet&.bound_repositories&.any?
256
+ return unless ForemanRhCloud.with_iop_smart_proxy?
257
+
258
+ @stream.array_field('yum_repos') do
259
+ host.content_facet.bound_repositories.each_with_index do |repo, index|
260
+ report_yum_repo(host.content_source.load_balancer_pulp_content_url, repo)
261
+ @stream.comma unless index == host.content_facet.bound_repositories.count - 1
262
+ end
263
+ end
264
+ end
265
+
266
+ def report_yum_repo(url_prefix, repo)
267
+ @stream.object do
268
+ @stream.simple_field('name', repo.content.name)
269
+ @stream.simple_field('id', repo.content.label)
270
+ @stream.simple_field('base_url', "#{url_prefix}/#{repo.generate_repo_path(repo.content.content_url)}")
271
+ @stream.simple_field('enabled', true)
272
+ @stream.simple_field('gpgcheck', true, :last)
273
+ end
274
+ end
251
275
  end
252
276
  end
253
277
  end
@@ -33,134 +33,7 @@ module ForemanRhCloud
33
33
 
34
34
  initializer 'foreman_rh_cloud.register_plugin', :before => :finisher_hook do |app|
35
35
  app.reloader.to_prepare do
36
- Foreman::Plugin.register :foreman_rh_cloud do
37
- requires_foreman '>= 3.13'
38
- register_gettext
39
-
40
- apipie_documented_controllers ["#{ForemanRhCloud::Engine.root}/app/controllers/api/v2/**/*.rb"]
41
-
42
- settings do
43
- category(:rh_cloud, N_('Insights')) do
44
- setting('allow_auto_inventory_upload', type: :boolean, description: N_('Enable automatic upload of your host inventory to the Red Hat cloud'), default: true, full_name: N_('Automatic inventory upload'))
45
- setting('allow_auto_insights_sync', type: :boolean, description: N_('Enable automatic synchronization of Insights recommendations from the Red Hat cloud'), default: true, full_name: N_('Synchronize recommendations Automatically'))
46
- setting('allow_auto_insights_mismatch_delete', type: :boolean, description: N_('Enable automatic deletion of mismatched host records from the Red Hat cloud'), default: false, full_name: N_('Automatic mismatch deletion'))
47
- setting('obfuscate_inventory_hostnames', type: :boolean, description: N_('Obfuscate host names sent to the Red Hat cloud. (If insights_minimal_data_collection is set to true, this setting is ignored because host names are not included in the report.)'), default: false, full_name: N_('Obfuscate host names'))
48
- setting('obfuscate_inventory_ips', type: :boolean, description: N_('Obfuscate ipv4 addresses sent to the Red Hat cloud. (If insights_minimal_data_collection is set to true, this setting is ignored because host IPv4 addresses are not included in the report.)'), default: false, full_name: N_('Obfuscate host ipv4 addresses.'))
49
- setting('exclude_installed_packages', type: :boolean, description: N_('Exclude installed packages from being uploaded to the Red Hat cloud. (If insights_minimal_data_collection is set to true, this setting is ignored and installed packages are always excluded.)'), default: false, full_name: N_("Exclude installed packages"))
50
- setting('include_parameter_tags', type: :boolean, description: N_('Should import include parameter tags from Foreman?'), default: false, full_name: N_('Include parameters in insights-client reports'))
51
- setting('rhc_instance_id', type: :string, description: N_('RHC daemon id'), default: nil, full_name: N_('ID of the RHC(Yggdrasil) daemon'))
52
- setting('insights_minimal_data_collection', type: :boolean, default: false, full_name: N_('Minimal data collection'), description: N_('Only include the minimum required data in inventory reports for uploading to Red Hat cloud. When this is true, installed packages are excluded from the report regardless of the exclude_installed_packages setting, and host names and IPv4 addresses are excluded from the report regardless of obfuscation settings.'))
53
- end
54
- end
55
-
56
- # Add permissions
57
- security_block :foreman_rh_cloud do
58
- permission(
59
- :generate_foreman_rh_cloud,
60
- 'foreman_inventory_upload/reports': [:generate],
61
- 'foreman_inventory_upload/tasks': [:create],
62
- 'api/v2/rh_cloud/inventory': [:get_hosts, :remove_hosts, :sync_inventory_status, :download_file, :generate_report, :enable_cloud_connector],
63
- 'foreman_inventory_upload/uploads': [:enable_cloud_connector],
64
- 'foreman_inventory_upload/uploads_settings': [:set_advanced_setting],
65
- 'foreman_inventory_upload/missing_hosts': [:remove_hosts],
66
- 'insights_cloud/settings': [:update],
67
- 'insights_cloud/tasks': [:create]
68
- )
69
- permission(
70
- :view_foreman_rh_cloud,
71
- 'foreman_inventory_upload/accounts': [:index],
72
- 'foreman_inventory_upload/reports': [:last],
73
- 'foreman_inventory_upload/uploads': [:auto_upload, :show_auto_upload, :download_file, :last],
74
- 'foreman_inventory_upload/tasks': [:show],
75
- 'foreman_inventory_upload/cloud_status': [:index],
76
- 'foreman_inventory_upload/uploads_settings': [:index],
77
- 'foreman_inventory_upload/missing_hosts': [:index],
78
- 'api/v2/rh_cloud/advisor_engine_config': [:show],
79
- 'react': [:index]
80
- )
81
- permission(
82
- :view_insights_hits,
83
- {
84
- '/foreman_rh_cloud/insights_cloud': [:index], # for bookmarks and later for showing the page
85
- 'insights_cloud/hits': [:index, :show, :auto_complete_search, :resolutions],
86
- 'insights_cloud/settings': [:index, :show],
87
- 'insights_cloud/ui_requests': [:forward_request],
88
- 'react': [:index],
89
- },
90
- :resource_type => ::InsightsHit.name
91
- )
92
- permission(
93
- :dispatch_cloud_requests,
94
- 'api/v2/rh_cloud/cloud_request': [:update]
95
- )
96
- permission(
97
- :control_organization_insights,
98
- 'insights_cloud/settings': [:set_org_parameter]
99
- )
100
- end
101
-
102
- plugin_permissions = [:view_foreman_rh_cloud, :generate_foreman_rh_cloud, :view_insights_hits, :dispatch_cloud_requests, :control_organization_insights]
103
-
104
- role 'ForemanRhCloud', plugin_permissions, 'Role granting permissions to view the hosts inventory,
105
- generate a report, upload it to the cloud and download it locally'
106
-
107
- add_permissions_to_default_roles Role::ORG_ADMIN => plugin_permissions,
108
- Role::MANAGER => plugin_permissions,
109
- Role::SYSTEM_ADMIN => plugin_permissions
110
-
111
- # Adding a top-level menu item
112
- sub_menu :top_menu, :insights_menu, caption: N_('Insights'), icon: 'fa fa-cloud', after: :hosts_menu do
113
- menu :top_menu,
114
- :inventory_upload,
115
- caption: N_('Inventory Upload'),
116
- url: '/foreman_rh_cloud/inventory_upload',
117
- url_hash: { controller: :react, action: :index },
118
- parent: :insights_menu
119
- menu :top_menu, :insights_hits, caption: N_('Recommendations'), url: '/foreman_rh_cloud/insights_cloud', url_hash: { controller: :react, action: :index }, parent: :insights_menu
120
- menu :top_menu,
121
- :insights_vulnerability,
122
- caption: N_('Vulnerability'),
123
- url: '/foreman_rh_cloud/insights_vulnerability',
124
- url_hash: { controller: :react, action: :index },
125
- parent: :insights_menu,
126
- if: -> { ForemanRhCloud.with_local_advisor_engine? }
127
- end
128
-
129
- register_facet InsightsFacet, :insights do
130
- configure_host do
131
- api_view :list => 'api/v2/hosts/insights/insights', :single => 'api/v2/hosts/insights/single'
132
- set_dependent_action :destroy
133
- end
134
- end
135
-
136
- register_global_js_file 'global'
137
-
138
- register_custom_status InventorySync::InventoryStatus
139
- register_custom_status InsightsClientReportStatus
140
-
141
- describe_host do
142
- overview_buttons_provider :insights_host_overview_buttons
143
- end
144
-
145
- extend_page 'hosts/show' do |context|
146
- context.add_pagelet :main_tabs,
147
- partial: 'hosts/insights_tab',
148
- name: _('Insights'),
149
- id: 'insights',
150
- onlyif: proc { |host| host.insights }
151
- end
152
-
153
- extend_page 'hosts/_list' do |context|
154
- context.with_profile :cloud, _('RH Cloud'), default: true do
155
- add_pagelet :hosts_table_column_header, key: :insights_recommendations_count, label: _('Recommendations'), sortable: true, width: '12%', class: 'hidden-xs ellipsis', priority: 100,
156
- export_data: CsvExporter::ExportDefinition.new(:insights_recommendations_count, callback: ->(host) { host&.insights_hits&.count })
157
- add_pagelet :hosts_table_column_content, key: :insights_recommendations_count, callback: ->(host) { hits_counts_cell(host) }, class: 'hidden-xs ellipsis text-center', priority: 100
158
- end
159
- end
160
-
161
- extend_template_helpers ForemanRhCloud::TemplateRendererHelper
162
- allowed_template_helpers :remediations_playbook, :download_rh_playbook
163
- end
36
+ ForemanRhCloud::Plugin.register
164
37
 
165
38
  ::Katello::UINotifications::Subscriptions::ManifestImportSuccess.include ForemanInventoryUpload::Notifications::ManifestImportSuccessNotificationOverride if defined?(Katello)
166
39
 
@@ -248,8 +121,12 @@ module ForemanRhCloud
248
121
  end
249
122
  end
250
123
 
251
- def self.with_local_advisor_engine?
252
- SETTINGS.dig(:foreman_rh_cloud, :use_local_advisor_engine) || false
124
+ def self.with_iop_smart_proxy?
125
+ SmartProxy.with_features('iop').exists?
126
+ end
127
+
128
+ def self.iop_smart_proxy
129
+ SmartProxy.with_features('iop').first
253
130
  end
254
131
 
255
132
  def self.ca_cert
@@ -264,6 +141,6 @@ module ForemanRhCloud
264
141
  end
265
142
 
266
143
  def self.on_prem_smart_proxy_features
267
- ['Insights']
144
+ ['iop']
268
145
  end
269
146
  end