foreman_rh_cloud 12.2.1 → 12.2.3

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 (59) 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/models/foreman_rh_cloud/ping.rb +90 -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/insights_api_forwarder.rb +14 -12
  16. data/app/services/foreman_rh_cloud/tags_auth.rb +3 -2
  17. data/app/views/api/v2/hosts/insights/base.rabl +2 -2
  18. data/app/views/api/v2/hosts/insights/single.rabl +1 -1
  19. data/config/routes.rb +6 -14
  20. data/lib/foreman_inventory_upload/async/generate_all_reports_job.rb +2 -2
  21. data/lib/foreman_inventory_upload/async/upload_report_job.rb +1 -1
  22. data/lib/foreman_inventory_upload/generators/slice.rb +24 -0
  23. data/lib/foreman_rh_cloud/engine.rb +6 -2
  24. data/lib/foreman_rh_cloud/plugin.rb +18 -2
  25. data/lib/foreman_rh_cloud/version.rb +1 -1
  26. data/lib/foreman_rh_cloud.rb +5 -6
  27. data/lib/insights_cloud/async/insights_scheduled_sync.rb +2 -2
  28. data/lib/inventory_sync/async/inventory_hosts_sync.rb +1 -1
  29. data/lib/inventory_sync/async/inventory_scheduled_sync.rb +2 -2
  30. data/lib/tasks/insights.rake +1 -1
  31. data/lib/tasks/rh_cloud_inventory.rake +20 -2
  32. data/package.json +1 -1
  33. data/test/controllers/insights_cloud/api/machine_telemetries_controller_test.rb +20 -3
  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/services/foreman_rh_cloud/insights_api_forwarder_test.rb +43 -2
  41. data/test/unit/services/foreman_rh_cloud/tags_auth_test.rb +15 -1
  42. data/test/unit/slice_generator_test.rb +33 -0
  43. data/test/unit/tags_generator_test.rb +4 -1
  44. data/webpack/CVEsHostDetailsTab/CVEsHostDetailsTab.js +1 -1
  45. data/webpack/CveDetailsPage/CveDetailsPage.js +1 -1
  46. data/webpack/CveDetailsPage/CveDetailsPage.test.js +1 -3
  47. data/webpack/ForemanColumnExtensions/index.js +1 -1
  48. data/webpack/ForemanRhCloudPages.js +1 -0
  49. data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationHelpers.js +26 -4
  50. data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationModal.js +85 -11
  51. data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationModalFooter.js +39 -5
  52. data/webpack/InsightsCloudSync/Components/RemediationModal/Resolutions.js +13 -0
  53. data/webpack/InsightsCloudSync/InsightsCloudSync.js +9 -7
  54. data/webpack/InsightsHostDetailsTab/NewHostDetailsTab.js +12 -10
  55. data/webpack/InsightsVulnerability/InsightsVulnerabilityListPage.js +1 -1
  56. data/webpack/IopRecommendationDetails/IopRecommendationDetails.js +1 -1
  57. data/webpack/common/Hooks/ConfigHooks.js +1 -2
  58. data/webpack/common/styles.scss +7 -0
  59. metadata +5 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a5297c9be7a8e61f55e175c20b5f322b19c015d9a29bdd9c1bf42248ad1ffedf
4
- data.tar.gz: 59cab12bcca78ee78eba81af4c0089f1dcaac84b35244936b707692c4881f7ba
3
+ metadata.gz: c2002305657053ddee42c958f1050b73e0d6b83bc9a41acadff095d216b07899
4
+ data.tar.gz: 5d4e414ae8ce2e25a4f3d845c226fe64e808471dd3ef96161f414f36ba0d1190
5
5
  SHA512:
6
- metadata.gz: d8a544fe9144aad08668231c90d3c221a316501dc3d7f3766c444d2617c22949a5d4bde889960f6ff5cd9a6005f07885cb99ca059ab8b64ca7a5f058fc8df192
7
- data.tar.gz: 123d446d857e98c371c362b26af1be131e59d41c7ade186a11d061fcb5078b39358a998be23eceb1e4dafcc66e9e6a8dd10c70652ad60b13f01d54675fbd4576
6
+ metadata.gz: f8a0ec3ca0ce175a0f72a81a12a7b2457e6f68f894fa91434decd92e6bd484cbcb467538376dc41180dbf6cd65ef344fe121ec7d0c6dba7095095f779b0239cb
7
+ data.tar.gz: e60d883392d906b2de8d439989ed89062f4cceab79a46382229fec503d541209cc921ebcd09ed0b860418ef55df37771eb2388519ab81b43d0dbf27897623bb6
@@ -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
@@ -0,0 +1,90 @@
1
+ module ForemanRhCloud
2
+ class Ping
3
+ OK_RETURN_CODE = 'ok'.freeze
4
+ FAIL_RETURN_CODE = 'FAIL'.freeze
5
+
6
+ class << self
7
+ include ForemanRhCloud::CertAuth
8
+
9
+ def iop_smart_proxy_url
10
+ @iop_smart_proxy_url ||= ForemanRhCloud.iop_smart_proxy.url
11
+ end
12
+
13
+ def service_urls
14
+ {
15
+ :advisor => "#{iop_smart_proxy_url}/api/insights/v1/status/live/",
16
+ :vulnerability => "#{iop_smart_proxy_url}/api/vulnerability/v1/apistatus",
17
+ }
18
+ end
19
+
20
+ def services
21
+ service_urls.keys
22
+ end
23
+
24
+ def status
25
+ {
26
+ iop_smart_proxy_exists: ForemanRhCloud.with_iop_smart_proxy?,
27
+ timeUTC: Time.zone.now.getutc,
28
+ }
29
+ end
30
+
31
+ def exception_watch(result, &blk)
32
+ ::Katello::Ping.exception_watch(result, &blk)
33
+ end
34
+
35
+ def ping
36
+ ping_services
37
+ end
38
+
39
+ def ping!
40
+ result = ping_services
41
+
42
+ if result[:status] != OK_RETURN_CODE
43
+ failed_names = result[:services].reject do |_name, details|
44
+ details[:status] == OK_RETURN_CODE
45
+ end
46
+ raise "The following services have not been started or are reporting errors: #{failed_names.keys.join(', ')}"
47
+ end
48
+
49
+ result
50
+ end
51
+
52
+ def ping_services
53
+ result = {}
54
+ services.each do |service|
55
+ result[service] = {}
56
+ ping_service(service, result[service])
57
+ end
58
+
59
+ # set overall status result code
60
+ result = { :services => result }
61
+ result[:status] = result[:services].each_value.any? { |v| v[:status] == FAIL_RETURN_CODE } ? FAIL_RETURN_CODE : OK_RETURN_CODE
62
+ result
63
+ end
64
+
65
+ def logger
66
+ Rails.logger
67
+ end
68
+
69
+ def ping_url(url)
70
+ response = execute_cloud_request(
71
+ method: :get,
72
+ url: url
73
+ )
74
+ return {} if response.empty?
75
+ begin
76
+ result = JSON.parse(response).with_indifferent_access
77
+ rescue JSON::ParserError, NoMethodError
78
+ result = { :response => response.body&.strip }
79
+ end
80
+ result
81
+ end
82
+
83
+ def ping_service(service_name, service_result_hash)
84
+ exception_watch(service_result_hash) do
85
+ ping_url(service_urls[service_name])
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
@@ -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
@@ -5,13 +5,13 @@ module ForemanRhCloud
5
5
  include ForemanRhCloud::GatewayRequest
6
6
 
7
7
  SCOPED_REQUESTS = [
8
- %r{/api/vulnerability/v1/vulnerabilities/cves},
9
- %r{/api/vulnerability/v1/dashbar},
10
- %r{/api/vulnerability/v1/cves/[^/]+/affected_systems},
11
- %r{/api/vulnerability/v1/systems/[^/]+/cves},
12
- %r{/api/insights/.*},
13
- %r{/api/inventory/.*},
14
- %r{/api/tasks/.*},
8
+ { test: %r{api/vulnerability/v1/vulnerabilities/cves}, tag_name: :tags },
9
+ { test: %r{api/vulnerability/v1/dashbar}, tag_name: :tags },
10
+ { test: %r{api/vulnerability/v1/cves/[^/]+/affected_systems}, tag_name: :tags },
11
+ { test: %r{api/vulnerability/v1/systems/[^/]+/cves}, tag_name: :tags },
12
+ { test: %r{api/insights/.*}, tag_name: :tags },
13
+ { test: %r{api/inventory/.*}, tag_name: :tags },
14
+ { test: %r{api/tasks/.*}, tag_name: :tags },
15
15
  ].freeze
16
16
 
17
17
  def forward_request(original_request, path, controller_name, user, organization, location)
@@ -31,10 +31,10 @@ module ForemanRhCloud
31
31
  execute_cloud_request(request_opts)
32
32
  end
33
33
 
34
- def prepare_tags(user, organization, location)
34
+ def prepare_tags(user, organization, location, tag_name)
35
35
  [
36
36
  TagsAuth.auth_tag_for(user, organization, location),
37
- ].map { |tag_value| [:tag, tag_value] }
37
+ ].map { |tag_value| [tag_name, tag_value] }
38
38
  end
39
39
 
40
40
  def prepare_request_opts(original_request, path, forward_payload, forward_params)
@@ -70,7 +70,8 @@ module ForemanRhCloud
70
70
  def prepare_forward_params(original_request, path, user:, organization:, location:)
71
71
  forward_params = original_request.query_parameters.to_a
72
72
 
73
- forward_params += prepare_tags(user, organization, location) if scope_request?(original_request, path)
73
+ tag_name = scope_request?(original_request, path)
74
+ forward_params += prepare_tags(user, organization, location, tag_name) if tag_name
74
75
 
75
76
  forward_params
76
77
  end
@@ -92,9 +93,10 @@ module ForemanRhCloud
92
93
  end
93
94
 
94
95
  def scope_request?(original_request, path)
95
- return false unless original_request.get?
96
+ return nil unless original_request.get?
96
97
 
97
- SCOPED_REQUESTS.any? { |request_pattern| request_pattern.match?(path) }
98
+ request_pattern = SCOPED_REQUESTS.find { |pattern| pattern[:test].match?(path) }
99
+ request_pattern[:tag_name] if request_pattern
98
100
  end
99
101
 
100
102
  def core_app_name
@@ -22,15 +22,16 @@ module ForemanRhCloud
22
22
  def update_tag
23
23
  logger.debug("Updating tags for user: #{@user}, org: #{@org.name}, loc: #{@loc.name}")
24
24
 
25
+ payload = tags_query_payload
25
26
  params = {
26
27
  method: :post,
27
28
  url: "#{InsightsCloud.gateway_url}/tags",
28
29
  headers: {
29
30
  content_type: :json,
30
31
  },
31
- payload: tags_query_payload.to_json,
32
+ payload: payload.to_json,
32
33
  }
33
- execute_cloud_request(params)
34
+ execute_cloud_request(params) unless payload[:host_id_list].empty?
34
35
  end
35
36
 
36
37
  def allowed_hosts
@@ -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'
@@ -79,10 +73,8 @@ Rails.application.routes.draw do
79
73
  end
80
74
 
81
75
  namespace 'rh_cloud' do
82
- unless ForemanRhCloud.with_local_advisor_engine?
83
- post 'enable_connector', to: 'inventory#enable_cloud_connector'
84
- post 'cloud_request', to: 'cloud_request#update'
85
- end
76
+ post 'enable_connector', to: 'inventory#enable_cloud_connector'
77
+ post 'cloud_request', to: 'cloud_request#update'
86
78
  get 'advisor_engine_config', to: 'advisor_engine_config#show'
87
79
  end
88
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
@@ -121,8 +121,12 @@ module ForemanRhCloud
121
121
  end
122
122
  end
123
123
 
124
- def self.with_local_advisor_engine?
125
- SETTINGS.dig(:foreman_rh_cloud, :use_local_advisor_engine) || false
124
+ def self.with_iop_smart_proxy?
125
+ SmartProxy.unscoped.with_features('iop').exists?
126
+ end
127
+
128
+ def self.iop_smart_proxy
129
+ SmartProxy.unscoped.with_features('iop').first
126
130
  end
127
131
 
128
132
  def self.ca_cert
@@ -48,6 +48,7 @@ module ForemanRhCloud
48
48
  'foreman_inventory_upload/uploads_settings': [:index],
49
49
  'foreman_inventory_upload/missing_hosts': [:index],
50
50
  'api/v2/rh_cloud/advisor_engine_config': [:show],
51
+ 'foreman_rh_cloud/foreman_rh_cloud': [:inventory_upload, :recommendations],
51
52
  'react': [:index]
52
53
  )
53
54
  permission(
@@ -87,7 +88,8 @@ module ForemanRhCloud
87
88
  caption: N_('Inventory Upload'),
88
89
  url: '/foreman_rh_cloud/inventory_upload',
89
90
  url_hash: { controller: :react, action: :index },
90
- parent: :insights_menu
91
+ parent: :insights_menu,
92
+ if: -> { !ForemanRhCloud.with_iop_smart_proxy? }
91
93
  menu :top_menu, :insights_hits, caption: N_('Recommendations'), url: '/foreman_rh_cloud/insights_cloud', url_hash: { controller: :react, action: :index }, parent: :insights_menu
92
94
  menu :top_menu,
93
95
  :insights_vulnerability,
@@ -95,9 +97,19 @@ module ForemanRhCloud
95
97
  url: '/foreman_rh_cloud/insights_vulnerability',
96
98
  url_hash: { controller: :react, action: :index },
97
99
  parent: :insights_menu,
98
- if: -> { ForemanRhCloud.with_local_advisor_engine? }
100
+ if: -> { ForemanRhCloud.with_iop_smart_proxy? }
99
101
  end
100
102
 
103
+ # In IoP case we want the page to be in the admin menu
104
+ menu :admin_menu,
105
+ :inventory_upload,
106
+ caption: N_('Inventory Upload'),
107
+ url: '/foreman_rh_cloud/inventory_upload',
108
+ url_hash: { controller: :react, action: :index },
109
+ parent: :administer_menu,
110
+ before: :upgrade,
111
+ if: -> { ForemanRhCloud.with_iop_smart_proxy? }
112
+
101
113
  register_facet InsightsFacet, :insights do
102
114
  configure_host do
103
115
  api_view :list => 'api/v2/hosts/insights/insights', :single => 'api/v2/hosts/insights/single'
@@ -109,6 +121,10 @@ module ForemanRhCloud
109
121
 
110
122
  register_custom_status InventorySync::InventoryStatus
111
123
  register_custom_status InsightsClientReportStatus
124
+ if ForemanRhCloud.with_iop_smart_proxy?
125
+ register_ping_extension { ForemanRhCloud::Ping.ping }
126
+ register_status_extension { ForemanRhCloud::Ping.status }
127
+ end
112
128
 
113
129
  describe_host do
114
130
  overview_buttons_provider :insights_host_overview_buttons
@@ -1,3 +1,3 @@
1
1
  module ForemanRhCloud
2
- VERSION = '12.2.1'.freeze
2
+ VERSION = '12.2.3'.freeze
3
3
  end
@@ -4,13 +4,12 @@ require 'uri'
4
4
 
5
5
  module ForemanRhCloud
6
6
  def self.on_premise_url
7
- return unless ForemanRhCloud.with_local_advisor_engine?
8
- port = ENV['ADVISOR_ENGINE_PORT'] || "24443"
9
- ENV['ADVISOR_ENGINE_URL'] || "https://localhost:#{port}"
7
+ return unless ForemanRhCloud.with_iop_smart_proxy?
8
+ ForemanRhCloud.iop_smart_proxy&.url
10
9
  end
11
10
 
12
11
  def self.env_or_on_premise_url(env_var_name)
13
- ENV[env_var_name] || on_premise_url
12
+ on_premise_url || ENV[env_var_name]
14
13
  end
15
14
 
16
15
  def self.base_url
@@ -47,7 +46,7 @@ module ForemanRhCloud
47
46
  end
48
47
 
49
48
  def self.proxy_string
50
- return '' if ForemanRhCloud.with_local_advisor_engine?
49
+ return '' if ForemanRhCloud.with_iop_smart_proxy?
51
50
 
52
51
  HttpProxy.default_global_content_proxy&.full_url ||
53
52
  ForemanRhCloud.global_foreman_proxy ||
@@ -106,7 +105,7 @@ module ForemanRhCloud
106
105
  end
107
106
 
108
107
  def self.legacy_insights_ca
109
- "#{ForemanRhCloud::Engine.root}/config/rh_cert-api_chain.pem" unless ForemanRhCloud.with_local_advisor_engine?
108
+ "#{ForemanRhCloud::Engine.root}/config/rh_cert-api_chain.pem" unless ForemanRhCloud.with_iop_smart_proxy?
110
109
  end
111
110
 
112
111
  def self.cloud_url_validator