foreman_rh_cloud 12.2.16 → 13.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.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/foreman_rh_cloud/locale/fr/foreman_rh_cloud.js +24 -78
  3. data/app/assets/javascripts/foreman_rh_cloud/locale/ja/foreman_rh_cloud.js +24 -78
  4. data/app/assets/javascripts/foreman_rh_cloud/locale/ka/foreman_rh_cloud.js +23 -77
  5. data/app/assets/javascripts/foreman_rh_cloud/locale/ko/foreman_rh_cloud.js +23 -77
  6. data/app/assets/javascripts/foreman_rh_cloud/locale/zh_CN/foreman_rh_cloud.js +23 -77
  7. data/app/controllers/concerns/insights_cloud/package_profile_upload_extensions.rb +3 -5
  8. data/app/controllers/foreman_inventory_upload/accounts_controller.rb +1 -1
  9. data/app/controllers/foreman_inventory_upload/uploads_controller.rb +1 -1
  10. data/app/controllers/insights_cloud/ui_requests_controller.rb +3 -2
  11. data/app/models/concerns/rh_cloud_host.rb +0 -14
  12. data/app/models/foreman_rh_cloud/ping.rb +1 -2
  13. data/app/models/insights_hit.rb +1 -1
  14. data/app/services/foreman_rh_cloud/cert_auth.rb +3 -13
  15. data/app/services/foreman_rh_cloud/gateway_request.rb +26 -0
  16. data/app/services/foreman_rh_cloud/insights_api_forwarder.rb +1 -3
  17. data/app/services/foreman_rh_cloud/tags_auth.rb +4 -15
  18. data/app/views/api/v2/advisor_engine/host_details.json.rabl +3 -1
  19. data/app/views/api/v2/hosts/insights/base.rabl +2 -3
  20. data/lib/foreman_inventory_upload/async/generate_report_job.rb +8 -13
  21. data/lib/foreman_inventory_upload/async/queue_for_upload_job.rb +26 -4
  22. data/lib/foreman_inventory_upload/async/upload_report_job.rb +96 -0
  23. data/lib/foreman_inventory_upload/generators/fact_helpers.rb +2 -2
  24. data/lib/foreman_inventory_upload/generators/slice.rb +3 -3
  25. data/lib/foreman_inventory_upload/scripts/uploader.sh.erb +49 -0
  26. data/lib/foreman_inventory_upload.rb +6 -6
  27. data/lib/foreman_rh_cloud/engine.rb +15 -34
  28. data/lib/foreman_rh_cloud/plugin.rb +13 -20
  29. data/lib/foreman_rh_cloud/version.rb +1 -1
  30. data/lib/foreman_rh_cloud.rb +3 -3
  31. data/lib/insights_cloud/async/connector_playbook_execution_reporter_task.rb +3 -3
  32. data/lib/inventory_sync/async/inventory_hosts_sync.rb +2 -0
  33. data/lib/tasks/rh_cloud_inventory.rake +31 -14
  34. data/locale/foreman_rh_cloud.pot +157 -261
  35. data/locale/fr/LC_MESSAGES/foreman_rh_cloud.mo +0 -0
  36. data/locale/fr/foreman_rh_cloud.po +26 -79
  37. data/locale/ja/LC_MESSAGES/foreman_rh_cloud.mo +0 -0
  38. data/locale/ja/foreman_rh_cloud.po +26 -79
  39. data/locale/ka/LC_MESSAGES/foreman_rh_cloud.mo +0 -0
  40. data/locale/ka/foreman_rh_cloud.po +24 -77
  41. data/locale/ko/LC_MESSAGES/foreman_rh_cloud.mo +0 -0
  42. data/locale/ko/foreman_rh_cloud.po +25 -78
  43. data/locale/zh_CN/LC_MESSAGES/foreman_rh_cloud.mo +0 -0
  44. data/locale/zh_CN/foreman_rh_cloud.po +25 -78
  45. data/package.json +1 -1
  46. data/test/controllers/accounts_controller_test.rb +1 -1
  47. data/test/controllers/insights_cloud/api/advisor_engine_controller_test.rb +1 -28
  48. data/test/controllers/insights_cloud/ui_requests_controller_test.rb +0 -26
  49. data/test/controllers/uploads_controller_test.rb +1 -1
  50. data/test/factories/insights_factories.rb +0 -29
  51. data/test/jobs/cloud_connector_announce_task_test.rb +2 -3
  52. data/test/jobs/connector_playbook_execution_reporter_task_test.rb +20 -32
  53. data/test/jobs/exponential_backoff_test.rb +8 -9
  54. data/test/jobs/insights_client_status_aging_test.rb +2 -3
  55. data/test/jobs/insights_full_sync_test.rb +7 -13
  56. data/test/jobs/insights_resolutions_sync_test.rb +5 -9
  57. data/test/jobs/insights_rules_sync_test.rb +3 -5
  58. data/test/jobs/inventory_full_sync_test.rb +5 -9
  59. data/test/jobs/inventory_hosts_sync_test.rb +6 -11
  60. data/test/jobs/inventory_scheduled_sync_test.rb +6 -10
  61. data/test/jobs/inventory_self_host_sync_test.rb +1 -1
  62. data/test/jobs/remove_insights_hosts_job_test.rb +15 -14
  63. data/test/jobs/upload_report_job_test.rb +36 -0
  64. data/test/unit/fact_helpers_test.rb +0 -47
  65. data/test/unit/services/foreman_rh_cloud/tags_auth_test.rb +0 -14
  66. data/test/unit/slice_generator_test.rb +0 -57
  67. data/webpack/ForemanColumnExtensions/index.js +0 -2
  68. data/webpack/ForemanInventoryUpload/Components/PageHeader/PageHeader.js +17 -24
  69. data/webpack/ForemanInventoryUpload/Components/PageHeader/__tests__/PageHeader.test.js +8 -178
  70. data/webpack/ForemanInventoryUpload/Components/PageHeader/__tests__/__snapshots__/PageHeader.test.js.snap +36 -0
  71. data/webpack/ForemanInventoryUpload/Components/PageHeader/__tests__/__snapshots__/PageTitle.test.js.snap +1 -1
  72. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/ToolbarButtons.js +1 -3
  73. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/__tests__/ToolbarButtons.test.js +51 -69
  74. data/webpack/ForemanInventoryUpload/ForemanInventoryHelpers.js +1 -1
  75. data/webpack/ForemanInventoryUpload/__tests__/__snapshots__/ForemanInventoryHelpers.test.js.snap +1 -1
  76. data/webpack/ForemanRhCloudFills.js +2 -6
  77. data/webpack/ForemanRhCloudHelpers.js +0 -4
  78. data/webpack/InsightsCloudSync/Components/InsightsSettings/InsightsSettings.js +3 -3
  79. data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTable.js +9 -3
  80. data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/InsightsTable.test.js +4 -24
  81. data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/__snapshots__/InsightsTable.test.js.snap +112 -0
  82. data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationModal.js +2 -2
  83. data/webpack/InsightsCloudSync/Components/ToolbarDropdown.js +3 -3
  84. data/webpack/InsightsCloudSync/InsightsCloudSync.js +3 -3
  85. data/webpack/InsightsCloudSync/InsightsCloudSync.test.js +0 -10
  86. data/webpack/InsightsCloudSync/__snapshots__/InsightsCloudSync.test.js.snap +1 -1
  87. data/webpack/InsightsHostDetailsTab/InsightsTab.scss +0 -4
  88. data/webpack/InsightsHostDetailsTab/InsightsTotalRiskChart.js +23 -59
  89. data/webpack/InsightsHostDetailsTab/NewHostDetailsTab.js +19 -6
  90. data/webpack/InsightsVulnerabilityHostIndexExtensions/CVECountCell.js +2 -8
  91. data/webpack/InsightsVulnerabilityHostIndexExtensions/__tests__/CVECountCell.test.js +4 -105
  92. data/webpack/__mocks__/foremanReact/common/hooks/API/APIHooks.js +3 -0
  93. data/webpack/__tests__/ForemanRhCloudHelpers.test.js +1 -16
  94. data/webpack/__tests__/__snapshots__/ForemanRhCloudHelpers.test.js.snap +0 -6
  95. data/webpack/common/Hooks/ConfigHooks.js +16 -3
  96. metadata +12 -31
  97. data/app/controllers/concerns/foreman_rh_cloud/registration_manager_extensions.rb +0 -39
  98. data/lib/foreman_inventory_upload/async/create_missing_insights_facets.rb +0 -30
  99. data/lib/foreman_inventory_upload/async/generate_host_report.rb +0 -20
  100. data/lib/foreman_inventory_upload/async/host_inventory_report_job.rb +0 -39
  101. data/lib/foreman_inventory_upload/async/single_host_report_job.rb +0 -20
  102. data/lib/foreman_inventory_upload/async/upload_report_direct_job.rb +0 -200
  103. data/test/jobs/create_missing_insights_facets_test.rb +0 -151
  104. data/test/jobs/generate_host_report_test.rb +0 -100
  105. data/test/jobs/generate_report_job_test.rb +0 -146
  106. data/test/jobs/host_inventory_report_job_test.rb +0 -244
  107. data/test/jobs/queue_for_upload_job_test.rb +0 -54
  108. data/test/jobs/single_host_report_job_test.rb +0 -155
  109. data/test/jobs/upload_report_direct_job_test.rb +0 -399
  110. data/test/unit/foreman_rh_cloud_iop_metadata_test.rb +0 -200
  111. data/test/unit/lib/foreman_rh_cloud/registration_manager_extensions_test.rb +0 -154
  112. data/test/unit/rh_cloud_host_test.rb +0 -191
  113. data/webpack/InsightsHostDetailsTab/__tests__/InsightsTotalRiskChart.test.js +0 -194
@@ -0,0 +1,96 @@
1
+ require 'tempfile'
2
+
3
+ module ForemanInventoryUpload
4
+ module Async
5
+ class UploadReportJob < ShellProcess
6
+ def self.output_label(label)
7
+ "upload_for_#{label}"
8
+ end
9
+
10
+ def plan(filename, organization_id, disconnected = false)
11
+ label = UploadReportJob.output_label(organization_id)
12
+ super(label, filename: filename, organization_id: organization_id, disconnected: disconnected)
13
+ end
14
+
15
+ def try_execute
16
+ if content_disconnected?
17
+ progress_output do |progress_output|
18
+ progress_output.write_line('Upload canceled because connection to Insights is not enabled or the --no-upload option was passed.')
19
+ progress_output.status = "Task aborted, exit 1"
20
+ done!
21
+ end
22
+ return
23
+ end
24
+
25
+ unless organization.owner_details&.fetch('upstreamConsumer')&.fetch('idCert')
26
+ logger.info("Skipping organization '#{organization}', no candlepin certificate defined.")
27
+ progress_output do |progress_output|
28
+ progress_output.write_line("Skipping organization #{organization}, no candlepin certificate defined.")
29
+ progress_output.status = "Task aborted, exit 1"
30
+ done!
31
+ end
32
+ return
33
+ end
34
+
35
+ Tempfile.create([organization.name, '.pem']) do |cer_file|
36
+ cer_file.write(certificate[:cert])
37
+ cer_file.write(certificate[:key])
38
+ cer_file.flush
39
+ @cer_path = cer_file.path
40
+ super
41
+ end
42
+ end
43
+
44
+ def command
45
+ ['/bin/bash', File.join(File.dirname(filename), ForemanInventoryUpload.upload_script_file)]
46
+ end
47
+
48
+ def env
49
+ env_vars = super.merge(
50
+ 'FILES' => filename,
51
+ 'CER_PATH' => @cer_path
52
+ )
53
+
54
+ http_proxy_string = ForemanRhCloud.http_proxy_string
55
+ if http_proxy_string
56
+ env_vars['http_proxy'] = http_proxy_string
57
+ env_vars['https_proxy'] = http_proxy_string
58
+ end
59
+ env_vars
60
+ end
61
+
62
+ def certificate
63
+ ForemanRhCloud.with_iop_smart_proxy? ? foreman_certificate : manifest_certificate
64
+ end
65
+
66
+ def manifest_certificate
67
+ @manifest_certificate ||= begin
68
+ candlepin_id_certificate = organization.owner_details['upstreamConsumer']['idCert']
69
+ {
70
+ cert: candlepin_id_certificate['cert'],
71
+ key: candlepin_id_certificate['key'],
72
+ }
73
+ end
74
+ end
75
+
76
+ def foreman_certificate
77
+ @foreman_certificate ||= {
78
+ cert: File.read(Setting[:ssl_certificate]),
79
+ key: File.read(Setting[:ssl_priv_key]),
80
+ }
81
+ end
82
+
83
+ def filename
84
+ input[:filename]
85
+ end
86
+
87
+ def organization
88
+ @organization ||= Organization.find(input[:organization_id])
89
+ end
90
+
91
+ def content_disconnected?
92
+ input[:disconnected] || !Setting[:subscription_connection_enabled]
93
+ end
94
+ end
95
+ end
96
+ end
@@ -59,7 +59,7 @@ module ForemanInventoryUpload
59
59
  def obfuscate_hostname?(host)
60
60
  # Returns true if hostname obfuscation should be applied for a given host, based on hierarchy:
61
61
  # 1. Global setting for hostname obfuscation.
62
- return true if Setting[:obfuscate_inventory_hostnames] && !ForemanRhCloud.with_iop_smart_proxy?
62
+ return true if Setting[:obfuscate_inventory_hostnames]
63
63
 
64
64
  insights_client_setting = fact_value(host, 'insights_client::obfuscate_hostname_enabled')
65
65
  insights_client_setting = ActiveModel::Type::Boolean.new.cast(insights_client_setting)
@@ -99,7 +99,7 @@ module ForemanInventoryUpload
99
99
  def obfuscate_ips?(host)
100
100
  # Returns true if IP obfuscation should be applied for a given host, based on hierarchy:
101
101
  # 1. Global setting for IP obfuscation.
102
- return true if Setting[:obfuscate_inventory_ips] && !ForemanRhCloud.with_iop_smart_proxy?
102
+ return true if Setting[:obfuscate_inventory_ips]
103
103
 
104
104
  insights_client_ipv4_setting = fact_value(host, 'insights_client::obfuscate_ipv4_enabled')
105
105
  insights_client_ipv6_setting = fact_value(host, 'insights_client::obfuscate_ipv6_enabled')
@@ -90,7 +90,7 @@ module ForemanInventoryUpload
90
90
  def report_host(host)
91
91
  host_ips_cache = host_ips(host)
92
92
  @stream.object do
93
- if Setting[:insights_minimal_data_collection] && !ForemanRhCloud.with_iop_smart_proxy?
93
+ if Setting[:insights_minimal_data_collection]
94
94
  insights_minimal_data_collection(host)
95
95
  else
96
96
  @stream.simple_field('fqdn', fqdn(host))
@@ -205,7 +205,7 @@ module ForemanInventoryUpload
205
205
  end.join(', '))
206
206
  end
207
207
  end
208
- if ForemanRhCloud.with_iop_smart_proxy? || (!Setting[:insights_minimal_data_collection] && !Setting[:exclude_installed_packages])
208
+ if !Setting[:insights_minimal_data_collection] && !Setting[:exclude_installed_packages]
209
209
  @stream.array_field('installed_packages') do
210
210
  first = true
211
211
  host.installed_packages.each do |package|
@@ -256,7 +256,7 @@ module ForemanInventoryUpload
256
256
 
257
257
  @stream.array_field('yum_repos') do
258
258
  host.content_facet.bound_repositories.each_with_index do |repo, index|
259
- report_yum_repo(host.content_source&.load_balancer_pulp_content_url || ::SmartProxy.pulp_primary.pulp_content_url, repo)
259
+ report_yum_repo(host.content_source.load_balancer_pulp_content_url, repo)
260
260
  @stream.comma unless index == host.content_facet.bound_repositories.count - 1
261
261
  end
262
262
  end
@@ -0,0 +1,49 @@
1
+ #! /bin/bash
2
+
3
+ DEST=<%= @upload_url %>
4
+ RH_USERNAME=<%= @rh_username %>
5
+
6
+ if [ -z "$FILES" ]
7
+ then
8
+ FILES=./*.tar.gz
9
+ fi
10
+
11
+ if [ -n "$CER_PATH" ]
12
+ then
13
+ AUTH_KEY="--cert"
14
+ AUTH_VAL="$CER_PATH"
15
+ else
16
+ if [ -z "$RH_USERNAME" ]
17
+ then
18
+ IFS= read -rp "Enter username: " RH_USERNAME
19
+ fi
20
+
21
+ if [ -z "$RH_PASSWORD" ]
22
+ then
23
+ IFS= read -rsp "Enter password: " RH_PASSWORD
24
+ fi
25
+
26
+ AUTH_KEY="-u"
27
+ AUTH_VAL="\"$RH_USERNAME\":\"$RH_PASSWORD\""
28
+ fi
29
+
30
+ # /tmp/a b/x.pem
31
+ # curl --cert /tmp/a\ b/x.pem
32
+
33
+ SCRIPT_DIR=$(realpath "$(dirname "${BASH_SOURCE:-0}")")
34
+ DONE_DIR="$SCRIPT_DIR/done/"
35
+ mkdir -p $DONE_DIR
36
+
37
+ for f in $FILES
38
+ do
39
+ curl -k -vvv -# --fail -F "file=@$f;type=application/vnd.redhat.qpc.tar+tgz" $DEST "$AUTH_KEY" "$AUTH_VAL"
40
+ status=$?
41
+ if [ $status -eq 0 ]; then
42
+ mv $f $DONE_DIR
43
+ echo "Done: $f"
44
+ fi
45
+ done
46
+ echo "Uploaded files moved to done/ folder"
47
+
48
+ # return the error code from the curl command
49
+ exit $status
@@ -48,6 +48,10 @@ module ForemanInventoryUpload
48
48
  @outputs_folder ||= ensure_folder(File.join(ForemanInventoryUpload.base_folder, 'outputs/'))
49
49
  end
50
50
 
51
+ def self.upload_script_file
52
+ 'uploader.sh'
53
+ end
54
+
51
55
  def self.facts_archive_name(organization, filter = nil)
52
56
  "report_for_#{organization}#{filter.empty? ? nil : "[#{filter.to_s.parameterize}]"}.tar.xz"
53
57
  end
@@ -84,12 +88,8 @@ module ForemanInventoryUpload
84
88
  inventory_base_url + "?hostname_or_id=#{ForemanRhCloud.foreman_host.fqdn}"
85
89
  end
86
90
 
87
- def self.host_by_id_url(host_uuid)
88
- "#{inventory_base_url}/#{host_uuid}"
89
- end
90
-
91
- def self.hosts_by_ids_url(host_uuids)
92
- host_ids_string = host_uuids.join(',')
91
+ def self.hosts_by_ids_url(host_ids)
92
+ host_ids_string = host_ids.join(',')
93
93
  "#{inventory_base_url}/#{host_ids_string}"
94
94
  end
95
95
  end
@@ -40,7 +40,6 @@ module ForemanRhCloud
40
40
  ::Host::Managed.include RhCloudHost
41
41
 
42
42
  ::Katello::Api::Rhsm::CandlepinDynflowProxyController.include InsightsCloud::PackageProfileUploadExtensions
43
- ::Katello::RegistrationManager.singleton_class.prepend ::ForemanRhCloud::RegistrationManagerExtensions
44
43
  end
45
44
  end
46
45
 
@@ -84,27 +83,6 @@ module ForemanRhCloud
84
83
  :description => N_('Configure Cloud Connector on given hosts'),
85
84
  :proxy_selector_override => ::RemoteExecutionProxySelector::INTERNAL_PROXY
86
85
  )
87
-
88
- ScopedSearch::AutoCompleteBuilder.class_eval do
89
- # Insights rule IDs always contain a pipe character.
90
- # example: hardening_ssh_config_perms|OPENSSH_HARDENING_CONFIG_PERMS
91
- # We need to override this method of scoped_search so that autocomplete
92
- # will correctly put the value in quotes (otherwise the "|" will be
93
- # interpreted as an OR.)
94
- # The only change from scoped_search code is adding the | to the regex in the final map.
95
- def complete_value_from_db(field, special_values, val)
96
- count = 20 - special_values.count
97
- completer_scope(field)
98
- .where(@options[:value_filter])
99
- .where(value_conditions(field.quoted_field, val))
100
- .select(field.quoted_field)
101
- .limit(count)
102
- .distinct
103
- .map(&field.field)
104
- .compact
105
- .map { |v| v.to_s =~ /\s|\|/ ? "\"#{v.gsub('"', '\"')}\"" : v }
106
- end
107
- end
108
86
  end
109
87
 
110
88
  # Ideally this code belongs to an initializer. The problem is that Katello controllers are not initialized completely until after the end of the to_prepare blocks
@@ -116,20 +94,23 @@ module ForemanRhCloud
116
94
  if defined?(Katello) && !Foreman.in_setup_db_rake?
117
95
  Katello::Api::V2::OrganizationsController.include Foreman::Controller::SmartProxyAuth
118
96
  # patch the callbacks order for :download_debug_certificate, since local_find_taxonomy has to run after the user is already initialized
119
- Katello::Api::V2::OrganizationsController.before_find_taxonomy_actions do
120
- Katello::Api::V2::OrganizationsController.add_smart_proxy_filters(
121
- [:index, :download_debug_certificate],
122
- features: ForemanRhCloud.on_prem_smart_proxy_features
123
- )
124
- end
97
+ Katello::Api::V2::OrganizationsController.skip_before_action(:local_find_taxonomy, only: :download_debug_certificate)
98
+ Katello::Api::V2::OrganizationsController.add_smart_proxy_filters(
99
+ [:index, :download_debug_certificate],
100
+ features: ForemanRhCloud.on_prem_smart_proxy_features
101
+ )
102
+ Katello::Api::V2::OrganizationsController.before_action(:local_find_taxonomy, only: :download_debug_certificate)
103
+
125
104
  Katello::Api::V2::RepositoriesController.include Foreman::Controller::SmartProxyAuth
126
105
  # patch the callbacks order for :index, since find_product has to run after the user is already initialized
127
- Katello::Api::V2::RepositoriesController.before_index_actions do
128
- Katello::Api::V2::RepositoriesController.add_smart_proxy_filters(
129
- :index,
130
- features: ForemanRhCloud.on_prem_smart_proxy_features
131
- )
132
- end
106
+ Katello::Api::V2::RepositoriesController.skip_before_action(:find_product, only: :index)
107
+ Katello::Api::V2::RepositoriesController.skip_before_action(:find_optional_organization, only: :index)
108
+ Katello::Api::V2::RepositoriesController.add_smart_proxy_filters(
109
+ :index,
110
+ features: ForemanRhCloud.on_prem_smart_proxy_features
111
+ )
112
+ Katello::Api::V2::RepositoriesController.before_action(:find_product, only: :index)
113
+ Katello::Api::V2::RepositoriesController.before_action(:find_optional_organization, only: :index)
133
114
  end
134
115
  end
135
116
 
@@ -13,15 +13,15 @@ module ForemanRhCloud
13
13
 
14
14
  settings do
15
15
  category(:rh_cloud, N_('Insights')) do
16
- setting('allow_auto_inventory_upload', type: :boolean, description: N_('Enable automatic upload of your host inventory to the Red Hat cloud. Ignored when using local Insights.'), default: true, full_name: N_('Automatic inventory upload'))
17
- setting('allow_auto_insights_sync', type: :boolean, description: N_('Enable automatic synchronization of Insights recommendations from the Red Hat cloud. Ignored when using local Insights.'), default: true, full_name: N_('Synchronize recommendations Automatically'))
18
- setting('allow_auto_insights_mismatch_delete', type: :boolean, description: N_('Enable automatic deletion of mismatched host records from the Red Hat cloud. Ignored when using local Insights.'), default: false, full_name: N_('Automatic mismatch deletion'))
19
- setting('obfuscate_inventory_hostnames', type: :boolean, description: N_('Obfuscate host names sent to the Red Hat cloud. (If insights_minimal_data_collection is set to true, this setting is ignored because host names are not included in the report.) Ignored when using local Insights.'), default: false, full_name: N_('Obfuscate host names'))
20
- setting('obfuscate_inventory_ips', type: :boolean, description: N_('Obfuscate ipv4 addresses sent to the Red Hat cloud. (If insights_minimal_data_collection is set to true, this setting is ignored because host IPv4 addresses are not included in the report.) Ignored when using local Insights.'), default: false, full_name: N_('Obfuscate host ipv4 addresses.'))
21
- setting('exclude_installed_packages', type: :boolean, description: N_('Exclude installed packages from being uploaded to the Red Hat cloud. (If insights_minimal_data_collection is set to true, this setting is ignored and installed packages are always excluded.) Ignored when using local Insights.'), default: false, full_name: N_("Exclude installed packages"))
22
- setting('include_parameter_tags', type: :boolean, description: N_('Should import include parameter tags from Foreman? Ignored when using local Insights.'), default: false, full_name: N_('Include parameters in insights-client reports'))
23
- setting('rhc_instance_id', type: :string, description: N_('RHC daemon id. Ignored when using local Insights.'), default: nil, full_name: N_('ID of the RHC(Yggdrasil) daemon'))
24
- setting('insights_minimal_data_collection', type: :boolean, default: false, full_name: N_('Minimal data collection'), description: N_('Only include the minimum required data in inventory reports for uploading to Red Hat cloud. When this is true, installed packages are excluded from the report regardless of the exclude_installed_packages setting, and host names and IPv4 addresses are excluded from the report regardless of obfuscation settings. Ignored when using local Insights.'))
16
+ 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'))
17
+ setting('allow_auto_insights_sync', type: :boolean, description: N_('Enable automatic synchronization of Insights recommendations from the Red Hat cloud'), default: true, full_name: N_('Synchronize recommendations Automatically'))
18
+ 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'))
19
+ setting('obfuscate_inventory_hostnames', type: :boolean, description: N_('Obfuscate host names sent to the Red Hat cloud. (If insights_minimal_data_collection is set to true, this setting is ignored because host names are not included in the report.)'), default: false, full_name: N_('Obfuscate host names'))
20
+ setting('obfuscate_inventory_ips', type: :boolean, description: N_('Obfuscate ipv4 addresses sent to the Red Hat cloud. (If insights_minimal_data_collection is set to true, this setting is ignored because host IPv4 addresses are not included in the report.)'), default: false, full_name: N_('Obfuscate host ipv4 addresses.'))
21
+ setting('exclude_installed_packages', type: :boolean, description: N_('Exclude installed packages from being uploaded to the Red Hat cloud. (If insights_minimal_data_collection is set to true, this setting is ignored and installed packages are always excluded.)'), default: false, full_name: N_("Exclude installed packages"))
22
+ 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'))
23
+ setting('rhc_instance_id', type: :string, description: N_('RHC daemon id'), default: nil, full_name: N_('ID of the RHC(Yggdrasil) daemon'))
24
+ setting('insights_minimal_data_collection', type: :boolean, default: false, full_name: N_('Minimal data collection'), description: N_('Only include the minimum required data in inventory reports for uploading to Red Hat cloud. When this is true, installed packages are excluded from the report regardless of the exclude_installed_packages setting, and host names and IPv4 addresses are excluded from the report regardless of obfuscation settings.'))
25
25
  end
26
26
  end
27
27
 
@@ -117,17 +117,14 @@ module ForemanRhCloud
117
117
  end
118
118
  end
119
119
 
120
- # Preload insights facet to avoid N+1 queries when rendering host list with facets
121
- add_controller_action_scope('Api::V2::HostsController', :index) do |base_scope|
122
- base_scope.preload(:insights)
123
- end
124
-
125
120
  register_global_js_file 'global'
126
121
 
127
122
  register_custom_status InventorySync::InventoryStatus
128
123
  register_custom_status InsightsClientReportStatus
129
- register_ping_extension { ForemanRhCloud::Ping.ping }
130
- register_status_extension { ForemanRhCloud::Ping.status }
124
+ if ForemanRhCloud.with_iop_smart_proxy?
125
+ register_ping_extension { ForemanRhCloud::Ping.ping }
126
+ register_status_extension { ForemanRhCloud::Ping.status }
127
+ end
131
128
 
132
129
  describe_host do
133
130
  overview_buttons_provider :insights_host_overview_buttons
@@ -149,10 +146,6 @@ module ForemanRhCloud
149
146
  end
150
147
  end
151
148
 
152
- ::Foreman::Plugin.app_metadata_registry.register(:foreman_rh_cloud, {
153
- iop: -> { ForemanRhCloud.with_iop_smart_proxy? },
154
- })
155
-
156
149
  extend_template_helpers ForemanRhCloud::TemplateRendererHelper
157
150
  allowed_template_helpers :remediations_playbook, :download_rh_playbook
158
151
  end
@@ -1,3 +1,3 @@
1
1
  module ForemanRhCloud
2
- VERSION = '12.2.16'.freeze
2
+ VERSION = '13.0.0'.freeze
3
3
  end
@@ -14,15 +14,15 @@ module ForemanRhCloud
14
14
 
15
15
  def self.base_url
16
16
  # for testing set ENV to 'https://ci.cloud.redhat.com'
17
- env_or_on_premise_url('SATELLITE_RH_CLOUD_URL') || 'https://cloud.redhat.com'
17
+ @base_url ||= env_or_on_premise_url('SATELLITE_RH_CLOUD_URL') || 'https://cloud.redhat.com'
18
18
  end
19
19
 
20
20
  def self.cert_base_url
21
- env_or_on_premise_url('SATELLITE_CERT_RH_CLOUD_URL') || 'https://cert.cloud.redhat.com'
21
+ @cert_base_url ||= env_or_on_premise_url('SATELLITE_CERT_RH_CLOUD_URL') || 'https://cert.cloud.redhat.com'
22
22
  end
23
23
 
24
24
  def self.legacy_insights_url
25
- env_or_on_premise_url('SATELLITE_LEGACY_INSIGHTS_URL') || 'https://cert-api.access.redhat.com'
25
+ @legacy_insights_url ||= env_or_on_premise_url('SATELLITE_LEGACY_INSIGHTS_URL') || 'https://cert-api.access.redhat.com'
26
26
  end
27
27
 
28
28
  def self.verify_ssl_method
@@ -126,10 +126,10 @@ module InsightsCloud
126
126
 
127
127
  def invocation_status
128
128
  hosts_state = Hash[job_invocation.targeting.hosts.map do |host|
129
- next unless host.insights_uuid
129
+ next unless host.insights&.uuid
130
130
  [
131
- host.insights_uuid,
132
- task_status(job_invocation.sub_task_for_host(host), host.insights_uuid),
131
+ host.insights.uuid,
132
+ task_status(job_invocation.sub_task_for_host(host), host.insights.uuid),
133
133
  ]
134
134
  end.compact]
135
135
 
@@ -8,6 +8,8 @@ module InventorySync
8
8
  set_callback :step, :around, :create_missing_hosts
9
9
 
10
10
  def plan(organizations)
11
+ # Do not run for local advisor, since we use sub-man id to identify hosts.
12
+ return if ForemanRhCloud.with_iop_smart_proxy?
11
13
  # by default the tasks will be executed concurrently
12
14
  super(organizations)
13
15
  plan_self_host_sync
@@ -9,20 +9,22 @@ namespace :rh_cloud_inventory do
9
9
  else
10
10
  organizations = [Organization.where(:id => ENV['organization_id']).first]
11
11
  end
12
+ disconnected = ForemanRhCloud.with_iop_smart_proxy?
12
13
  User.as_anonymous_admin do
13
14
  organizations.each do |organization|
14
15
  ForemanTasks.async_task(
15
16
  ForemanInventoryUpload::Async::GenerateReportJob,
16
17
  ForemanInventoryUpload.generated_reports_folder,
17
- organization.id
18
+ organization.id,
19
+ disconnected
18
20
  )
19
21
  puts "Generated and uploaded inventory report for organization '#{organization.name}'"
20
22
  end
21
23
  end
22
24
  end
23
25
  desc 'Generate inventory report to be sent to Red Hat cloud'
24
- task generate: [:environment, 'dynflow:client'] do
25
- organization_ids = [ENV['organization_id']]
26
+ task generate: :environment do
27
+ organizations = [ENV['organization_id']]
26
28
  base_folder = ENV['target'] || Dir.pwd
27
29
  filter = ENV['hosts_filter']
28
30
 
@@ -32,22 +34,36 @@ namespace :rh_cloud_inventory do
32
34
  puts "Using #{base_folder} for the output"
33
35
  end
34
36
 
35
- if organization_ids.empty?
37
+ if organizations.empty?
36
38
  puts "Must specify organization_id"
37
39
  return
38
40
  end
39
41
 
40
42
  User.as_anonymous_admin do
41
- organization_ids.each do |organization_id|
42
- ForemanTasks.sync_task(
43
- ForemanInventoryUpload::Async::HostInventoryReportJob,
44
- base_folder,
45
- organization_id,
46
- filter,
47
- false # don't upload; the user ran report:generate and not report:generate_upload
48
- )
43
+ organizations.each do |organization|
44
+ target = File.join(base_folder, ForemanInventoryUpload.facts_archive_name(organization, filter))
45
+ archived_report_generator = ForemanInventoryUpload::Generators::ArchivedReport.new(target, Logger.new(STDOUT))
46
+ archived_report_generator.render(organization: organization, filter: filter)
47
+ puts "Successfully generated #{target} for organization id #{organization}"
48
+
49
+ next unless ForemanRhCloud.with_iop_smart_proxy?
50
+
51
+ puts 'Creating missing insights facets'
52
+ hosts_without_facets = ForemanInventoryUpload::Generators::Queries.for_org(organization, hosts_query: 'null? insights_uuid')
53
+ hosts_without_facets.each do |batch|
54
+ facets = batch.pluck(:id, 'katello_subscription_facets.uuid').map do |host_id, uuid|
55
+ {
56
+ host_id: host_id,
57
+ uuid: uuid,
58
+ }
59
+ end
60
+ # We don't need to validate the facets here as we create the necessary fields.
61
+ # rubocop:disable Rails/SkipsModelValidations
62
+ InsightsFacet.upsert_all(facets, unique_by: :host_id) unless facets.empty?
63
+ # rubocop:enable Rails/SkipsModelValidations
64
+ end
65
+ puts 'Missing Insights facets created'
49
66
  end
50
- puts "Check the Uploading tab for report uploading status." if Setting[:subscription_connection_enabled]
51
67
  end
52
68
  end
53
69
  desc 'Upload generated inventory report to Red Hat cloud'
@@ -55,7 +71,8 @@ namespace :rh_cloud_inventory do
55
71
  base_folder = ENV['target'] || ForemanInventoryUpload.generated_reports_folder
56
72
  organization_id = ENV['organization_id']
57
73
  report_file = ForemanInventoryUpload.facts_archive_name(organization_id)
58
- ForemanTasks.sync_task(ForemanInventoryUpload::Async::QueueForUploadJob, base_folder, report_file, organization_id)
74
+ disconnected = ForemanRhCloud.with_iop_smart_proxy?
75
+ ForemanTasks.sync_task(ForemanInventoryUpload::Async::QueueForUploadJob, base_folder, report_file, organization_id, disconnected)
59
76
  puts "Uploaded #{report_file}"
60
77
  end
61
78
  end