foreman_rh_cloud 5.0.38 → 6.0.42
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/cloud_request_controller.rb +11 -5
- data/app/controllers/insights_cloud/settings_controller.rb +14 -0
- data/app/services/foreman_rh_cloud/cert_auth.rb +1 -1
- data/app/services/foreman_rh_cloud/cloud_ping_service.rb +1 -1
- data/app/services/foreman_rh_cloud/cloud_presence.rb +4 -4
- data/app/services/foreman_rh_cloud/cloud_request_forwarder.rb +3 -3
- data/config/Gemfile.lock.gh_test +215 -226
- data/config/routes.rb +2 -0
- data/lib/foreman_inventory_upload/async/generate_all_reports_job.rb +4 -0
- data/lib/foreman_inventory_upload/async/upload_report_job.rb +5 -1
- data/lib/foreman_rh_cloud/engine.rb +7 -4
- data/lib/foreman_rh_cloud/settings.rb +11 -0
- data/lib/foreman_rh_cloud/version.rb +1 -1
- data/lib/insights_cloud/async/connector_playbook_execution_reporter_task.rb +3 -2
- data/lib/insights_cloud/async/insights_full_sync.rb +2 -1
- data/lib/insights_cloud/generators/playbook_progress_generator.rb +2 -2
- data/lib/insights_cloud.rb +4 -0
- data/package.json +6 -6
- data/test/controllers/insights_cloud/api/cloud_request_controller_test.rb +27 -0
- data/test/controllers/insights_sync/settings_controller_test.rb +17 -0
- data/test/jobs/connector_playbook_execution_reporter_task_test.rb +1 -7
- data/test/jobs/upload_report_job_test.rb +1 -1
- data/test/unit/playbook_progress_generator_test.rb +1 -1
- data/webpack/ForemanRhCloudFills.js +1 -1
- metadata +4 -5
- data/app/models/setting/rh_cloud.rb +0 -29
- data/config/package-lock.json +0 -41822
data/config/routes.rb
CHANGED
@@ -25,6 +25,8 @@ Rails.application.routes.draw do
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
match 'hits/:host_id', to: 'hits#show', via: :get
|
28
|
+
|
29
|
+
post ':organization_id/parameter', to: 'settings#set_org_parameter', constraints: { organization_id: %r{[^\/]+} }
|
28
30
|
end
|
29
31
|
|
30
32
|
namespace :foreman_rh_cloud do
|
@@ -13,7 +13,7 @@ module ForemanInventoryUpload
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def run
|
16
|
-
if
|
16
|
+
if content_disconnected?
|
17
17
|
progress_output do |progress_output|
|
18
18
|
progress_output.write_line('Upload was stopped since disconnected mode setting is enabled for content on this instance.')
|
19
19
|
progress_output.status = "Task aborted, exit 1"
|
@@ -74,6 +74,10 @@ module ForemanInventoryUpload
|
|
74
74
|
def organization
|
75
75
|
@organization ||= Organization.find(input[:organization_id])
|
76
76
|
end
|
77
|
+
|
78
|
+
def content_disconnected?
|
79
|
+
Setting[:content_disconnected]
|
80
|
+
end
|
77
81
|
end
|
78
82
|
end
|
79
83
|
end
|
@@ -21,7 +21,7 @@ module ForemanRhCloud
|
|
21
21
|
end
|
22
22
|
|
23
23
|
initializer 'foreman_rh_cloud.load_default_settings', :before => :load_config_initializers do
|
24
|
-
require_dependency File.expand_path('
|
24
|
+
require_dependency File.expand_path('settings.rb', __dir__)
|
25
25
|
end
|
26
26
|
|
27
27
|
config.autoload_paths += Dir["#{config.root}/app/controllers/concerns"]
|
@@ -29,7 +29,6 @@ module ForemanRhCloud
|
|
29
29
|
config.autoload_paths += Dir["#{config.root}/app/models/concerns"]
|
30
30
|
config.autoload_paths += Dir["#{config.root}/app/services"]
|
31
31
|
config.autoload_paths += Dir["#{config.root}/app/overrides"]
|
32
|
-
config.autoload_paths += Dir["#{config.root}/app/services"]
|
33
32
|
config.autoload_paths += Dir["#{config.root}/lib"]
|
34
33
|
|
35
34
|
config.eager_load_paths += Dir["#{config.root}/lib"]
|
@@ -43,7 +42,7 @@ module ForemanRhCloud
|
|
43
42
|
|
44
43
|
initializer 'foreman_rh_cloud.register_plugin', :before => :finisher_hook do |_app|
|
45
44
|
Foreman::Plugin.register :foreman_rh_cloud do
|
46
|
-
requires_foreman '>=
|
45
|
+
requires_foreman '>= 3.3'
|
47
46
|
|
48
47
|
apipie_documented_controllers ["#{ForemanRhCloud::Engine.root}/app/controllers/api/v2/**/*.rb"]
|
49
48
|
|
@@ -83,9 +82,13 @@ module ForemanRhCloud
|
|
83
82
|
:dispatch_cloud_requests,
|
84
83
|
'api/v2/rh_cloud/cloud_request': [:update]
|
85
84
|
)
|
85
|
+
permission(
|
86
|
+
:control_organization_insights,
|
87
|
+
'insights_cloud/settings': [:set_org_parameter]
|
88
|
+
)
|
86
89
|
end
|
87
90
|
|
88
|
-
plugin_permissions = [:view_foreman_rh_cloud, :generate_foreman_rh_cloud, :view_insights_hits, :dispatch_cloud_requests]
|
91
|
+
plugin_permissions = [:view_foreman_rh_cloud, :generate_foreman_rh_cloud, :view_insights_hits, :dispatch_cloud_requests, :control_organization_insights]
|
89
92
|
|
90
93
|
role 'ForemanRhCloud', plugin_permissions, 'Role granting permissions to view the hosts inventory,
|
91
94
|
generate a report, upload it to the cloud and download it locally'
|
@@ -0,0 +1,11 @@
|
|
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('obfuscate_inventory_hostnames', type: :boolean, description: N_('Obfuscate host names sent to the Red Hat cloud'), default: false, full_name: N_('Obfuscate host names'))
|
6
|
+
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'))
|
7
|
+
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"))
|
8
|
+
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'))
|
9
|
+
setting('rhc_instance_id', type: :string, description: N_('RHC daemon id'), default: nil, full_name: N_('ID of the RHC(Yggdrasil) daemon'))
|
10
|
+
end
|
11
|
+
end
|
@@ -67,7 +67,6 @@ module InsightsCloud
|
|
67
67
|
private
|
68
68
|
|
69
69
|
def connector_playbook_job?(job_invocation)
|
70
|
-
puts "Job invocation id: #{job_invocation&.remote_execution_feature_id}, feature id: #{connector_feature_id}"
|
71
70
|
job_invocation&.remote_execution_feature_id == connector_feature_id
|
72
71
|
end
|
73
72
|
|
@@ -137,6 +136,7 @@ module InsightsCloud
|
|
137
136
|
|
138
137
|
def report_job_progress(invocation_status)
|
139
138
|
generator = InsightsCloud::Generators::PlaybookProgressGenerator.new(correlation_id)
|
139
|
+
all_hosts_success = true
|
140
140
|
|
141
141
|
invocation_status.each do |host_name, status|
|
142
142
|
# skip host if the host already reported that it's finished
|
@@ -151,9 +151,10 @@ module InsightsCloud
|
|
151
151
|
if status['state'] == 'stopped'
|
152
152
|
generator.host_finished_message(host_name, status['exit_status'])
|
153
153
|
status['report_done'] = true
|
154
|
+
all_hosts_success &&= status['exit_status'] == 0
|
154
155
|
end
|
155
156
|
end
|
156
|
-
generator.job_finished_message if done?(invocation_status)
|
157
|
+
generator.job_finished_message(all_hosts_success) if done?(invocation_status)
|
157
158
|
|
158
159
|
send_report(generator.generate)
|
159
160
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'cgi'
|
1
2
|
require 'rest-client'
|
2
3
|
|
3
4
|
module InsightsCloud
|
@@ -122,7 +123,7 @@ module InsightsCloud
|
|
122
123
|
end
|
123
124
|
|
124
125
|
def to_rule_id(results_url)
|
125
|
-
|
126
|
+
CGI.unescape(safe_results_match(results_url)[:id] || '')
|
126
127
|
end
|
127
128
|
|
128
129
|
def safe_results_match(results_url)
|
@@ -30,12 +30,12 @@ module InsightsCloud
|
|
30
30
|
}
|
31
31
|
end
|
32
32
|
|
33
|
-
def job_finished_message
|
33
|
+
def job_finished_message(success)
|
34
34
|
@messages << {
|
35
35
|
"type": "playbook_run_completed",
|
36
36
|
"version": 3,
|
37
37
|
"correlation_id": correlation_id,
|
38
|
-
"status":
|
38
|
+
"status": success ? 'success' : 'failure',
|
39
39
|
}
|
40
40
|
end
|
41
41
|
|
data/lib/insights_cloud.rb
CHANGED
data/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "foreman_rh_cloud",
|
3
|
-
"version": "
|
3
|
+
"version": "6.0.42",
|
4
4
|
"description": "Inventory Upload =============",
|
5
5
|
"main": "index.js",
|
6
6
|
"scripts": {
|
@@ -22,14 +22,14 @@
|
|
22
22
|
"url": "http://projects.theforeman.org/projects/foreman_rh_cloud/issues"
|
23
23
|
},
|
24
24
|
"peerDependencies": {
|
25
|
-
"@theforeman/vendor": ">=8.16.0"
|
25
|
+
"@theforeman/vendor": ">= 8.16.0"
|
26
26
|
},
|
27
27
|
"devDependencies": {
|
28
28
|
"@babel/core": "~7.7.0",
|
29
|
-
"@theforeman/builder": ">=8.16.0",
|
30
|
-
"@theforeman/stories": ">=8.16.0",
|
31
|
-
"@theforeman/test": ">=8.16.0",
|
32
|
-
"@theforeman/eslint-plugin-foreman": ">=8.16.0",
|
29
|
+
"@theforeman/builder": ">= 8.16.0",
|
30
|
+
"@theforeman/stories": ">= 8.16.0",
|
31
|
+
"@theforeman/test": ">= 8.16.0",
|
32
|
+
"@theforeman/eslint-plugin-foreman": ">= 8.16.0",
|
33
33
|
"babel-eslint": "~10.0.0",
|
34
34
|
"eslint": "~6.7.2",
|
35
35
|
"eslint-plugin-spellcheck": "~0.0.17",
|
@@ -40,6 +40,33 @@ module InsightsCloud::Api
|
|
40
40
|
assert_response :success
|
41
41
|
end
|
42
42
|
|
43
|
+
test 'Starts playbook run for correct directive with capitalized keys' do
|
44
|
+
host1 = FactoryBot.create(:host, :with_insights_hits)
|
45
|
+
host1.insights.uuid = 'TEST_UUID1'
|
46
|
+
host1.insights.save!
|
47
|
+
host2 = FactoryBot.create(:host, :with_insights_hits)
|
48
|
+
host2.insights.uuid = 'TEST_UUID2'
|
49
|
+
host2.insights.save!
|
50
|
+
|
51
|
+
mock_composer = mock('composer')
|
52
|
+
::JobInvocationComposer.expects(:for_feature).with do |feature, host_ids, params|
|
53
|
+
feature == :rh_cloud_connector_run_playbook &&
|
54
|
+
host_ids.first == host1.id &&
|
55
|
+
host_ids.last == host2.id
|
56
|
+
end.returns(mock_composer)
|
57
|
+
mock_composer.expects(:trigger!)
|
58
|
+
mock_composer.expects(:job_invocation)
|
59
|
+
|
60
|
+
params = run_playbook_request
|
61
|
+
params['Directive'] = params.delete('directive')
|
62
|
+
params['Metadata'] = params.delete('metadata')
|
63
|
+
params['Content'] = params.delete('content')
|
64
|
+
|
65
|
+
post :update, params: run_playbook_request
|
66
|
+
|
67
|
+
assert_response :success
|
68
|
+
end
|
69
|
+
|
43
70
|
private
|
44
71
|
|
45
72
|
def run_playbook_request
|
@@ -27,4 +27,21 @@ class SettingsControllerTest < ActionController::TestCase
|
|
27
27
|
assert_equal true, actual['insightsSyncEnabled']
|
28
28
|
assert_equal true, Setting[:allow_auto_insights_sync]
|
29
29
|
end
|
30
|
+
|
31
|
+
test 'Should update an organization parameter' do
|
32
|
+
FactoryBot.create(:common_parameter, name: InsightsCloud.enable_cloud_remediations_param, value: false)
|
33
|
+
host = FactoryBot.create(:host)
|
34
|
+
|
35
|
+
# make sure the parameter is there
|
36
|
+
assert_equal false, host.host_params[InsightsCloud.enable_cloud_remediations_param]
|
37
|
+
|
38
|
+
post :set_org_parameter, params: { parameter: InsightsCloud.enable_cloud_remediations_param, value: true, organization_id: host.organization.id }, session: set_session_user
|
39
|
+
|
40
|
+
# needed for properly access host_params
|
41
|
+
User.as_anonymous_admin do
|
42
|
+
# refresh the host record
|
43
|
+
host = Host.find(host.id)
|
44
|
+
assert_equal true, host.host_params[InsightsCloud.enable_cloud_remediations_param]
|
45
|
+
end
|
46
|
+
end
|
30
47
|
end
|
@@ -14,7 +14,7 @@ class ConnectorPlaybookExecutionReporterTaskTest < ActiveSupport::TestCase
|
|
14
14
|
end
|
15
15
|
|
16
16
|
setup do
|
17
|
-
|
17
|
+
RemoteExecutionFeature.register(
|
18
18
|
:rh_cloud_connector_run_playbook,
|
19
19
|
N_('Run RH Cloud playbook'),
|
20
20
|
description: N_('Run playbook genrated by Red Hat remediations app'),
|
@@ -22,14 +22,10 @@ class ConnectorPlaybookExecutionReporterTaskTest < ActiveSupport::TestCase
|
|
22
22
|
provided_inputs: ['playbook_url', 'report_url', 'correlation_id', 'report_interval']
|
23
23
|
)
|
24
24
|
|
25
|
-
puts "REX Register: #{feature.id}"
|
26
|
-
|
27
25
|
@job_invocation = generate_job_invocation
|
28
26
|
|
29
27
|
# reset connector feature ID cache
|
30
28
|
TestConnectorPlaybookExecutionReporterTask.instance_variable_set(:@connector_feature_id, nil)
|
31
|
-
|
32
|
-
puts RemoteExecutionFeature.all.to_a
|
33
29
|
end
|
34
30
|
|
35
31
|
test 'It reports finish playbook messages' do
|
@@ -115,8 +111,6 @@ class ConnectorPlaybookExecutionReporterTaskTest < ActiveSupport::TestCase
|
|
115
111
|
)
|
116
112
|
feature = RemoteExecutionFeature.feature!(:rh_cloud_connector_run_playbook).id
|
117
113
|
|
118
|
-
puts "Generated feature: #{feature}"
|
119
|
-
|
120
114
|
job_invocation = FactoryBot.create(
|
121
115
|
:job_invocation,
|
122
116
|
remote_execution_feature_id: feature,
|
@@ -12,7 +12,7 @@ class UploadReportJobTest < ActiveSupport::TestCase
|
|
12
12
|
'idCert' => 'TEST_CERT',
|
13
13
|
}
|
14
14
|
)
|
15
|
-
|
15
|
+
ForemanInventoryUpload::Async::UploadReportJob.any_instance.expects(:content_disconnected?).returns(true)
|
16
16
|
|
17
17
|
ForemanTasks.sync_task(ForemanInventoryUpload::Async::UploadReportJob, '', organization.id)
|
18
18
|
|
@@ -51,7 +51,7 @@ class PlaybookProgressGeneratorTest < ActiveSupport::TestCase
|
|
51
51
|
end
|
52
52
|
|
53
53
|
test 'Outputs job finished message' do
|
54
|
-
@generator.job_finished_message
|
54
|
+
@generator.job_finished_message(true)
|
55
55
|
|
56
56
|
actual = @generator.generate
|
57
57
|
actual_message = JSON.parse(actual)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman_rh_cloud
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 6.0.42
|
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: 2022-
|
11
|
+
date: 2022-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: katello
|
@@ -158,7 +158,6 @@ files:
|
|
158
158
|
- app/models/insights_resolution.rb
|
159
159
|
- app/models/insights_rule.rb
|
160
160
|
- app/models/inventory_sync/inventory_status.rb
|
161
|
-
- app/models/setting/rh_cloud.rb
|
162
161
|
- app/models/task_output_line.rb
|
163
162
|
- app/models/task_output_status.rb
|
164
163
|
- app/overrides/hosts_list.rb
|
@@ -182,7 +181,6 @@ files:
|
|
182
181
|
- app/views/layouts/foreman_rh_cloud/application.html.erb
|
183
182
|
- config/Gemfile.lock.gh_test
|
184
183
|
- config/database.yml.example
|
185
|
-
- config/package-lock.json
|
186
184
|
- config/package-lock.json.gh_test
|
187
185
|
- config/package-lock.json.plugin
|
188
186
|
- config/rh_cert-api_chain.pem
|
@@ -220,6 +218,7 @@ files:
|
|
220
218
|
- lib/foreman_inventory_upload/scripts/uploader.sh.erb
|
221
219
|
- lib/foreman_rh_cloud.rb
|
222
220
|
- lib/foreman_rh_cloud/engine.rb
|
221
|
+
- lib/foreman_rh_cloud/settings.rb
|
223
222
|
- lib/foreman_rh_cloud/version.rb
|
224
223
|
- lib/insights_cloud.rb
|
225
224
|
- lib/insights_cloud/async/cloud_connector_announce_task.rb
|
@@ -675,7 +674,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
675
674
|
- !ruby/object:Gem::Version
|
676
675
|
version: '0'
|
677
676
|
requirements: []
|
678
|
-
rubygems_version: 3.
|
677
|
+
rubygems_version: 3.3.7
|
679
678
|
signing_key:
|
680
679
|
specification_version: 4
|
681
680
|
summary: Summary of ForemanRhCloud.
|
@@ -1,29 +0,0 @@
|
|
1
|
-
class Setting::RhCloud < Setting
|
2
|
-
::Setting::BLANK_ATTRS.concat %w{rhc_instance_id}
|
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
|
-
|
14
|
-
def self.default_settings
|
15
|
-
[
|
16
|
-
set('allow_auto_inventory_upload', N_('Enable automatic upload of your host inventory to the Red Hat cloud'), true, N_('Automatic inventory upload')),
|
17
|
-
set('allow_auto_insights_sync', N_('Enable automatic synchronization of Insights recommendations from the Red Hat cloud'), false, N_('Synchronize recommendations Automatically')),
|
18
|
-
set('obfuscate_inventory_hostnames', N_('Obfuscate host names sent to the Red Hat cloud'), false, N_('Obfuscate host names')),
|
19
|
-
set('obfuscate_inventory_ips', N_('Obfuscate ipv4 addresses sent to the Red Hat cloud'), false, N_('Obfuscate host ipv4 addresses')),
|
20
|
-
set('exclude_installed_packages', N_('Exclude installed packages from being uploaded to the Red Hat cloud'), false, N_("Exclude installed Packages")),
|
21
|
-
set('include_parameter_tags', N_('Should import include parameter tags from Foreman?'), false, N_('Include parameters in insights-client reports')),
|
22
|
-
set('rhc_instance_id', N_('RHC daemon id'), nil, N_('ID of the RHC(Yggdrasil) daemon')),
|
23
|
-
]
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.humanized_category
|
27
|
-
N_('RH Cloud')
|
28
|
-
end
|
29
|
-
end
|