foreman_rh_cloud 2.0.12 → 2.0.16

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 (117) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +13 -0
  3. data/app/controllers/foreman_inventory_upload/accounts_controller.rb +2 -0
  4. data/app/controllers/foreman_inventory_upload/uploads_controller.rb +18 -0
  5. data/app/helpers/foreman_inventory_upload_host_helper.rb +2 -3
  6. data/app/models/concerns/rh_cloud_host.rb +4 -1
  7. data/app/models/insights_hit.rb +1 -1
  8. data/app/models/setting/rh_cloud.rb +5 -3
  9. data/app/overrides/hosts_list.rb +1 -1
  10. data/app/services/foreman_rh_cloud/cloud_auth.rb +28 -0
  11. data/app/views/foreman_rh_cloud/react/insights_cloud.html.erb +1 -6
  12. data/app/views/foreman_rh_cloud/react/inventory_upload.html.erb +1 -1
  13. data/app/views/hosts/_insights_tab.html.erb +1 -7
  14. data/app/views/layouts/foreman_rh_cloud/application.html.erb +0 -1
  15. data/config/Gemfile.lock.gh_test +815 -0
  16. data/config/database.yml.example +17 -0
  17. data/config/package-lock.json.gh_test +36317 -0
  18. data/config/routes.rb +2 -0
  19. data/db/migrate/20201007115752_add_hits_count_to_insights_facets_table.foreman_rh_cloud.rb +5 -0
  20. data/db/migrate/20201007121540_setup_hits_count_cache.foreman_rh_cloud.rb +10 -0
  21. data/lib/foreman_inventory_upload.rb +1 -1
  22. data/lib/foreman_inventory_upload/generators/archived_report.rb +1 -1
  23. data/lib/foreman_inventory_upload/generators/fact_helpers.rb +35 -0
  24. data/lib/foreman_inventory_upload/generators/json_stream.rb +7 -2
  25. data/lib/foreman_inventory_upload/generators/queries.rb +2 -0
  26. data/lib/foreman_inventory_upload/generators/slice.rb +27 -25
  27. data/lib/foreman_rh_cloud.rb +2 -1
  28. data/lib/foreman_rh_cloud/engine.rb +3 -3
  29. data/lib/foreman_rh_cloud/version.rb +1 -1
  30. data/lib/insights_cloud/async/insights_full_sync.rb +4 -25
  31. data/lib/inventory_sync/async/inventory_full_sync.rb +2 -23
  32. data/lib/tasks/rh_cloud_inventory.rake +23 -0
  33. data/package.json +1 -1
  34. data/test/unit/fact_helpers_test.rb +22 -0
  35. data/test/unit/insights_facet_test.rb +7 -0
  36. data/test/unit/slice_generator_test.rb +142 -2
  37. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountList.fixtures.js +14 -1
  38. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListActions.js +22 -18
  39. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListReducer.js +16 -0
  40. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListSelectors.js +6 -0
  41. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListActions.test.js +7 -0
  42. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListReducer.test.js +12 -8
  43. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListSelectors.test.js +9 -0
  44. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListActions.test.js.snap +19 -0
  45. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListReducer.test.js.snap +11 -0
  46. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListSelectors.test.js.snap +6 -0
  47. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/AutoUploadSwitcher.fixtures.js +2 -0
  48. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/AutoUploadSwitcherActions.js +10 -11
  49. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/AutoUploadSwitcherConstants.js +0 -1
  50. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/__tests__/AutoUploadSwitcherActions.test.js +12 -2
  51. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/__tests__/__snapshots__/AutoUploadSwitcherActions.test.js.snap +17 -0
  52. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/ExcludePackagesSwitcher.fixtures.js +1 -0
  53. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/ExcludePackagesSwitcher.js +30 -0
  54. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/ExcludePackagesSwitcherActions.js +29 -0
  55. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/ExcludePackagesSwitcherConstants.js +1 -0
  56. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/__tests__/ExcludePackagesSwitcher.test.js +13 -0
  57. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/__tests__/ExcludePackagesSwitcherActions.test.js +21 -0
  58. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/__tests__/__snapshots__/ExcludePackagesSwitcher.test.js.snap +38 -0
  59. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/__tests__/__snapshots__/ExcludePackagesSwitcherActions.test.js.snap +31 -0
  60. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/__tests__/__snapshots__/integration.test.js.snap +41 -0
  61. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/__tests__/integration.test.js +36 -0
  62. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/excludePackagesSwitcher.scss +3 -0
  63. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/index.js +20 -0
  64. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/HostObfuscationSwitcher.fixtures.js +2 -1
  65. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/HostObfuscationSwitcher.js +1 -0
  66. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/HostObfuscationSwitcher.scss +3 -0
  67. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/HostObfuscationSwitcherActions.js +10 -11
  68. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/HostObfuscationSwitcherConstants.js +0 -2
  69. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/__tests__/HostObfuscationSwitcherActions.test.js +12 -2
  70. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/__tests__/__snapshots__/HostObfuscationSwitcherActions.test.js.snap +18 -1
  71. data/webpack/ForemanInventoryUpload/Components/InventorySettings/InventorySettings.js +4 -0
  72. data/webpack/ForemanInventoryUpload/Components/InventorySettings/__tests__/__snapshots__/InventorySettings.test.js.snap +2 -0
  73. data/webpack/ForemanInventoryUpload/Components/IpsObfuscationSwitcher/IpsObfuscationSwitcher.fixtures.js +1 -0
  74. data/webpack/ForemanInventoryUpload/Components/IpsObfuscationSwitcher/IpsObfuscationSwitcher.js +29 -0
  75. data/webpack/ForemanInventoryUpload/Components/IpsObfuscationSwitcher/IpsObfuscationSwitcherActions.js +29 -0
  76. data/webpack/ForemanInventoryUpload/Components/IpsObfuscationSwitcher/IpsObfuscationSwitcherConstants.js +1 -0
  77. data/webpack/ForemanInventoryUpload/Components/IpsObfuscationSwitcher/__tests__/IpsObfuscationSwitcher.test.js +13 -0
  78. data/webpack/ForemanInventoryUpload/Components/IpsObfuscationSwitcher/__tests__/IpsObfuscationSwitcherActions.test.js +21 -0
  79. data/webpack/ForemanInventoryUpload/Components/IpsObfuscationSwitcher/__tests__/__snapshots__/IpsObfuscationSwitcher.test.js.snap +38 -0
  80. data/webpack/ForemanInventoryUpload/Components/IpsObfuscationSwitcher/__tests__/__snapshots__/IpsObfuscationSwitcherActions.test.js.snap +31 -0
  81. data/webpack/ForemanInventoryUpload/Components/IpsObfuscationSwitcher/index.js +20 -0
  82. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButton.js +8 -2
  83. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js +9 -11
  84. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonConstants.js +1 -1
  85. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonReducer.js +2 -2
  86. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/SyncButtonActions.test.js +18 -0
  87. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/SyncButtonReducer.test.js +1 -8
  88. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/SyncButtonActions.test.js.snap +62 -0
  89. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/SyncButtonReducer.test.js.snap +0 -7
  90. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/components/Modal.js +2 -2
  91. data/webpack/ForemanInventoryUpload/Components/TabHeader/TabHeader.js +6 -1
  92. data/webpack/ForemanInventoryUpload/Components/Terminal/Terminal.js +2 -4
  93. data/webpack/ForemanInventoryUpload/ForemanInventoryHelpers.js +8 -0
  94. data/webpack/InsightsCloudSync/Components/InsightsSettings/InsightsSettingsActions.js +17 -20
  95. data/webpack/InsightsCloudSync/Components/InsightsSettings/InsightsSettingsConstants.js +0 -6
  96. data/webpack/InsightsCloudSync/Components/InsightsSettings/InsightsSettingsReducer.js +0 -4
  97. data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsActions.test.js +16 -0
  98. data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsReducer.test.js +1 -24
  99. data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/__snapshots__/InsightsSettingsActions.test.js.snap +38 -4
  100. data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/__snapshots__/InsightsSettingsReducer.test.js.snap +0 -14
  101. data/webpack/InsightsCloudSync/InsightsCloudSync.js +3 -5
  102. data/webpack/InsightsCloudSync/InsightsCloudSync.test.js +1 -3
  103. data/webpack/InsightsCloudSync/InsightsCloudSyncActions.js +10 -11
  104. data/webpack/InsightsCloudSync/InsightsCloudSyncConstants.js +0 -2
  105. data/webpack/InsightsCloudSync/__snapshots__/InsightsCloudSync.test.js.snap +1 -1
  106. data/webpack/InsightsHostDetailsTab/InsightsTab.js +8 -6
  107. data/webpack/InsightsHostDetailsTab/InsightsTab.scss +2 -2
  108. data/webpack/InsightsHostDetailsTab/InsightsTabActions.js +9 -8
  109. data/webpack/InsightsHostDetailsTab/InsightsTabConstants.js +0 -1
  110. data/webpack/InsightsHostDetailsTab/InsightsTabReducer.js +2 -9
  111. data/webpack/InsightsHostDetailsTab/__tests__/InsightsTabActions.test.js +7 -1
  112. data/webpack/InsightsHostDetailsTab/__tests__/InsightsTabReducer.test.js +0 -9
  113. data/webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTab.test.js.snap +26 -22
  114. data/webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTabActions.test.js.snap +40 -2
  115. data/webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTabReducer.test.js.snap +0 -7
  116. metadata +30 -3
  117. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/hostObfuscationSwitcher.scss +0 -0
data/config/routes.rb CHANGED
@@ -8,6 +8,8 @@ Rails.application.routes.draw do
8
8
  get 'auto_upload', to: 'uploads#show_auto_upload'
9
9
  post 'auto_upload', to: 'uploads#auto_upload'
10
10
  post 'host_obfuscation', to: 'uploads#host_obfuscation'
11
+ post 'installed_packages_inclusion', to: 'uploads#installed_packages_inclusion'
12
+ post 'ips_obfuscation', to: 'uploads#ips_obfuscation'
11
13
 
12
14
  resources :tasks, only: [:create]
13
15
  end
@@ -0,0 +1,5 @@
1
+ class AddHitsCountToInsightsFacetsTable < ActiveRecord::Migration[5.0]
2
+ def change
3
+ add_column :insights_facets, :hits_count, :integer
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ class SetupHitsCountCache < ActiveRecord::Migration[5.0]
2
+ def up
3
+ ActiveRecord::Base.connection.execute <<-SQL.squish
4
+ UPDATE insights_facets
5
+ SET hits_count = (SELECT count(1)
6
+ FROM insights_hits
7
+ WHERE insights_hits.host_id = insights_facets.host_id)
8
+ SQL
9
+ end
10
+ end
@@ -48,7 +48,7 @@ module ForemanInventoryUpload
48
48
  end
49
49
 
50
50
  def self.facts_archive_name(organization)
51
- "report_for_#{organization}.tar.gz"
51
+ "report_for_#{organization}.tar.xz"
52
52
  end
53
53
 
54
54
  def self.upload_url
@@ -28,7 +28,7 @@ module ForemanInventoryUpload
28
28
 
29
29
  @logger.info 'Archiving generated report'
30
30
  # success = system('tar', '-zcvf', @target, '-C', tmpdir, '.')
31
- Open3.popen2e('tar', '-zcvf', @target, '-C', tmpdir, '.') do |_in, out, wait_thr|
31
+ Open3.popen2e('tar', '-Jcvf', @target, '-C', tmpdir, '.') do |_in, out, wait_thr|
32
32
  @logger.info("tar: #{out.read}")
33
33
 
34
34
  if wait_thr.value.success?
@@ -1,3 +1,5 @@
1
+ require 'json'
2
+
1
3
  module ForemanInventoryUpload
2
4
  module Generators
3
5
  module FactHelpers
@@ -69,6 +71,39 @@ module ForemanInventoryUpload
69
71
  def obfuscate_fqdn(fqdn)
70
72
  "#{Digest::SHA1.hexdigest(fqdn)}.example.com"
71
73
  end
74
+
75
+ def obfuscate_ips?(host)
76
+ insights_client_setting = fact_value(host, 'insights_client::obfuscate_ip_enabled')
77
+ insights_client_setting = ActiveModel::Type::Boolean.new.cast(insights_client_setting)
78
+ return insights_client_setting unless insights_client_setting.nil?
79
+
80
+ Setting[:obfuscate_inventory_ips]
81
+ end
82
+
83
+ def host_ips(host)
84
+ return obfuscated_ips(host) if obfuscate_ips?(host)
85
+
86
+ # return a pass through proxy hash in case no obfuscation needed
87
+ Hash.new { |h, k| k }
88
+ end
89
+
90
+ def obfuscated_ips(host)
91
+ insights_client_ips = JSON.parse(fact_value(host, 'insights_client::ips') || '[]')
92
+
93
+ obfuscated_ips = Hash[
94
+ insights_client_ips.map { |ip_record| [ip_record['original'], ip_record['obfuscated']] }
95
+ ]
96
+
97
+ obfuscated_ips.default_proc = proc do |hash, key|
98
+ hash[key] = obfuscate_ip(key, hash)
99
+ end
100
+
101
+ obfuscated_ips
102
+ end
103
+
104
+ def obfuscate_ip(ip, ips_dict)
105
+ "10.230.230.#{ips_dict.count + 1}"
106
+ end
72
107
  end
73
108
  end
74
109
  end
@@ -26,8 +26,13 @@ module ForemanInventoryUpload
26
26
  @out << string
27
27
  end
28
28
 
29
- def simple_field(name, value, last = false)
30
- @out << "\"#{name}\": #{stringify_value(value)}#{last ? '' : ','}" unless value.nil?
29
+ def simple_field(name, value, last = false, &block)
30
+ return if value.nil? || value.try(:empty?)
31
+ return if value.kind_of?(Array) && value.compact.empty?
32
+
33
+ block ||= ->(value) { value }
34
+
35
+ @out << "\"#{name}\": #{stringify_value(block.call(value))}#{last ? '' : ','}"
31
36
  end
32
37
 
33
38
  def array_field(name, last = false, &block)
@@ -24,7 +24,9 @@ module ForemanInventoryUpload
24
24
  'dmi::system::product_name',
25
25
  'dmi::chassis::asset_tag',
26
26
  'insights_client::obfuscate_hostname_enabled',
27
+ 'insights_client::obfuscate_ip_enabled',
27
28
  'insights_client::hostname',
29
+ 'insights_client::ips',
28
30
  ]).pluck(:name, :id)
29
31
  ]
30
32
  end
@@ -40,6 +40,7 @@ module ForemanInventoryUpload
40
40
  end
41
41
 
42
42
  def report_host(host)
43
+ host_ips_cache = host_ips(host)
43
44
  @stream.object do
44
45
  @stream.simple_field('fqdn', fqdn(host))
45
46
  @stream.simple_field('account', account_id(host.organization).to_s)
@@ -47,10 +48,10 @@ module ForemanInventoryUpload
47
48
  @stream.simple_field('satellite_id', host.subscription_facet&.uuid)
48
49
  @stream.simple_field('bios_uuid', fact_value(host, 'dmi::system::uuid'))
49
50
  @stream.simple_field('vm_uuid', fact_value(host, 'virt::uuid'))
50
- report_ip_addresses(host)
51
+ report_ip_addresses(host, host_ips_cache)
51
52
  report_mac_addresses(host)
52
53
  @stream.object_field('system_profile') do
53
- report_system_profile(host)
54
+ report_system_profile(host, host_ips_cache)
54
55
  end
55
56
  @stream.array_field('facts') do
56
57
  @stream.object do
@@ -96,17 +97,17 @@ module ForemanInventoryUpload
96
97
  end
97
98
  end
98
99
 
99
- def report_system_profile(host)
100
- @stream.simple_field('number_of_cpus', fact_value(host, 'cpu::cpu(s)').to_i)
101
- @stream.simple_field('number_of_sockets', fact_value(host, 'cpu::cpu_socket(s)').to_i)
102
- @stream.simple_field('cores_per_socket', fact_value(host, 'cpu::core(s)_per_socket').to_i)
103
- @stream.simple_field('system_memory_bytes', kilobytes_to_bytes(fact_value(host, 'memory::memtotal').to_i))
100
+ def report_system_profile(host, host_ips_cache)
101
+ @stream.simple_field('number_of_cpus', fact_value(host, 'cpu::cpu(s)')) { |v| v.to_i }
102
+ @stream.simple_field('number_of_sockets', fact_value(host, 'cpu::cpu_socket(s)')) { |v| v.to_i }
103
+ @stream.simple_field('cores_per_socket', fact_value(host, 'cpu::core(s)_per_socket')) { |v| v.to_i }
104
+ @stream.simple_field('system_memory_bytes', fact_value(host, 'memory::memtotal')) { |v| kilobytes_to_bytes(v.to_i) }
104
105
  @stream.array_field('network_interfaces') do
105
106
  @stream.raw(host.interfaces.map do |nic|
106
107
  {
107
- 'ipv4_addresses': [nic.ip].compact,
108
+ 'ipv4_addresses': [host_ips_cache[nic.ip]].compact,
108
109
  'ipv6_addresses': [nic.ip6].compact,
109
- 'mtu': nic.try(:mtu),
110
+ 'mtu': nic.try(:mtu) && nic.mtu.to_i,
110
111
  'mac_address': nic.mac,
111
112
  'name': nic.identifier,
112
113
  }.compact.to_json
@@ -123,18 +124,16 @@ module ForemanInventoryUpload
123
124
  end
124
125
  end
125
126
  @stream.simple_field(
126
- 'os_release',
127
- os_release_value(
128
- name: fact_value(host, 'distribution::name'),
129
- version: fact_value(host, 'distribution::version'),
130
- codename: fact_value(host, 'distribution::id')
131
- )
132
- )
127
+ 'os_release', [
128
+ fact_value(host, 'distribution::name'),
129
+ fact_value(host, 'distribution::version'),
130
+ fact_value(host, 'distribution::id'),
131
+ ]
132
+ ) { |v| os_release_value(*v) }
133
133
  @stream.simple_field('os_kernel_version', fact_value(host, 'uname::release'))
134
134
  @stream.simple_field('arch', host.architecture&.name)
135
135
  @stream.simple_field('subscription_status', host.subscription_status_label)
136
136
  @stream.simple_field('katello_agent_running', host.content_facet&.katello_agent_installed?)
137
- @stream.simple_field('satellite_managed', true)
138
137
  @stream.simple_field(
139
138
  'infrastructure_type',
140
139
  ActiveModel::Type::Boolean.new.cast(fact_value(host, 'virt::is_guest')) ? 'virtual' : 'physical'
@@ -150,13 +149,16 @@ module ForemanInventoryUpload
150
149
  end.join(', '))
151
150
  end
152
151
  end
153
- @stream.array_field('installed_packages', :last) do
154
- first = true
155
- host.installed_packages.each do |package|
156
- @stream.raw("#{first ? '' : ', '}#{@stream.stringify_value(package.nvra)}")
157
- first = false
152
+ unless Setting[:exclude_installed_packages]
153
+ @stream.array_field('installed_packages') do
154
+ first = true
155
+ host.installed_packages.each do |package|
156
+ @stream.raw("#{first ? '' : ', '}#{@stream.stringify_value(package.nvra)}")
157
+ first = false
158
+ end
158
159
  end
159
160
  end
161
+ @stream.simple_field('satellite_managed', true, :last)
160
162
  end
161
163
 
162
164
  def report_satellite_facts(host)
@@ -175,8 +177,8 @@ module ForemanInventoryUpload
175
177
  @stream.simple_field('organization_id', host.organization_id, :last)
176
178
  end
177
179
 
178
- def report_ip_addresses(host)
179
- ip_addresses = host.interfaces.map { |nic| nic.ip }.compact
180
+ def report_ip_addresses(host, host_ips_cache)
181
+ ip_addresses = host.interfaces.map { |nic| host_ips_cache[nic.ip] }.compact
180
182
 
181
183
  @stream.string_array_value('ip_addresses', ip_addresses)
182
184
  end
@@ -187,7 +189,7 @@ module ForemanInventoryUpload
187
189
  @stream.string_array_value('mac_addresses', macs)
188
190
  end
189
191
 
190
- def os_release_value(name:, version:, codename:)
192
+ def os_release_value(name, version, codename)
191
193
  "#{name} #{version} (#{codename})"
192
194
  end
193
195
  end
@@ -28,7 +28,8 @@ module ForemanRhCloud
28
28
  def self.proxy_setting(logger: Foreman::Logging.logger('background'))
29
29
  HttpProxy.default_global_content_proxy&.full_url ||
30
30
  ForemanRhCloud.cdn_proxy(logger: logger) ||
31
- ForemanRhCloud.global_foreman_proxy
31
+ ForemanRhCloud.global_foreman_proxy ||
32
+ ''
32
33
  end
33
34
 
34
35
  def self.cdn_proxy(logger: Foreman::Logging.logger('app'))
@@ -13,6 +13,7 @@ module ForemanRhCloud
13
13
  config.autoload_paths += Dir["#{config.root}/app/helpers/concerns"]
14
14
  config.autoload_paths += Dir["#{config.root}/app/models/concerns"]
15
15
  config.autoload_paths += Dir["#{config.root}/app/overrides"]
16
+ config.autoload_paths += Dir["#{config.root}/app/services"]
16
17
  config.autoload_paths += Dir["#{config.root}/lib"]
17
18
 
18
19
  config.eager_load_paths += Dir["#{config.root}/lib"]
@@ -54,8 +55,8 @@ module ForemanRhCloud
54
55
 
55
56
  # Adding a sub menu after hosts menu
56
57
  divider :top_menu, caption: N_('RH Cloud'), parent: :configure_menu
57
- menu :top_menu, :inventory_upload, :caption => N_('Inventory Upload'), :url_hash => { controller: :'foreman_rh_cloud/react', :action => :inventory_upload}, parent: :configure_menu
58
- menu :top_menu, :insights_hits_import, :caption => N_('Insights'), :url_hash => { controller: :'foreman_rh_cloud/react', :action => :insights_cloud }, parent: :configure_menu
58
+ menu :top_menu, :inventory_upload, caption: N_('Inventory Upload'), url_hash: { controller: :'foreman_rh_cloud/react', action: :inventory_upload }, parent: :configure_menu
59
+ menu :top_menu, :insights_hits_import, caption: N_('Insights'), url_hash: { controller: :'foreman_rh_cloud/react', action: :insights_cloud }, parent: :configure_menu
59
60
 
60
61
  register_facet InsightsFacet, :insights do
61
62
  configure_host do
@@ -78,7 +79,6 @@ module ForemanRhCloud
78
79
  ::Katello::UINotifications::Subscriptions::ManifestImportSuccess.include ForemanInventoryUpload::Notifications::ManifestImportSuccessNotificationOverride if defined?(Katello)
79
80
 
80
81
  ::Host::Managed.include RhCloudHost
81
- ::Host::Base.include RhCloudHost
82
82
  end
83
83
 
84
84
  initializer "foreman_rh_cloud.set_dynflow.config.on_init", :before => :finisher_hook do |_app|
@@ -1,3 +1,3 @@
1
1
  module ForemanRhCloud
2
- VERSION = '2.0.12'.freeze
2
+ VERSION = '2.0.16'.freeze
3
3
  end
@@ -3,6 +3,8 @@ require 'rest-client'
3
3
  module InsightsCloud
4
4
  module Async
5
5
  class InsightsFullSync < ::ApplicationJob
6
+ include ::ForemanRhCloud::CloudAuth
7
+
6
8
  def perform
7
9
  hits = query_insights_hits
8
10
 
@@ -16,10 +18,6 @@ module InsightsCloud
16
18
  Foreman::Logging.logger('background')
17
19
  end
18
20
 
19
- def rh_credentials
20
- @rh_credentials ||= query_refresh_token
21
- end
22
-
23
21
  private
24
22
 
25
23
  def query_insights_hits
@@ -36,25 +34,6 @@ module InsightsCloud
36
34
  JSON.parse(hits_response)
37
35
  end
38
36
 
39
- def query_refresh_token
40
- token_response = RestClient::Request.execute(
41
- method: :post,
42
- url: ForemanRhCloud.authentication_url,
43
- verify_ssl: ForemanRhCloud.verify_ssl_method,
44
- proxy: ForemanRhCloud.transformed_http_proxy_string(logger: logger),
45
- payload: {
46
- grant_type: 'refresh_token',
47
- client_id: 'rhsm-api',
48
- refresh_token: Setting[:rh_cloud_token],
49
- }
50
- )
51
-
52
- JSON.parse(token_response)['access_token']
53
- rescue RestClient::ExceptionWithResponse => e
54
- Foreman::Logging.exception('Unable to authenticate using rh_cloud_token setting', e)
55
- raise ::Foreman::WrappedException.new(e, N_('Unable to authenticate using rh_cloud_token setting'))
56
- end
57
-
58
37
  def setup_host_names(host_names)
59
38
  @host_ids = Hash[
60
39
  Host.unscoped.where(name: host_names).pluck(:name, :id)
@@ -67,8 +46,6 @@ module InsightsCloud
67
46
 
68
47
  def replace_hits_data(hits)
69
48
  InsightsHit.transaction do
70
- InsightsHit.delete_all
71
- InsightsHit.create(hits.map { |hits_hash| to_model_hash(hits_hash) }.compact)
72
49
  # create new facets for hosts that are missing one
73
50
  hosts_with_existing_facets = InsightsFacet.where(host_id: @host_ids.values).pluck(:host_id)
74
51
  InsightsFacet.create(
@@ -81,6 +58,8 @@ module InsightsCloud
81
58
  end
82
59
  end.compact
83
60
  )
61
+ InsightsHit.delete_all
62
+ InsightsHit.create(hits.map { |hits_hash| to_model_hash(hits_hash) }.compact)
84
63
  end
85
64
  end
86
65
 
@@ -3,6 +3,8 @@ require 'rest-client'
3
3
  module InventorySync
4
4
  module Async
5
5
  class InventoryFullSync < ::ApplicationJob
6
+ include ::ForemanRhCloud::CloudAuth
7
+
6
8
  def perform(organization)
7
9
  @organization = organization
8
10
  @subscribed_hosts_ids = Set.new(
@@ -37,10 +39,6 @@ module InventorySync
37
39
  @host_statuses
38
40
  end
39
41
 
40
- def rh_credentials
41
- @rh_credentials ||= query_refresh_token
42
- end
43
-
44
42
  private
45
43
 
46
44
  def update_hosts_status(status_hashes, touched)
@@ -77,25 +75,6 @@ module InventorySync
77
75
 
78
76
  JSON.parse(hosts_inventory_response)
79
77
  end
80
-
81
- def query_refresh_token
82
- token_response = RestClient::Request.execute(
83
- method: :post,
84
- url: ForemanRhCloud.authentication_url,
85
- verify_ssl: ForemanRhCloud.verify_ssl_method,
86
- proxy: ForemanRhCloud.transformed_http_proxy_string(logger: logger),
87
- payload: {
88
- grant_type: 'refresh_token',
89
- client_id: 'rhsm-api',
90
- refresh_token: Setting[:rh_cloud_token],
91
- }
92
- )
93
-
94
- JSON.parse(token_response)['access_token']
95
- rescue RestClient::ExceptionWithResponse => e
96
- Foreman::Logging.exception('Unable to authenticate using rh_cloud_token setting', e)
97
- raise ::Foreman::WrappedException.new(e, N_('Unable to authenticate using rh_cloud_token setting'))
98
- end
99
78
  end
100
79
  end
101
80
  end
@@ -2,6 +2,21 @@ require 'tempfile'
2
2
 
3
3
  namespace :rh_cloud_inventory do
4
4
  namespace :report do
5
+ desc 'Generate inventory report and send it to Red Hat cloud'
6
+ task generate_upload: [:environment, 'dynflow:client'] do
7
+ unless ENV['organization_id'].nil?
8
+ organizations = [ Organization.where(:id => ENV['organization_id']).first ]
9
+ else
10
+ organizations = Organization.unscoped.all
11
+ end
12
+
13
+ User.as_anonymous_admin do
14
+ organizations.each do |organization|
15
+ ForemanInventoryUpload::Async::GenerateReportJob.perform_now(ForemanInventoryUpload.generated_reports_folder, organization.id)
16
+ puts "Generated and uploaded inventory report for organization '#{organization.name}'"
17
+ end
18
+ end
19
+ end
5
20
  desc 'Generate inventory report to be sent to Red Hat cloud'
6
21
  task generate: :environment do
7
22
  portal_user = ENV['portal_user']
@@ -27,6 +42,14 @@ namespace :rh_cloud_inventory do
27
42
  end
28
43
  end
29
44
  end
45
+ desc 'Upload generated inventory report to Red Hat cloud'
46
+ task upload: [:environment, 'dynflow:client'] do
47
+ base_folder = ENV['target'] || ForemanInventoryUpload.generated_reports_folder
48
+ organization_id = ENV['organization_id']
49
+ report_file = ForemanInventoryUpload.facts_archive_name(organization_id)
50
+ ForemanInventoryUpload::Async::QueueForUploadJob.perform_now(base_folder, report_file, organization_id)
51
+ puts "Uploaded #{report_file}"
52
+ end
30
53
  end
31
54
 
32
55
  desc "Synchronize Insights hosts hits"
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foreman_rh_cloud",
3
- "version": "2.0.12",
3
+ "version": "2.0.14",
4
4
  "description": "Inventory Upload =============",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -26,4 +26,26 @@ class FactHelpersTest < ActiveSupport::TestCase
26
26
 
27
27
  assert actual
28
28
  end
29
+
30
+ test 'obfuscates ips with insights-client data' do
31
+ host = mock('host')
32
+ @instance.expects(:fact_value).with(host, 'insights_client::ips').returns(
33
+ '[{"obfuscated": "10.230.230.1", "original": "224.0.0.1"}, {"obfuscated": "10.230.230.2", "original": "224.0.0.251"}]'
34
+ )
35
+
36
+ actual = @instance.obfuscated_ips(host)
37
+
38
+ assert_equal '10.230.230.1', actual['224.0.0.1']
39
+ assert_equal '10.230.230.3', actual['224.0.0.2']
40
+ end
41
+
42
+ test 'obfuscates ips without insights-client data' do
43
+ host = mock('host')
44
+ @instance.expects(:fact_value).with(host, 'insights_client::ips').returns(nil)
45
+
46
+ actual = @instance.obfuscated_ips(host)
47
+
48
+ assert_equal '10.230.230.1', actual['224.0.0.1']
49
+ assert_equal '10.230.230.2', actual['224.0.0.2']
50
+ end
29
51
  end