foreman_rh_cloud 5.0.38 → 5.0.42

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7bb7932e40d6ef999b5266897539d444e9ab7a38606e6f66dff58fb568d70fdc
4
- data.tar.gz: f6e6a8ae8ddfb3544fbe31c807f9917fe7aa2d5d1d05014055528bb193290109
3
+ metadata.gz: 21744025612c50afc1aa1c943e33a0c2dd6e76e8a2ee778ae74068d57c8d971f
4
+ data.tar.gz: 491d74b6e3ad554de98c2ce45c5b95806547855ab8794aa9a51e3e08bc6e3bca
5
5
  SHA512:
6
- metadata.gz: dcc37dffd7f108e1687b671ea0f5b157644c6a9576310d917daafefd4011ad01ccced6d48941823873a3da076ab20da2db33fe2c463cc0e962f69a79ea565400
7
- data.tar.gz: 72f7a08cc3f30d0bddaaf63e0198df2761a40153c7185d1e30328a1c00b9496e7ce33b34ceec44ecf69989ab570001173524cfc49e5a9e127a540bf4684f9d02
6
+ metadata.gz: a4e8097f9923909d623e445a0b0ca604e737409ee6ce06962e0ae9122f9d8a95d568a41b8e5b2061d2629e6290605f72209f861a9dd7c709661703a927bb5cdf
7
+ data.tar.gz: 6c62744629566595c8f2ddb4e6b649ac6131efe177666455c97d9dc7353c1f7e2102f90938c2828f95ddfc57fa65a11244cf0a7cc2641595df429948ce01117e
@@ -27,16 +27,18 @@ module Api::V2::RhCloud
27
27
  private
28
28
 
29
29
  def metadata
30
- params['metadata']
30
+ params['Metadata'] || params['metadata']
31
31
  end
32
32
 
33
33
  def content
34
+ content = params['Content'] || params['content']
35
+
34
36
  # the content received as base 64 of the string in double quotes
35
- Base64.decode64(params['content']).tr('"', '')
37
+ Base64.decode64(content).tr('"', '')
36
38
  end
37
39
 
38
40
  def directive
39
- params['directive']
41
+ params['Directive'] || params['directive']
40
42
  end
41
43
 
42
44
  def handle_run_playbook_request
@@ -44,9 +46,13 @@ module Api::V2::RhCloud
44
46
  logger.error("Reporting URL is not valid: #{metadata['return_url']}") && return unless valid_url?(metadata['return_url'])
45
47
 
46
48
  hosts = metadata['hosts'].split(',')
47
- host_ids = host_ids(hosts)
48
49
 
49
- logger.warn("Some hosts were not found. Looked for: #{hosts}, found ids: #{host_ids}") unless host_ids.length == hosts.length
50
+ # select hosts from the metadata list that are not disabled by the parameter.
51
+ host_ids = Host.search_for("not params.#{InsightsCloud.enable_cloud_remediations_param} = f")
52
+ .where(id: host_ids(hosts))
53
+ .pluck(:id)
54
+
55
+ logger.warn("Some hosts were not found/ignored. Looked for: #{hosts}, found ids: #{host_ids}") unless host_ids.length == hosts.length
50
56
 
51
57
  logger.error("sat_org_id is not present in the metadata") && return unless metadata['sat_org_id']
52
58
  org_id = metadata['sat_org_id'].to_i
@@ -9,6 +9,20 @@ module InsightsCloud
9
9
  render_setting(:insightsSyncEnabled, :allow_auto_insights_sync)
10
10
  end
11
11
 
12
+ def set_org_parameter
13
+ parameter = params.require(:parameter)
14
+ new_value = ActiveModel::Type::Boolean.new.cast(params.require(:value))
15
+ org_id = params.require(:organization_id)
16
+
17
+ organization = Organization.authorized.find(org_id)
18
+
19
+ org_param = organization.organization_parameters.find_or_create_by(name: parameter) do |org_param|
20
+ org_param.name = parameter
21
+ end
22
+ org_param.value = new_value
23
+ org_param.save!
24
+ end
25
+
12
26
  private
13
27
 
14
28
  def render_setting(node_name, setting)
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
@@ -32,6 +32,10 @@ module ForemanInventoryUpload
32
32
  def plan_generate_report(folder, organization)
33
33
  plan_action(ForemanInventoryUpload::Async::GenerateReportJob, folder, organization.id)
34
34
  end
35
+
36
+ def logger
37
+ action_logger
38
+ end
35
39
  end
36
40
  end
37
41
  end
@@ -83,9 +83,13 @@ module ForemanRhCloud
83
83
  :dispatch_cloud_requests,
84
84
  'api/v2/rh_cloud/cloud_request': [:update]
85
85
  )
86
+ permission(
87
+ :control_organization_insights,
88
+ 'insights_cloud/settings': [:set_org_parameter]
89
+ )
86
90
  end
87
91
 
88
- plugin_permissions = [:view_foreman_rh_cloud, :generate_foreman_rh_cloud, :view_insights_hits, :dispatch_cloud_requests]
92
+ plugin_permissions = [:view_foreman_rh_cloud, :generate_foreman_rh_cloud, :view_insights_hits, :dispatch_cloud_requests, :control_organization_insights]
89
93
 
90
94
  role 'ForemanRhCloud', plugin_permissions, 'Role granting permissions to view the hosts inventory,
91
95
  generate a report, upload it to the cloud and download it locally'
@@ -1,3 +1,3 @@
1
1
  module ForemanRhCloud
2
- VERSION = '5.0.38'.freeze
2
+ VERSION = '5.0.42'.freeze
3
3
  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
- URI.decode(safe_results_match(results_url)[:id] || '')
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": "success",
38
+ "status": success ? 'success' : 'failure',
39
39
  }
40
40
  end
41
41
 
@@ -28,4 +28,8 @@ module InsightsCloud
28
28
  def self.enable_client_param
29
29
  'host_registration_insights'
30
30
  end
31
+
32
+ def self.enable_cloud_remediations_param
33
+ 'enable_cloud_remediations'
34
+ end
31
35
  end
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foreman_rh_cloud",
3
- "version": "5.0.38",
3
+ "version": "5.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
- feature = RemoteExecutionFeature.register(
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,
@@ -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: 5.0.38
4
+ version: 5.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-06-09 00:00:00.000000000 Z
11
+ date: 2022-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: katello
@@ -182,7 +182,6 @@ files:
182
182
  - app/views/layouts/foreman_rh_cloud/application.html.erb
183
183
  - config/Gemfile.lock.gh_test
184
184
  - config/database.yml.example
185
- - config/package-lock.json
186
185
  - config/package-lock.json.gh_test
187
186
  - config/package-lock.json.plugin
188
187
  - config/rh_cert-api_chain.pem
@@ -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.2.22
677
+ rubygems_version: 3.3.7
679
678
  signing_key:
680
679
  specification_version: 4
681
680
  summary: Summary of ForemanRhCloud.