foreman_rh_cloud 3.0.32 → 4.0.21.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/foreman_inventory_upload/reports_controller.rb +1 -3
- data/app/controllers/foreman_inventory_upload/tasks_controller.rb +13 -5
- data/app/controllers/foreman_inventory_upload/uploads_controller.rb +4 -4
- data/app/controllers/insights_cloud/api/machine_telemetries_controller.rb +3 -6
- data/app/controllers/insights_cloud/hits_controller.rb +3 -7
- data/app/models/insights_client_report_status.rb +22 -11
- data/app/services/foreman_rh_cloud/cloud_auth.rb +0 -16
- data/app/services/foreman_rh_cloud/cloud_request_forwarder.rb +15 -12
- data/app/services/foreman_rh_cloud/remediations_retriever.rb +4 -6
- data/app/subscribers/foreman_rh_cloud/insights_subscriber.rb +9 -0
- data/config/Gemfile.lock.gh_test +95 -93
- data/config/database.yml.example +2 -2
- data/config/routes.rb +1 -20
- data/lib/foreman_inventory_upload/generators/fact_helpers.rb +1 -22
- data/lib/foreman_inventory_upload/generators/queries.rb +0 -1
- data/lib/foreman_inventory_upload/generators/slice.rb +5 -6
- data/lib/foreman_inventory_upload/generators/tags.rb +2 -11
- data/lib/foreman_inventory_upload.rb +1 -9
- data/lib/foreman_rh_cloud/engine.rb +10 -17
- data/lib/foreman_rh_cloud/version.rb +1 -1
- data/lib/foreman_rh_cloud.rb +1 -12
- data/lib/insights_cloud/async/insights_full_sync.rb +14 -9
- data/lib/insights_cloud/async/insights_resolutions_sync.rb +6 -13
- data/lib/insights_cloud/async/insights_rules_sync.rb +9 -13
- data/lib/inventory_sync/async/host_result.rb +5 -4
- data/lib/inventory_sync/async/inventory_full_sync.rb +10 -21
- data/lib/inventory_sync/async/inventory_hosts_sync.rb +3 -18
- data/lib/inventory_sync/async/inventory_scheduled_sync.rb +0 -12
- data/lib/inventory_sync/async/query_inventory_job.rb +5 -6
- data/lib/tasks/insights.rake +0 -15
- data/lib/tasks/rh_cloud_inventory.rake +1 -8
- data/package.json +3 -3
- data/test/controllers/insights_cloud/api/machine_telemetries_controller_test.rb +0 -41
- data/test/factories/inventory_upload_factories.rb +1 -1
- data/test/jobs/insights_full_sync_test.rb +0 -1
- data/test/jobs/insights_resolutions_sync_test.rb +1 -11
- data/test/jobs/insights_rules_sync_test.rb +0 -1
- data/test/jobs/inventory_full_sync_test.rb +2 -38
- data/test/models/insights_client_report_status_test.rb +72 -70
- data/test/test_plugin_helper.rb +0 -2
- data/test/unit/fact_helpers_test.rb +2 -2
- data/test/unit/services/foreman_rh_cloud/cloud_request_forwarder_test.rb +3 -21
- data/test/unit/services/foreman_rh_cloud/template_renderer_helper_test.rb +0 -1
- data/test/unit/slice_generator_test.rb +27 -70
- data/test/unit/tags_generator_test.rb +0 -56
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/PageDescription.js +0 -11
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/__tests__/__snapshots__/PageDescription.test.js.snap +0 -11
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js +63 -28
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/integrations.test.js.snap +3 -2
- 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 +0 -1
- data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationModal.scss +0 -14
- data/webpack/InsightsCloudSync/Components/__tests__/__snapshots__/NoTokenEmptyState.test.js.snap +13 -20
- data/webpack/InsightsCloudSync/InsightsCloudSync.js +1 -4
- data/webpack/InsightsCloudSync/InsightsCloudSyncActions.js +20 -44
- data/webpack/InsightsCloudSync/InsightsCloudSyncConstants.js +0 -2
- data/webpack/InsightsCloudSync/__snapshots__/InsightsCloudSync.test.js.snap +2 -2
- data/webpack/InsightsCloudSync/__tests__/__snapshots__/InsightsCloudSyncActions.test.js.snap +7 -11
- metadata +4 -33
- data/app/controllers/api/v2/rh_cloud/inventory_controller.rb +0 -50
- data/app/controllers/concerns/inventory_upload/report_actions.rb +0 -26
- data/app/controllers/concerns/inventory_upload/task_actions.rb +0 -25
- data/app/helpers/foreman_insights_deprecations_helper.rb +0 -9
- data/app/helpers/foreman_insights_host_helper.rb +0 -19
- data/app/overrides/old_plugin_deprecation.rb +0 -20
- data/app/services/foreman_rh_cloud/cloud_request.rb +0 -14
- data/app/services/foreman_rh_cloud/insights_status_cleaner.rb +0 -17
- data/config/package-lock.json +0 -41822
- data/config/package-lock.json.plugin +0 -32774
- data/db/migrate/20210720000001_remove_old_insights_statuses.foreman_rh_cloud.rb +0 -6
- data/lib/insights_cloud/async/insights_client_status_aging.rb +0 -23
- data/lib/inventory_sync/async/inventory_self_host_sync.rb +0 -39
- data/test/controllers/inventory_upload/api/inventory_controller_test.rb +0 -53
- data/test/jobs/insights_client_status_aging_test.rb +0 -33
- data/test/jobs/inventory_hosts_sync_test.rb +0 -283
- data/test/jobs/inventory_scheduled_sync_test.rb +0 -22
- data/test/jobs/inventory_self_host_sync_test.rb +0 -104
- data/test/unit/foreman_rh_cloud_self_host_test.rb +0 -28
- data/test/unit/services/foreman_rh_cloud/insights_status_cleaner_test.rb +0 -31
- data/webpack/common/ForemanTasks/ForemanTasksActions.js +0 -64
- data/webpack/common/ForemanTasks/ForemanTasksHelpers.js +0 -7
- data/webpack/common/ForemanTasks/index.js +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97882071192995f2da93032050b9ecdfa616dba407c8d032bfd29f6741ea9d56
|
4
|
+
data.tar.gz: 88bca49cea9ee2abac2d2dc9d608a33329ad9e214d57035424e8e24984691537
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67dd2ada55ac862b2d57ddf893e7408d002c40c2f89a141e6bf8c115d6eeee32d19b156e7668751f591665f948fa04d628719e5f6f5ab9e4609c02f0a14a93f4
|
7
|
+
data.tar.gz: 54ded7bb163e4a38cd3fa4a62dfe101484b98e87c016514b985190f77a07c7556e980dd8574dc5fb70cacb3fcc521a37a1f4f2325e5360cdbb2ddd6f38816804
|
@@ -2,8 +2,6 @@
|
|
2
2
|
|
3
3
|
module ForemanInventoryUpload
|
4
4
|
class ReportsController < ::ApplicationController
|
5
|
-
include InventoryUpload::ReportActions
|
6
|
-
|
7
5
|
def last
|
8
6
|
label = ForemanInventoryUpload::Async::GenerateReportJob.output_label(params[:organization_id])
|
9
7
|
output = ForemanInventoryUpload::Async::ProgressOutput.get(label)&.full_output
|
@@ -22,7 +20,7 @@ module ForemanInventoryUpload
|
|
22
20
|
def generate
|
23
21
|
organization_id = params[:organization_id]
|
24
22
|
|
25
|
-
|
23
|
+
ForemanInventoryUpload::Async::GenerateReportJob.perform_later(ForemanInventoryUpload.generated_reports_folder, organization_id)
|
26
24
|
|
27
25
|
render json: {
|
28
26
|
action_status: 'success',
|
@@ -1,17 +1,25 @@
|
|
1
1
|
module ForemanInventoryUpload
|
2
2
|
class TasksController < ::ApplicationController
|
3
|
-
include InventoryUpload::TaskActions
|
4
|
-
|
5
3
|
def create
|
6
4
|
selected_org = Organization.current
|
5
|
+
subscribed_hosts_ids = Set.new(
|
6
|
+
ForemanInventoryUpload::Generators::Queries.for_slice(
|
7
|
+
Host.unscoped.where(organization: selected_org)
|
8
|
+
).pluck(:id)
|
9
|
+
)
|
7
10
|
|
8
|
-
|
11
|
+
if subscribed_hosts_ids.empty?
|
12
|
+
return render json: {
|
13
|
+
message: N_('Nothing to sync, there are no hosts with subscription for this organization.'),
|
14
|
+
}, status: :method_not_allowed
|
15
|
+
else
|
16
|
+
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
|
9
19
|
|
10
20
|
render json: {
|
11
21
|
task: task,
|
12
22
|
}, status: :ok
|
13
|
-
rescue InventoryUpload::TaskActions::NothingToSyncError => error
|
14
|
-
render json: { message: error.message }, status: :internal_server_error
|
15
23
|
end
|
16
24
|
|
17
25
|
def show
|
@@ -1,7 +1,5 @@
|
|
1
1
|
module ForemanInventoryUpload
|
2
2
|
class UploadsController < ::ApplicationController
|
3
|
-
include InventoryUpload::ReportActions
|
4
|
-
|
5
3
|
def last
|
6
4
|
label = ForemanInventoryUpload::Async::UploadReportJob.output_label(params[:organization_id])
|
7
5
|
output = ForemanInventoryUpload::Async::ProgressOutput.get(label)&.full_output
|
@@ -12,9 +10,11 @@ module ForemanInventoryUpload
|
|
12
10
|
end
|
13
11
|
|
14
12
|
def download_file
|
15
|
-
filename
|
13
|
+
filename = ForemanInventoryUpload.facts_archive_name(params[:organization_id])
|
14
|
+
files = Dir["{#{ForemanInventoryUpload.uploads_file_path(filename)},#{ForemanInventoryUpload.done_file_path(filename)}}"]
|
16
15
|
|
17
|
-
send_file
|
16
|
+
return send_file files.first, disposition: 'attachment', filename: filename unless files.empty?
|
17
|
+
raise ::Foreman::Exception.new("The report file doesn't exist")
|
18
18
|
end
|
19
19
|
|
20
20
|
def enable_cloud_connector
|
@@ -5,7 +5,6 @@ module InsightsCloud::Api
|
|
5
5
|
include ::InsightsCloud::ClientAuthentication
|
6
6
|
include ::InsightsCloud::CandlepinCache
|
7
7
|
|
8
|
-
before_action :set_admin_user, only: [:forward_request]
|
9
8
|
before_action :cert_uuid, :ensure_org, :ensure_branch_id, :only => [:forward_request, :branch_info]
|
10
9
|
before_action :ensure_telemetry_enabled_for_consumer, :only => [:forward_request]
|
11
10
|
|
@@ -76,11 +75,9 @@ module InsightsCloud::Api
|
|
76
75
|
return unless request.path == '/redhat_access/r/insights/platform/ingress/v1/upload' ||
|
77
76
|
request.path.include?('/redhat_access/r/insights/uploads/')
|
78
77
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
@host.get_status(InsightsClientReportStatus).refresh!
|
83
|
-
@host.refresh_global_status!
|
78
|
+
data = @cloud_response.code.to_s.start_with?('2')
|
79
|
+
host_status = @host.get_status(InsightsClientReportStatus)
|
80
|
+
host_status.update(reported_at: Time.now.utc, status: host_status.to_status(data: data))
|
84
81
|
end
|
85
82
|
end
|
86
83
|
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.preload(:host, :rule)
|
6
|
+
hits = resource_base_search_and_page.where(host: Host.authorized).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 = InsightsHit.with_playbook.search_for(params[:query])
|
27
27
|
else
|
28
|
-
hits = resource_base_search_and_page.
|
28
|
+
hits = resource_base_search_and_page.where(id: remediation_ids_param)
|
29
29
|
end
|
30
30
|
|
31
31
|
hits.preload(:host, rule: :resolutions)
|
@@ -74,9 +74,5 @@ 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
|
81
77
|
end
|
82
78
|
end
|
@@ -1,11 +1,10 @@
|
|
1
1
|
class InsightsClientReportStatus < HostStatus::Status
|
2
2
|
REPORT_INTERVAL = 48.hours
|
3
3
|
|
4
|
-
REPORTING = 0
|
5
|
-
NO_REPORT = 1
|
6
|
-
|
7
|
-
|
8
|
-
scope :reporting, -> { where(status: REPORTING) }
|
4
|
+
REPORTING = 0 # host_registration_insights = true & getting data
|
5
|
+
NO_REPORT = 1 # host_registration_insights = true & not getting data
|
6
|
+
NOT_MANAGED = 2 # host_registration_insights = false
|
7
|
+
NOT_MANAGED_WITH_DATA = 3 # host_registration_insights = false & getting data
|
9
8
|
|
10
9
|
def self.status_name
|
11
10
|
N_('Insights')
|
@@ -17,6 +16,10 @@ class InsightsClientReportStatus < HostStatus::Status
|
|
17
16
|
N_('Reporting')
|
18
17
|
when NO_REPORT
|
19
18
|
N_('Not reporting')
|
19
|
+
when NOT_MANAGED
|
20
|
+
N_('Not reporting (not set by registration)')
|
21
|
+
when NOT_MANAGED_WITH_DATA
|
22
|
+
N_('Reporting (not set by registration)')
|
20
23
|
end
|
21
24
|
end
|
22
25
|
|
@@ -26,16 +29,20 @@ class InsightsClientReportStatus < HostStatus::Status
|
|
26
29
|
::HostStatus::Global::OK
|
27
30
|
when NO_REPORT
|
28
31
|
::HostStatus::Global::ERROR
|
32
|
+
when NOT_MANAGED
|
33
|
+
::HostStatus::Global::OK
|
34
|
+
when NOT_MANAGED_WITH_DATA
|
35
|
+
::HostStatus::Global::WARN
|
29
36
|
end
|
30
37
|
end
|
31
38
|
|
32
|
-
def to_status
|
33
|
-
|
34
|
-
|
39
|
+
def to_status(data: false)
|
40
|
+
if insights_param
|
41
|
+
return REPORTING if data
|
42
|
+
return in_interval? ? REPORTING : NO_REPORT
|
43
|
+
end
|
35
44
|
|
36
|
-
|
37
|
-
def relevant?(_options = {})
|
38
|
-
persisted?
|
45
|
+
data ? NOT_MANAGED_WITH_DATA : NOT_MANAGED
|
39
46
|
end
|
40
47
|
|
41
48
|
private
|
@@ -44,4 +51,8 @@ class InsightsClientReportStatus < HostStatus::Status
|
|
44
51
|
return false unless reported_at
|
45
52
|
(Time.now.utc - reported_at).to_i < REPORT_INTERVAL.to_i
|
46
53
|
end
|
54
|
+
|
55
|
+
def insights_param
|
56
|
+
host.host_params_hash.dig('host_registration_insights', :value)
|
57
|
+
end
|
47
58
|
end
|
@@ -2,12 +2,6 @@ module ForemanRhCloud
|
|
2
2
|
module CloudAuth
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
|
-
include CloudRequest
|
6
|
-
|
7
|
-
def cloud_auth_available?
|
8
|
-
Setting[:rh_cloud_token].present?
|
9
|
-
end
|
10
|
-
|
11
5
|
def rh_credentials
|
12
6
|
@rh_credentials ||= query_refresh_token
|
13
7
|
end
|
@@ -30,15 +24,5 @@ module ForemanRhCloud
|
|
30
24
|
Foreman::Logging.exception('Unable to authenticate using rh_cloud_token setting', e)
|
31
25
|
raise ::Foreman::WrappedException.new(e, N_('Unable to authenticate using rh_cloud_token setting'))
|
32
26
|
end
|
33
|
-
|
34
|
-
def execute_cloud_request(params)
|
35
|
-
final_params = {
|
36
|
-
headers: {
|
37
|
-
Authorization: "Bearer #{rh_credentials}",
|
38
|
-
},
|
39
|
-
}.deep_merge(params)
|
40
|
-
|
41
|
-
super(final_params)
|
42
|
-
end
|
43
27
|
end
|
44
28
|
end
|
@@ -2,7 +2,7 @@ require 'rest-client'
|
|
2
2
|
|
3
3
|
module ForemanRhCloud
|
4
4
|
class CloudRequestForwarder
|
5
|
-
include ForemanRhCloud::
|
5
|
+
include ::ForemanRhCloud::CloudAuth
|
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,16 +22,21 @@ 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,
|
25
26
|
payload: forward_payload,
|
26
27
|
headers: {
|
27
28
|
params: forward_params,
|
28
29
|
user_agent: http_user_agent(original_request),
|
29
|
-
content_type: original_request.media_type
|
30
|
+
content_type: original_request.media_type,
|
30
31
|
},
|
31
32
|
}
|
32
33
|
base_params.merge(path_params(original_request.path, certs))
|
33
34
|
end
|
34
35
|
|
36
|
+
def execute_cloud_request(request_opts)
|
37
|
+
RestClient::Request.execute request_opts
|
38
|
+
end
|
39
|
+
|
35
40
|
def prepare_forward_payload(original_request, controller_name)
|
36
41
|
forward_payload = original_request.request_parameters[controller_name]
|
37
42
|
|
@@ -56,15 +61,13 @@ module ForemanRhCloud
|
|
56
61
|
|
57
62
|
def path_params(request_path, certs)
|
58
63
|
case request_path
|
59
|
-
when
|
64
|
+
when metadata_request?
|
60
65
|
{
|
61
|
-
url: ForemanRhCloud.
|
62
|
-
ssl_client_cert: OpenSSL::X509::Certificate.new(certs[:cert]),
|
63
|
-
ssl_client_key: OpenSSL::PKey::RSA.new(certs[:key]),
|
66
|
+
url: ForemanRhCloud.base_url + request_path.sub('/redhat_access/r/insights', '/api'),
|
64
67
|
}
|
65
|
-
when
|
68
|
+
when platform_request?
|
66
69
|
{
|
67
|
-
url: ForemanRhCloud.cert_base_url + '/
|
70
|
+
url: ForemanRhCloud.cert_base_url + request_path.sub('/redhat_access/r/insights/platform', '/api'),
|
68
71
|
ssl_client_cert: OpenSSL::X509::Certificate.new(certs[:cert]),
|
69
72
|
ssl_client_key: OpenSSL::PKey::RSA.new(certs[:key]),
|
70
73
|
}
|
@@ -78,12 +81,12 @@ module ForemanRhCloud
|
|
78
81
|
end
|
79
82
|
end
|
80
83
|
|
81
|
-
def
|
82
|
-
->(request_path) { request_path.include? '/
|
84
|
+
def metadata_request?
|
85
|
+
->(request_path) { request_path.include? '/static' }
|
83
86
|
end
|
84
87
|
|
85
|
-
def
|
86
|
-
->(request_path) { request_path
|
88
|
+
def platform_request?
|
89
|
+
->(request_path) { request_path.include? '/platform' }
|
87
90
|
end
|
88
91
|
|
89
92
|
def prepare_forward_cloud_url(base_url, request_path)
|
@@ -12,11 +12,6 @@ module ForemanRhCloud
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def create_playbook
|
15
|
-
unless cloud_auth_available?
|
16
|
-
logger.debug('Cloud authentication is not available, cannot continue')
|
17
|
-
return
|
18
|
-
end
|
19
|
-
|
20
15
|
response = query_playbook
|
21
16
|
|
22
17
|
logger.debug("Got playbook response: #{response.body}")
|
@@ -67,11 +62,14 @@ module ForemanRhCloud
|
|
67
62
|
end
|
68
63
|
|
69
64
|
def query_playbook
|
70
|
-
|
65
|
+
RestClient::Request.execute(
|
71
66
|
method: :post,
|
72
67
|
url: InsightsCloud.playbook_url,
|
68
|
+
verify_ssl: ForemanRhCloud.verify_ssl_method,
|
69
|
+
proxy: ForemanRhCloud.transformed_http_proxy_string(logger: logger),
|
73
70
|
headers: {
|
74
71
|
content_type: :json,
|
72
|
+
Authorization: "Bearer #{rh_credentials}",
|
75
73
|
},
|
76
74
|
payload: playbook_request.to_json
|
77
75
|
)
|