foreman_rh_cloud 2.0.11 → 2.0.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: beb9afa713376417b3673803766cb7502efeabb52640e5d4a392eadf75b0f1b3
4
- data.tar.gz: 1ee3c8b02c4748412ebdbc1547278460d19ced4fddfb55c913ecc38e07e71d2b
3
+ metadata.gz: 32e82a148a80e18485bbcc80e69715ad4cbda072aaf6e011e18030212461aa4e
4
+ data.tar.gz: 9294a0e1779a60bfa568c0413f9f3c84ab464a563cb36060798637b97f2adcff
5
5
  SHA512:
6
- metadata.gz: 650e22398af35c4cc866c53d33988ca02d1c30909e62b6b9b6839c0c354d6d2ab56c6928b839b490119c350246520f9c8ca3d2aacc6c05d23bf7fbd22d6fd8e5
7
- data.tar.gz: 8a501092f95cbb44def78a581fa70fff1d245b72af0332362c5efe3de2f3cc3db70e4842111644d0ed27c0e96a9458e28e0fbc8850e810efe4660a9bce39cb0c
6
+ metadata.gz: 5652f82aaf2127c5eba23bc81e92959a665993ea329a8462c4078b946f840cf06f9c6f385b18cfce494be83df376ed9d697f15691929b297133994edab745569
7
+ data.tar.gz: 71fcfbb4dff6cb22e1078c732c42a0ffe99ec14e865ec88a9668c53fc9f91919661a1d406cc34b45cbd59c8bf058803d3ec3b5aa23b1127cf759c708fc3c3bc2
@@ -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,13 +56,6 @@ module ForemanInventoryUpload
54
56
  env_vars
55
57
  end
56
58
 
57
- def http_proxy_string
58
- @http_proxy_string ||=
59
- HttpProxy.default_global_content_proxy&.full_url ||
60
- cdn_proxy ||
61
- global_foreman_proxy
62
- end
63
-
64
59
  def rh_credentials
65
60
  @rh_credentials ||= begin
66
61
  candlepin_id_certificate = @organization.owner_details['upstreamConsumer']['idCert']
@@ -70,31 +65,6 @@ module ForemanInventoryUpload
70
65
  }
71
66
  end
72
67
  end
73
-
74
- def cdn_proxy
75
- cdn_settings = SETTINGS[:katello][:cdn_proxy] || {}
76
-
77
- return nil unless cdn_settings[:host]
78
-
79
- proxy_uri = URI('')
80
-
81
- original_uri = URI.parse(cdn_settings[:host])
82
-
83
- proxy_uri.scheme = original_uri.scheme || 'http'
84
- proxy_uri.host = original_uri.host || original_uri.path
85
- proxy_uri.port = cdn_settings[:port]
86
- proxy_uri.user = cdn_settings[:user]
87
- proxy_uri.password = cdn_settings[:password]
88
-
89
- proxy_uri.to_s
90
- rescue URI::Error => e
91
- logger.warn("cdn_proxy parsing failed: #{e}")
92
- nil
93
- end
94
-
95
- def global_foreman_proxy
96
- Setting[:http_proxy]
97
- end
98
68
  end
99
69
  end
100
70
  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,56 @@ 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
+ end
33
+
34
+ def self.cdn_proxy(logger: Foreman::Logging.logger('app'))
35
+ proxy_config = SETTINGS[:katello][:cdn_proxy]
36
+ return nil unless proxy_config
37
+
38
+ uri = URI('')
39
+ uri.host = proxy_config[:host]
40
+ uri.port = proxy_config[:port]
41
+ uri.scheme = proxy_config[:scheme] || 'http'
42
+
43
+ if proxy_config[:user]
44
+ uri.user = CGI.escape(proxy_config[:user])
45
+ uri.password = CGI.escape(proxy_config[:password])
46
+ end
47
+ uri.to_s
48
+ rescue URI::Error => e
49
+ logger.warn("cdn_proxy parsing failed: #{e}")
50
+ nil
51
+ end
52
+
53
+ def self.global_foreman_proxy
54
+ Setting[:http_proxy]
55
+ end
56
+
57
+ # This method assumes uri_string contains uri-encoded username and p@$$word:
58
+ # http://user:p%40%24%24word@localhost:8888
59
+ def self.transform_scheme(uri_string)
60
+ transformed_uri = URI.parse(uri_string)
61
+
62
+ case transformed_uri.scheme
63
+ when "http"
64
+ transformed_uri.scheme = 'proxy'
65
+ when "https"
66
+ transformed_uri.scheme = 'proxys'
67
+ end
68
+
69
+ transformed_uri.to_s
70
+ end
17
71
  end
@@ -1,3 +1,3 @@
1
1
  module ForemanRhCloud
2
- VERSION = '2.0.11'.freeze
2
+ VERSION = '2.0.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": "2.0.11",
3
+ "version": "2.0.12",
4
4
  "description": "Inventory Upload =============",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,65 @@
1
+ require 'test_plugin_helper'
2
+
3
+ class RhCloudHttpProxyTest < ActiveSupport::TestCase
4
+ setup do
5
+ @global_content_proxy_mock = 'http://global:content@localhost:8888'
6
+ @global_foreman_proxy_mock = 'http://global:foreman@localhost:8888'
7
+ @katello_cdn_proxy_mock = {
8
+ host: 'localhost',
9
+ port: '8888',
10
+ user: 'katello',
11
+ password: 'cdn',
12
+ scheme: 'http',
13
+ }
14
+ @katello_cdn_proxy_string_mock = 'http://katello:cdn@localhost:8888'
15
+ end
16
+
17
+ test 'selects global content proxy' do
18
+ setup_global_content_proxy
19
+ setup_global_foreman_proxy
20
+ setup_cdn_proxy do
21
+ assert_equal @global_content_proxy_mock, ForemanRhCloud.proxy_setting
22
+ end
23
+ end
24
+
25
+ test 'selects cdn proxy' do
26
+ setup_global_foreman_proxy
27
+ setup_cdn_proxy do
28
+ assert_equal @katello_cdn_proxy_string_mock, ForemanRhCloud.proxy_setting
29
+ end
30
+ end
31
+
32
+ test 'selects global foreman proxy' do
33
+ setup_global_foreman_proxy
34
+
35
+ assert_equal @global_foreman_proxy_mock, ForemanRhCloud.proxy_setting
36
+ end
37
+
38
+ def setup_global_content_proxy
39
+ http_proxy = FactoryBot.create(:http_proxy, url: @global_content_proxy_mock)
40
+ HttpProxy.stubs(:default_global_content_proxy).returns(http_proxy)
41
+ end
42
+
43
+ def setup_global_foreman_proxy
44
+ FactoryBot.create(:setting, :name => 'http_proxy', :value => @global_foreman_proxy_mock)
45
+ end
46
+
47
+ def setup_cdn_proxy
48
+ old_cdn_setting = SETTINGS[:katello][:cdn_proxy]
49
+ SETTINGS[:katello][:cdn_proxy] = @katello_cdn_proxy_mock
50
+ yield
51
+ ensure
52
+ SETTINGS[:katello][:cdn_proxy] = old_cdn_setting
53
+ end
54
+
55
+ test 'transform proxy scheme test' do
56
+ mock_http_proxy = 'http://user:password@localhost:8888'
57
+ mock_https_proxy = 'https://user:password@localhost:8888'
58
+
59
+ transformed_http_uri = URI.parse(ForemanRhCloud.transform_scheme(mock_http_proxy))
60
+ transformed_https_uri = URI.parse(ForemanRhCloud.transform_scheme(mock_https_proxy))
61
+
62
+ assert_equal 'proxy', transformed_http_uri.scheme
63
+ assert_equal 'proxys', transformed_https_uri.scheme
64
+ end
65
+ 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: 2.0.11
4
+ version: 2.0.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
@@ -174,6 +174,7 @@ files:
174
174
  - test/unit/fact_helpers_test.rb
175
175
  - test/unit/insights_facet_test.rb
176
176
  - test/unit/metadata_generator_test.rb
177
+ - test/unit/rh_cloud_http_proxy_test.rb
177
178
  - test/unit/shell_process_job_test.rb
178
179
  - test/unit/slice_generator_test.rb
179
180
  - webpack/ForemanInventoryUpload/Components/AccountList/AccountList.fixtures.js
@@ -515,24 +516,25 @@ required_rubygems_version: !ruby/object:Gem::Requirement
515
516
  - !ruby/object:Gem::Version
516
517
  version: '0'
517
518
  requirements: []
518
- rubygems_version: 3.0.8
519
+ rubygems_version: 3.0.6
519
520
  signing_key:
520
521
  specification_version: 4
521
522
  summary: Summary of ForemanRhCloud.
522
523
  test_files:
524
+ - test/controllers/uploads_controller_test.rb
525
+ - test/controllers/insights_sync/settings_controller_test.rb
526
+ - test/controllers/accounts_controller_test.rb
527
+ - test/controllers/reports_controller_test.rb
523
528
  - test/test_plugin_helper.rb
529
+ - test/jobs/upload_report_job_test.rb
530
+ - test/jobs/insights_full_sync_test.rb
531
+ - test/jobs/inventory_full_sync_test.rb
524
532
  - test/factories/inventory_upload_factories.rb
525
533
  - test/factories/insights_factories.rb
526
- - test/controllers/reports_controller_test.rb
527
- - test/controllers/uploads_controller_test.rb
528
- - test/controllers/accounts_controller_test.rb
529
- - test/controllers/insights_sync/settings_controller_test.rb
530
- - test/unit/slice_generator_test.rb
531
- - test/unit/metadata_generator_test.rb
532
534
  - test/unit/shell_process_job_test.rb
535
+ - test/unit/metadata_generator_test.rb
533
536
  - test/unit/insights_facet_test.rb
534
- - test/unit/archived_report_generator_test.rb
537
+ - test/unit/rh_cloud_http_proxy_test.rb
535
538
  - test/unit/fact_helpers_test.rb
536
- - test/jobs/inventory_full_sync_test.rb
537
- - test/jobs/insights_full_sync_test.rb
538
- - test/jobs/upload_report_job_test.rb
539
+ - test/unit/archived_report_generator_test.rb
540
+ - test/unit/slice_generator_test.rb