foreman_rh_cloud 3.0.16 → 3.0.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/concerns/insights_cloud/candlepin_cache.rb +28 -0
- data/app/controllers/concerns/insights_cloud/client_authentication.rb +23 -0
- data/app/controllers/foreman_inventory_upload/accounts_controller.rb +1 -1
- data/app/controllers/foreman_inventory_upload/uploads_controller.rb +1 -8
- data/app/controllers/insights_cloud/api/machine_telemetries_controller.rb +73 -0
- data/app/controllers/insights_cloud/hits_controller.rb +3 -3
- data/app/controllers/insights_cloud/tasks_controller.rb +6 -1
- data/app/models/insights_hit.rb +16 -1
- data/app/models/insights_resolution.rb +3 -0
- data/app/models/insights_rule.rb +3 -0
- data/app/models/setting/rh_cloud.rb +12 -2
- data/app/services/foreman_rh_cloud/branch_info.rb +57 -0
- data/app/services/foreman_rh_cloud/cloud_request_forwarder.rb +102 -0
- data/config/routes.rb +10 -0
- data/db/migrate/20210214000001_create_rules_and_resolutions.foreman_rh_cloud.rb +24 -0
- data/db/migrate/20210214000002_add_rule_id_to_hits.foreman_rh_cloud.rb +5 -0
- data/lib/foreman_inventory_upload/generators/slice.rb +3 -3
- data/lib/foreman_rh_cloud.rb +9 -0
- data/lib/foreman_rh_cloud/engine.rb +1 -0
- data/lib/foreman_rh_cloud/version.rb +1 -1
- data/lib/insights_cloud.rb +4 -0
- data/lib/insights_cloud/async/insights_full_sync.rb +29 -0
- data/lib/insights_cloud/async/insights_rules_sync.rb +80 -0
- data/lib/insights_cloud/async/rules_result.rb +13 -0
- data/package.json +1 -1
- data/test/controllers/insights_cloud/api/machine_telemetries_controller_test.rb +107 -0
- data/test/factories/insights_factories.rb +2 -1
- data/test/factories/inventory_upload_factories.rb +12 -0
- data/test/jobs/insights_full_sync_test.rb +17 -0
- data/test/jobs/insights_rules_sync_test.rb +198 -0
- data/test/unit/services/foreman_rh_cloud/branch_info_test.rb +60 -0
- data/test/unit/services/foreman_rh_cloud/cloud_request_forwarder_test.rb +106 -0
- data/test/unit/slice_generator_test.rb +29 -3
- data/webpack/ForemanInventoryUpload/Components/AccountList/AccountList.fixtures.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListActions.test.js.snap +1 -1
- data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListReducer.test.js.snap +1 -1
- data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListSelectors.test.js.snap +2 -2
- data/webpack/ForemanInventoryUpload/Components/Dashboard/DashboardActions.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/DashboardActions.test.js +4 -4
- data/webpack/ForemanInventoryUpload/Components/PageHeader/PageHeader.js +2 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/PageHeader.scss +12 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/__tests__/__snapshots__/PageHeader.test.js.snap +1 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SettingsWarning/SettingsWarning.js +64 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SettingsWarning/SettingsWarning.test.js +18 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SettingsWarning/__snapshots__/SettingsWarning.test.js.snap +30 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SettingsWarning/index.js +25 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButton.js +2 -2
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/SyncButton.test.js +1 -1
- data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTable.js +9 -5
- data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableActions.js +55 -30
- data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableConstants.js +10 -9
- data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableHelpers.js +14 -6
- data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableSelectors.js +4 -0
- data/webpack/InsightsCloudSync/Components/InsightsTable/SelectAllAlert.js +4 -10
- data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/InsightsTableActions.test.js +48 -0
- data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/__snapshots__/InsightsTable.test.js.snap +11 -24
- data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/__snapshots__/InsightsTableActions.test.js.snap +132 -0
- data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/__snapshots__/InsightsTableSelectors.test.js.snap +1 -0
- data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/fixtures.js +1 -1
- data/webpack/InsightsCloudSync/Components/InsightsTable/table.scss +10 -0
- data/webpack/InsightsCloudSync/InsightsCloudSync.js +18 -16
- data/webpack/InsightsCloudSync/InsightsCloudSyncActions.js +23 -20
- data/webpack/InsightsCloudSync/InsightsCloudSyncConstants.js +1 -1
- data/webpack/InsightsCloudSync/__snapshots__/InsightsCloudSync.test.js.snap +36 -36
- data/webpack/InsightsCloudSync/__tests__/InsightsCloudSyncActions.test.js +9 -0
- data/webpack/InsightsCloudSync/__tests__/__snapshots__/InsightsCloudSyncActions.test.js.snap +11 -0
- data/webpack/__mocks__/foremanReact/redux/API/index.js +1 -0
- metadata +29 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de4c573e51011ac6fd99707859fa86d659454b7f30183494ab5e240e773bec0a
|
4
|
+
data.tar.gz: f0510f09adf430834e01b9732a9cf6faedff0b18471e7b90fbca8a47fe867a13
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5ef31993d25982136027082f9fb3d382133378627afd0f5da6eeb5eb24a971aa36cdb7f8995347b017ab438124219113e6b326a52f1821e0ccbdb0a6e402f52
|
7
|
+
data.tar.gz: e5da37635a059fadc6e6c62464aec98f75e803fddb1f8b1ca9b23ad27e42cffdb006bdd4ae5e59d10317d8599f6629ff8f4e08065a15947aff7f93133ec49e8a
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module InsightsCloud
|
2
|
+
module CandlepinCache
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
def upstream_owner(org)
|
6
|
+
# We use a cache because owner_details is a call to Candlepin
|
7
|
+
Rails.cache.fetch("rh_cloud_upstream_owner_#{org.id}", expires_in: 1.minute) do
|
8
|
+
org.owner_details['upstreamConsumer']
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def cp_owner_id(org)
|
13
|
+
owner = upstream_owner(org)
|
14
|
+
owner['uuid'] if owner
|
15
|
+
end
|
16
|
+
|
17
|
+
def candlepin_id_cert(org)
|
18
|
+
owner = upstream_owner(org)
|
19
|
+
return unless owner
|
20
|
+
id_cert = {
|
21
|
+
cert: owner.dig('idCert', 'cert'),
|
22
|
+
key: owner.dig('idCert', 'key'),
|
23
|
+
}
|
24
|
+
return unless id_cert.values.all?
|
25
|
+
id_cert
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module InsightsCloud
|
2
|
+
module ClientAuthentication
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
include ::Katello::Authentication::ClientAuthentication
|
6
|
+
|
7
|
+
def authorize
|
8
|
+
client_authorized? || super
|
9
|
+
end
|
10
|
+
|
11
|
+
def client_authorized?
|
12
|
+
authenticate_client && valid_machine_user?
|
13
|
+
end
|
14
|
+
|
15
|
+
def valid_machine_user?
|
16
|
+
subscribed_host_by_uuid(User.current.uuid).present?
|
17
|
+
end
|
18
|
+
|
19
|
+
def subscribed_host_by_uuid(uuid)
|
20
|
+
@host = Host.unscoped.joins(:subscription_facet).where(:katello_subscription_facets => {:uuid => uuid }).first
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -24,7 +24,7 @@ module ForemanInventoryUpload
|
|
24
24
|
autoUploadEnabled: Setting[:allow_auto_inventory_upload],
|
25
25
|
hostObfuscationEnabled: Setting[:obfuscate_inventory_hostnames],
|
26
26
|
ipsObfuscationEnabled: Setting[:obfuscate_inventory_ips],
|
27
|
-
cloudToken: Setting[:rh_cloud_token]
|
27
|
+
cloudToken: !Setting[:rh_cloud_token].empty?,
|
28
28
|
excludePackages: Setting[:exclude_installed_packages],
|
29
29
|
accounts: accounts,
|
30
30
|
CloudConnectorStatus: cloud_connector_status,
|
@@ -14,14 +14,7 @@ module ForemanInventoryUpload
|
|
14
14
|
files = Dir["{#{ForemanInventoryUpload.uploads_file_path(filename)},#{ForemanInventoryUpload.done_file_path(filename)}}"]
|
15
15
|
|
16
16
|
return send_file files.first, disposition: 'attachment', filename: filename unless files.empty?
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
|
-
def throw_flash_error(message)
|
21
|
-
process_error(
|
22
|
-
:redirect => foreman_inventory_upload_index_path,
|
23
|
-
:error_msg => message
|
24
|
-
)
|
17
|
+
raise ::Foreman::Exception.new("The report file doesn't exist")
|
25
18
|
end
|
26
19
|
|
27
20
|
def enable_cloud_connector
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module InsightsCloud::Api
|
2
|
+
class MachineTelemetriesController < ::Api::V2::BaseController
|
3
|
+
layout false
|
4
|
+
|
5
|
+
include ::InsightsCloud::ClientAuthentication
|
6
|
+
include ::InsightsCloud::CandlepinCache
|
7
|
+
|
8
|
+
before_action :cert_uuid, :ensure_org, :ensure_branch_id, :only => [:forward_request, :branch_info]
|
9
|
+
before_action :ensure_telemetry_enabled_for_consumer, :only => [:forward_request]
|
10
|
+
|
11
|
+
skip_after_action :log_response_body, :only => [:forward_request]
|
12
|
+
skip_before_action :check_media_type, :only => [:forward_request]
|
13
|
+
|
14
|
+
# The method that "proxies" requests over to Cloud
|
15
|
+
def forward_request
|
16
|
+
certs = candlepin_id_cert @organization
|
17
|
+
cloud_response = ::ForemanRhCloud::CloudRequestForwarder.new.forward_request(request, controller_name, @branch_id, certs)
|
18
|
+
|
19
|
+
if cloud_response.code == 401
|
20
|
+
return render json: {
|
21
|
+
:message => 'Authentication to the Insights Service failed.',
|
22
|
+
:headers => {},
|
23
|
+
}, status: :bad_gateway
|
24
|
+
end
|
25
|
+
|
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
|
+
end
|
29
|
+
|
30
|
+
assign_header(response, cloud_response, :x_resource_count, true)
|
31
|
+
assign_header(response, cloud_response, :x_rh_insights_request_id, false)
|
32
|
+
|
33
|
+
render json: cloud_response, status: cloud_response.code
|
34
|
+
end
|
35
|
+
|
36
|
+
def branch_info
|
37
|
+
render :json => ForemanRhCloud::BranchInfo.new.generate(@uuid, @host, @branch_id, request.host).to_json
|
38
|
+
end
|
39
|
+
|
40
|
+
def assign_header(res, cloud_res, header, transform)
|
41
|
+
header_content = cloud_res.headers[header]
|
42
|
+
return unless header_content
|
43
|
+
new_header = transform ? header.to_s.tr('_', '-') : header.to_s
|
44
|
+
res.headers[new_header] = header_content
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def ensure_telemetry_enabled_for_consumer
|
50
|
+
render_message 'Telemetry is not enabled for your organization', :status => 403 unless telemetry_config
|
51
|
+
end
|
52
|
+
|
53
|
+
def telemetry_config
|
54
|
+
::RedhatAccess::TelemetryConfiguration.find_or_create_by(:organization_id => @organization.id) do |conf|
|
55
|
+
conf.enable_telemetry = true
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def cert_uuid
|
60
|
+
@uuid ||= User.current.login
|
61
|
+
end
|
62
|
+
|
63
|
+
def ensure_org
|
64
|
+
@organization = @host.organization
|
65
|
+
return render_message 'Organization not found or invalid', :status => 400 unless @organization
|
66
|
+
end
|
67
|
+
|
68
|
+
def ensure_branch_id
|
69
|
+
@branch_id = cp_owner_id(@organization)
|
70
|
+
return render_message "Branch ID not found for organization #{@organization.title}", :status => 400 unless @branch_id
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -3,11 +3,11 @@ module InsightsCloud
|
|
3
3
|
include Foreman::Controller::AutoCompleteSearch
|
4
4
|
|
5
5
|
def index
|
6
|
-
hits = resource_base_search_and_page.preload(:host)
|
6
|
+
hits = resource_base_search_and_page.preload(:host, :rule)
|
7
7
|
|
8
8
|
render json: {
|
9
|
-
hasToken: Setting[:rh_cloud_token].
|
10
|
-
hits: hits.map { |hit| hit.attributes.merge(hostname: hit.host&.name) },
|
9
|
+
hasToken: !Setting[:rh_cloud_token].empty?,
|
10
|
+
hits: hits.map { |hit| hit.attributes.merge(hostname: hit.host&.name, has_playbook: hit.has_playbook?) },
|
11
11
|
itemCount: hits.count,
|
12
12
|
}, status: :ok
|
13
13
|
end
|
@@ -1,7 +1,12 @@
|
|
1
1
|
module InsightsCloud
|
2
2
|
class TasksController < ::ApplicationController
|
3
3
|
def create
|
4
|
-
InsightsCloud::Async::InsightsFullSync.
|
4
|
+
job = InsightsCloud::Async::InsightsFullSync.perform_later
|
5
|
+
task = ForemanTasks::Task.find_by(external_id: job.provider_job_id)
|
6
|
+
|
7
|
+
render json: {
|
8
|
+
task: task,
|
9
|
+
}, status: :ok
|
5
10
|
end
|
6
11
|
end
|
7
12
|
end
|
data/app/models/insights_hit.rb
CHANGED
@@ -4,7 +4,22 @@ class InsightsHit < ApplicationRecord
|
|
4
4
|
# since the facet is one-to-one association with a host, we can connect
|
5
5
|
# through host_id column on both this model and facet.
|
6
6
|
belongs_to :insights_facet, foreign_key: 'host_id', primary_key: 'host_id', counter_cache: :hits_count
|
7
|
+
|
8
|
+
has_one :rule, class_name: 'InsightsRule', foreign_key: 'rule_id', primary_key: 'rule_id'
|
9
|
+
|
10
|
+
scope :with_playbook, -> { joins(:rule) }
|
11
|
+
|
7
12
|
scoped_search on: :title, complete_value: true
|
8
|
-
scoped_search on: :total_risk, complete_value:
|
13
|
+
scoped_search on: :total_risk, complete_value: true
|
14
|
+
scoped_search on: :rule_id, complete_value: true, only_explicit: true
|
9
15
|
scoped_search relation: :host, on: :name, rename: :hostname, complete_value: true
|
16
|
+
scoped_search on: :rule_id, rename: :with_playbook, only_explicit: true, complete_value: false, ext_method: :find_with_playbook
|
17
|
+
|
18
|
+
def self.find_with_playbook(key, operator, value)
|
19
|
+
{ joins: :rule }
|
20
|
+
end
|
21
|
+
|
22
|
+
def has_playbook?
|
23
|
+
!rule.nil?
|
24
|
+
end
|
10
25
|
end
|
@@ -1,16 +1,26 @@
|
|
1
1
|
class Setting::RhCloud < Setting
|
2
2
|
::Setting::BLANK_ATTRS.concat %w{rh_cloud_token}
|
3
3
|
|
4
|
+
def self.load_defaults
|
5
|
+
return false unless table_exists?
|
6
|
+
transaction do
|
7
|
+
# If the user had auto_upload default setting, we will not surprise him, and force the value to false
|
8
|
+
# for new users, the default will be set to true and the value will remain nil
|
9
|
+
Setting.where(name: 'allow_auto_inventory_upload', value: nil).where("settings.default LIKE '%false%'").update_all(value: "--- false\n...")
|
10
|
+
super
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
4
14
|
def self.default_settings
|
5
15
|
return unless ActiveRecord::Base.connection.table_exists?('settings')
|
6
|
-
return unless super
|
7
16
|
[
|
8
|
-
set('allow_auto_inventory_upload', N_('Allow automatic upload of the host inventory to the Red Hat cloud'),
|
17
|
+
set('allow_auto_inventory_upload', N_('Allow automatic upload of the host inventory to the Red Hat cloud'), true, N_('Allow automatic inventory uploads')),
|
9
18
|
set('allow_auto_insights_sync', N_('Allow recommendations synchronization from Red Hat cloud'), false, N_('Allow recommendations synchronization')),
|
10
19
|
set('obfuscate_inventory_hostnames', N_('Obfuscate host names sent to Red Hat cloud'), false, N_('Obfuscate host names')),
|
11
20
|
set('obfuscate_inventory_ips', N_('Obfuscate ip addresses sent to Red Hat cloud'), false, N_('Obfuscate IPs')),
|
12
21
|
set('rh_cloud_token', N_('Authentication token to Red Hat cloud services. Used to authenticate requests to cloud APIs'), nil, N_('Red Hat Cloud token'), nil, encrypted: true),
|
13
22
|
set('exclude_installed_packages', N_('Exclude installed packages from Red Hat cloud inventory report'), false, N_("Don't upload installed packages")),
|
23
|
+
set('include_parameter_tags', N_('Should import include parameter tags from Foreman?'), false, N_('Include parameters in insights-client reports')),
|
14
24
|
]
|
15
25
|
end
|
16
26
|
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module ForemanRhCloud
|
2
|
+
class BranchInfo
|
3
|
+
def generate(uuid, host, branch_id, request_hostname)
|
4
|
+
{
|
5
|
+
:remote_leaf => uuid,
|
6
|
+
:remote_branch => branch_id,
|
7
|
+
:display_name => host.organization.name,
|
8
|
+
:hostname => request_hostname,
|
9
|
+
:product => {
|
10
|
+
:type => core_app_name,
|
11
|
+
:major_version => core_app_version.major,
|
12
|
+
:minor_version => core_app_version.minor,
|
13
|
+
},
|
14
|
+
:organization_id => host.organization.id,
|
15
|
+
:satellite_instance_id => Foreman.instance_id,
|
16
|
+
:labels => host_labels(host),
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
def core_app_name
|
21
|
+
'Foreman'
|
22
|
+
end
|
23
|
+
|
24
|
+
def core_app_version
|
25
|
+
Foreman::Version.new
|
26
|
+
end
|
27
|
+
|
28
|
+
def new_label(key, value, namespace)
|
29
|
+
{
|
30
|
+
:namespace => namespace,
|
31
|
+
:key => key,
|
32
|
+
:value => value,
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
def labels_from_items(items, label_namespace, label_lamb, label_value_method = :to_s)
|
37
|
+
items.map { |item| new_label(label_lamb.call(item), item.public_send(label_value_method), label_namespace) }
|
38
|
+
end
|
39
|
+
|
40
|
+
def host_labels(host)
|
41
|
+
labels = [new_label('Organization', host.organization.name, 'Satellite')]
|
42
|
+
labels += labels_from_items(host.location.title.split('/'), 'Satellite', ->(item) { 'Location' }) if host.location
|
43
|
+
labels += labels_from_items(host.hostgroup.title.split('/'), 'Satellite', ->(item) { 'Host Group' }) if host.hostgroup
|
44
|
+
labels += labels_from_items(host.host_collections, 'Satellite', ->(item) { 'Host Collection' }, :name)
|
45
|
+
|
46
|
+
if Setting[:include_parameter_tags]
|
47
|
+
labels += labels_from_items(
|
48
|
+
host.host_inherited_params_objects,
|
49
|
+
'SatelliteParameter',
|
50
|
+
->(item) { item.name },
|
51
|
+
:value)
|
52
|
+
end
|
53
|
+
|
54
|
+
labels
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
|
3
|
+
module ForemanRhCloud
|
4
|
+
class CloudRequestForwarder
|
5
|
+
include ::ForemanRhCloud::CloudAuth
|
6
|
+
|
7
|
+
def forward_request(original_request, controller_name, branch_id, certs)
|
8
|
+
forward_params = prepare_forward_params(original_request, branch_id)
|
9
|
+
logger.debug("Request parameters for telemetry request: #{forward_params}")
|
10
|
+
|
11
|
+
forward_payload = prepare_forward_payload(original_request, controller_name)
|
12
|
+
|
13
|
+
logger.debug("User agent for telemetry is: #{http_user_agent original_request}")
|
14
|
+
|
15
|
+
request_opts = prepare_request_opts(original_request, forward_payload, forward_params, certs)
|
16
|
+
|
17
|
+
logger.debug("Sending request to: #{request_opts[:url]}")
|
18
|
+
|
19
|
+
execute_cloud_request(request_opts)
|
20
|
+
end
|
21
|
+
|
22
|
+
def prepare_request_opts(original_request, forward_payload, forward_params, certs)
|
23
|
+
base_params = {
|
24
|
+
method: original_request.method,
|
25
|
+
verify_ssl: ForemanRhCloud.verify_ssl_method,
|
26
|
+
payload: forward_payload,
|
27
|
+
headers: {
|
28
|
+
params: forward_params,
|
29
|
+
user_agent: http_user_agent(original_request),
|
30
|
+
},
|
31
|
+
}
|
32
|
+
|
33
|
+
if no_cert_paths.any? { |path| path.match original_request.path }
|
34
|
+
base_params.merge(url: prepare_forward_cloud_url(ForemanRhCloud.base_url, original_request.path))
|
35
|
+
else
|
36
|
+
base_params.merge(
|
37
|
+
url: prepare_forward_cloud_url(ForemanRhCloud.cert_base_url, original_request.path),
|
38
|
+
ssl_client_cert: OpenSSL::X509::Certificate.new(certs[:cert]),
|
39
|
+
ssl_client_key: OpenSSL::PKey::RSA.new(certs[:key])
|
40
|
+
)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def no_cert_paths
|
45
|
+
[
|
46
|
+
"/redhat_access/r/insights/v1/static/release/insights-core.egg",
|
47
|
+
"/redhat_access/r/insights/v1/static/uploader.v2.json",
|
48
|
+
"/redhat_access/r/insights/v1/static/uploader.v2.json.asc",
|
49
|
+
"/redhat_access/r/insights/v1/static/core/insights-core.egg",
|
50
|
+
]
|
51
|
+
end
|
52
|
+
|
53
|
+
def execute_cloud_request(request_opts)
|
54
|
+
RestClient::Request.execute request_opts
|
55
|
+
end
|
56
|
+
|
57
|
+
def prepare_forward_payload(original_request, controller_name)
|
58
|
+
forward_payload = original_request.request_parameters[controller_name]
|
59
|
+
|
60
|
+
forward_payload = original_request.raw_post.clone if original_request.post? && original_request.raw_post
|
61
|
+
forward_payload = original_request.body.read if original_request.put?
|
62
|
+
|
63
|
+
forward_payload = original_request.params.slice(:file, :metadata) if original_request.params[:file]
|
64
|
+
|
65
|
+
# fix rails behaviour for http PATCH:
|
66
|
+
forward_payload = forward_payload.to_json if original_request.format.json? && original_request.patch? && forward_payload && !forward_payload.is_a?(String)
|
67
|
+
forward_payload
|
68
|
+
end
|
69
|
+
|
70
|
+
def prepare_forward_params(original_request, branch_id)
|
71
|
+
forward_params = original_request.query_parameters
|
72
|
+
if original_request.user_agent && !original_request.user_agent.include?('redhat_access_cfme')
|
73
|
+
forward_params = forward_params.merge(:branch_id => branch_id)
|
74
|
+
end
|
75
|
+
|
76
|
+
forward_params
|
77
|
+
end
|
78
|
+
|
79
|
+
def prepare_forward_cloud_url(base_url, request_path)
|
80
|
+
cloud_path = request_path.sub('/redhat_access/r/insights/platform/', '')
|
81
|
+
.sub('/redhat_access/r/insights/', '')
|
82
|
+
|
83
|
+
"#{base_url}/api/#{cloud_path}"
|
84
|
+
end
|
85
|
+
|
86
|
+
def core_app_name
|
87
|
+
'Foreman'
|
88
|
+
end
|
89
|
+
|
90
|
+
def core_app_version
|
91
|
+
Foreman::Version.new
|
92
|
+
end
|
93
|
+
|
94
|
+
def http_user_agent(original_request)
|
95
|
+
"#{core_app_name}/#{core_app_version};#{ForemanRhCloud::Engine.engine_name}/#{ForemanRhCloud::VERSION};#{original_request.env['HTTP_USER_AGENT']}"
|
96
|
+
end
|
97
|
+
|
98
|
+
def logger
|
99
|
+
Foreman::Logging.logger('app')
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
data/config/routes.rb
CHANGED
@@ -32,4 +32,14 @@ Rails.application.routes.draw do
|
|
32
32
|
get 'inventory_upload', to: '/react#index'
|
33
33
|
get 'insights_cloud', to: '/react#index' # Uses foreman's react controller
|
34
34
|
end
|
35
|
+
|
36
|
+
scope :module => :'insights_cloud/api', :path => :redhat_access do
|
37
|
+
scope 'r/insights/v1' do
|
38
|
+
get 'branch_info', to: 'machine_telemetries#branch_info'
|
39
|
+
end
|
40
|
+
|
41
|
+
scope '/r/insights' do
|
42
|
+
match '/*path', :constraints => lambda { |req| !req.path.include?('view/api') }, to: 'machine_telemetries#forward_request', via: [:get, :post, :delete,:put, :patch]
|
43
|
+
end
|
44
|
+
end
|
35
45
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class CreateRulesAndResolutions < ActiveRecord::Migration[5.2]
|
2
|
+
def change
|
3
|
+
create_table :insights_rules do |t|
|
4
|
+
t.string :rule_id
|
5
|
+
t.string :description
|
6
|
+
t.string :category_name
|
7
|
+
t.string :impact_name
|
8
|
+
t.string :summary
|
9
|
+
t.string :generic
|
10
|
+
t.string :reason
|
11
|
+
t.integer :total_risk
|
12
|
+
t.boolean :reboot_required
|
13
|
+
t.string :more_info
|
14
|
+
t.integer :rating
|
15
|
+
end
|
16
|
+
|
17
|
+
create_table :insights_resolutions do |t|
|
18
|
+
t.string :rule_id
|
19
|
+
t.integer :system_type
|
20
|
+
t.string :resolution
|
21
|
+
t.boolean :has_playbook
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|