foreman_rh_cloud 12.2.1 → 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.
- checksums.yaml +4 -4
- data/app/controllers/api/v2/rh_cloud/advisor_engine_config_controller.rb +1 -1
- data/app/controllers/api/v2/rh_cloud/cloud_request_controller.rb +3 -0
- data/app/controllers/api/v2/rh_cloud/inventory_controller.rb +3 -0
- data/app/controllers/concerns/foreman_rh_cloud/iop_smart_proxy_access.rb +28 -0
- data/app/controllers/concerns/insights_cloud/package_profile_upload_extensions.rb +1 -1
- data/app/controllers/foreman_inventory_upload/uploads_controller.rb +3 -0
- data/app/controllers/foreman_rh_cloud/foreman_rh_cloud_controller.rb +22 -0
- data/app/controllers/insights_cloud/api/machine_telemetries_controller.rb +19 -5
- data/app/services/foreman_rh_cloud/cert_auth.rb +1 -1
- data/app/services/foreman_rh_cloud/cloud_request.rb +1 -1
- data/app/services/foreman_rh_cloud/cloud_request_forwarder.rb +1 -1
- data/app/services/foreman_rh_cloud/hit_remediations_retriever.rb +27 -10
- data/app/views/api/v2/hosts/insights/base.rabl +2 -2
- data/app/views/api/v2/hosts/insights/single.rabl +1 -1
- data/config/routes.rb +6 -14
- data/lib/foreman_inventory_upload/async/generate_all_reports_job.rb +2 -2
- data/lib/foreman_inventory_upload/async/upload_report_job.rb +1 -1
- data/lib/foreman_inventory_upload/generators/slice.rb +24 -0
- data/lib/foreman_rh_cloud/engine.rb +6 -2
- data/lib/foreman_rh_cloud/plugin.rb +14 -2
- data/lib/foreman_rh_cloud/version.rb +1 -1
- data/lib/foreman_rh_cloud.rb +5 -6
- data/lib/insights_cloud/async/insights_scheduled_sync.rb +2 -2
- data/lib/inventory_sync/async/inventory_hosts_sync.rb +1 -1
- data/lib/inventory_sync/async/inventory_scheduled_sync.rb +2 -2
- data/lib/tasks/insights.rake +1 -1
- data/lib/tasks/rh_cloud_inventory.rake +20 -2
- data/package.json +1 -1
- data/test/controllers/insights_cloud/api/machine_telemetries_controller_test.rb +20 -3
- data/test/controllers/insights_sync/settings_controller_test.rb +1 -1
- data/test/factories/inventory_upload_factories.rb +4 -112
- data/test/jobs/inventory_scheduled_sync_test.rb +3 -3
- data/test/test_plugin_helper.rb +8 -2
- data/test/unit/rh_cloud_http_proxy_test.rb +3 -3
- data/test/unit/services/foreman_rh_cloud/cloud_request_forwarder_test.rb +4 -1
- data/test/unit/slice_generator_test.rb +33 -0
- data/test/unit/tags_generator_test.rb +4 -1
- data/webpack/CVEsHostDetailsTab/CVEsHostDetailsTab.js +1 -1
- data/webpack/CveDetailsPage/CveDetailsPage.js +1 -1
- data/webpack/CveDetailsPage/CveDetailsPage.test.js +1 -3
- data/webpack/ForemanRhCloudPages.js +1 -0
- data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationHelpers.js +26 -4
- data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationModal.js +85 -11
- data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationModalFooter.js +39 -5
- data/webpack/InsightsCloudSync/Components/RemediationModal/Resolutions.js +13 -0
- data/webpack/InsightsCloudSync/InsightsCloudSync.js +9 -7
- data/webpack/InsightsHostDetailsTab/NewHostDetailsTab.js +12 -10
- data/webpack/InsightsVulnerability/InsightsVulnerabilityListPage.js +1 -1
- data/webpack/IopRecommendationDetails/IopRecommendationDetails.js +1 -1
- data/webpack/common/Hooks/ConfigHooks.js +1 -2
- data/webpack/common/styles.scss +7 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3bc2f9bf0700b7f22d4bee9c0b1f02b10d7b91a441bfa125f38cf2b3b00f655
|
4
|
+
data.tar.gz: 21a3c48d1720f8ffbea0dd00fbf3b660dc6adea2a097254fd4c9a6c85791f49b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
@@ -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
|
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
|
@@ -11,7 +11,7 @@ module ForemanRhCloud
|
|
11
11
|
|
12
12
|
def execute_cloud_request(params)
|
13
13
|
organization = params.delete(:organization)
|
14
|
-
certs = ForemanRhCloud.
|
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]),
|
@@ -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.
|
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
|
-
@
|
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
|
-
@
|
21
|
-
|
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
|
-
@
|
31
|
-
|
32
|
-
[
|
33
|
-
|
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
|
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
|
-
|
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
|
-
|
39
|
-
|
40
|
-
|
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
|
-
|
83
|
-
|
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.
|
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
|
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.
|
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.
|
125
|
-
|
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
|
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.
|
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'
|
data/lib/foreman_rh_cloud.rb
CHANGED
@@ -4,13 +4,12 @@ require 'uri'
|
|
4
4
|
|
5
5
|
module ForemanRhCloud
|
6
6
|
def self.on_premise_url
|
7
|
-
return unless ForemanRhCloud.
|
8
|
-
|
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]
|
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.
|
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.
|
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
|
@@ -13,7 +13,7 @@ module InsightsCloud
|
|
13
13
|
return
|
14
14
|
end
|
15
15
|
|
16
|
-
if ForemanRhCloud.
|
16
|
+
if ForemanRhCloud.with_iop_smart_proxy?
|
17
17
|
plan_self
|
18
18
|
else
|
19
19
|
after_delay do
|
@@ -23,7 +23,7 @@ module InsightsCloud
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def run
|
26
|
-
output[:status] = _('The scheduled process is disabled because this Foreman is configured with
|
26
|
+
output[:status] = _('The scheduled process is disabled because this Foreman is configured with a local IoP Smart Proxy.') if ForemanRhCloud.with_iop_smart_proxy?
|
27
27
|
end
|
28
28
|
|
29
29
|
def plan_full_sync
|
@@ -9,7 +9,7 @@ module InventorySync
|
|
9
9
|
|
10
10
|
def plan(organizations)
|
11
11
|
# Do not run for local advisor, since we use sub-man id to identify hosts.
|
12
|
-
return if ForemanRhCloud.
|
12
|
+
return if ForemanRhCloud.with_iop_smart_proxy?
|
13
13
|
# by default the tasks will be executed concurrently
|
14
14
|
super(organizations)
|
15
15
|
plan_self_host_sync
|
@@ -13,7 +13,7 @@ module InventorySync
|
|
13
13
|
return
|
14
14
|
end
|
15
15
|
|
16
|
-
if ForemanRhCloud.
|
16
|
+
if ForemanRhCloud.with_iop_smart_proxy?
|
17
17
|
plan_self # so that 'run' runs
|
18
18
|
else
|
19
19
|
after_delay do
|
@@ -35,7 +35,7 @@ module InventorySync
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def run
|
38
|
-
output[:status] = _('The scheduled process is disabled because this Foreman is configured with
|
38
|
+
output[:status] = _('The scheduled process is disabled because this Foreman is configured with a local IoP Smart Proxy.') if ForemanRhCloud.with_iop_smart_proxy?
|
39
39
|
end
|
40
40
|
|
41
41
|
def plan_remove_insights_hosts(org_id)
|
data/lib/tasks/insights.rake
CHANGED
@@ -24,7 +24,7 @@ namespace :rh_cloud_insights do
|
|
24
24
|
desc "Re-announce all organizations into Sources on RH cloud."
|
25
25
|
task announce_to_sources: [:environment] do
|
26
26
|
logger = Logging::Logger.new(STDOUT)
|
27
|
-
if ForemanRhCloud.
|
27
|
+
if ForemanRhCloud.with_iop_smart_proxy?
|
28
28
|
logger.warn('Task announce_to_sources is not available when using local advisor engine')
|
29
29
|
else
|
30
30
|
Organization.unscoped.each do |org|
|
@@ -9,7 +9,7 @@ namespace :rh_cloud_inventory do
|
|
9
9
|
else
|
10
10
|
organizations = [Organization.where(:id => ENV['organization_id']).first]
|
11
11
|
end
|
12
|
-
disconnected = ForemanRhCloud.
|
12
|
+
disconnected = ForemanRhCloud.with_iop_smart_proxy?
|
13
13
|
User.as_anonymous_admin do
|
14
14
|
organizations.each do |organization|
|
15
15
|
ForemanTasks.async_task(
|
@@ -45,6 +45,24 @@ namespace :rh_cloud_inventory do
|
|
45
45
|
archived_report_generator = ForemanInventoryUpload::Generators::ArchivedReport.new(target, Logger.new(STDOUT))
|
46
46
|
archived_report_generator.render(organization: organization, filter: filter)
|
47
47
|
puts "Successfully generated #{target} for organization id #{organization}"
|
48
|
+
|
49
|
+
next unless ForemanRhCloud.with_iop_smart_proxy?
|
50
|
+
|
51
|
+
puts 'Creating missing insights facets'
|
52
|
+
hosts_without_facets = ForemanInventoryUpload::Generators::Queries.for_org(organization, hosts_query: 'null? insights_uuid')
|
53
|
+
hosts_without_facets.each do |batch|
|
54
|
+
facets = batch.pluck(:id, 'katello_subscription_facets.uuid').map do |host_id, uuid|
|
55
|
+
{
|
56
|
+
host_id: host_id,
|
57
|
+
uuid: uuid,
|
58
|
+
}
|
59
|
+
end
|
60
|
+
# We don't need to validate the facets here as we create the necessary fields.
|
61
|
+
# rubocop:disable Rails/SkipsModelValidations
|
62
|
+
InsightsFacet.upsert_all(facets, unique_by: :host_id) unless facets.empty?
|
63
|
+
# rubocop:enable Rails/SkipsModelValidations
|
64
|
+
end
|
65
|
+
puts 'Missing Insights facets created'
|
48
66
|
end
|
49
67
|
end
|
50
68
|
end
|
@@ -53,7 +71,7 @@ namespace :rh_cloud_inventory do
|
|
53
71
|
base_folder = ENV['target'] || ForemanInventoryUpload.generated_reports_folder
|
54
72
|
organization_id = ENV['organization_id']
|
55
73
|
report_file = ForemanInventoryUpload.facts_archive_name(organization_id)
|
56
|
-
disconnected = ForemanRhCloud.
|
74
|
+
disconnected = ForemanRhCloud.with_iop_smart_proxy?
|
57
75
|
ForemanTasks.sync_task(ForemanInventoryUpload::Async::QueueForUploadJob, base_folder, report_file, organization_id, disconnected)
|
58
76
|
puts "Uploaded #{report_file}"
|
59
77
|
end
|
data/package.json
CHANGED
@@ -17,8 +17,8 @@ module InsightsCloud::Api
|
|
17
17
|
@http_req = RestClient::Request.new(:method => 'GET', :url => 'http://test.theforeman.org')
|
18
18
|
|
19
19
|
org = FactoryBot.create(:organization)
|
20
|
-
host = FactoryBot.create(:host, :with_subscription, :organization => org)
|
21
|
-
User.current = ::Katello::CpConsumerUser.new(:uuid => host.subscription_facet.uuid, :login => host.subscription_facet.uuid)
|
20
|
+
@host = FactoryBot.create(:host, :with_subscription, :organization => org)
|
21
|
+
User.current = ::Katello::CpConsumerUser.new(:uuid => @host.subscription_facet.uuid, :login => @host.subscription_facet.uuid)
|
22
22
|
InsightsCloud::Api::MachineTelemetriesController.any_instance.stubs(:upstream_owner).returns({ 'uuid' => 'abcdefg' })
|
23
23
|
|
24
24
|
setup_certs_expectation do
|
@@ -151,6 +151,20 @@ module InsightsCloud::Api
|
|
151
151
|
assert_equal 'Cloud request failed', JSON.parse(@response.body)['message']
|
152
152
|
assert_match /#{@body}/, JSON.parse(@response.body)['response']
|
153
153
|
end
|
154
|
+
|
155
|
+
test "should create insights facet" do
|
156
|
+
assert_nil InsightsFacet.find_by(host_id: @host.id)
|
157
|
+
ForemanRhCloud.stubs(:with_iop_smart_proxy?).returns(true)
|
158
|
+
req = RestClient::Request.new(:method => 'GET', :url => 'http://test.theforeman.org/')
|
159
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, "OK")
|
160
|
+
net_http_resp[:content_type] = 'application/zip'
|
161
|
+
res = RestClient::Response.create(@body, net_http_resp, req)
|
162
|
+
::ForemanRhCloud::CloudRequestForwarder.any_instance.stubs(:forward_request).returns(res)
|
163
|
+
|
164
|
+
get :forward_request, params: { "path" => "/redhat_access/r/insights/uploads/" }
|
165
|
+
|
166
|
+
assert_not_nil InsightsFacet.find_by(host_id: @host.id)
|
167
|
+
end
|
154
168
|
end
|
155
169
|
|
156
170
|
context '#branch_info' do
|
@@ -166,7 +180,10 @@ module InsightsCloud::Api
|
|
166
180
|
:with_content,
|
167
181
|
:with_hostgroup,
|
168
182
|
:with_parameter,
|
169
|
-
|
183
|
+
content_facet: FactoryBot.build(
|
184
|
+
:content_facet,
|
185
|
+
content_view_environments: [make_cve(lifecycle_environment: env), make_cve(lifecycle_environment: env2)]
|
186
|
+
),
|
170
187
|
organization: env.organization
|
171
188
|
)
|
172
189
|
|
@@ -3,7 +3,7 @@ require 'test_plugin_helper'
|
|
3
3
|
class SettingsControllerTest < ActionController::TestCase
|
4
4
|
tests InsightsCloud::SettingsController
|
5
5
|
def setup
|
6
|
-
ForemanRhCloud.stubs(:
|
6
|
+
ForemanRhCloud.stubs(:with_iop_smart_proxy?).returns(false)
|
7
7
|
end
|
8
8
|
|
9
9
|
test 'should return allow_auto_insights_sync setting' do
|