foreman_rh_cloud 3.0.21.1 → 3.0.24.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/api/v2/rh_cloud/inventory_controller.rb +50 -0
- data/app/controllers/concerns/inventory_upload/report_actions.rb +26 -0
- data/app/controllers/concerns/inventory_upload/task_actions.rb +25 -0
- data/app/controllers/foreman_inventory_upload/reports_controller.rb +3 -1
- data/app/controllers/foreman_inventory_upload/tasks_controller.rb +5 -13
- data/app/controllers/foreman_inventory_upload/uploads_controller.rb +4 -4
- data/app/controllers/insights_cloud/api/machine_telemetries_controller.rb +20 -7
- data/app/controllers/insights_cloud/hits_controller.rb +7 -3
- data/app/helpers/foreman_insights_deprecations_helper.rb +9 -0
- data/app/helpers/foreman_insights_host_helper.rb +19 -0
- data/app/models/insights_client_report_status.rb +47 -0
- data/app/overrides/old_plugin_deprecation.rb +20 -0
- data/app/services/foreman_rh_cloud/cloud_auth.rb +12 -0
- data/app/services/foreman_rh_cloud/cloud_request.rb +14 -0
- data/app/services/foreman_rh_cloud/cloud_request_forwarder.rb +1 -14
- data/app/services/foreman_rh_cloud/insights_status_cleaner.rb +17 -0
- data/app/services/foreman_rh_cloud/remediations_retriever.rb +1 -4
- data/config/package-lock.json.plugin +32774 -0
- data/config/routes.rb +19 -0
- data/db/migrate/20210720000001_remove_old_insights_statuses.foreman_rh_cloud.rb +6 -0
- data/lib/foreman_inventory_upload.rb +9 -1
- data/lib/foreman_inventory_upload/generators/fact_helpers.rb +19 -0
- data/lib/foreman_inventory_upload/generators/queries.rb +1 -0
- data/lib/foreman_inventory_upload/generators/slice.rb +7 -6
- data/lib/foreman_rh_cloud/engine.rb +20 -10
- data/lib/foreman_rh_cloud/version.rb +1 -1
- data/lib/insights_cloud/async/insights_client_status_aging.rb +23 -0
- data/lib/insights_cloud/async/insights_full_sync.rb +4 -14
- data/lib/insights_cloud/async/insights_resolutions_sync.rb +1 -4
- data/lib/insights_cloud/async/insights_rules_sync.rb +2 -7
- data/lib/inventory_sync/async/host_result.rb +4 -0
- data/lib/inventory_sync/async/inventory_full_sync.rb +2 -1
- data/lib/inventory_sync/async/inventory_hosts_sync.rb +16 -2
- data/lib/inventory_sync/async/inventory_scheduled_sync.rb +12 -0
- data/lib/inventory_sync/async/inventory_self_host_sync.rb +30 -0
- data/lib/inventory_sync/async/query_inventory_job.rb +6 -5
- data/lib/tasks/insights.rake +15 -0
- data/lib/tasks/rh_cloud_inventory.rake +8 -1
- data/package.json +1 -1
- data/test/controllers/insights_cloud/api/machine_telemetries_controller_test.rb +41 -0
- data/test/controllers/inventory_upload/api/inventory_controller_test.rb +53 -0
- data/test/factories/inventory_upload_factories.rb +1 -1
- data/test/jobs/insights_client_status_aging_test.rb +33 -0
- data/test/jobs/insights_full_sync_test.rb +3 -0
- data/test/jobs/insights_resolutions_sync_test.rb +3 -0
- data/test/jobs/insights_rules_sync_test.rb +3 -0
- data/test/jobs/inventory_full_sync_test.rb +3 -0
- data/test/jobs/inventory_hosts_sync_test.rb +267 -0
- data/test/jobs/inventory_scheduled_sync_test.rb +22 -0
- data/test/jobs/inventory_self_host_sync_test.rb +103 -0
- data/test/models/insights_client_report_status_test.rb +75 -0
- data/test/test_plugin_helper.rb +2 -0
- data/test/unit/services/foreman_rh_cloud/cloud_request_forwarder_test.rb +3 -3
- data/test/unit/services/foreman_rh_cloud/insights_status_cleaner_test.rb +31 -0
- data/test/unit/slice_generator_test.rb +81 -29
- data/webpack/ForemanInventoryUpload/Components/FullScreenModal/FullScreenModal.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/FullScreenModal/__tests__/__snapshots__/FullScreenModal.test.js.snap +1 -1
- data/webpack/ForemanInventoryUpload/Components/FullScreenModal/fullScreenModal.scss +14 -16
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/PageDescription.js +11 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/__tests__/__snapshots__/PageDescription.test.js.snap +11 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js +28 -63
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/integrations.test.js.snap +2 -3
- data/webpack/ForemanInventoryUpload/Components/Terminal/Terminal.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/Terminal/__tests__/Terminal.test.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/Terminal/__tests__/__snapshots__/Terminal.test.js.snap +2 -2
- data/webpack/ForemanInventoryUpload/Components/Terminal/terminal.scss +25 -27
- data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableActions.js +19 -19
- data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/__snapshots__/InsightsTableActions.test.js.snap +14 -14
- data/webpack/InsightsCloudSync/Components/RemediationModal/RemediateButton.js +1 -0
- data/webpack/InsightsCloudSync/Components/__tests__/__snapshots__/NoTokenEmptyState.test.js.snap +20 -13
- data/webpack/InsightsCloudSync/InsightsCloudSync.js +4 -1
- data/webpack/InsightsCloudSync/InsightsCloudSyncActions.js +44 -20
- data/webpack/InsightsCloudSync/InsightsCloudSyncConstants.js +2 -0
- data/webpack/InsightsCloudSync/__snapshots__/InsightsCloudSync.test.js.snap +2 -2
- data/webpack/InsightsCloudSync/__tests__/__snapshots__/InsightsCloudSyncActions.test.js.snap +11 -7
- data/webpack/common/ForemanTasks/ForemanTasksActions.js +64 -0
- data/webpack/common/ForemanTasks/ForemanTasksHelpers.js +7 -0
- data/webpack/common/ForemanTasks/index.js +1 -0
- metadata +33 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0157c9f96dcbfa67895f62e292af8f9171c6d90a60f3eb8fdca5de57bd42918c
|
4
|
+
data.tar.gz: 24c8de05e245d54d789bacbed59bf7bd8c85d40f7252a59b60b599ab8941f5e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd9e22b6176184b7c40d64229170458a59d2e70fbca128b892d299359c3e531afae0ebf760d07f57ba304bc042d86a601ef13472e8e8c3686eb670620185ee70
|
7
|
+
data.tar.gz: ca49d14fb99c6de0480cf180b1f38d7a70cca26808ef141cc6c504fbfc08daeda3f89127def3cc18e6d8ed2afbef835704d48ef4011442b33f7ec407def79fea
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Api
|
2
|
+
module V2
|
3
|
+
module RhCloud
|
4
|
+
class InventoryController < ::Api::V2::BaseController
|
5
|
+
include ::Api::Version2
|
6
|
+
include InventoryUpload::ReportActions
|
7
|
+
include InventoryUpload::TaskActions
|
8
|
+
|
9
|
+
api :GET, "/organizations/:organization_id/rh_cloud/report", N_("Download latest report")
|
10
|
+
def download_file
|
11
|
+
filename, file = report_file(params[:organization_id])
|
12
|
+
|
13
|
+
send_file file, disposition: 'attachment', filename: filename
|
14
|
+
rescue InventoryUpload::ReportActions::ReportMissingError => error
|
15
|
+
render json: { message: error.message }, status: :not_found
|
16
|
+
end
|
17
|
+
|
18
|
+
api :POST, "/organizations/:organization_id/rh_cloud/report", N_("Start report generation")
|
19
|
+
def generate_report
|
20
|
+
organization_id = params[:organization_id]
|
21
|
+
|
22
|
+
start_report_generation(organization_id)
|
23
|
+
|
24
|
+
render json: {
|
25
|
+
action_status: 'success',
|
26
|
+
}, status: :ok
|
27
|
+
end
|
28
|
+
|
29
|
+
api :POST, "/organizations/:organization_id/rh_cloud/inventory_sync", N_("Start inventory synchronization")
|
30
|
+
def sync_inventory_status
|
31
|
+
selected_org = Organization.find(params[:organization_id])
|
32
|
+
|
33
|
+
task = start_inventory_sync(selected_org)
|
34
|
+
|
35
|
+
render json: {
|
36
|
+
task: task,
|
37
|
+
}, status: :ok
|
38
|
+
rescue InventoryUpload::TaskActions::NothingToSyncError => error
|
39
|
+
render json: { message: error.message }, status: :bad_request
|
40
|
+
end
|
41
|
+
|
42
|
+
api :POST, "rh_cloud/enable_connector", N_("Enable cloud connector")
|
43
|
+
def enable_cloud_connector
|
44
|
+
cloud_connector = ForemanRhCloud::CloudConnector.new
|
45
|
+
render json: cloud_connector.install.to_json
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module InventoryUpload
|
2
|
+
module ReportActions
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
class ReportMissingError < Foreman::Exception
|
6
|
+
MESSAGE = N_("The report file %{filename} doesn't exist")
|
7
|
+
|
8
|
+
def initialize(**params)
|
9
|
+
super(self.class::MESSAGE % params, params)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def start_report_generation(organization_id)
|
14
|
+
ForemanInventoryUpload::Async::GenerateReportJob.perform_later(ForemanInventoryUpload.generated_reports_folder, organization_id)
|
15
|
+
end
|
16
|
+
|
17
|
+
def report_file(organization_id)
|
18
|
+
filename = ForemanInventoryUpload.facts_archive_name(organization_id)
|
19
|
+
files = Dir["{#{ForemanInventoryUpload.uploads_file_path(filename)},#{ForemanInventoryUpload.done_file_path(filename)}}"]
|
20
|
+
|
21
|
+
raise ReportMissingError.new(filename: filename) if files.empty?
|
22
|
+
|
23
|
+
[filename, files.first]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module InventoryUpload
|
2
|
+
module TaskActions
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
class NothingToSyncError < Foreman::Exception
|
6
|
+
MESSAGE = N_('Nothing to sync, there are no hosts with subscription for this organization.')
|
7
|
+
|
8
|
+
def initialize(**params)
|
9
|
+
super(self.class::MESSAGE, params)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def start_inventory_sync(selected_org)
|
14
|
+
subscribed_hosts = ForemanInventoryUpload::Generators::Queries.for_slice(
|
15
|
+
Host.unscoped.where(organization: selected_org)
|
16
|
+
)
|
17
|
+
|
18
|
+
if subscribed_hosts.empty?
|
19
|
+
raise NothingToSyncError
|
20
|
+
end
|
21
|
+
|
22
|
+
ForemanTasks.async_task(InventorySync::Async::InventoryFullSync, selected_org)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
module ForemanInventoryUpload
|
4
4
|
class ReportsController < ::ApplicationController
|
5
|
+
include InventoryUpload::ReportActions
|
6
|
+
|
5
7
|
def last
|
6
8
|
label = ForemanInventoryUpload::Async::GenerateReportJob.output_label(params[:organization_id])
|
7
9
|
output = ForemanInventoryUpload::Async::ProgressOutput.get(label)&.full_output
|
@@ -20,7 +22,7 @@ module ForemanInventoryUpload
|
|
20
22
|
def generate
|
21
23
|
organization_id = params[:organization_id]
|
22
24
|
|
23
|
-
|
25
|
+
start_report_generation(organization_id)
|
24
26
|
|
25
27
|
render json: {
|
26
28
|
action_status: 'success',
|
@@ -1,25 +1,17 @@
|
|
1
1
|
module ForemanInventoryUpload
|
2
2
|
class TasksController < ::ApplicationController
|
3
|
+
include InventoryUpload::TaskActions
|
4
|
+
|
3
5
|
def create
|
4
6
|
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
7
|
|
11
|
-
|
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
|
-
task = ForemanTasks.async_task(InventorySync::Async::InventoryFullSync, selected_org)
|
17
|
-
end
|
18
|
-
return render json: { message: N_('there was an issue triggering the task') }, status: :internal_server_error unless task
|
8
|
+
task = start_inventory_sync(selected_org)
|
19
9
|
|
20
10
|
render json: {
|
21
11
|
task: task,
|
22
12
|
}, status: :ok
|
13
|
+
rescue InventoryUpload::TaskActions::NothingToSyncError => error
|
14
|
+
render json: { message: error.message }, status: :internal_server_error
|
23
15
|
end
|
24
16
|
|
25
17
|
def show
|
@@ -1,5 +1,7 @@
|
|
1
1
|
module ForemanInventoryUpload
|
2
2
|
class UploadsController < ::ApplicationController
|
3
|
+
include InventoryUpload::ReportActions
|
4
|
+
|
3
5
|
def last
|
4
6
|
label = ForemanInventoryUpload::Async::UploadReportJob.output_label(params[:organization_id])
|
5
7
|
output = ForemanInventoryUpload::Async::ProgressOutput.get(label)&.full_output
|
@@ -10,11 +12,9 @@ module ForemanInventoryUpload
|
|
10
12
|
end
|
11
13
|
|
12
14
|
def download_file
|
13
|
-
filename =
|
14
|
-
files = Dir["{#{ForemanInventoryUpload.uploads_file_path(filename)},#{ForemanInventoryUpload.done_file_path(filename)}}"]
|
15
|
+
filename, file = report_file(params[:organization_id])
|
15
16
|
|
16
|
-
|
17
|
-
raise ::Foreman::Exception.new("The report file doesn't exist")
|
17
|
+
send_file file, disposition: 'attachment', filename: filename
|
18
18
|
end
|
19
19
|
|
20
20
|
def enable_cloud_connector
|
@@ -5,32 +5,34 @@ module InsightsCloud::Api
|
|
5
5
|
include ::InsightsCloud::ClientAuthentication
|
6
6
|
include ::InsightsCloud::CandlepinCache
|
7
7
|
|
8
|
+
before_action :set_admin_user, only: [:forward_request]
|
8
9
|
before_action :cert_uuid, :ensure_org, :ensure_branch_id, :only => [:forward_request, :branch_info]
|
9
10
|
before_action :ensure_telemetry_enabled_for_consumer, :only => [:forward_request]
|
10
11
|
|
11
12
|
skip_after_action :log_response_body, :only => [:forward_request]
|
12
13
|
skip_before_action :check_media_type, :only => [:forward_request]
|
14
|
+
after_action :update_host_insights_status, only: [:forward_request]
|
13
15
|
|
14
16
|
# The method that "proxies" requests over to Cloud
|
15
17
|
def forward_request
|
16
18
|
certs = candlepin_id_cert @organization
|
17
|
-
cloud_response = ::ForemanRhCloud::CloudRequestForwarder.new.forward_request(request, controller_name, @branch_id, certs)
|
19
|
+
@cloud_response = ::ForemanRhCloud::CloudRequestForwarder.new.forward_request(request, controller_name, @branch_id, certs)
|
18
20
|
|
19
|
-
if cloud_response.code == 401
|
21
|
+
if @cloud_response.code == 401
|
20
22
|
return render json: {
|
21
23
|
:message => 'Authentication to the Insights Service failed.',
|
22
24
|
:headers => {},
|
23
25
|
}, status: :bad_gateway
|
24
26
|
end
|
25
27
|
|
26
|
-
if cloud_response.headers[:content_disposition]
|
27
|
-
return send_data cloud_response, disposition: cloud_response.headers[:content_disposition], type: cloud_response.headers[:content_type]
|
28
|
+
if @cloud_response.headers[:content_disposition]
|
29
|
+
return send_data @cloud_response, disposition: @cloud_response.headers[:content_disposition], type: @cloud_response.headers[:content_type]
|
28
30
|
end
|
29
31
|
|
30
|
-
assign_header(response, cloud_response, :x_resource_count, true)
|
31
|
-
assign_header(response, cloud_response, :x_rh_insights_request_id, false)
|
32
|
+
assign_header(response, @cloud_response, :x_resource_count, true)
|
33
|
+
assign_header(response, @cloud_response, :x_rh_insights_request_id, false)
|
32
34
|
|
33
|
-
render json: cloud_response, status: cloud_response.code
|
35
|
+
render json: @cloud_response, status: @cloud_response.code
|
34
36
|
end
|
35
37
|
|
36
38
|
def branch_info
|
@@ -69,5 +71,16 @@ module InsightsCloud::Api
|
|
69
71
|
@branch_id = cp_owner_id(@organization)
|
70
72
|
return render_message "Branch ID not found for organization #{@organization.title}", :status => 400 unless @branch_id
|
71
73
|
end
|
74
|
+
|
75
|
+
def update_host_insights_status
|
76
|
+
return unless request.path == '/redhat_access/r/insights/platform/ingress/v1/upload' ||
|
77
|
+
request.path.include?('/redhat_access/r/insights/uploads/')
|
78
|
+
|
79
|
+
return unless @cloud_response.code.to_s.start_with?('2')
|
80
|
+
|
81
|
+
# create insights status if it wasn't there in the first place and refresh its reporting date
|
82
|
+
@host.get_status(InsightsClientReportStatus).refresh!
|
83
|
+
@host.refresh_global_status!
|
84
|
+
end
|
72
85
|
end
|
73
86
|
end
|
@@ -3,7 +3,7 @@ module InsightsCloud
|
|
3
3
|
include Foreman::Controller::AutoCompleteSearch
|
4
4
|
|
5
5
|
def index
|
6
|
-
hits = resource_base_search_and_page.
|
6
|
+
hits = resource_base_search_and_page.preload(:host, :rule)
|
7
7
|
|
8
8
|
render json: {
|
9
9
|
hasToken: !Setting[:rh_cloud_token].empty?,
|
@@ -23,9 +23,9 @@ module InsightsCloud
|
|
23
23
|
|
24
24
|
def resolutions
|
25
25
|
if remediation_all_selected_param
|
26
|
-
hits =
|
26
|
+
hits = resource_base.with_playbook.search_for(params[:query])
|
27
27
|
else
|
28
|
-
hits = resource_base_search_and_page.where(id: remediation_ids_param)
|
28
|
+
hits = resource_base_search_and_page.with_playbook.where(id: remediation_ids_param)
|
29
29
|
end
|
30
30
|
|
31
31
|
hits.preload(:host, rule: :resolutions)
|
@@ -74,5 +74,9 @@ module InsightsCloud
|
|
74
74
|
def remediation_all_selected_param
|
75
75
|
ActiveModel::Type::Boolean.new.cast(params[:isAllSelected])
|
76
76
|
end
|
77
|
+
|
78
|
+
def resource_base
|
79
|
+
super.where(host: Host.authorized)
|
80
|
+
end
|
77
81
|
end
|
78
82
|
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module ForemanInsightsDeprecationsHelper
|
2
|
+
def old_plugin_deprecation_warning
|
3
|
+
alert(
|
4
|
+
class: 'alert-warning',
|
5
|
+
close: false,
|
6
|
+
text: _('redhat_access plugin is deprecated and will be removed in Satellite 6.10. You can find recommendations for your hosts on hosts index and details pages.')
|
7
|
+
)
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module ForemanInsightsHostHelper
|
2
|
+
def insights_host_overview_buttons(host)
|
3
|
+
search_condition = "hostname=#{host.fqdn}"
|
4
|
+
[
|
5
|
+
{
|
6
|
+
button: link_to_if_authorized(
|
7
|
+
_("Recommendations"),
|
8
|
+
hash_for_foreman_rh_cloud_insights_cloud_path(
|
9
|
+
search: search_condition,
|
10
|
+
select_all: true
|
11
|
+
),
|
12
|
+
title: _("Host Insights recommendations"),
|
13
|
+
class: 'btn btn-default'
|
14
|
+
),
|
15
|
+
priority: 1000,
|
16
|
+
},
|
17
|
+
]
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
class InsightsClientReportStatus < HostStatus::Status
|
2
|
+
REPORT_INTERVAL = 48.hours
|
3
|
+
|
4
|
+
REPORTING = 0
|
5
|
+
NO_REPORT = 1
|
6
|
+
|
7
|
+
scope :stale, -> { where.not(reported_at: (Time.now - REPORT_INTERVAL)..Time.now) }
|
8
|
+
scope :reporting, -> { where(status: REPORTING) }
|
9
|
+
|
10
|
+
def self.status_name
|
11
|
+
N_('Insights')
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_label(_options = {})
|
15
|
+
case status
|
16
|
+
when REPORTING
|
17
|
+
N_('Reporting')
|
18
|
+
when NO_REPORT
|
19
|
+
N_('Not reporting')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_global(_options = {})
|
24
|
+
case status
|
25
|
+
when REPORTING
|
26
|
+
::HostStatus::Global::OK
|
27
|
+
when NO_REPORT
|
28
|
+
::HostStatus::Global::ERROR
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_status
|
33
|
+
in_interval? ? REPORTING : NO_REPORT
|
34
|
+
end
|
35
|
+
|
36
|
+
# prevent creation of the status on global refresh, but show it if the record already exists
|
37
|
+
def relevant?(_options = {})
|
38
|
+
persisted?
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def in_interval?
|
44
|
+
return false unless reported_at
|
45
|
+
(Time.now.utc - reported_at).to_i < REPORT_INTERVAL.to_i
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
Deface::Override.new(
|
2
|
+
virtual_path: 'redhat_access/analytics_dashboard/welcome',
|
3
|
+
name: 'deprecation_warning',
|
4
|
+
insert_before: 'div#welcome',
|
5
|
+
text: '<%= old_plugin_deprecation_warning %>'
|
6
|
+
)
|
7
|
+
|
8
|
+
Deface::Override.new(
|
9
|
+
virtual_path: 'redhat_access/analytics_dashboard/index',
|
10
|
+
name: 'deprecation_warning_index_not_met',
|
11
|
+
insert_before: 'article#content',
|
12
|
+
text: '<%= old_plugin_deprecation_warning %>'
|
13
|
+
)
|
14
|
+
|
15
|
+
Deface::Override.new(
|
16
|
+
virtual_path: 'redhat_access/analytics_dashboard/index',
|
17
|
+
name: 'deprecation_warning_index_met',
|
18
|
+
insert_before: 'div.main-content',
|
19
|
+
text: '<%= old_plugin_deprecation_warning %>'
|
20
|
+
)
|
@@ -2,6 +2,8 @@ module ForemanRhCloud
|
|
2
2
|
module CloudAuth
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
|
+
include CloudRequest
|
6
|
+
|
5
7
|
def rh_credentials
|
6
8
|
@rh_credentials ||= query_refresh_token
|
7
9
|
end
|
@@ -24,5 +26,15 @@ module ForemanRhCloud
|
|
24
26
|
Foreman::Logging.exception('Unable to authenticate using rh_cloud_token setting', e)
|
25
27
|
raise ::Foreman::WrappedException.new(e, N_('Unable to authenticate using rh_cloud_token setting'))
|
26
28
|
end
|
29
|
+
|
30
|
+
def execute_cloud_request(params)
|
31
|
+
final_params = {
|
32
|
+
headers: {
|
33
|
+
Authorization: "Bearer #{rh_credentials}",
|
34
|
+
},
|
35
|
+
}.deep_merge(params)
|
36
|
+
|
37
|
+
super(final_params)
|
38
|
+
end
|
27
39
|
end
|
28
40
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module ForemanRhCloud
|
2
|
+
module CloudRequest
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
def execute_cloud_request(params)
|
6
|
+
final_params = {
|
7
|
+
verify_ssl: ForemanRhCloud.verify_ssl_method,
|
8
|
+
proxy: ForemanRhCloud.transformed_http_proxy_string(logger: logger),
|
9
|
+
}.deep_merge(params)
|
10
|
+
|
11
|
+
RestClient::Request.execute(final_params)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -2,7 +2,7 @@ require 'rest-client'
|
|
2
2
|
|
3
3
|
module ForemanRhCloud
|
4
4
|
class CloudRequestForwarder
|
5
|
-
include
|
5
|
+
include ForemanRhCloud::CloudRequest
|
6
6
|
|
7
7
|
def forward_request(original_request, controller_name, branch_id, certs)
|
8
8
|
forward_params = prepare_forward_params(original_request, branch_id)
|
@@ -22,7 +22,6 @@ module ForemanRhCloud
|
|
22
22
|
def prepare_request_opts(original_request, forward_payload, forward_params, certs)
|
23
23
|
base_params = {
|
24
24
|
method: original_request.method,
|
25
|
-
verify_ssl: ForemanRhCloud.verify_ssl_method,
|
26
25
|
payload: forward_payload,
|
27
26
|
headers: {
|
28
27
|
params: forward_params,
|
@@ -33,10 +32,6 @@ module ForemanRhCloud
|
|
33
32
|
base_params.merge(path_params(original_request.path, certs))
|
34
33
|
end
|
35
34
|
|
36
|
-
def execute_cloud_request(request_opts)
|
37
|
-
RestClient::Request.execute request_opts
|
38
|
-
end
|
39
|
-
|
40
35
|
def prepare_forward_payload(original_request, controller_name)
|
41
36
|
forward_payload = original_request.request_parameters[controller_name]
|
42
37
|
|
@@ -61,10 +56,6 @@ module ForemanRhCloud
|
|
61
56
|
|
62
57
|
def path_params(request_path, certs)
|
63
58
|
case request_path
|
64
|
-
when metadata_request?
|
65
|
-
{
|
66
|
-
url: ForemanRhCloud.base_url + request_path.sub('/redhat_access/r/insights', '/api'),
|
67
|
-
}
|
68
59
|
when platform_request?
|
69
60
|
{
|
70
61
|
url: ForemanRhCloud.cert_base_url + request_path.sub('/redhat_access/r/insights/platform', '/api'),
|
@@ -81,10 +72,6 @@ module ForemanRhCloud
|
|
81
72
|
end
|
82
73
|
end
|
83
74
|
|
84
|
-
def metadata_request?
|
85
|
-
->(request_path) { request_path.include? '/static' }
|
86
|
-
end
|
87
|
-
|
88
75
|
def platform_request?
|
89
76
|
->(request_path) { request_path.include? '/platform' }
|
90
77
|
end
|