Skip to content

Commit 86db83d

Browse files
committed
Patch Katello controllers to enable access by smart proxy
1 parent b59d34e commit 86db83d

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

db/seeds.d/200_features.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
f = Feature.where(:name => 'insights').first_or_create
2+
raise "Unable to create proxy feature: #{format_errors f}" if f.nil? || f.errors.any?

lib/foreman_rh_cloud/engine.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,29 @@ def self.register_scheduled_task(task_class, cronline)
210210
)
211211
end
212212

213+
# Ideally this code belongs to an initializer. The problem is that Katello controllers are not initialized completely until after the end of the to_prepare blocks
214+
# This means I can patch the controller only in the after_initialize block that is promised to run after the to_prepare
215+
# initializer 'foreman_rh_cloud.allow_smart_proxy_actions', :before => :finisher_hook, :after => 'katello.register_plugin' do |_app|
216+
# end
217+
config.after_initialize do
218+
if defined?(Katello)
219+
Katello::Api::V2::OrganizationsController.include Foreman::Controller::SmartProxyAuth
220+
Katello::Api::V2::OrganizationsController.add_smart_proxy_filters(
221+
:download_debug_certificate,
222+
features: ForemanRhCloud.on_prem_smart_proxy_features
223+
)
224+
Katello::Api::V2::OrganizationsController.add_smart_proxy_filters(
225+
:index,
226+
features: ForemanRhCloud.on_prem_smart_proxy_features
227+
)
228+
Katello::Api::V2::RepositoriesController.include Foreman::Controller::SmartProxyAuth
229+
Katello::Api::V2::RepositoriesController.add_smart_proxy_filters(
230+
:index,
231+
features: ForemanRhCloud.on_prem_smart_proxy_features
232+
)
233+
end
234+
end
235+
213236
rake_tasks do
214237
Rake::Task['db:seed'].enhance do
215238
ForemanRhCloud::Engine.load_seed
@@ -231,4 +254,8 @@ def self.ca_cert
231254
::SETTINGS[:ssl_ca_file]
232255
end
233256
end
257+
258+
def self.on_prem_smart_proxy_features
259+
['insights']
260+
end
234261
end

test/unit/rh_cloud_http_proxy_test.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ class RhCloudHttpProxyTest < ActiveSupport::TestCase
44
setup do
55
@global_content_proxy_mock = 'http://global:content@localhost:80'
66
@global_foreman_proxy_mock = 'http://global:foreman@localhost:80'
7+
ForemanRhCloud.stubs(:with_local_advisor_engine?).returns(false)
78
end
89

910
test 'selects global content proxy' do
@@ -18,6 +19,13 @@ class RhCloudHttpProxyTest < ActiveSupport::TestCase
1819
assert_equal @global_foreman_proxy_mock, ForemanRhCloud.proxy_setting
1920
end
2021

22+
test 'returns empty string in on-prem setup' do
23+
ForemanRhCloud.unstub(:with_local_advisor_engine?)
24+
ForemanRhCloud.stubs(:with_local_advisor_engine?).returns(true)
25+
26+
assert_equal '', ForemanRhCloud.proxy_setting
27+
end
28+
2129
def setup_global_content_proxy
2230
http_proxy = FactoryBot.create(:http_proxy, url: @global_content_proxy_mock)
2331
HttpProxy.stubs(:default_global_content_proxy).returns(http_proxy)

0 commit comments

Comments
 (0)