Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop cdn_proxy settings #944

Merged
merged 1 commit into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/services/foreman_rh_cloud/cloud_connector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def install
:satellite_cloud_connector_password => token_value,
}

if (http_proxy = ForemanRhCloud.proxy_setting(logger: Foreman::Logging.logger('app')))
if (http_proxy = ForemanRhCloud.proxy_setting)
input[:satellite_cloud_connector_http_proxy] = http_proxy
end

Expand Down
2 changes: 1 addition & 1 deletion app/services/foreman_rh_cloud/cloud_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module CloudRequest
def execute_cloud_request(params)
final_params = {
verify_ssl: ForemanRhCloud.verify_ssl_method,
proxy: ForemanRhCloud.transformed_http_proxy_string(logger: logger),
proxy: ForemanRhCloud.transformed_http_proxy_string,
}.deep_merge(params)

response = RestClient::Request.execute(final_params)
Expand Down
2 changes: 1 addition & 1 deletion lib/foreman_inventory_upload/async/upload_report_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def env
'CER_PATH' => @cer_path
)

http_proxy_string = ForemanRhCloud.http_proxy_string(logger: logger)
http_proxy_string = ForemanRhCloud.http_proxy_string
if http_proxy_string
env_vars['http_proxy'] = http_proxy_string
env_vars['https_proxy'] = http_proxy_string
Expand Down
34 changes: 7 additions & 27 deletions lib/foreman_rh_cloud.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,20 @@ def self.query_limit
@query_limit ||= ENV['SATELLITE_RH_CLOUD_QUERY_LIMIT'] ? ENV['SATELLITE_RH_CLOUD_QUERY_LIMIT'].to_i : 100
end

def self.http_proxy_string(logger: Foreman::Logging.logger('background'))
ForemanRhCloud.proxy_setting(logger: logger)
def self.http_proxy_string
ForemanRhCloud.proxy_setting
end

def self.transformed_http_proxy_string(logger: Foreman::Logging.logger('background'))
ForemanRhCloud.transform_scheme(ForemanRhCloud.proxy_setting(logger: logger))
def self.transformed_http_proxy_string
ForemanRhCloud.transform_scheme(ForemanRhCloud.proxy_setting)
end

def self.proxy_setting(logger: Foreman::Logging.logger('background'))
fix_port(proxy_string(logger: logger))
def self.proxy_setting
fix_port(proxy_string)
end

def self.proxy_string(logger: Foreman::Logging.logger('background'))
def self.proxy_string
HttpProxy.default_global_content_proxy&.full_url ||
ForemanRhCloud.cdn_proxy(logger: logger) ||
ForemanRhCloud.global_foreman_proxy ||
''
end
Expand All @@ -62,25 +61,6 @@ def self.fix_port(uri_string)
uri.to_s
end

def self.cdn_proxy(logger: Foreman::Logging.logger('app'))
proxy_config = SETTINGS[:katello][:cdn_proxy]
return nil unless proxy_config

uri = URI('')
uri.host = proxy_config[:host]
uri.port = proxy_config[:port]
uri.scheme = proxy_config[:scheme] || 'http'

if proxy_config[:user]
uri.user = CGI.escape(proxy_config[:user])
uri.password = CGI.escape(proxy_config[:password])
end
uri.to_s
rescue URI::Error => e
logger.warn("cdn_proxy parsing failed: #{e}")
nil
end

def self.global_foreman_proxy
Setting[:http_proxy]
end
Expand Down
27 changes: 1 addition & 26 deletions test/unit/rh_cloud_http_proxy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,12 @@ class RhCloudHttpProxyTest < ActiveSupport::TestCase
setup do
@global_content_proxy_mock = 'http://global:content@localhost:80'
@global_foreman_proxy_mock = 'http://global:foreman@localhost:80'
@katello_cdn_proxy_mock = {
host: 'localhost',
port: '80',
user: 'katello',
password: 'cdn',
scheme: 'http',
}
@katello_cdn_proxy_string_mock = 'http://katello:cdn@localhost:80'
end

test 'selects global content proxy' do
setup_global_content_proxy
setup_global_foreman_proxy
setup_cdn_proxy do
assert_equal @global_content_proxy_mock, ForemanRhCloud.proxy_setting
end
end

test 'selects cdn proxy' do
setup_global_foreman_proxy
setup_cdn_proxy do
assert_equal @katello_cdn_proxy_string_mock, ForemanRhCloud.proxy_setting
end
assert_equal @global_content_proxy_mock, ForemanRhCloud.proxy_setting
end

test 'selects global foreman proxy' do
Expand All @@ -44,14 +27,6 @@ def setup_global_foreman_proxy
Setting[:http_proxy] = @global_foreman_proxy_mock
end

def setup_cdn_proxy
old_cdn_setting = SETTINGS[:katello][:cdn_proxy]
SETTINGS[:katello][:cdn_proxy] = @katello_cdn_proxy_mock
yield
ensure
SETTINGS[:katello][:cdn_proxy] = old_cdn_setting
end

test 'transform proxy scheme test' do
mock_http_proxy = 'http://user:password@localhost:8888'
mock_https_proxy = 'https://user:password@localhost:8888'
Expand Down
Loading