foreman_rh_cloud 1.0.10 → 1.0.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +33 -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/controllers/insights_cloud/hits_controller.rb +17 -0
  6. data/app/helpers/foreman_inventory_upload_host_helper.rb +2 -3
  7. data/app/models/concerns/rh_cloud_host.rb +15 -0
  8. data/app/models/insights_hit.rb +1 -1
  9. data/app/models/setting/rh_cloud.rb +2 -0
  10. data/app/overrides/hosts_list.rb +1 -1
  11. data/app/services/foreman_rh_cloud/cloud_auth.rb +28 -0
  12. data/app/views/hosts/_insights_tab.html.erb +15 -0
  13. data/config/routes.rb +3 -0
  14. data/db/migrate/20201007115752_add_hits_count_to_insights_facets_table.foreman_rh_cloud.rb +5 -0
  15. data/db/migrate/20201007121540_setup_hits_count_cache.foreman_rh_cloud.rb +10 -0
  16. data/lib/foreman_inventory_upload/async/generate_report_job.rb +1 -1
  17. data/lib/foreman_inventory_upload/async/shell_process.rb +15 -9
  18. data/lib/foreman_inventory_upload/async/upload_report_job.rb +21 -9
  19. data/lib/foreman_inventory_upload/generators/fact_helpers.rb +35 -0
  20. data/lib/foreman_inventory_upload/generators/json_stream.rb +7 -2
  21. data/lib/foreman_inventory_upload/generators/metadata.rb +3 -0
  22. data/lib/foreman_inventory_upload/generators/queries.rb +4 -4
  23. data/lib/foreman_inventory_upload/generators/slice.rb +27 -25
  24. data/lib/foreman_rh_cloud.rb +55 -0
  25. data/lib/foreman_rh_cloud/engine.rb +13 -2
  26. data/lib/foreman_rh_cloud/version.rb +1 -1
  27. data/lib/insights_cloud/async/insights_full_sync.rb +5 -24
  28. data/lib/inventory_sync/async/inventory_full_sync.rb +3 -22
  29. data/lib/tasks/insights.rake +15 -0
  30. data/lib/tasks/rh_cloud_inventory.rake +37 -0
  31. data/package.json +3 -1
  32. data/test/jobs/upload_report_job_test.rb +34 -0
  33. data/test/unit/fact_helpers_test.rb +22 -0
  34. data/test/unit/insights_facet_test.rb +7 -0
  35. data/test/unit/metadata_generator_test.rb +2 -0
  36. data/test/unit/rh_cloud_http_proxy_test.rb +65 -0
  37. data/test/unit/slice_generator_test.rb +167 -2
  38. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountList.fixtures.js +14 -1
  39. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListActions.js +22 -18
  40. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListReducer.js +16 -0
  41. data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListSelectors.js +6 -0
  42. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListActions.test.js +7 -0
  43. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListReducer.test.js +12 -8
  44. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListSelectors.test.js +9 -0
  45. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListActions.test.js.snap +19 -0
  46. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListReducer.test.js.snap +11 -0
  47. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListSelectors.test.js.snap +6 -0
  48. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/AutoUploadSwitcher.fixtures.js +2 -0
  49. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/AutoUploadSwitcherActions.js +10 -11
  50. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/AutoUploadSwitcherConstants.js +0 -1
  51. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/__tests__/AutoUploadSwitcherActions.test.js +12 -2
  52. data/webpack/ForemanInventoryUpload/Components/AutoUploadSwitcher/__tests__/__snapshots__/AutoUploadSwitcherActions.test.js.snap +17 -0
  53. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/ExcludePackagesSwitcher.fixtures.js +1 -0
  54. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/ExcludePackagesSwitcher.js +30 -0
  55. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/ExcludePackagesSwitcherActions.js +29 -0
  56. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/ExcludePackagesSwitcherConstants.js +1 -0
  57. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/__tests__/ExcludePackagesSwitcher.test.js +13 -0
  58. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/__tests__/ExcludePackagesSwitcherActions.test.js +21 -0
  59. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/__tests__/__snapshots__/ExcludePackagesSwitcher.test.js.snap +38 -0
  60. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/__tests__/__snapshots__/ExcludePackagesSwitcherActions.test.js.snap +31 -0
  61. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/__tests__/__snapshots__/integration.test.js.snap +41 -0
  62. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/__tests__/integration.test.js +38 -0
  63. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/excludePackagesSwitcher.scss +3 -0
  64. data/webpack/ForemanInventoryUpload/Components/ExcludePackagesSwitcher/index.js +20 -0
  65. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/HostObfuscationSwitcher.fixtures.js +2 -1
  66. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/HostObfuscationSwitcher.js +1 -0
  67. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/HostObfuscationSwitcher.scss +3 -0
  68. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/HostObfuscationSwitcherActions.js +10 -11
  69. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/HostObfuscationSwitcherConstants.js +0 -2
  70. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/__tests__/HostObfuscationSwitcherActions.test.js +12 -2
  71. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/__tests__/__snapshots__/HostObfuscationSwitcherActions.test.js.snap +18 -1
  72. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/__snapshots__/integration.test.js.snap +3 -0
  73. data/webpack/ForemanInventoryUpload/Components/InventorySettings/InventorySettings.js +4 -0
  74. data/webpack/ForemanInventoryUpload/Components/InventorySettings/__tests__/__snapshots__/InventorySettings.test.js.snap +2 -0
  75. data/webpack/ForemanInventoryUpload/Components/IpsObfuscationSwitcher/IpsObfuscationSwitcher.fixtures.js +1 -0
  76. data/webpack/ForemanInventoryUpload/Components/IpsObfuscationSwitcher/IpsObfuscationSwitcher.js +29 -0
  77. data/webpack/ForemanInventoryUpload/Components/IpsObfuscationSwitcher/IpsObfuscationSwitcherActions.js +29 -0
  78. data/webpack/ForemanInventoryUpload/Components/IpsObfuscationSwitcher/IpsObfuscationSwitcherConstants.js +1 -0
  79. data/webpack/ForemanInventoryUpload/Components/IpsObfuscationSwitcher/__tests__/IpsObfuscationSwitcher.test.js +13 -0
  80. data/webpack/ForemanInventoryUpload/Components/IpsObfuscationSwitcher/__tests__/IpsObfuscationSwitcherActions.test.js +21 -0
  81. data/webpack/ForemanInventoryUpload/Components/IpsObfuscationSwitcher/__tests__/__snapshots__/IpsObfuscationSwitcher.test.js.snap +38 -0
  82. data/webpack/ForemanInventoryUpload/Components/IpsObfuscationSwitcher/__tests__/__snapshots__/IpsObfuscationSwitcherActions.test.js.snap +31 -0
  83. data/webpack/ForemanInventoryUpload/Components/IpsObfuscationSwitcher/index.js +20 -0
  84. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButton.js +8 -2
  85. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js +9 -11
  86. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonConstants.js +1 -1
  87. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonReducer.js +2 -2
  88. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/SyncButtonActions.test.js +18 -0
  89. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/SyncButtonReducer.test.js +1 -8
  90. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/SyncButtonActions.test.js.snap +62 -0
  91. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/SyncButtonReducer.test.js.snap +0 -7
  92. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/components/Modal.js +2 -2
  93. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/components/Toast.js +1 -1
  94. data/webpack/ForemanInventoryUpload/Components/StatusChart/StatusChart.js +1 -1
  95. data/webpack/ForemanInventoryUpload/Components/StatusChart/__tests__/__snapshots__/StatusChart.test.js.snap +1 -1
  96. data/webpack/ForemanInventoryUpload/Components/TabContainer/tabContainer.scss +1 -1
  97. data/webpack/ForemanInventoryUpload/Components/TabHeader/TabHeader.js +6 -1
  98. data/webpack/ForemanInventoryUpload/Components/Terminal/Terminal.js +2 -4
  99. data/webpack/ForemanInventoryUpload/ForemanInventoryHelpers.js +8 -0
  100. data/webpack/ForemanRhCloudPages.js +2 -0
  101. data/webpack/ForemanRhCloudReducers.js +2 -0
  102. data/webpack/ForemanRhCloudSelectors.js +5 -0
  103. data/webpack/ForemanRhCloudTestHelpers.js +6 -1
  104. data/webpack/InsightsCloudSync/Components/InsightsSettings/InsightsSettingsActions.js +17 -20
  105. data/webpack/InsightsCloudSync/Components/InsightsSettings/InsightsSettingsConstants.js +0 -6
  106. data/webpack/InsightsCloudSync/Components/InsightsSettings/InsightsSettingsReducer.js +0 -4
  107. data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsActions.test.js +16 -0
  108. data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsReducer.test.js +1 -24
  109. data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/__snapshots__/InsightsSettingsActions.test.js.snap +38 -4
  110. data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/__snapshots__/InsightsSettingsReducer.test.js.snap +0 -14
  111. data/webpack/InsightsCloudSync/InsightsCloudSync.js +1 -1
  112. data/webpack/InsightsCloudSync/InsightsCloudSyncActions.js +10 -11
  113. data/webpack/InsightsCloudSync/InsightsCloudSyncConstants.js +0 -2
  114. data/webpack/InsightsCloudSync/__snapshots__/InsightsCloudSync.test.js.snap +1 -1
  115. data/webpack/InsightsHostDetailsTab/InsightsTab.js +64 -0
  116. data/webpack/InsightsHostDetailsTab/InsightsTab.scss +86 -0
  117. data/webpack/InsightsHostDetailsTab/InsightsTabActions.js +31 -0
  118. data/webpack/InsightsHostDetailsTab/InsightsTabConstants.js +2 -0
  119. data/webpack/InsightsHostDetailsTab/InsightsTabReducer.js +19 -0
  120. data/webpack/InsightsHostDetailsTab/InsightsTabSelectors.js +3 -0
  121. data/webpack/InsightsHostDetailsTab/__tests__/InsightsTab.fixtures.js +25 -0
  122. data/webpack/InsightsHostDetailsTab/__tests__/InsightsTab.test.js +13 -0
  123. data/webpack/InsightsHostDetailsTab/__tests__/InsightsTabActions.test.js +19 -0
  124. data/webpack/InsightsHostDetailsTab/__tests__/InsightsTabIntegration.test.js +17 -0
  125. data/webpack/InsightsHostDetailsTab/__tests__/InsightsTabReducer.test.js +26 -0
  126. data/webpack/InsightsHostDetailsTab/__tests__/InsightsTabSelectors.test.js +13 -0
  127. data/webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTab.test.js.snap +30 -0
  128. data/webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTabActions.test.js.snap +58 -0
  129. data/webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTabReducer.test.js.snap +34 -0
  130. data/webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTabSelectors.test.js.snap +20 -0
  131. data/webpack/InsightsHostDetailsTab/components/ListItem/ListItem.js +69 -0
  132. data/webpack/InsightsHostDetailsTab/components/ListItem/index.js +1 -0
  133. data/webpack/InsightsHostDetailsTab/index.js +20 -0
  134. data/webpack/__tests__/__snapshots__/ForemanRhCloudSelectors.test.js.snap +1 -0
  135. data/webpack/__tests__/__snapshots__/ForemanRhCloudTestHelpers.test.js.snap +3 -0
  136. data/webpack/stories/decorators/withCardsDecorator.js +1 -1
  137. metadata +67 -16
  138. data/lib/tasks/generator.rake +0 -29
  139. data/webpack/ForemanInventoryUpload/Components/HostObfuscationSwitcher/hostObfuscationSwitcher.scss +0 -0
@@ -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
@@ -1,4 +1,6 @@
1
1
  require 'foreman_rh_cloud/engine.rb'
2
+ require 'cgi'
3
+ require 'uri'
2
4
 
3
5
  module ForemanRhCloud
4
6
  def self.base_url
@@ -14,4 +16,57 @@ module ForemanRhCloud
14
16
  def self.verify_ssl_method
15
17
  @verify_ssl_method ||= ENV['SATELLITE_RH_CLOUD_URL'] ? OpenSSL::SSL::VERIFY_NONE : OpenSSL::SSL::VERIFY_PEER
16
18
  end
19
+
20
+ def self.http_proxy_string(logger: Foreman::Logging.logger('background'))
21
+ ForemanRhCloud.proxy_setting(logger: logger)
22
+ end
23
+
24
+ def self.transformed_http_proxy_string(logger: Foreman::Logging.logger('background'))
25
+ ForemanRhCloud.transform_scheme(ForemanRhCloud.proxy_setting(logger: logger))
26
+ end
27
+
28
+ def self.proxy_setting(logger: Foreman::Logging.logger('background'))
29
+ HttpProxy.default_global_content_proxy&.full_url ||
30
+ ForemanRhCloud.cdn_proxy(logger: logger) ||
31
+ ForemanRhCloud.global_foreman_proxy ||
32
+ ''
33
+ end
34
+
35
+ def self.cdn_proxy(logger: Foreman::Logging.logger('app'))
36
+ proxy_config = SETTINGS[:katello][:cdn_proxy]
37
+ return nil unless proxy_config
38
+
39
+ uri = URI('')
40
+ uri.host = proxy_config[:host]
41
+ uri.port = proxy_config[:port]
42
+ uri.scheme = proxy_config[:scheme] || 'http'
43
+
44
+ if proxy_config[:user]
45
+ uri.user = CGI.escape(proxy_config[:user])
46
+ uri.password = CGI.escape(proxy_config[:password])
47
+ end
48
+ uri.to_s
49
+ rescue URI::Error => e
50
+ logger.warn("cdn_proxy parsing failed: #{e}")
51
+ nil
52
+ end
53
+
54
+ def self.global_foreman_proxy
55
+ Setting[:http_proxy]
56
+ end
57
+
58
+ # This method assumes uri_string contains uri-encoded username and p@$$word:
59
+ # http://user:p%40%24%24word@localhost:8888
60
+ def self.transform_scheme(uri_string)
61
+ transformed_uri = URI.parse(uri_string)
62
+
63
+ case transformed_uri.scheme
64
+ when "http"
65
+ transformed_uri.scheme = 'proxy'
66
+ when "https"
67
+ transformed_uri.scheme = 'proxys'
68
+ end
69
+
70
+ transformed_uri.to_s
71
+ end
17
72
  end
@@ -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
@@ -66,9 +67,19 @@ module ForemanRhCloud
66
67
  register_global_js_file 'subscriptions_extension'
67
68
 
68
69
  register_custom_status(InventorySync::InventoryStatus)
70
+
71
+ extend_page 'hosts/show' do |context|
72
+ context.add_pagelet :main_tabs,
73
+ partial: 'hosts/insights_tab',
74
+ name: _('Insights'),
75
+ onlyif: proc { |host| host.insights }
76
+ end
69
77
  end
70
78
 
71
79
  ::Katello::UINotifications::Subscriptions::ManifestImportSuccess.include ForemanInventoryUpload::Notifications::ManifestImportSuccessNotificationOverride if defined?(Katello)
80
+
81
+ ::Host::Managed.include RhCloudHost
82
+ ::Host::Base.include RhCloudHost
72
83
  end
73
84
 
74
85
  initializer "foreman_rh_cloud.set_dynflow.config.on_init", :before => :finisher_hook do |_app|
@@ -1,3 +1,3 @@
1
1
  module ForemanRhCloud
2
- VERSION = '1.0.10'.freeze
2
+ VERSION = '1.0.14'.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
@@ -27,6 +25,7 @@ module InsightsCloud
27
25
  method: :get,
28
26
  url: InsightsCloud.hits_export_url,
29
27
  verify_ssl: ForemanRhCloud.verify_ssl_method,
28
+ proxy: ForemanRhCloud.transformed_http_proxy_string(logger: logger),
30
29
  headers: {
31
30
  Authorization: "Bearer #{rh_credentials}",
32
31
  }
@@ -35,24 +34,6 @@ module InsightsCloud
35
34
  JSON.parse(hits_response)
36
35
  end
37
36
 
38
- def query_refresh_token
39
- token_response = RestClient::Request.execute(
40
- method: :post,
41
- url: ForemanRhCloud.authentication_url,
42
- verify_ssl: ForemanRhCloud.verify_ssl_method,
43
- payload: {
44
- grant_type: 'refresh_token',
45
- client_id: 'rhsm-api',
46
- refresh_token: Setting[:rh_cloud_token],
47
- }
48
- )
49
-
50
- JSON.parse(token_response)['access_token']
51
- rescue RestClient::ExceptionWithResponse => e
52
- Foreman::Logging.exception('Unable to authenticate using rh_cloud_token setting', e)
53
- raise ::Foreman::WrappedException.new(e, N_('Unable to authenticate using rh_cloud_token setting'))
54
- end
55
-
56
37
  def setup_host_names(host_names)
57
38
  @host_ids = Hash[
58
39
  Host.unscoped.where(name: host_names).pluck(:name, :id)
@@ -65,8 +46,6 @@ module InsightsCloud
65
46
 
66
47
  def replace_hits_data(hits)
67
48
  InsightsHit.transaction do
68
- InsightsHit.delete_all
69
- InsightsHit.create(hits.map { |hits_hash| to_model_hash(hits_hash) }.compact)
70
49
  # create new facets for hosts that are missing one
71
50
  hosts_with_existing_facets = InsightsFacet.where(host_id: @host_ids.values).pluck(:host_id)
72
51
  InsightsFacet.create(
@@ -79,6 +58,8 @@ module InsightsCloud
79
58
  end
80
59
  end.compact
81
60
  )
61
+ InsightsHit.delete_all
62
+ InsightsHit.create(hits.map { |hits_hash| to_model_hash(hits_hash) }.compact)
82
63
  end
83
64
  end
84
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)
@@ -65,6 +63,7 @@ module InventorySync
65
63
  method: :get,
66
64
  url: ForemanInventoryUpload.inventory_export_url,
67
65
  verify_ssl: ForemanRhCloud.verify_ssl_method,
66
+ proxy: ForemanRhCloud.transformed_http_proxy_string(logger: logger),
68
67
  headers: {
69
68
  Authorization: "Bearer #{rh_credentials}",
70
69
  params: {
@@ -76,24 +75,6 @@ module InventorySync
76
75
 
77
76
  JSON.parse(hosts_inventory_response)
78
77
  end
79
-
80
- def query_refresh_token
81
- token_response = RestClient::Request.execute(
82
- method: :post,
83
- url: ForemanRhCloud.authentication_url,
84
- verify_ssl: ForemanRhCloud.verify_ssl_method,
85
- payload: {
86
- grant_type: 'refresh_token',
87
- client_id: 'rhsm-api',
88
- refresh_token: Setting[:rh_cloud_token],
89
- }
90
- )
91
-
92
- JSON.parse(token_response)['access_token']
93
- rescue RestClient::ExceptionWithResponse => e
94
- Foreman::Logging.exception('Unable to authenticate using rh_cloud_token setting', e)
95
- raise ::Foreman::WrappedException.new(e, N_('Unable to authenticate using rh_cloud_token setting'))
96
- end
97
78
  end
98
79
  end
99
80
  end
@@ -0,0 +1,15 @@
1
+ namespace :rh_cloud_insights do
2
+ desc "Synchronize Insights inventory"
3
+ task sync: :environment do
4
+ if ! ENV['organization_id'].nil?
5
+ organizations = [ Organization.where(:id => ENV['organization_id']).first ]
6
+ else
7
+ organizations = Organization.all
8
+ end
9
+
10
+ organizations.each do |organization|
11
+ InventorySync::Async::InventoryFullSync.perform_now(organization)
12
+ puts "Synchronized inventory for organization '#{organization.name}'"
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,37 @@
1
+ require 'tempfile'
2
+
3
+ namespace :rh_cloud_inventory do
4
+ namespace :report do
5
+ desc 'Generate inventory report to be sent to Red Hat cloud'
6
+ task generate: :environment do
7
+ portal_user = ENV['portal_user']
8
+ organizations = [ENV['organization_id']]
9
+ base_folder = ENV['target'] || Dir.pwd
10
+
11
+ unless portal_user || organizations.empty?
12
+ puts "Must specify either portal_user or organization_id"
13
+ end
14
+
15
+ User.as_anonymous_admin do
16
+ if portal_user
17
+ puts "Generating report for all organizations associated with #{portal_user}"
18
+ base_folder = File.join(base_folder, portal_user)
19
+ organizations = ForemanInventoryUpload::Generators::Queries.organizations_for_user(portal_user).pluck(:id)
20
+ end
21
+
22
+ organizations.each do |organization|
23
+ target = File.join(base_folder, ForemanInventoryUpload.facts_archive_name(organization))
24
+ archived_report_generator = ForemanInventoryUpload::Generators::ArchivedReport.new(target, Logger.new(STDOUT))
25
+ archived_report_generator.render(organization: organization)
26
+ puts "Successfully generated #{target} for organization id #{organization}"
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ desc "Synchronize Insights hosts hits"
33
+ task sync: :environment do
34
+ InsightsCloud::Async::InsightsFullSync.perform_now()
35
+ puts "Synchronized Insights hosts hits data"
36
+ end
37
+ end
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foreman_rh_cloud",
3
- "version": "0.0.1",
3
+ "version": "1.0.14",
4
4
  "description": "Inventory Upload =============",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -47,6 +47,8 @@
47
47
  "eslint": "^4.10.0",
48
48
  "eslint-import-resolver-babel-module": "^4.0.0",
49
49
  "eslint-plugin-patternfly-react": "0.2.0",
50
+ "eslint-plugin-promise": "^4.2.1",
51
+ "eslint-plugin-spellcheck": "^0.0.17",
50
52
  "identity-obj-proxy": "^3.0.0",
51
53
  "jed": "^1.1.1",
52
54
  "jest-cli": "^23.6.0",
@@ -0,0 +1,34 @@
1
+ require 'test_plugin_helper'
2
+
3
+ class UploadReportJobTest < ActiveJob::TestCase
4
+ include FolderIsolation
5
+
6
+ test 'returns aborted state when disconnected' do
7
+ organization = FactoryBot.create(:organization)
8
+ Organization.any_instance.stubs(:owner_details).returns(
9
+ 'upstreamConsumer' => {
10
+ 'idCert' => 'TEST_CERT',
11
+ }
12
+ )
13
+ FactoryBot.create(:setting, :name => 'content_disconnected', :value => true)
14
+
15
+ ForemanInventoryUpload::Async::UploadReportJob.perform_now('', organization.id)
16
+
17
+ label = ForemanInventoryUpload::Async::UploadReportJob.output_label(organization.id)
18
+ progress_output = ForemanInventoryUpload::Async::ProgressOutput.get(label)
19
+ assert_match(/Upload was stopped/, progress_output.full_output)
20
+ assert_match(/exit 1/, progress_output.status)
21
+ end
22
+
23
+ test 'returns aborted state when no certificate defined on organization' do
24
+ organization = FactoryBot.create(:organization)
25
+ Organization.any_instance.expects(:owner_details).returns(nil)
26
+
27
+ ForemanInventoryUpload::Async::UploadReportJob.perform_now('', organization.id)
28
+
29
+ label = ForemanInventoryUpload::Async::UploadReportJob.output_label(organization.id)
30
+ progress_output = ForemanInventoryUpload::Async::ProgressOutput.get(label)
31
+ assert_match(/Skipping organization/, progress_output.full_output)
32
+ assert_match(/exit 1/, progress_output.status)
33
+ end
34
+ end