foreman_rh_cloud 4.0.25 → 5.0.28
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 +4 -1
- data/app/controllers/concerns/inventory_upload/report_actions.rb +1 -1
- data/app/controllers/foreman_inventory_upload/cloud_status_controller.rb +26 -0
- data/app/controllers/foreman_inventory_upload/reports_controller.rb +1 -1
- data/app/controllers/insights_cloud/api/machine_telemetries_controller.rb +18 -4
- data/app/controllers/insights_cloud/hits_controller.rb +0 -1
- data/app/models/setting/rh_cloud.rb +0 -1
- data/app/models/task_output_line.rb +2 -0
- data/app/models/task_output_status.rb +2 -0
- data/app/services/foreman_rh_cloud/cloud_ping_service.rb +83 -0
- data/app/services/foreman_rh_cloud/cloud_request_forwarder.rb +15 -3
- data/config/Gemfile.lock.gh_test +169 -160
- data/config/database.yml.example +2 -2
- data/config/package-lock.json.plugin +10551 -7500
- data/config/rh_cert-api_chain.pem +74 -0
- data/config/routes.rb +3 -1
- data/db/migrate/20211027000001_create_task_output.foreman_rh_cloud.rb +18 -0
- data/lib/foreman_inventory_upload/async/generate_all_reports_job.rb +11 -7
- data/lib/foreman_inventory_upload/async/generate_report_job.rb +24 -12
- data/lib/foreman_inventory_upload/async/progress_output.rb +5 -28
- data/lib/foreman_inventory_upload/async/queue_for_upload_job.rb +20 -5
- data/lib/foreman_inventory_upload/async/shell_process.rb +17 -4
- data/lib/foreman_inventory_upload/async/upload_report_job.rb +22 -13
- data/lib/foreman_inventory_upload/generators/queries.rb +0 -16
- data/lib/foreman_inventory_upload/generators/tags.rb +1 -2
- data/lib/foreman_rh_cloud/engine.rb +4 -11
- data/lib/foreman_rh_cloud/version.rb +1 -1
- data/lib/foreman_rh_cloud.rb +16 -1
- data/lib/insights_cloud/async/insights_client_status_aging.rb +4 -0
- data/lib/insights_cloud/async/insights_full_sync.rb +4 -0
- data/lib/insights_cloud/async/insights_generate_notifications.rb +4 -0
- data/lib/insights_cloud/async/insights_resolutions_sync.rb +7 -2
- data/lib/insights_cloud/async/insights_rules_sync.rb +10 -2
- data/lib/insights_cloud/async/insights_scheduled_sync.rb +11 -7
- data/lib/insights_cloud.rb +4 -0
- data/lib/inventory_sync/async/inventory_full_sync.rb +4 -0
- data/lib/inventory_sync/async/inventory_hosts_sync.rb +4 -0
- data/lib/inventory_sync/async/inventory_scheduled_sync.rb +4 -0
- data/lib/inventory_sync/async/inventory_self_host_sync.rb +4 -0
- data/lib/inventory_sync/async/query_inventory_job.rb +4 -0
- data/lib/tasks/rh_cloud_inventory.rake +4 -11
- data/package.json +7 -12
- data/test/controllers/insights_cloud/api/machine_telemetries_controller_test.rb +20 -39
- data/test/controllers/inventory_upload/cloud_status_controller_test.rb +44 -0
- data/test/factories/inventory_upload_factories.rb +14 -0
- data/test/jobs/insights_resolutions_sync_test.rb +10 -1
- data/test/jobs/upload_report_job_test.rb +5 -3
- data/test/test_plugin_helper.rb +53 -0
- data/test/unit/foreman_rh_cloud_self_host_test.rb +28 -0
- data/test/unit/services/foreman_rh_cloud/cloud_request_forwarder_test.rb +29 -34
- data/test/unit/services/foreman_rh_cloud/cloud_status_service_test.rb +66 -0
- data/test/unit/shell_process_job_test.rb +3 -1
- data/test/unit/slice_generator_test.rb +24 -4
- data/test/unit/tags_generator_test.rb +16 -16
- data/webpack/ForemanInventoryUpload/Components/AccountList/accountList.scss +8 -0
- data/webpack/ForemanInventoryUpload/Components/InventorySettings/InventorySettings.scss +0 -4
- data/webpack/ForemanInventoryUpload/Components/PageHeader/PageHeader.scss +17 -4
- data/webpack/ForemanInventoryUpload/Components/PageHeader/PageTitle.js +36 -12
- data/webpack/ForemanInventoryUpload/Components/PageHeader/__tests__/__snapshots__/PageTitle.test.js.snap +58 -37
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/CloudPingModal/index.js +144 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/CloudPingModal/index.scss +5 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/PageDescription.js +12 -10
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/__tests__/__snapshots__/PageDescription.test.js.snap +10 -10
- data/webpack/ForemanInventoryUpload/ForemanInventoryConstants.js +2 -0
- data/webpack/ForemanInventoryUpload/SubscriptionsPageExtension/InventoryAutoUpload/__tests__/__snapshots__/InventoryAutoUpload.test.js.snap +1 -1
- data/webpack/InsightsCloudSync/Components/InsightsHeader/InsightsHeader.scss +5 -1
- data/webpack/InsightsCloudSync/Components/InsightsHeader/index.js +6 -6
- data/webpack/InsightsCloudSync/Components/InsightsSettings/InsightsSettings.js +9 -5
- data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/__snapshots__/InsightsSettings.test.js.snap +6 -6
- data/webpack/InsightsCloudSync/Components/InsightsSettings/insightsSettings.scss +1 -14
- data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTable.js +5 -24
- data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableConstants.js +11 -4
- data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableSelectors.js +0 -3
- data/webpack/InsightsCloudSync/Components/InsightsTable/Pagination.js +51 -0
- data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/__snapshots__/InsightsTable.test.js.snap +7 -69
- data/webpack/InsightsCloudSync/Components/InsightsTable/table.scss +10 -0
- data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationModal.js +11 -10
- data/webpack/InsightsCloudSync/Components/RemediationModal/index.js +0 -2
- data/webpack/InsightsCloudSync/Components/ToolbarDropdown.js +32 -0
- data/webpack/InsightsCloudSync/Components/__tests__/__snapshots__/InsightsHeader.test.js.snap +5 -5
- data/webpack/InsightsCloudSync/Components/__tests__/__snapshots__/NoTokenEmptyState.test.js.snap +24 -13
- data/webpack/InsightsCloudSync/InsightsCloudSync.js +19 -13
- data/webpack/InsightsCloudSync/InsightsCloudSync.scss +82 -2
- data/webpack/InsightsCloudSync/__snapshots__/InsightsCloudSync.test.js.snap +16 -6
- data/webpack/__mocks__/foremanReact/components/Head.js +11 -0
- data/webpack/common/Switcher/HelpLabel.js +1 -1
- data/webpack/common/Switcher/SwitcherPF4.js +1 -1
- data/webpack/common/Switcher/SwitcherPF4.scss +6 -7
- data/webpack/common/Switcher/__tests__/__snapshots__/HelpLabel.test.js.snap +1 -1
- data/webpack/common/Switcher/__tests__/__snapshots__/SwitcherPF4.test.js.snap +2 -1
- metadata +20 -24
- data/webpack/InsightsCloudSync/Components/InsightsSyncSwitcher/InsightsSyncSwitcher.fixtures.js +0 -1
- data/webpack/InsightsCloudSync/Components/InsightsSyncSwitcher/InsightsSyncSwitcher.js +0 -45
- data/webpack/InsightsCloudSync/Components/InsightsSyncSwitcher/__tests__/InsightsSyncSwitcher.test.js +0 -17
- data/webpack/InsightsCloudSync/Components/InsightsSyncSwitcher/__tests__/__snapshots__/InsightsSyncSwitcher.test.js.snap +0 -38
- data/webpack/InsightsCloudSync/Components/InsightsSyncSwitcher/index.js +0 -1
- data/webpack/InsightsCloudSync/Components/InsightsSyncSwitcher/insightsSyncSwitcher.scss +0 -3
- data/webpack/InsightsCloudSync/Components/RemediationModal/RemediateButton.js +0 -59
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 012fcceed18a6413326df32052bee870b299682bc114d5c3e59954bda33b2475
|
4
|
+
data.tar.gz: bb72b384fc54d6c19951c453c69b0ecaae5d26bf844fc85b4d4b56f04e1e76bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70904b446fce3a2ca3a794c418aaa1591f4276bd35d1636a629e7361b75c62163fc76ad45caa024752a763ef6a9e6344e979dff8f9e9a017c19ac878f667a649
|
7
|
+
data.tar.gz: 4fd0e25610e4848565178f19e5a3ffb1da2d9b1505cd604f18a9276bba931f6fea3fbbddcd6c1e375a9d655a4c0b506c3937d89e9e7899b4aed37ae05c72b542
|
@@ -7,6 +7,7 @@ module Api
|
|
7
7
|
include InventoryUpload::TaskActions
|
8
8
|
|
9
9
|
api :GET, "/organizations/:organization_id/rh_cloud/report", N_("Download latest report")
|
10
|
+
param :organization_id, Integer, required: true, desc: N_("Set the current organization context for the request")
|
10
11
|
def download_file
|
11
12
|
filename, file = report_file(params[:organization_id])
|
12
13
|
|
@@ -16,6 +17,7 @@ module Api
|
|
16
17
|
end
|
17
18
|
|
18
19
|
api :POST, "/organizations/:organization_id/rh_cloud/report", N_("Start report generation")
|
20
|
+
param :organization_id, Integer, required: true, desc: N_("Set the current organization context for the request")
|
19
21
|
def generate_report
|
20
22
|
organization_id = params[:organization_id]
|
21
23
|
|
@@ -27,6 +29,7 @@ module Api
|
|
27
29
|
end
|
28
30
|
|
29
31
|
api :POST, "/organizations/:organization_id/rh_cloud/inventory_sync", N_("Start inventory synchronization")
|
32
|
+
param :organization_id, Integer, required: true, desc: N_("Set the current organization context for the request")
|
30
33
|
def sync_inventory_status
|
31
34
|
selected_org = Organization.find(params[:organization_id])
|
32
35
|
|
@@ -39,7 +42,7 @@ module Api
|
|
39
42
|
render json: { message: error.message }, status: :bad_request
|
40
43
|
end
|
41
44
|
|
42
|
-
api :POST, "rh_cloud/enable_connector", N_("Enable cloud connector")
|
45
|
+
api :POST, "/rh_cloud/enable_connector", N_("Enable cloud connector")
|
43
46
|
def enable_cloud_connector
|
44
47
|
cloud_connector = ForemanRhCloud::CloudConnector.new
|
45
48
|
render json: cloud_connector.install.to_json
|
@@ -11,7 +11,7 @@ module InventoryUpload
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def start_report_generation(organization_id)
|
14
|
-
ForemanInventoryUpload::Async::GenerateReportJob
|
14
|
+
ForemanTasks.async_task(ForemanInventoryUpload::Async::GenerateReportJob, ForemanInventoryUpload.generated_reports_folder, organization_id)
|
15
15
|
end
|
16
16
|
|
17
17
|
def report_file(organization_id)
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module ForemanInventoryUpload
|
2
|
+
class CloudStatusController < ::ApplicationController
|
3
|
+
def index
|
4
|
+
organizations = User.current.my_organizations
|
5
|
+
|
6
|
+
ping_service = ForemanRhCloud::CloudPingService.new(organizations, logger)
|
7
|
+
ping_result = ping_service.ping
|
8
|
+
ping_result[:cert_auth] = ping_result[:cert_auth].map do |org, status_hash|
|
9
|
+
status_hash.merge(
|
10
|
+
{
|
11
|
+
org_id: org.id,
|
12
|
+
org_name: org.name,
|
13
|
+
}
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
render json: {
|
18
|
+
ping: ping_result,
|
19
|
+
}, status: :ok
|
20
|
+
end
|
21
|
+
|
22
|
+
def logger
|
23
|
+
Foreman::Logging.logger('app')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -7,7 +7,7 @@ module ForemanInventoryUpload
|
|
7
7
|
def last
|
8
8
|
label = ForemanInventoryUpload::Async::GenerateReportJob.output_label(params[:organization_id])
|
9
9
|
output = ForemanInventoryUpload::Async::ProgressOutput.get(label)&.full_output
|
10
|
-
task_label = ForemanInventoryUpload::Async::GenerateAllReportsJob.
|
10
|
+
task_label = ForemanInventoryUpload::Async::GenerateAllReportsJob.name
|
11
11
|
scheduled = ForemanTasks::Task.where(
|
12
12
|
:label => task_label,
|
13
13
|
:state => 'scheduled'
|
@@ -25,6 +25,14 @@ module InsightsCloud::Api
|
|
25
25
|
}, status: :bad_gateway
|
26
26
|
end
|
27
27
|
|
28
|
+
if @cloud_response.code >= 300
|
29
|
+
return render json: {
|
30
|
+
:message => 'Cloud request failed',
|
31
|
+
:headers => {},
|
32
|
+
:response => @cloud_response,
|
33
|
+
}, status: @cloud_response.code
|
34
|
+
end
|
35
|
+
|
28
36
|
if @cloud_response.headers[:content_disposition]
|
29
37
|
return send_data @cloud_response, disposition: @cloud_response.headers[:content_disposition], type: @cloud_response.headers[:content_type]
|
30
38
|
end
|
@@ -49,13 +57,19 @@ module InsightsCloud::Api
|
|
49
57
|
private
|
50
58
|
|
51
59
|
def ensure_telemetry_enabled_for_consumer
|
52
|
-
|
60
|
+
unless (config = telemetry_config(@host))
|
61
|
+
logger.debug("Rejected telemetry forwarding for host #{@host.name}, insights param is set to: #{config}")
|
62
|
+
render_message 'Telemetry is not enabled for this host', :status => 403
|
63
|
+
end
|
64
|
+
config
|
53
65
|
end
|
54
66
|
|
55
|
-
def telemetry_config
|
56
|
-
|
57
|
-
|
67
|
+
def telemetry_config(host)
|
68
|
+
param_value = nil
|
69
|
+
User.as_anonymous_admin do
|
70
|
+
param_value = host.host_param(InsightsCloud.enable_client_param)
|
58
71
|
end
|
72
|
+
param_value
|
59
73
|
end
|
60
74
|
|
61
75
|
def cert_uuid
|
@@ -9,7 +9,6 @@ module InsightsCloud
|
|
9
9
|
hasToken: !Setting[:rh_cloud_token].empty?,
|
10
10
|
hits: hits.map { |hit| hit.attributes.merge(hostname: hit.host&.name, has_playbook: hit.has_playbook?) },
|
11
11
|
itemCount: hits.count,
|
12
|
-
isExperimentalMode: Setting[:lab_features],
|
13
12
|
}, status: :ok
|
14
13
|
end
|
15
14
|
|
@@ -12,7 +12,6 @@ class Setting::RhCloud < Setting
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def self.default_settings
|
15
|
-
return unless ActiveRecord::Base.connection.table_exists?('settings')
|
16
15
|
[
|
17
16
|
set('allow_auto_inventory_upload', N_('Enable automatic upload of your host inventory to the Red Hat cloud'), true, N_('Automatic inventory upload')),
|
18
17
|
set('allow_auto_insights_sync', N_('Enable automatic synchronization of Insights recommendations from the Red Hat cloud'), false, N_('Synchronize recommendations Automatically')),
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
|
3
|
+
module ForemanRhCloud
|
4
|
+
class CloudPingService
|
5
|
+
class TokenPing
|
6
|
+
include ForemanRhCloud::CloudAuth
|
7
|
+
|
8
|
+
attr_accessor :logger
|
9
|
+
|
10
|
+
def initialize(logger)
|
11
|
+
@logger = logger
|
12
|
+
end
|
13
|
+
|
14
|
+
def ping
|
15
|
+
execute_cloud_request(
|
16
|
+
method: :get,
|
17
|
+
url: ForemanRhCloud.base_url + "/api/inventory/v1/hosts?per_page=1",
|
18
|
+
headers: {
|
19
|
+
content_type: :json,
|
20
|
+
}
|
21
|
+
)
|
22
|
+
rescue StandardError => ex
|
23
|
+
ex
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class CertPing
|
28
|
+
include ForemanRhCloud::CloudRequest
|
29
|
+
include InsightsCloud::CandlepinCache
|
30
|
+
|
31
|
+
attr_accessor :logger
|
32
|
+
|
33
|
+
def initialize(org, logger)
|
34
|
+
@org = org
|
35
|
+
@logger = logger
|
36
|
+
end
|
37
|
+
|
38
|
+
def ping
|
39
|
+
certs = candlepin_id_cert(@org)
|
40
|
+
return StandardError.new('certificate missing') unless certs
|
41
|
+
|
42
|
+
execute_cloud_request(
|
43
|
+
method: :get,
|
44
|
+
url: ForemanRhCloud.cert_base_url + "/api/apicast-tests/ping",
|
45
|
+
headers: {
|
46
|
+
content_type: :json,
|
47
|
+
},
|
48
|
+
ssl_client_cert: OpenSSL::X509::Certificate.new(certs[:cert]),
|
49
|
+
ssl_client_key: OpenSSL::PKey::RSA.new(certs[:key])
|
50
|
+
)
|
51
|
+
rescue StandardError => ex
|
52
|
+
ex
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def initialize(organizations, logger)
|
57
|
+
@organizations = organizations
|
58
|
+
@logger = logger
|
59
|
+
end
|
60
|
+
|
61
|
+
def ping
|
62
|
+
token_response = TokenPing.new(@logger).ping
|
63
|
+
{
|
64
|
+
token_auth: {
|
65
|
+
success: token_response.is_a?(RestClient::Response),
|
66
|
+
error: (token_response.is_a?(Exception) ? token_response.inspect : nil),
|
67
|
+
},
|
68
|
+
cert_auth: Hash[
|
69
|
+
@organizations.map do |org|
|
70
|
+
cert_response = CertPing.new(org, @logger).ping
|
71
|
+
[
|
72
|
+
org,
|
73
|
+
{
|
74
|
+
success: cert_response.is_a?(RestClient::Response),
|
75
|
+
error: (cert_response.is_a?(Exception) ? cert_response.inspect : nil),
|
76
|
+
},
|
77
|
+
]
|
78
|
+
end
|
79
|
+
],
|
80
|
+
}
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -17,6 +17,8 @@ module ForemanRhCloud
|
|
17
17
|
logger.debug("Sending request to: #{request_opts[:url]}")
|
18
18
|
|
19
19
|
execute_cloud_request(request_opts)
|
20
|
+
rescue RestClient::Exception => error_response
|
21
|
+
error_response.response
|
20
22
|
end
|
21
23
|
|
22
24
|
def prepare_request_opts(original_request, forward_payload, forward_params, certs)
|
@@ -62,12 +64,18 @@ module ForemanRhCloud
|
|
62
64
|
ssl_client_cert: OpenSSL::X509::Certificate.new(certs[:cert]),
|
63
65
|
ssl_client_key: OpenSSL::PKey::RSA.new(certs[:key]),
|
64
66
|
}
|
67
|
+
when connection_test_request?
|
68
|
+
{
|
69
|
+
url: ForemanRhCloud.cert_base_url + '/api/apicast-tests/ping',
|
70
|
+
ssl_client_cert: OpenSSL::X509::Certificate.new(certs[:cert]),
|
71
|
+
ssl_client_key: OpenSSL::PKey::RSA.new(certs[:key]),
|
72
|
+
}
|
65
73
|
else # Legacy insights API
|
66
74
|
{
|
67
75
|
url: ForemanRhCloud.legacy_insights_url + request_path.sub('/redhat_access/r/insights', '/r/insights'),
|
68
76
|
ssl_client_cert: OpenSSL::X509::Certificate.new(certs[:cert]),
|
69
77
|
ssl_client_key: OpenSSL::PKey::RSA.new(certs[:key]),
|
70
|
-
ssl_ca_file:
|
78
|
+
ssl_ca_file: ForemanRhCloud.legacy_insights_ca,
|
71
79
|
}
|
72
80
|
end
|
73
81
|
end
|
@@ -76,6 +84,10 @@ module ForemanRhCloud
|
|
76
84
|
->(request_path) { request_path.include? '/platform' }
|
77
85
|
end
|
78
86
|
|
87
|
+
def connection_test_request?
|
88
|
+
->(request_path) { request_path =~ /redhat_access\/r\/insights\/?$/ }
|
89
|
+
end
|
90
|
+
|
79
91
|
def prepare_forward_cloud_url(base_url, request_path)
|
80
92
|
cloud_path = request_path.sub('/redhat_access/r/insights/platform/', '')
|
81
93
|
.sub('/redhat_access/r/insights/', '')
|
@@ -84,11 +96,11 @@ module ForemanRhCloud
|
|
84
96
|
end
|
85
97
|
|
86
98
|
def core_app_name
|
87
|
-
|
99
|
+
BranchInfo.new.core_app_name
|
88
100
|
end
|
89
101
|
|
90
102
|
def core_app_version
|
91
|
-
|
103
|
+
BranchInfo.new.core_app_version
|
92
104
|
end
|
93
105
|
|
94
106
|
def http_user_agent(original_request)
|