foreman_rh_cloud 3.0.26 → 4.0.21.1

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.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/foreman_inventory_upload/reports_controller.rb +1 -3
  3. data/app/controllers/foreman_inventory_upload/tasks_controller.rb +13 -5
  4. data/app/controllers/foreman_inventory_upload/uploads_controller.rb +4 -4
  5. data/app/controllers/insights_cloud/api/machine_telemetries_controller.rb +3 -6
  6. data/app/controllers/insights_cloud/hits_controller.rb +3 -7
  7. data/app/models/insights_client_report_status.rb +22 -11
  8. data/app/services/foreman_rh_cloud/cloud_auth.rb +0 -16
  9. data/app/services/foreman_rh_cloud/cloud_request_forwarder.rb +14 -11
  10. data/app/services/foreman_rh_cloud/remediations_retriever.rb +4 -6
  11. data/app/subscribers/foreman_rh_cloud/insights_subscriber.rb +9 -0
  12. data/config/Gemfile.lock.gh_test +95 -93
  13. data/config/routes.rb +1 -20
  14. data/lib/foreman_inventory_upload/generators/fact_helpers.rb +0 -19
  15. data/lib/foreman_inventory_upload/generators/queries.rb +0 -1
  16. data/lib/foreman_inventory_upload/generators/slice.rb +5 -6
  17. data/lib/foreman_inventory_upload/generators/tags.rb +1 -3
  18. data/lib/foreman_inventory_upload.rb +1 -9
  19. data/lib/foreman_rh_cloud/engine.rb +10 -17
  20. data/lib/foreman_rh_cloud/version.rb +1 -1
  21. data/lib/insights_cloud/async/insights_full_sync.rb +14 -9
  22. data/lib/insights_cloud/async/insights_resolutions_sync.rb +6 -13
  23. data/lib/insights_cloud/async/insights_rules_sync.rb +9 -13
  24. data/lib/inventory_sync/async/host_result.rb +0 -4
  25. data/lib/inventory_sync/async/inventory_full_sync.rb +1 -7
  26. data/lib/inventory_sync/async/inventory_hosts_sync.rb +2 -21
  27. data/lib/inventory_sync/async/inventory_scheduled_sync.rb +0 -12
  28. data/lib/inventory_sync/async/query_inventory_job.rb +5 -6
  29. data/lib/tasks/insights.rake +0 -15
  30. data/lib/tasks/rh_cloud_inventory.rake +1 -8
  31. data/package.json +1 -1
  32. data/test/controllers/insights_cloud/api/machine_telemetries_controller_test.rb +0 -41
  33. data/test/factories/inventory_upload_factories.rb +1 -1
  34. data/test/jobs/insights_full_sync_test.rb +0 -1
  35. data/test/jobs/insights_resolutions_sync_test.rb +1 -11
  36. data/test/jobs/insights_rules_sync_test.rb +0 -1
  37. data/test/jobs/inventory_full_sync_test.rb +0 -10
  38. data/test/models/insights_client_report_status_test.rb +72 -70
  39. data/test/test_plugin_helper.rb +0 -2
  40. data/test/unit/services/foreman_rh_cloud/cloud_request_forwarder_test.rb +3 -4
  41. data/test/unit/services/foreman_rh_cloud/template_renderer_helper_test.rb +0 -1
  42. data/test/unit/slice_generator_test.rb +27 -70
  43. data/test/unit/tags_generator_test.rb +0 -41
  44. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/PageDescription.js +0 -11
  45. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/__tests__/__snapshots__/PageDescription.test.js.snap +0 -11
  46. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js +63 -28
  47. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/integrations.test.js.snap +3 -2
  48. data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableActions.js +19 -19
  49. data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/__snapshots__/InsightsTableActions.test.js.snap +14 -14
  50. data/webpack/InsightsCloudSync/Components/RemediationModal/RemediateButton.js +0 -1
  51. data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationModal.scss +0 -14
  52. data/webpack/InsightsCloudSync/Components/__tests__/__snapshots__/NoTokenEmptyState.test.js.snap +13 -20
  53. data/webpack/InsightsCloudSync/InsightsCloudSync.js +1 -4
  54. data/webpack/InsightsCloudSync/InsightsCloudSyncActions.js +20 -44
  55. data/webpack/InsightsCloudSync/InsightsCloudSyncConstants.js +0 -2
  56. data/webpack/InsightsCloudSync/__snapshots__/InsightsCloudSync.test.js.snap +2 -2
  57. data/webpack/InsightsCloudSync/__tests__/__snapshots__/InsightsCloudSyncActions.test.js.snap +7 -11
  58. metadata +4 -30
  59. data/app/controllers/api/v2/rh_cloud/inventory_controller.rb +0 -50
  60. data/app/controllers/concerns/inventory_upload/report_actions.rb +0 -26
  61. data/app/controllers/concerns/inventory_upload/task_actions.rb +0 -25
  62. data/app/helpers/foreman_insights_deprecations_helper.rb +0 -9
  63. data/app/helpers/foreman_insights_host_helper.rb +0 -19
  64. data/app/overrides/old_plugin_deprecation.rb +0 -20
  65. data/app/services/foreman_rh_cloud/cloud_request.rb +0 -14
  66. data/app/services/foreman_rh_cloud/insights_status_cleaner.rb +0 -17
  67. data/config/package-lock.json.plugin +0 -32774
  68. data/db/migrate/20210720000001_remove_old_insights_statuses.foreman_rh_cloud.rb +0 -6
  69. data/lib/insights_cloud/async/insights_client_status_aging.rb +0 -23
  70. data/lib/inventory_sync/async/inventory_self_host_sync.rb +0 -39
  71. data/test/controllers/inventory_upload/api/inventory_controller_test.rb +0 -53
  72. data/test/jobs/insights_client_status_aging_test.rb +0 -33
  73. data/test/jobs/inventory_hosts_sync_test.rb +0 -268
  74. data/test/jobs/inventory_scheduled_sync_test.rb +0 -22
  75. data/test/jobs/inventory_self_host_sync_test.rb +0 -104
  76. data/test/unit/services/foreman_rh_cloud/insights_status_cleaner_test.rb +0 -31
  77. data/webpack/common/ForemanTasks/ForemanTasksActions.js +0 -64
  78. data/webpack/common/ForemanTasks/ForemanTasksHelpers.js +0 -7
  79. data/webpack/common/ForemanTasks/index.js +0 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1a30fca135e4f60623ae8d50f3ae579b60b03769214d6635713f2d78d394c104
4
- data.tar.gz: 0da61a8209494baea39169da75800e5b09738c065712b249dbad21abb771f369
3
+ metadata.gz: 97882071192995f2da93032050b9ecdfa616dba407c8d032bfd29f6741ea9d56
4
+ data.tar.gz: 88bca49cea9ee2abac2d2dc9d608a33329ad9e214d57035424e8e24984691537
5
5
  SHA512:
6
- metadata.gz: bd3887751accfdb3f4873c69b74791483c690d1d884a3b122c9c2b70842bec4919965767174e75f8362be09de630d738979b8e5510b8cbf9f0fa496684cff690
7
- data.tar.gz: c6b5ef0482a81d7faf69f3f679b2e015b2ca01421bf1115b45607cd2f73072b7b001e9d82526c1f8c1bdbd9240e3a1013ef4e1d72db251f888909c0b21b80f21
6
+ metadata.gz: 67dd2ada55ac862b2d57ddf893e7408d002c40c2f89a141e6bf8c115d6eeee32d19b156e7668751f591665f948fa04d628719e5f6f5ab9e4609c02f0a14a93f4
7
+ data.tar.gz: 54ded7bb163e4a38cd3fa4a62dfe101484b98e87c016514b985190f77a07c7556e980dd8574dc5fb70cacb3fcc521a37a1f4f2325e5360cdbb2ddd6f38816804
@@ -2,8 +2,6 @@
2
2
 
3
3
  module ForemanInventoryUpload
4
4
  class ReportsController < ::ApplicationController
5
- include InventoryUpload::ReportActions
6
-
7
5
  def last
8
6
  label = ForemanInventoryUpload::Async::GenerateReportJob.output_label(params[:organization_id])
9
7
  output = ForemanInventoryUpload::Async::ProgressOutput.get(label)&.full_output
@@ -22,7 +20,7 @@ module ForemanInventoryUpload
22
20
  def generate
23
21
  organization_id = params[:organization_id]
24
22
 
25
- start_report_generation(organization_id)
23
+ ForemanInventoryUpload::Async::GenerateReportJob.perform_later(ForemanInventoryUpload.generated_reports_folder, organization_id)
26
24
 
27
25
  render json: {
28
26
  action_status: 'success',
@@ -1,17 +1,25 @@
1
1
  module ForemanInventoryUpload
2
2
  class TasksController < ::ApplicationController
3
- include InventoryUpload::TaskActions
4
-
5
3
  def create
6
4
  selected_org = Organization.current
5
+ subscribed_hosts_ids = Set.new(
6
+ ForemanInventoryUpload::Generators::Queries.for_slice(
7
+ Host.unscoped.where(organization: selected_org)
8
+ ).pluck(:id)
9
+ )
7
10
 
8
- task = start_inventory_sync(selected_org)
11
+ if subscribed_hosts_ids.empty?
12
+ return render json: {
13
+ message: N_('Nothing to sync, there are no hosts with subscription for this organization.'),
14
+ }, status: :method_not_allowed
15
+ else
16
+ task = ForemanTasks.async_task(InventorySync::Async::InventoryFullSync, selected_org)
17
+ end
18
+ return render json: { message: N_('there was an issue triggering the task') }, status: :internal_server_error unless task
9
19
 
10
20
  render json: {
11
21
  task: task,
12
22
  }, status: :ok
13
- rescue InventoryUpload::TaskActions::NothingToSyncError => error
14
- render json: { message: error.message }, status: :internal_server_error
15
23
  end
16
24
 
17
25
  def show
@@ -1,7 +1,5 @@
1
1
  module ForemanInventoryUpload
2
2
  class UploadsController < ::ApplicationController
3
- include InventoryUpload::ReportActions
4
-
5
3
  def last
6
4
  label = ForemanInventoryUpload::Async::UploadReportJob.output_label(params[:organization_id])
7
5
  output = ForemanInventoryUpload::Async::ProgressOutput.get(label)&.full_output
@@ -12,9 +10,11 @@ module ForemanInventoryUpload
12
10
  end
13
11
 
14
12
  def download_file
15
- filename, file = report_file(params[:organization_id])
13
+ filename = ForemanInventoryUpload.facts_archive_name(params[:organization_id])
14
+ files = Dir["{#{ForemanInventoryUpload.uploads_file_path(filename)},#{ForemanInventoryUpload.done_file_path(filename)}}"]
16
15
 
17
- send_file file, disposition: 'attachment', filename: filename
16
+ return send_file files.first, disposition: 'attachment', filename: filename unless files.empty?
17
+ raise ::Foreman::Exception.new("The report file doesn't exist")
18
18
  end
19
19
 
20
20
  def enable_cloud_connector
@@ -5,7 +5,6 @@ module InsightsCloud::Api
5
5
  include ::InsightsCloud::ClientAuthentication
6
6
  include ::InsightsCloud::CandlepinCache
7
7
 
8
- before_action :set_admin_user, only: [:forward_request]
9
8
  before_action :cert_uuid, :ensure_org, :ensure_branch_id, :only => [:forward_request, :branch_info]
10
9
  before_action :ensure_telemetry_enabled_for_consumer, :only => [:forward_request]
11
10
 
@@ -76,11 +75,9 @@ module InsightsCloud::Api
76
75
  return unless request.path == '/redhat_access/r/insights/platform/ingress/v1/upload' ||
77
76
  request.path.include?('/redhat_access/r/insights/uploads/')
78
77
 
79
- return unless @cloud_response.code.to_s.start_with?('2')
80
-
81
- # create insights status if it wasn't there in the first place and refresh its reporting date
82
- @host.get_status(InsightsClientReportStatus).refresh!
83
- @host.refresh_global_status!
78
+ data = @cloud_response.code.to_s.start_with?('2')
79
+ host_status = @host.get_status(InsightsClientReportStatus)
80
+ host_status.update(reported_at: Time.now.utc, status: host_status.to_status(data: data))
84
81
  end
85
82
  end
86
83
  end
@@ -3,7 +3,7 @@ module InsightsCloud
3
3
  include Foreman::Controller::AutoCompleteSearch
4
4
 
5
5
  def index
6
- hits = resource_base_search_and_page.preload(:host, :rule)
6
+ hits = resource_base_search_and_page.where(host: Host.authorized).preload(:host, :rule)
7
7
 
8
8
  render json: {
9
9
  hasToken: !Setting[:rh_cloud_token].empty?,
@@ -23,9 +23,9 @@ module InsightsCloud
23
23
 
24
24
  def resolutions
25
25
  if remediation_all_selected_param
26
- hits = resource_base.with_playbook.search_for(params[:query])
26
+ hits = InsightsHit.with_playbook.search_for(params[:query])
27
27
  else
28
- hits = resource_base_search_and_page.with_playbook.where(id: remediation_ids_param)
28
+ hits = resource_base_search_and_page.where(id: remediation_ids_param)
29
29
  end
30
30
 
31
31
  hits.preload(:host, rule: :resolutions)
@@ -74,9 +74,5 @@ module InsightsCloud
74
74
  def remediation_all_selected_param
75
75
  ActiveModel::Type::Boolean.new.cast(params[:isAllSelected])
76
76
  end
77
-
78
- def resource_base
79
- super.where(host: Host.authorized)
80
- end
81
77
  end
82
78
  end
@@ -1,11 +1,10 @@
1
1
  class InsightsClientReportStatus < HostStatus::Status
2
2
  REPORT_INTERVAL = 48.hours
3
3
 
4
- REPORTING = 0
5
- NO_REPORT = 1
6
-
7
- scope :stale, -> { where.not(reported_at: (Time.now - REPORT_INTERVAL)..Time.now) }
8
- scope :reporting, -> { where(status: REPORTING) }
4
+ REPORTING = 0 # host_registration_insights = true & getting data
5
+ NO_REPORT = 1 # host_registration_insights = true & not getting data
6
+ NOT_MANAGED = 2 # host_registration_insights = false
7
+ NOT_MANAGED_WITH_DATA = 3 # host_registration_insights = false & getting data
9
8
 
10
9
  def self.status_name
11
10
  N_('Insights')
@@ -17,6 +16,10 @@ class InsightsClientReportStatus < HostStatus::Status
17
16
  N_('Reporting')
18
17
  when NO_REPORT
19
18
  N_('Not reporting')
19
+ when NOT_MANAGED
20
+ N_('Not reporting (not set by registration)')
21
+ when NOT_MANAGED_WITH_DATA
22
+ N_('Reporting (not set by registration)')
20
23
  end
21
24
  end
22
25
 
@@ -26,16 +29,20 @@ class InsightsClientReportStatus < HostStatus::Status
26
29
  ::HostStatus::Global::OK
27
30
  when NO_REPORT
28
31
  ::HostStatus::Global::ERROR
32
+ when NOT_MANAGED
33
+ ::HostStatus::Global::OK
34
+ when NOT_MANAGED_WITH_DATA
35
+ ::HostStatus::Global::WARN
29
36
  end
30
37
  end
31
38
 
32
- def to_status
33
- in_interval? ? REPORTING : NO_REPORT
34
- end
39
+ def to_status(data: false)
40
+ if insights_param
41
+ return REPORTING if data
42
+ return in_interval? ? REPORTING : NO_REPORT
43
+ end
35
44
 
36
- # prevent creation of the status on global refresh, but show it if the record already exists
37
- def relevant?(_options = {})
38
- persisted?
45
+ data ? NOT_MANAGED_WITH_DATA : NOT_MANAGED
39
46
  end
40
47
 
41
48
  private
@@ -44,4 +51,8 @@ class InsightsClientReportStatus < HostStatus::Status
44
51
  return false unless reported_at
45
52
  (Time.now.utc - reported_at).to_i < REPORT_INTERVAL.to_i
46
53
  end
54
+
55
+ def insights_param
56
+ host.host_params_hash.dig('host_registration_insights', :value)
57
+ end
47
58
  end
@@ -2,12 +2,6 @@ module ForemanRhCloud
2
2
  module CloudAuth
3
3
  extend ActiveSupport::Concern
4
4
 
5
- include CloudRequest
6
-
7
- def cloud_auth_available?
8
- Setting[:rh_cloud_token].present?
9
- end
10
-
11
5
  def rh_credentials
12
6
  @rh_credentials ||= query_refresh_token
13
7
  end
@@ -30,15 +24,5 @@ module ForemanRhCloud
30
24
  Foreman::Logging.exception('Unable to authenticate using rh_cloud_token setting', e)
31
25
  raise ::Foreman::WrappedException.new(e, N_('Unable to authenticate using rh_cloud_token setting'))
32
26
  end
33
-
34
- def execute_cloud_request(params)
35
- final_params = {
36
- headers: {
37
- Authorization: "Bearer #{rh_credentials}",
38
- },
39
- }.deep_merge(params)
40
-
41
- super(final_params)
42
- end
43
27
  end
44
28
  end
@@ -2,7 +2,7 @@ require 'rest-client'
2
2
 
3
3
  module ForemanRhCloud
4
4
  class CloudRequestForwarder
5
- include ForemanRhCloud::CloudRequest
5
+ include ::ForemanRhCloud::CloudAuth
6
6
 
7
7
  def forward_request(original_request, controller_name, branch_id, certs)
8
8
  forward_params = prepare_forward_params(original_request, branch_id)
@@ -22,6 +22,7 @@ module ForemanRhCloud
22
22
  def prepare_request_opts(original_request, forward_payload, forward_params, certs)
23
23
  base_params = {
24
24
  method: original_request.method,
25
+ verify_ssl: ForemanRhCloud.verify_ssl_method,
25
26
  payload: forward_payload,
26
27
  headers: {
27
28
  params: forward_params,
@@ -32,6 +33,10 @@ module ForemanRhCloud
32
33
  base_params.merge(path_params(original_request.path, certs))
33
34
  end
34
35
 
36
+ def execute_cloud_request(request_opts)
37
+ RestClient::Request.execute request_opts
38
+ end
39
+
35
40
  def prepare_forward_payload(original_request, controller_name)
36
41
  forward_payload = original_request.request_parameters[controller_name]
37
42
 
@@ -56,15 +61,13 @@ module ForemanRhCloud
56
61
 
57
62
  def path_params(request_path, certs)
58
63
  case request_path
59
- when platform_request?
64
+ when metadata_request?
60
65
  {
61
- url: ForemanRhCloud.cert_base_url + request_path.sub('/redhat_access/r/insights/platform', '/api'),
62
- ssl_client_cert: OpenSSL::X509::Certificate.new(certs[:cert]),
63
- ssl_client_key: OpenSSL::PKey::RSA.new(certs[:key]),
66
+ url: ForemanRhCloud.base_url + request_path.sub('/redhat_access/r/insights', '/api'),
64
67
  }
65
- when connection_test_request?
68
+ when platform_request?
66
69
  {
67
- url: ForemanRhCloud.cert_base_url + '/api/apicast-tests/ping',
70
+ url: ForemanRhCloud.cert_base_url + request_path.sub('/redhat_access/r/insights/platform', '/api'),
68
71
  ssl_client_cert: OpenSSL::X509::Certificate.new(certs[:cert]),
69
72
  ssl_client_key: OpenSSL::PKey::RSA.new(certs[:key]),
70
73
  }
@@ -78,12 +81,12 @@ module ForemanRhCloud
78
81
  end
79
82
  end
80
83
 
81
- def platform_request?
82
- ->(request_path) { request_path.include? '/platform' }
84
+ def metadata_request?
85
+ ->(request_path) { request_path.include? '/static' }
83
86
  end
84
87
 
85
- def connection_test_request?
86
- ->(request_path) { request_path =~ /redhat_access\/r\/insights\/?$/ }
88
+ def platform_request?
89
+ ->(request_path) { request_path.include? '/platform' }
87
90
  end
88
91
 
89
92
  def prepare_forward_cloud_url(base_url, request_path)
@@ -12,11 +12,6 @@ module ForemanRhCloud
12
12
  end
13
13
 
14
14
  def create_playbook
15
- unless cloud_auth_available?
16
- logger.debug('Cloud authentication is not available, cannot continue')
17
- return
18
- end
19
-
20
15
  response = query_playbook
21
16
 
22
17
  logger.debug("Got playbook response: #{response.body}")
@@ -67,11 +62,14 @@ module ForemanRhCloud
67
62
  end
68
63
 
69
64
  def query_playbook
70
- execute_cloud_request(
65
+ RestClient::Request.execute(
71
66
  method: :post,
72
67
  url: InsightsCloud.playbook_url,
68
+ verify_ssl: ForemanRhCloud.verify_ssl_method,
69
+ proxy: ForemanRhCloud.transformed_http_proxy_string(logger: logger),
73
70
  headers: {
74
71
  content_type: :json,
72
+ Authorization: "Bearer #{rh_credentials}",
75
73
  },
76
74
  payload: playbook_request.to_json
77
75
  )
@@ -0,0 +1,9 @@
1
+ module ForemanRhCloud
2
+ class InsightsSubscriber < ::Foreman::BaseSubscriber
3
+ def call(*args)
4
+ host = args.first.payload[:object]
5
+ host_status = host.get_status(InsightsClientReportStatus)
6
+ host_status.update(status: host_status.to_status)
7
+ end
8
+ end
9
+ end