foreman_rh_cloud 0.9.11 → 0.9.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9a1ce84facb4e9281463d4f91b5a6082f87e1ef122bcde049b37427a21905dcc
4
- data.tar.gz: 402653f54c9b5ac26c79ab326c8f0aad91645a0f91869be550f2056847bdde37
3
+ metadata.gz: 4410aae42d90d765e8b16d784c50196a52b86b828f59272bd21baf163e7ab7c5
4
+ data.tar.gz: cef39240dfcf09f438b003bb9a9cf3e802ffd23a863fe7dd98485cfc0cb0db7f
5
5
  SHA512:
6
- metadata.gz: f36d854c682c3158599d5e18648ba365654deffa1ea35acd1601dda6801ebc28b57185c564766f31bde813c1f4f7c37644387c8a8f4f4d8685198a2e18c5b605
7
- data.tar.gz: a0825d23ebff413d07a72c850728b5d22f030e3fc4323440d97b87e64f6d2a568dd1f9b4ded362cae56a4888e9fe375dbf81ba294aae6374126bc3bd82ca1731
6
+ metadata.gz: a2d171f326d72a4d0eb1070b431a476f9a7eb2857ee108f726aeac752f78236a269a2d7387857ae83a1f3be1fb1d07ddbeeec3d8c7934d6c22f750a2bf290c4e
7
+ data.tar.gz: 1d1afc18d5614e1160ee48bdce951dfc2275126dcd7e9b5cd8a9771c61f7651920326e9d4c6faf7374b365abd21ebb882dd13b330fc3fc45d2bd75697c7eb37e
@@ -47,6 +47,8 @@ module ForemanInventoryUpload
47
47
  'FILES' => @filename,
48
48
  'CER_PATH' => @cer_path
49
49
  )
50
+
51
+ http_proxy_string = ForemanRhCloud.http_proxy_string(logger: logger)
50
52
  if http_proxy_string
51
53
  env_vars['http_proxy'] = http_proxy_string
52
54
  env_vars['https_proxy'] = http_proxy_string
@@ -54,14 +56,6 @@ module ForemanInventoryUpload
54
56
  env_vars
55
57
  end
56
58
 
57
- def http_proxy_string
58
- @http_proxy_string ||= begin
59
- if Setting[:content_default_http_proxy]
60
- HttpProxy.unscoped.find_by(name: Setting[:content_default_http_proxy])&.full_url
61
- end
62
- end
63
- end
64
-
65
59
  def rh_credentials
66
60
  @rh_credentials ||= begin
67
61
  candlepin_id_certificate = @organization.owner_details['upstreamConsumer']['idCert']
@@ -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,55 @@ 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
+ ForemanRhCloud.cdn_proxy(logger: logger) ||
30
+ ForemanRhCloud.global_foreman_proxy
31
+ end
32
+
33
+ def self.cdn_proxy(logger: Foreman::Logging.logger('app'))
34
+ proxy_config = SETTINGS[:katello][:cdn_proxy]
35
+ return nil unless proxy_config
36
+
37
+ uri = URI('')
38
+ uri.host = proxy_config[:host]
39
+ uri.port = proxy_config[:port]
40
+ uri.scheme = proxy_config[:scheme] || 'http'
41
+
42
+ if proxy_config[:user]
43
+ uri.user = CGI.escape(proxy_config[:user])
44
+ uri.password = CGI.escape(proxy_config[:password])
45
+ end
46
+ uri.to_s
47
+ rescue URI::Error => e
48
+ logger.warn("cdn_proxy parsing failed: #{e}")
49
+ nil
50
+ end
51
+
52
+ def self.global_foreman_proxy
53
+ Setting[:http_proxy]
54
+ end
55
+
56
+ # This method assumes uri_string contains uri-encoded username and p@$$word:
57
+ # http://user:p%40%24%24word@localhost:8888
58
+ def self.transform_scheme(uri_string)
59
+ transformed_uri = URI.parse(uri_string)
60
+
61
+ case transformed_uri.scheme
62
+ when "http"
63
+ transformed_uri.scheme = 'proxy'
64
+ when "https"
65
+ transformed_uri.scheme = 'proxys'
66
+ end
67
+
68
+ transformed_uri.to_s
69
+ end
17
70
  end
@@ -1,3 +1,3 @@
1
1
  module ForemanRhCloud
2
- VERSION = '0.9.11'.freeze
2
+ VERSION = '0.9.12'.freeze
3
3
  end
@@ -27,6 +27,7 @@ module InsightsCloud
27
27
  method: :get,
28
28
  url: InsightsCloud.hits_export_url,
29
29
  verify_ssl: ForemanRhCloud.verify_ssl_method,
30
+ proxy: ForemanRhCloud.transformed_http_proxy_string(logger: logger),
30
31
  headers: {
31
32
  Authorization: "Bearer #{rh_credentials}",
32
33
  }
@@ -40,6 +41,7 @@ module InsightsCloud
40
41
  method: :post,
41
42
  url: ForemanRhCloud.authentication_url,
42
43
  verify_ssl: ForemanRhCloud.verify_ssl_method,
44
+ proxy: ForemanRhCloud.transformed_http_proxy_string(logger: logger),
43
45
  payload: {
44
46
  grant_type: 'refresh_token',
45
47
  client_id: 'rhsm-api',
@@ -65,6 +65,7 @@ module InventorySync
65
65
  method: :get,
66
66
  url: ForemanInventoryUpload.inventory_export_url,
67
67
  verify_ssl: ForemanRhCloud.verify_ssl_method,
68
+ proxy: ForemanRhCloud.transformed_http_proxy_string(logger: logger),
68
69
  headers: {
69
70
  Authorization: "Bearer #{rh_credentials}",
70
71
  params: {
@@ -82,6 +83,7 @@ module InventorySync
82
83
  method: :post,
83
84
  url: ForemanRhCloud.authentication_url,
84
85
  verify_ssl: ForemanRhCloud.verify_ssl_method,
86
+ proxy: ForemanRhCloud.transformed_http_proxy_string(logger: logger),
85
87
  payload: {
86
88
  grant_type: 'refresh_token',
87
89
  client_id: 'rhsm-api',
@@ -12,17 +12,19 @@ namespace :rh_cloud_inventory do
12
12
  puts "Must specify either portal_user or organization_id"
13
13
  end
14
14
 
15
- if portal_user
16
- puts "Generating report for all organizations associated with #{portal_user}"
17
- base_folder = File.join(base_folder, portal_user)
18
- organizations = ForemanInventoryUpload::Generators::Queries.organizations_for_user(portal_user).pluck(:id)
19
- end
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
20
21
 
21
- organizations.each do |organization|
22
- target = File.join(base_folder, ForemanInventoryUpload.facts_archive_name(organization))
23
- archived_report_generator = ForemanInventoryUpload::Generators::ArchivedReport.new(target, Logger.new(STDOUT))
24
- archived_report_generator.render(organization: organization)
25
- puts "Successfully generated #{target} for organization id #{organization}"
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
26
28
  end
27
29
  end
28
30
  end
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foreman_rh_cloud",
3
- "version": "0.9.11",
3
+ "version": "0.9.12",
4
4
  "description": "Inventory Upload =============",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,52 @@
1
+ require 'test_plugin_helper'
2
+
3
+ class RhCloudHttpProxyTest < ActiveSupport::TestCase
4
+ setup do
5
+ @global_foreman_proxy_mock = 'http://global:foreman@localhost:8888'
6
+ @katello_cdn_proxy_mock = {
7
+ host: 'localhost',
8
+ port: '8888',
9
+ user: 'katello',
10
+ password: 'cdn',
11
+ scheme: 'http',
12
+ }
13
+ @katello_cdn_proxy_string_mock = 'http://katello:cdn@localhost:8888'
14
+ end
15
+
16
+ test 'selects cdn proxy' do
17
+ setup_global_foreman_proxy
18
+
19
+ setup_cdn_proxy do
20
+ assert_equal @katello_cdn_proxy_string_mock, ForemanRhCloud.proxy_setting
21
+ end
22
+ end
23
+
24
+ test 'selects global foreman proxy' do
25
+ setup_global_foreman_proxy
26
+
27
+ assert_equal @global_foreman_proxy_mock, ForemanRhCloud.proxy_setting
28
+ end
29
+
30
+ def setup_global_foreman_proxy
31
+ FactoryBot.create(:setting, :name => 'http_proxy', :value => @global_foreman_proxy_mock)
32
+ end
33
+
34
+ def setup_cdn_proxy
35
+ old_cdn_setting = SETTINGS[:katello][:cdn_proxy]
36
+ SETTINGS[:katello][:cdn_proxy] = @katello_cdn_proxy_mock
37
+ yield
38
+ ensure
39
+ SETTINGS[:katello][:cdn_proxy] = old_cdn_setting
40
+ end
41
+
42
+ test 'transform proxy scheme test' do
43
+ mock_http_proxy = 'http://user:password@localhost:8888'
44
+ mock_https_proxy = 'https://user:password@localhost:8888'
45
+
46
+ transformed_http_uri = URI.parse(ForemanRhCloud.transform_scheme(mock_http_proxy))
47
+ transformed_https_uri = URI.parse(ForemanRhCloud.transform_scheme(mock_https_proxy))
48
+
49
+ assert_equal 'proxy', transformed_http_uri.scheme
50
+ assert_equal 'proxys', transformed_https_uri.scheme
51
+ end
52
+ end
@@ -147,6 +147,10 @@ class ReportGeneratorTest < ActiveSupport::TestCase
147
147
  end
148
148
 
149
149
  test 'generates a report with satellite facts' do
150
+ hostgroup = FactoryBot.create(:hostgroup)
151
+ @host.hostgroup = hostgroup
152
+ @host.save!
153
+
150
154
  Foreman.expects(:instance_id).twice.returns('satellite-id')
151
155
  batch = Host.where(id: @host.id).in_batches.first
152
156
  generator = create_generator(batch)
@@ -166,6 +170,7 @@ class ReportGeneratorTest < ActiveSupport::TestCase
166
170
  assert_tag(@host.content_view.name, actual_host, 'content_view')
167
171
  assert_tag(@host.location.name, actual_host, 'location')
168
172
  assert_tag(@host.organization.name, actual_host, 'organization')
173
+ assert_tag(@host.hostgroup.name, actual_host, 'hostgroup')
169
174
 
170
175
  assert_equal false, satellite_facts['is_hostname_obfuscated']
171
176
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_rh_cloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.11
4
+ version: 0.9.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Foreman Red Hat Cloud team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-16 00:00:00.000000000 Z
11
+ date: 2020-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: katello
@@ -146,6 +146,7 @@ files:
146
146
  - test/unit/fact_helpers_test.rb
147
147
  - test/unit/insights_facet_test.rb
148
148
  - test/unit/metadata_generator_test.rb
149
+ - test/unit/rh_cloud_http_proxy_test.rb
149
150
  - test/unit/shell_process_job_test.rb
150
151
  - test/unit/slice_generator_test.rb
151
152
  - webpack/ForemanInventoryUpload/Components/AccountList/AccountList.fixtures.js
@@ -494,24 +495,25 @@ required_rubygems_version: !ruby/object:Gem::Requirement
494
495
  - !ruby/object:Gem::Version
495
496
  version: '0'
496
497
  requirements: []
497
- rubygems_version: 3.0.8
498
+ rubygems_version: 3.0.6
498
499
  signing_key:
499
500
  specification_version: 4
500
501
  summary: Summary of ForemanRhCloud.
501
502
  test_files:
503
+ - test/controllers/uploads_controller_test.rb
504
+ - test/controllers/insights_sync/settings_controller_test.rb
505
+ - test/controllers/accounts_controller_test.rb
506
+ - test/controllers/reports_controller_test.rb
502
507
  - test/test_plugin_helper.rb
508
+ - test/jobs/upload_report_job_test.rb
509
+ - test/jobs/insights_full_sync_test.rb
510
+ - test/jobs/inventory_full_sync_test.rb
503
511
  - test/factories/inventory_upload_factories.rb
504
512
  - test/factories/insights_factories.rb
505
- - test/controllers/reports_controller_test.rb
506
- - test/controllers/uploads_controller_test.rb
507
- - test/controllers/accounts_controller_test.rb
508
- - test/controllers/insights_sync/settings_controller_test.rb
509
- - test/unit/slice_generator_test.rb
510
- - test/unit/metadata_generator_test.rb
511
513
  - test/unit/shell_process_job_test.rb
514
+ - test/unit/metadata_generator_test.rb
512
515
  - test/unit/insights_facet_test.rb
513
- - test/unit/archived_report_generator_test.rb
516
+ - test/unit/rh_cloud_http_proxy_test.rb
514
517
  - test/unit/fact_helpers_test.rb
515
- - test/jobs/inventory_full_sync_test.rb
516
- - test/jobs/insights_full_sync_test.rb
517
- - test/jobs/upload_report_job_test.rb
518
+ - test/unit/archived_report_generator_test.rb
519
+ - test/unit/slice_generator_test.rb