foreman_rh_cloud 10.0.6 → 11.0.0
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/README.md +3 -3
- data/app/controllers/insights_cloud/api/machine_telemetries_controller.rb +14 -28
- data/app/services/foreman_rh_cloud/cloud_request.rb +3 -9
- data/app/services/foreman_rh_cloud/cloud_request_forwarder.rb +3 -3
- data/app/services/foreman_rh_cloud/url_remediations_retriever.rb +1 -1
- data/config/initializers/zeitwerk.rb +3 -0
- data/lib/foreman_rh_cloud/engine.rb +103 -97
- data/lib/foreman_rh_cloud/version.rb +1 -1
- data/lib/insights_cloud/async/insights_full_sync.rb +9 -14
- data/lib/insights_cloud/async/insights_resolutions_sync.rb +1 -5
- data/package.json +1 -1
- data/test/controllers/insights_cloud/api/machine_telemetries_controller_test.rb +2 -48
- data/test/jobs/insights_full_sync_test.rb +0 -28
- data/test/jobs/insights_resolutions_sync_test.rb +0 -22
- data/test/unit/services/foreman_rh_cloud/cloud_request_forwarder_test.rb +0 -24
- data/test/unit/services/foreman_rh_cloud/url_remediations_retriever_test.rb +2 -2
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/PageDescription.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/__tests__/__snapshots__/PageDescription.test.js.snap +1 -1
- metadata +11 -17
- data/lib/foreman_rh_cloud/settings.rb +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fcd4ee874e42e9236bbc4fae540911c372af73f3a336507c9421693b8fb128da
|
4
|
+
data.tar.gz: da0c96b9b8fb3d737d0f8902da7176adbd2f1a8810260ddeba547c3a22004ec7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 12343eaac2bfb4c666c156a84a868f02a3b684f4a4bf044f7a838d9134d140ec6fb698b356c35efb8b11618fa0c36b3a61c0cc411caf48ff91b8fc9957528074
|
7
|
+
data.tar.gz: 41f578f21a65aee43ade158a99991c1b3b7b37ee2000e0e1c8c7d55cba60ac94d31e734d205e589bfc1bf1850fb98142b91ea975b3d9580361a11803eac8f17b
|
data/README.md
CHANGED
@@ -15,7 +15,7 @@ for how to install Foreman plugins
|
|
15
15
|
|
16
16
|
#### Inventory upload
|
17
17
|
|
18
|
-
In UI:
|
18
|
+
In UI: Configure -> Inventory Upload -> Restart
|
19
19
|
|
20
20
|
From command-line:
|
21
21
|
|
@@ -38,7 +38,7 @@ From command-line:
|
|
38
38
|
|
39
39
|
#### Fetch hosts remediation data
|
40
40
|
|
41
|
-
In UI:
|
41
|
+
In UI: Configure -> Insights -> Sync now
|
42
42
|
|
43
43
|
From command-line:
|
44
44
|
|
@@ -46,7 +46,7 @@ From command-line:
|
|
46
46
|
|
47
47
|
#### Synchronize inventory status
|
48
48
|
|
49
|
-
In UI:
|
49
|
+
In UI: Configure -> Inventory Upload -> Sync inventory status
|
50
50
|
|
51
51
|
From command-line:
|
52
52
|
|
@@ -16,41 +16,27 @@ module InsightsCloud::Api
|
|
16
16
|
# The method that "proxies" requests over to Cloud
|
17
17
|
def forward_request
|
18
18
|
certs = candlepin_id_cert @organization
|
19
|
-
|
20
|
-
@cloud_response = ::ForemanRhCloud::CloudRequestForwarder.new.forward_request(request, controller_name, @branch_id, certs)
|
21
|
-
rescue RestClient::Exceptions::Timeout => e
|
22
|
-
response_obj = e.response.presence || e.exception
|
23
|
-
return render json: { message: response_obj.to_s, error: response_obj.to_s }, status: :gateway_timeout
|
24
|
-
rescue RestClient::Unauthorized => e
|
25
|
-
logger.warn("Forwarding request auth error: #{e}")
|
26
|
-
message = 'Authentication to the Insights Service failed.'
|
27
|
-
return render json: { message: message, error: message }, status: :unauthorized
|
28
|
-
rescue RestClient::NotModified => e
|
29
|
-
logger.info("Forwarding request not modified: #{e}")
|
30
|
-
message = 'Cloud request not modified'
|
31
|
-
return render json: { message: message, error: message }, status: :not_modified
|
32
|
-
rescue RestClient::ExceptionWithResponse => e
|
33
|
-
response_obj = e.response.presence || e.exception
|
34
|
-
code = response_obj.try(:code) || response_obj.try(:http_code) || 500
|
35
|
-
message = 'Cloud request failed'
|
19
|
+
@cloud_response = ::ForemanRhCloud::CloudRequestForwarder.new.forward_request(request, controller_name, @branch_id, certs)
|
36
20
|
|
21
|
+
if @cloud_response.code == 401
|
37
22
|
return render json: {
|
38
|
-
:message =>
|
39
|
-
:error => response_obj.to_s,
|
23
|
+
:message => 'Authentication to the Insights Service failed.',
|
40
24
|
:headers => {},
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
25
|
+
}, status: :bad_gateway
|
26
|
+
end
|
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
|
47
34
|
end
|
48
35
|
|
49
36
|
# Append redhat-specific headers
|
50
37
|
@cloud_response.headers.each do |key, value|
|
51
38
|
assign_header(response, @cloud_response, key, false) if key.to_s.start_with?('x_rh_')
|
52
39
|
end
|
53
|
-
|
54
40
|
# Append general headers
|
55
41
|
assign_header(response, @cloud_response, :x_resource_count, true)
|
56
42
|
headers[Rack::ETAG] = @cloud_response.headers[:etag]
|
@@ -60,8 +46,8 @@ module InsightsCloud::Api
|
|
60
46
|
# content type
|
61
47
|
send_data @cloud_response, disposition: @cloud_response.headers[:content_disposition], type: @cloud_response.headers[:content_type]
|
62
48
|
elsif @cloud_response.headers[:content_type] =~ /zip/
|
63
|
-
#
|
64
|
-
#
|
49
|
+
# if there is no Content-Disposition, but the content type is binary according the content type,
|
50
|
+
# forward the request as binry too
|
65
51
|
send_data @cloud_response, type: @cloud_response.headers[:content_type]
|
66
52
|
else
|
67
53
|
render json: @cloud_response, status: @cloud_response.code
|
@@ -13,15 +13,9 @@ module ForemanRhCloud
|
|
13
13
|
logger.debug("Response headers for request url #{final_params[:url]} are: #{response.headers}")
|
14
14
|
|
15
15
|
response
|
16
|
-
rescue RestClient::
|
17
|
-
logger.debug("
|
18
|
-
raise
|
19
|
-
rescue RestClient::ExceptionWithResponse => ex
|
20
|
-
logger.debug("Response headers for request url #{final_params[:url]} with status code #{ex.http_code} are: #{ex.http_headers} and body: #{ex.http_body}")
|
21
|
-
raise
|
22
|
-
rescue StandardError => ex
|
23
|
-
logger.debug("Exception raised for request url #{final_params[:url]}: #{ex}")
|
24
|
-
raise
|
16
|
+
rescue RestClient::Exception => ex
|
17
|
+
logger.debug("Failed response with code #{ex.http_code} headers for request url #{final_params[:url]} are: #{ex.http_headers} and body: #{ex.http_body}")
|
18
|
+
raise ex
|
25
19
|
end
|
26
20
|
end
|
27
21
|
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)
|
@@ -49,9 +51,7 @@ module ForemanRhCloud
|
|
49
51
|
|
50
52
|
def prepare_forward_params(original_request, branch_id)
|
51
53
|
forward_params = original_request.query_parameters
|
52
|
-
|
53
|
-
user_agent = original_request.user_agent.present? && !original_request.user_agent.include?('redhat_access_cfme')
|
54
|
-
if user_agent && !compliance_request
|
54
|
+
if original_request.user_agent && !original_request.user_agent.include?('redhat_access_cfme')
|
55
55
|
forward_params = forward_params.merge(:branch_id => branch_id)
|
56
56
|
end
|
57
57
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module ForemanRhCloud
|
2
|
-
class
|
2
|
+
class URLRemediationsRetriever < RemediationsRetriever
|
3
3
|
attr_reader :url, :payload, :headers
|
4
4
|
|
5
5
|
def initialize(url:, organization_id:, payload: '', headers: {}, logger: Logger.new(IO::NULL))
|
@@ -20,15 +20,6 @@ module ForemanRhCloud
|
|
20
20
|
rescue ActiveRecord::TransactionIsolationError
|
21
21
|
end
|
22
22
|
|
23
|
-
initializer 'foreman_rh_cloud.load_default_settings', :before => :load_config_initializers do
|
24
|
-
require_dependency File.expand_path('settings.rb', __dir__)
|
25
|
-
end
|
26
|
-
|
27
|
-
config.autoload_paths += Dir["#{config.root}/app/controllers/concerns"]
|
28
|
-
config.autoload_paths += Dir["#{config.root}/app/helpers/concerns"]
|
29
|
-
config.autoload_paths += Dir["#{config.root}/app/models/concerns"]
|
30
|
-
config.autoload_paths += Dir["#{config.root}/app/services"]
|
31
|
-
config.autoload_paths += Dir["#{config.root}/app/overrides"]
|
32
23
|
config.autoload_paths += Dir["#{config.root}/lib"]
|
33
24
|
|
34
25
|
config.eager_load_paths += Dir["#{config.root}/lib"]
|
@@ -40,109 +31,124 @@ module ForemanRhCloud
|
|
40
31
|
end
|
41
32
|
end
|
42
33
|
|
43
|
-
initializer 'foreman_rh_cloud.register_plugin', :before => :finisher_hook do |
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
permission(
|
64
|
-
:view_foreman_rh_cloud,
|
65
|
-
'foreman_inventory_upload/accounts': [:index],
|
66
|
-
'foreman_inventory_upload/reports': [:last],
|
67
|
-
'foreman_inventory_upload/uploads': [:auto_upload, :show_auto_upload, :download_file, :last],
|
68
|
-
'foreman_inventory_upload/tasks': [:show],
|
69
|
-
'foreman_inventory_upload/cloud_status': [:index],
|
70
|
-
'foreman_inventory_upload/uploads_settings': [:index],
|
71
|
-
'foreman_inventory_upload/missing_hosts': [:index],
|
72
|
-
'react': [:index]
|
73
|
-
)
|
74
|
-
permission(
|
75
|
-
:view_insights_hits,
|
76
|
-
{
|
77
|
-
'/foreman_rh_cloud/insights_cloud': [:index], # for bookmarks and later for showing the page
|
78
|
-
'insights_cloud/hits': [:index, :show, :auto_complete_search, :resolutions],
|
79
|
-
'insights_cloud/settings': [:index, :show],
|
80
|
-
'react': [:index],
|
81
|
-
},
|
82
|
-
:resource_type => ::InsightsHit.name
|
83
|
-
)
|
84
|
-
permission(
|
85
|
-
:dispatch_cloud_requests,
|
86
|
-
'api/v2/rh_cloud/cloud_request': [:update]
|
87
|
-
)
|
88
|
-
permission(
|
89
|
-
:control_organization_insights,
|
90
|
-
'insights_cloud/settings': [:set_org_parameter]
|
91
|
-
)
|
92
|
-
end
|
34
|
+
initializer 'foreman_rh_cloud.register_plugin', :before => :finisher_hook do |app|
|
35
|
+
app.reloader.to_prepare do
|
36
|
+
Foreman::Plugin.register :foreman_rh_cloud do
|
37
|
+
requires_foreman '>= 3.13'
|
38
|
+
register_gettext
|
39
|
+
|
40
|
+
apipie_documented_controllers ["#{ForemanRhCloud::Engine.root}/app/controllers/api/v2/**/*.rb"]
|
41
|
+
|
42
|
+
settings do
|
43
|
+
category(:rh_cloud, N_('RHCloud')) do
|
44
|
+
setting('allow_auto_inventory_upload', type: :boolean, description: N_('Enable automatic upload of your host inventory to the Red Hat cloud'), default: true, full_name: N_('Automatic inventory upload'))
|
45
|
+
setting('allow_auto_insights_sync', type: :boolean, description: N_('Enable automatic synchronization of Insights recommendations from the Red Hat cloud'), default: false, full_name: N_('Synchronize recommendations Automatically'))
|
46
|
+
setting('allow_auto_insights_mismatch_delete', type: :boolean, description: N_('Enable automatic deletion of mismatched host records from the Red Hat cloud'), default: false, full_name: N_('Automatic mismatch deletion'))
|
47
|
+
setting('obfuscate_inventory_hostnames', type: :boolean, description: N_('Obfuscate host names sent to the Red Hat cloud'), default: false, full_name: N_('Obfuscate host names'))
|
48
|
+
setting('obfuscate_inventory_ips', type: :boolean, description: N_('Obfuscate ipv4 addresses sent to the Red Hat cloud'), default: false, full_name: N_('Obfuscate host ipv4 addresses'))
|
49
|
+
setting('exclude_installed_packages', type: :boolean, description: N_('Exclude installed packages from being uploaded to the Red Hat cloud'), default: false, full_name: N_("Exclude installed Packages"))
|
50
|
+
setting('include_parameter_tags', type: :boolean, description: N_('Should import include parameter tags from Foreman?'), default: false, full_name: N_('Include parameters in insights-client reports'))
|
51
|
+
setting('rhc_instance_id', type: :string, description: N_('RHC daemon id'), default: nil, full_name: N_('ID of the RHC(Yggdrasil) daemon'))
|
52
|
+
end
|
53
|
+
end
|
93
54
|
|
94
|
-
|
55
|
+
# Add permissions
|
56
|
+
security_block :foreman_rh_cloud do
|
57
|
+
permission(
|
58
|
+
:generate_foreman_rh_cloud,
|
59
|
+
'foreman_inventory_upload/reports': [:generate],
|
60
|
+
'foreman_inventory_upload/tasks': [:create],
|
61
|
+
'api/v2/rh_cloud/inventory': [:get_hosts, :remove_hosts, :sync_inventory_status, :download_file, :generate_report, :enable_cloud_connector],
|
62
|
+
'foreman_inventory_upload/uploads': [:enable_cloud_connector],
|
63
|
+
'foreman_inventory_upload/uploads_settings': [:set_advanced_setting],
|
64
|
+
'foreman_inventory_upload/missing_hosts': [:remove_hosts],
|
65
|
+
'insights_cloud/settings': [:update],
|
66
|
+
'insights_cloud/tasks': [:create]
|
67
|
+
)
|
68
|
+
permission(
|
69
|
+
:view_foreman_rh_cloud,
|
70
|
+
'foreman_inventory_upload/accounts': [:index],
|
71
|
+
'foreman_inventory_upload/reports': [:last],
|
72
|
+
'foreman_inventory_upload/uploads': [:auto_upload, :show_auto_upload, :download_file, :last],
|
73
|
+
'foreman_inventory_upload/tasks': [:show],
|
74
|
+
'foreman_inventory_upload/cloud_status': [:index],
|
75
|
+
'foreman_inventory_upload/uploads_settings': [:index],
|
76
|
+
'foreman_inventory_upload/missing_hosts': [:index],
|
77
|
+
'react': [:index]
|
78
|
+
)
|
79
|
+
permission(
|
80
|
+
:view_insights_hits,
|
81
|
+
{
|
82
|
+
'/foreman_rh_cloud/insights_cloud': [:index], # for bookmarks and later for showing the page
|
83
|
+
'insights_cloud/hits': [:index, :show, :auto_complete_search, :resolutions],
|
84
|
+
'insights_cloud/settings': [:index, :show],
|
85
|
+
'react': [:index],
|
86
|
+
},
|
87
|
+
:resource_type => ::InsightsHit.name
|
88
|
+
)
|
89
|
+
permission(
|
90
|
+
:dispatch_cloud_requests,
|
91
|
+
'api/v2/rh_cloud/cloud_request': [:update]
|
92
|
+
)
|
93
|
+
permission(
|
94
|
+
:control_organization_insights,
|
95
|
+
'insights_cloud/settings': [:set_org_parameter]
|
96
|
+
)
|
97
|
+
end
|
98
|
+
|
99
|
+
plugin_permissions = [:view_foreman_rh_cloud, :generate_foreman_rh_cloud, :view_insights_hits, :dispatch_cloud_requests, :control_organization_insights]
|
95
100
|
|
96
|
-
|
97
|
-
|
101
|
+
role 'ForemanRhCloud', plugin_permissions, 'Role granting permissions to view the hosts inventory,
|
102
|
+
generate a report, upload it to the cloud and download it locally'
|
98
103
|
|
99
|
-
|
100
|
-
|
101
|
-
|
104
|
+
add_permissions_to_default_roles Role::ORG_ADMIN => plugin_permissions,
|
105
|
+
Role::MANAGER => plugin_permissions,
|
106
|
+
Role::SYSTEM_ADMIN => plugin_permissions
|
102
107
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
108
|
+
# Adding a sub menu after hosts menu
|
109
|
+
divider :top_menu, caption: N_('RH Cloud'), parent: :configure_menu
|
110
|
+
menu :top_menu, :inventory_upload, caption: N_('Inventory Upload'), url: '/foreman_rh_cloud/inventory_upload', url_hash: { controller: :react, action: :index }, parent: :configure_menu
|
111
|
+
menu :top_menu, :insights_hits, caption: N_('Insights'), url: '/foreman_rh_cloud/insights_cloud', url_hash: { controller: :react, action: :index }, parent: :configure_menu
|
107
112
|
|
108
|
-
|
109
|
-
|
110
|
-
|
113
|
+
register_facet InsightsFacet, :insights do
|
114
|
+
configure_host do
|
115
|
+
set_dependent_action :destroy
|
116
|
+
end
|
111
117
|
end
|
112
|
-
end
|
113
118
|
|
114
|
-
|
119
|
+
register_global_js_file 'global'
|
115
120
|
|
116
|
-
|
117
|
-
|
121
|
+
register_custom_status InventorySync::InventoryStatus
|
122
|
+
register_custom_status InsightsClientReportStatus
|
118
123
|
|
119
|
-
|
120
|
-
|
121
|
-
|
124
|
+
describe_host do
|
125
|
+
overview_buttons_provider :insights_host_overview_buttons
|
126
|
+
end
|
122
127
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
128
|
+
extend_page 'hosts/show' do |context|
|
129
|
+
context.add_pagelet :main_tabs,
|
130
|
+
partial: 'hosts/insights_tab',
|
131
|
+
name: _('Insights'),
|
132
|
+
id: 'insights',
|
133
|
+
onlyif: proc { |host| host.insights }
|
134
|
+
end
|
130
135
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
+
extend_page 'hosts/_list' do |context|
|
137
|
+
context.with_profile :cloud, _('RH Cloud'), default: true do
|
138
|
+
add_pagelet :hosts_table_column_header, key: :insights_recommendations_count, label: _('Recommendations'), sortable: true, width: '12%', class: 'hidden-xs ellipsis', priority: 100,
|
139
|
+
export_data: CsvExporter::ExportDefinition.new(:insights_recommendations_count, callback: ->(host) { host&.insights_hits&.count })
|
140
|
+
add_pagelet :hosts_table_column_content, key: :insights_recommendations_count, callback: ->(host) { hits_counts_cell(host) }, class: 'hidden-xs ellipsis text-center', priority: 100
|
141
|
+
end
|
136
142
|
end
|
137
|
-
end
|
138
143
|
|
139
|
-
|
140
|
-
|
141
|
-
|
144
|
+
extend_template_helpers ForemanRhCloud::TemplateRendererHelper
|
145
|
+
allowed_template_helpers :remediations_playbook, :download_rh_playbook
|
146
|
+
end
|
142
147
|
|
143
|
-
|
148
|
+
::Katello::UINotifications::Subscriptions::ManifestImportSuccess.include ForemanInventoryUpload::Notifications::ManifestImportSuccessNotificationOverride if defined?(Katello)
|
144
149
|
|
145
|
-
|
150
|
+
::Host::Managed.include RhCloudHost
|
151
|
+
end
|
146
152
|
end
|
147
153
|
|
148
154
|
rake_tasks do
|
@@ -9,11 +9,10 @@ module InsightsCloud
|
|
9
9
|
|
10
10
|
def plan(organizations)
|
11
11
|
organizations = organizations.select do |organization|
|
12
|
-
|
13
|
-
if cert_auth_available?(organization) && !organization.manifest_expired? && checker.can_connect?
|
12
|
+
if cert_auth_available?(organization)
|
14
13
|
true
|
15
14
|
else
|
16
|
-
logger.
|
15
|
+
logger.debug("Certificate is not available for org: #{organization.name}, skipping insights sync")
|
17
16
|
false
|
18
17
|
end
|
19
18
|
end
|
@@ -21,23 +20,19 @@ module InsightsCloud
|
|
21
20
|
sequence do
|
22
21
|
# This can be turned off when we enable automatic status syncs
|
23
22
|
# This step will query cloud inventory to retrieve inventory uuids for each host
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
plan_rules_sync(organizations)
|
30
|
-
plan_notifications
|
31
|
-
end
|
23
|
+
plan_hosts_sync(organizations)
|
24
|
+
plan_self(organization_ids: organizations.map(&:id))
|
25
|
+
concurrence do
|
26
|
+
plan_rules_sync(organizations)
|
27
|
+
plan_notifications
|
32
28
|
end
|
33
29
|
end
|
34
30
|
end
|
35
31
|
|
36
32
|
def try_execute
|
37
33
|
organizations.each do |organization|
|
38
|
-
|
39
|
-
|
40
|
-
logger.info("A manifest is not available for org: #{organization.name}, or it has expired, or been deleted. skipping insights sync")
|
34
|
+
unless cert_auth_available?(organization)
|
35
|
+
logger.debug("Certificate is not available for org: #{organization.name}, skipping insights sync")
|
41
36
|
next
|
42
37
|
end
|
43
38
|
|
@@ -13,11 +13,7 @@ module InsightsCloud
|
|
13
13
|
InsightsResolution.delete_all
|
14
14
|
rule_ids = relevant_rules
|
15
15
|
Organization.all.each do |organization|
|
16
|
-
|
17
|
-
if !cert_auth_available?(organization) || organization.manifest_expired? || !checker.can_connect?
|
18
|
-
logger.info("A manifest is not available for org: #{organization.name}, or it has expired, or been deleted. skipping resolutions sync")
|
19
|
-
next
|
20
|
-
end
|
16
|
+
next if !cert_auth_available?(organization) || organization.manifest_expired?
|
21
17
|
api_response = query_insights_resolutions(rule_ids, organization) unless rule_ids.empty?
|
22
18
|
written_rules = write_resolutions(api_response) if api_response
|
23
19
|
rule_ids -= Array(written_rules)
|
data/package.json
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'test_plugin_helper'
|
2
|
-
require 'rest-client'
|
3
2
|
|
4
3
|
module InsightsCloud::Api
|
5
4
|
class MachineTelemetriesControllerTest < ActionController::TestCase
|
@@ -34,18 +33,6 @@ module InsightsCloud::Api
|
|
34
33
|
assert_equal @body, @response.body
|
35
34
|
end
|
36
35
|
|
37
|
-
test "should handle timeout from cloud" do
|
38
|
-
::ForemanRhCloud::CloudRequestForwarder.any_instance.
|
39
|
-
stubs(:forward_request).
|
40
|
-
raises(RestClient::Exceptions::OpenTimeout.new("Timed out connecting to server"))
|
41
|
-
|
42
|
-
get :forward_request, params: { "path" => "platform/module-update-router/v1/channel" }
|
43
|
-
request_response = JSON.parse(@response.body)
|
44
|
-
# I can't get @response.status to take a nil value so I'm not asserting for that
|
45
|
-
|
46
|
-
assert_equal 'Timed out connecting to server', request_response['error']
|
47
|
-
end
|
48
|
-
|
49
36
|
test "should respond with the same content type" do
|
50
37
|
net_http_resp = Net::HTTPResponse.new(1.0, 200, "OK")
|
51
38
|
net_http_resp.add_field 'Set-Cookie', 'Monster'
|
@@ -96,46 +83,13 @@ module InsightsCloud::Api
|
|
96
83
|
assert_equal net_http_resp[:content_type], @response.headers['Content-Type']
|
97
84
|
end
|
98
85
|
|
99
|
-
test "should handle StandardError" do
|
100
|
-
error_message = "Connection refused"
|
101
|
-
::ForemanRhCloud::CloudRequestForwarder.any_instance.stubs(:execute_cloud_request).raises(Errno::ECONNREFUSED.new)
|
102
|
-
|
103
|
-
get :forward_request, params: { "path" => "platform/module-update-router/v1/channel" }
|
104
|
-
assert_equal 502, @response.status
|
105
|
-
body = JSON.parse(@response.body)
|
106
|
-
assert_equal error_message, body['error']
|
107
|
-
end
|
108
|
-
|
109
|
-
test "should handle 304 cloud" do
|
110
|
-
net_http_resp = Net::HTTPResponse.new(1.0, 304, "Not Modified")
|
111
|
-
res = RestClient::Response.create(@body, net_http_resp, @http_req)
|
112
|
-
|
113
|
-
::ForemanRhCloud::CloudRequestForwarder.any_instance.stubs(:execute_cloud_request).raises(RestClient::NotModified.new(res))
|
114
|
-
|
115
|
-
get :forward_request, params: { "path" => "platform/module-update-router/v1/channel" }
|
116
|
-
assert_equal 304, @response.status
|
117
|
-
assert_equal 'Cloud request not modified', JSON.parse(@response.body)['message']
|
118
|
-
end
|
119
|
-
|
120
|
-
test "should handle RestClient::Exceptions::Timeout" do
|
121
|
-
timeout_message = "execution expired"
|
122
|
-
::ForemanRhCloud::CloudRequestForwarder.any_instance.stubs(:execute_cloud_request).raises(RestClient::Exceptions::Timeout.new(timeout_message))
|
123
|
-
|
124
|
-
get :forward_request, params: { "path" => "platform/module-update-router/v1/channel" }
|
125
|
-
assert_equal 504, @response.status
|
126
|
-
body = JSON.parse(@response.body)
|
127
|
-
assert_equal timeout_message, body['message']
|
128
|
-
assert_equal timeout_message, body['error']
|
129
|
-
end
|
130
|
-
|
131
86
|
test "should handle failed authentication to cloud" do
|
132
87
|
net_http_resp = Net::HTTPResponse.new(1.0, 401, "Unauthorized")
|
133
88
|
res = RestClient::Response.create(@body, net_http_resp, @http_req)
|
134
|
-
|
135
|
-
::ForemanRhCloud::CloudRequestForwarder.any_instance.stubs(:execute_cloud_request).raises(RestClient::Unauthorized.new(res))
|
89
|
+
::ForemanRhCloud::CloudRequestForwarder.any_instance.stubs(:forward_request).returns(res)
|
136
90
|
|
137
91
|
get :forward_request, params: { "path" => "platform/module-update-router/v1/channel" }
|
138
|
-
assert_equal
|
92
|
+
assert_equal 502, @response.status
|
139
93
|
assert_equal 'Authentication to the Insights Service failed.', JSON.parse(@response.body)['message']
|
140
94
|
end
|
141
95
|
|
@@ -65,8 +65,6 @@ class InsightsFullSyncTest < ActiveSupport::TestCase
|
|
65
65
|
end
|
66
66
|
|
67
67
|
test 'Hits data is replaced with data from cloud' do
|
68
|
-
Organization.any_instance.stubs(:manifest_expired?).returns(false)
|
69
|
-
Katello::UpstreamConnectionChecker.any_instance.stubs(:can_connect?).returns(true)
|
70
68
|
InsightsCloud::Async::InsightsFullSync.any_instance.expects(:query_insights_hits).returns(@hits)
|
71
69
|
|
72
70
|
InsightsCloud::Async::InsightsFullSync.any_instance.expects(:plan_hosts_sync)
|
@@ -81,31 +79,7 @@ class InsightsFullSyncTest < ActiveSupport::TestCase
|
|
81
79
|
assert_equal 1, @host2.insights.hits.count
|
82
80
|
end
|
83
81
|
|
84
|
-
test 'Manifest is expired do not run task steps' do
|
85
|
-
Organization.any_instance.stubs(:manifest_expired?).returns(true)
|
86
|
-
Katello::UpstreamConnectionChecker.any_instance.stubs(:can_connect?).returns(true)
|
87
|
-
|
88
|
-
InsightsCloud::Async::InsightsFullSync.any_instance.expects(:query_insights_hits).never
|
89
|
-
InsightsCloud::Async::InsightsFullSync.any_instance.expects(:plan_hosts_sync).never
|
90
|
-
InsightsCloud::Async::InsightsFullSync.any_instance.expects(:plan_self).never
|
91
|
-
|
92
|
-
ForemanTasks.sync_task(InsightsCloud::Async::InsightsFullSync, [@host1.organization])
|
93
|
-
end
|
94
|
-
|
95
|
-
test 'Manifest is deleted do not run task steps' do
|
96
|
-
Organization.any_instance.stubs(:manifest_expired?).returns(false)
|
97
|
-
Katello::UpstreamConnectionChecker.any_instance.stubs(:can_connect?).returns(false)
|
98
|
-
|
99
|
-
InsightsCloud::Async::InsightsFullSync.any_instance.expects(:query_insights_hits).never
|
100
|
-
InsightsCloud::Async::InsightsFullSync.any_instance.expects(:plan_hosts_sync).never
|
101
|
-
InsightsCloud::Async::InsightsFullSync.any_instance.expects(:plan_self).never
|
102
|
-
|
103
|
-
ForemanTasks.sync_task(InsightsCloud::Async::InsightsFullSync, [@host1.organization])
|
104
|
-
end
|
105
|
-
|
106
82
|
test 'Hits counters are reset correctly' do
|
107
|
-
Organization.any_instance.stubs(:manifest_expired?).returns(false)
|
108
|
-
Katello::UpstreamConnectionChecker.any_instance.stubs(:can_connect?).returns(true)
|
109
83
|
InsightsCloud::Async::InsightsFullSync.any_instance.expects(:query_insights_hits).returns(@hits).twice
|
110
84
|
|
111
85
|
InsightsCloud::Async::InsightsFullSync.any_instance.stubs(:plan_hosts_sync)
|
@@ -123,8 +97,6 @@ class InsightsFullSyncTest < ActiveSupport::TestCase
|
|
123
97
|
end
|
124
98
|
|
125
99
|
test 'Hits ignoring non-existent hosts' do
|
126
|
-
Organization.any_instance.stubs(:manifest_expired?).returns(false)
|
127
|
-
Katello::UpstreamConnectionChecker.any_instance.stubs(:can_connect?).returns(true)
|
128
100
|
hits_json = <<-HITS_JSON
|
129
101
|
[
|
130
102
|
{
|
@@ -73,7 +73,6 @@ class InsightsResolutionsSyncTest < ActiveSupport::TestCase
|
|
73
73
|
end
|
74
74
|
|
75
75
|
test 'Resolutions data is replaced with data from cloud' do
|
76
|
-
Katello::UpstreamConnectionChecker.any_instance.stubs(:can_connect?).returns(true)
|
77
76
|
InsightsCloud::Async::InsightsResolutionsSync.any_instance.stubs(:query_insights_resolutions).returns(@resolutions)
|
78
77
|
|
79
78
|
ForemanTasks.sync_task(InsightsCloud::Async::InsightsResolutionsSync)
|
@@ -83,28 +82,7 @@ class InsightsResolutionsSyncTest < ActiveSupport::TestCase
|
|
83
82
|
assert_equal 2, @rule.resolutions.count
|
84
83
|
end
|
85
84
|
|
86
|
-
test 'Manifest is deleted do not run task steps' do
|
87
|
-
Organization.any_instance.stubs(:manifest_expired?).returns(false)
|
88
|
-
Katello::UpstreamConnectionChecker.any_instance.stubs(:can_connect?).returns(false)
|
89
|
-
InsightsCloud::Async::InsightsResolutionsSync.any_instance.expects(:query_insights_resolutions).never
|
90
|
-
|
91
|
-
ForemanTasks.sync_task(InsightsCloud::Async::InsightsResolutionsSync)
|
92
|
-
|
93
|
-
assert_equal 0, InsightsResolution.all.count
|
94
|
-
end
|
95
|
-
|
96
|
-
test 'Manifest is expired do not run task steps' do
|
97
|
-
Organization.any_instance.stubs(:manifest_expired?).returns(true)
|
98
|
-
Katello::UpstreamConnectionChecker.any_instance.stubs(:can_connect?).returns(true)
|
99
|
-
InsightsCloud::Async::InsightsResolutionsSync.any_instance.expects(:query_insights_resolutions).never
|
100
|
-
|
101
|
-
ForemanTasks.sync_task(InsightsCloud::Async::InsightsResolutionsSync)
|
102
|
-
|
103
|
-
assert_equal 0, InsightsResolution.all.count
|
104
|
-
end
|
105
|
-
|
106
85
|
test 'Skips pinging the cloud if no rule ids were found' do
|
107
|
-
Katello::UpstreamConnectionChecker.any_instance.stubs(:can_connect?).returns(true)
|
108
86
|
InsightsCloud::Async::InsightsResolutionsSync.any_instance.expects(:query_insights_resolutions).never
|
109
87
|
InsightsRule.all.delete_all
|
110
88
|
|
@@ -112,30 +112,6 @@ class CloudRequestForwarderTest < ActiveSupport::TestCase
|
|
112
112
|
assert_equal params.merge(:branch_id => 74), @forwarder.prepare_forward_params(req, 74)
|
113
113
|
end
|
114
114
|
|
115
|
-
test 'should NOT add branch id into forwarded params for compliance urls' do
|
116
|
-
user_agent = { :foo => :bar }
|
117
|
-
params = { :page => 5, :per_page => 42 }
|
118
|
-
|
119
|
-
uris = [
|
120
|
-
"/redhat_access/r/insights/platform/compliance/v2/systems/MyUUID/policies",
|
121
|
-
"/redhat_access/r/insights/platform/compliance/v2/policies/MyUUID",
|
122
|
-
"/redhat_access/r/insights/platform/compliance/v2/systems/MyUUID",
|
123
|
-
"/redhat_access/r/insights/platform/compliance/v2/policies",
|
124
|
-
"/redhat_access/r/insights/platform/compliance/v2/",
|
125
|
-
]
|
126
|
-
uris.each do |uri|
|
127
|
-
req = ActionDispatch::Request.new(
|
128
|
-
'REQUEST_URI' => uri,
|
129
|
-
'REQUEST_METHOD' => 'GET',
|
130
|
-
'HTTP_USER_AGENT' => user_agent,
|
131
|
-
'rack.input' => ::Puma::NullIO.new,
|
132
|
-
'action_dispatch.request.query_parameters' => params
|
133
|
-
)
|
134
|
-
req.stubs(:path).returns(uri)
|
135
|
-
refute @forwarder.prepare_forward_params(req, 74).key?(:branch_id), "Branch id should not be added for #{uri}"
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
115
|
test 'should reuse BranchInfo identifiers for user_agent' do
|
140
116
|
user_agent = { :foo => :bar }
|
141
117
|
params = { :page => 5, :per_page => 42 }
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'test_plugin_helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class URLRemediationsRetrieverTest < ActiveSupport::TestCase
|
4
4
|
test 'Calls the given url' do
|
5
|
-
retreiver = ForemanRhCloud::
|
5
|
+
retreiver = ForemanRhCloud::URLRemediationsRetriever.new(
|
6
6
|
organization_id: FactoryBot.create(:organization).id,
|
7
7
|
url: 'http://test.example.com',
|
8
8
|
payload: 'TEST_PAYLOAD',
|
@@ -42,7 +42,7 @@ export const PageDescription = () => (
|
|
42
42
|
{__('For more information about the Subscriptions service, see:')}
|
43
43
|
|
44
44
|
<a
|
45
|
-
href="https://
|
45
|
+
href="https://access.redhat.com/documentation/en-us/subscription_central/2020-04/html/getting_started_with_subscription_watch/assembly-about-subscriptionwatch"
|
46
46
|
target="_blank"
|
47
47
|
rel="noopener noreferrer"
|
48
48
|
>
|
@@ -40,7 +40,7 @@ exports[`PageDescription rendering render without Props 1`] = `
|
|
40
40
|
For more information about the Subscriptions service, see:
|
41
41
|
|
42
42
|
<a
|
43
|
-
href="https://
|
43
|
+
href="https://access.redhat.com/documentation/en-us/subscription_central/2020-04/html/getting_started_with_subscription_watch/assembly-about-subscriptionwatch"
|
44
44
|
rel="noopener noreferrer"
|
45
45
|
target="_blank"
|
46
46
|
>
|
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman_rh_cloud
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 11.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Foreman Red Hat Cloud team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-09-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: foreman_ansible
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 15.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 15.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: foreman-tasks
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 10.0.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 10.0.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: katello
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -45,9 +45,6 @@ dependencies:
|
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: 4.14.0.rc1.1
|
48
|
-
- - "<"
|
49
|
-
- !ruby/object:Gem::Version
|
50
|
-
version: '4.15'
|
51
48
|
type: :runtime
|
52
49
|
prerelease: false
|
53
50
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -55,9 +52,6 @@ dependencies:
|
|
55
52
|
- - ">="
|
56
53
|
- !ruby/object:Gem::Version
|
57
54
|
version: 4.14.0.rc1.1
|
58
|
-
- - "<"
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
version: '4.15'
|
61
55
|
- !ruby/object:Gem::Dependency
|
62
56
|
name: rdoc
|
63
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -150,6 +144,7 @@ files:
|
|
150
144
|
- app/views/job_templates/rh_cloud_remediations.erb
|
151
145
|
- app/views/layouts/foreman_rh_cloud/application.html.erb
|
152
146
|
- config/database.yml.example
|
147
|
+
- config/initializers/zeitwerk.rb
|
153
148
|
- config/package-lock.json.plugin
|
154
149
|
- config/rh_cert-api_chain.pem
|
155
150
|
- config/routes.rb
|
@@ -191,7 +186,6 @@ files:
|
|
191
186
|
- lib/foreman_rh_cloud.rb
|
192
187
|
- lib/foreman_rh_cloud/async/exponential_backoff.rb
|
193
188
|
- lib/foreman_rh_cloud/engine.rb
|
194
|
-
- lib/foreman_rh_cloud/settings.rb
|
195
189
|
- lib/foreman_rh_cloud/version.rb
|
196
190
|
- lib/insights_cloud.rb
|
197
191
|
- lib/insights_cloud/async/cloud_connector_announce_task.rb
|
@@ -1,12 +0,0 @@
|
|
1
|
-
Foreman::SettingManager.define(:foreman) do
|
2
|
-
category(:rh_cloud, N_('RHCloud')) do
|
3
|
-
setting('allow_auto_inventory_upload', type: :boolean, description: N_('Enable automatic upload of your host inventory to the Red Hat cloud'), default: true, full_name: N_('Automatic inventory upload'))
|
4
|
-
setting('allow_auto_insights_sync', type: :boolean, description: N_('Enable automatic synchronization of Insights recommendations from the Red Hat cloud'), default: false, full_name: N_('Synchronize recommendations Automatically'))
|
5
|
-
setting('allow_auto_insights_mismatch_delete', type: :boolean, description: N_('Enable automatic deletion of mismatched host records from the Red Hat cloud'), default: false, full_name: N_('Automatic mismatch deletion'))
|
6
|
-
setting('obfuscate_inventory_hostnames', type: :boolean, description: N_('Obfuscate host names sent to the Red Hat cloud'), default: false, full_name: N_('Obfuscate host names'))
|
7
|
-
setting('obfuscate_inventory_ips', type: :boolean, description: N_('Obfuscate ipv4 addresses sent to the Red Hat cloud'), default: false, full_name: N_('Obfuscate host ipv4 addresses'))
|
8
|
-
setting('exclude_installed_packages', type: :boolean, description: N_('Exclude installed packages from being uploaded to the Red Hat cloud'), default: false, full_name: N_("Exclude installed Packages"))
|
9
|
-
setting('include_parameter_tags', type: :boolean, description: N_('Should import include parameter tags from Foreman?'), default: false, full_name: N_('Include parameters in insights-client reports'))
|
10
|
-
setting('rhc_instance_id', type: :string, description: N_('RHC daemon id'), default: nil, full_name: N_('ID of the RHC(Yggdrasil) daemon'))
|
11
|
-
end
|
12
|
-
end
|