Skip to content

Commit

Permalink
Fixes #30951 - Provide a rackup_path plugin DSL
Browse files Browse the repository at this point in the history
Currently there's http_rackup_path and https_rackup_path. In practice
all built in modules and most (all?) plugins that I know define the same
rackup config for both HTTP and HTTPS. Having a DSL method to do this
simplifies code.
  • Loading branch information
ekohl authored and ehelms committed Oct 2, 2020
1 parent 774fb1d commit 88fbc8e
Show file tree
Hide file tree
Showing 14 changed files with 27 additions and 24 deletions.
5 changes: 5 additions & 0 deletions lib/proxy/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ class ::Proxy::Plugin
class << self
attr_reader :get_http_rackup_path, :get_https_rackup_path, :get_uses_provider

def rackup_path(path)
http_rackup_path(path)
https_rackup_path(path)
end

def http_rackup_path(path)
@get_http_rackup_path = path
end
Expand Down
3 changes: 1 addition & 2 deletions modules/bmc/bmc_plugin.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module Proxy::BMC
class Plugin < Proxy::Plugin
http_rackup_path File.expand_path("http_config.ru", File.expand_path(__dir__))
https_rackup_path File.expand_path("http_config.ru", File.expand_path(__dir__))
rackup_path File.expand_path("http_config.ru", __dir__)

plugin :bmc, ::Proxy::VERSION
end
Expand Down
3 changes: 1 addition & 2 deletions modules/dhcp/dhcp_plugin.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
class Proxy::DhcpPlugin < ::Proxy::Plugin
http_rackup_path File.expand_path("http_config.ru", File.expand_path(__dir__))
https_rackup_path File.expand_path("http_config.ru", File.expand_path(__dir__))
rackup_path File.expand_path("http_config.ru", __dir__)

uses_provider
default_settings :use_provider => 'dhcp_isc', :server => '127.0.0.1', :subnets => [], :ping_free_ip => true
Expand Down
3 changes: 1 addition & 2 deletions modules/dns/dns_plugin.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module Proxy::Dns
class Plugin < ::Proxy::Plugin
http_rackup_path File.expand_path("http_config.ru", File.expand_path(__dir__))
https_rackup_path File.expand_path("http_config.ru", File.expand_path(__dir__))
rackup_path File.expand_path("http_config.ru", __dir__)

uses_provider
default_settings :use_provider => 'dns_nsupdate', :dns_ttl => 86_400
Expand Down
3 changes: 1 addition & 2 deletions modules/facts/facts_plugin.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
class Proxy::FactsPlugin < ::Proxy::Plugin
http_rackup_path File.expand_path("http_config.ru", File.expand_path(__dir__))
https_rackup_path File.expand_path("http_config.ru", File.expand_path(__dir__))
rackup_path File.expand_path("http_config.ru", __dir__)

default_settings :enabled => false
plugin :facts, ::Proxy::VERSION
Expand Down
3 changes: 1 addition & 2 deletions modules/httpboot/httpboot_plugin.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module Proxy::Httpboot
class Plugin < ::Proxy::Plugin
http_rackup_path File.expand_path("http_config.ru", File.expand_path(__dir__))
https_rackup_path File.expand_path("http_config.ru", File.expand_path(__dir__))
rackup_path File.expand_path("http_config.ru", __dir__)

plugin :httpboot, ::Proxy::VERSION

Expand Down
3 changes: 1 addition & 2 deletions modules/logs/logs_plugin.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
class ::Proxy::LogsPlugin < ::Proxy::Plugin
http_rackup_path File.expand_path("http_config.ru", File.expand_path(__dir__))
https_rackup_path File.expand_path("http_config.ru", File.expand_path(__dir__))
rackup_path File.expand_path("http_config.ru", __dir__)

plugin :logs, ::Proxy::VERSION
default_settings :enabled => true
Expand Down
3 changes: 1 addition & 2 deletions modules/puppet_proxy/puppet_plugin.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module Proxy::Puppet
class Plugin < Proxy::Plugin
http_rackup_path File.expand_path("http_config.ru", File.expand_path(__dir__))
https_rackup_path File.expand_path("http_config.ru", File.expand_path(__dir__))
rackup_path File.expand_path("http_config.ru", __dir__)

plugin :puppet, ::Proxy::VERSION

Expand Down
3 changes: 1 addition & 2 deletions modules/puppetca/puppetca_plugin.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module Proxy::PuppetCa
class Plugin < ::Proxy::Plugin
http_rackup_path File.expand_path("http_config.ru", File.expand_path(__dir__))
https_rackup_path File.expand_path("http_config.ru", File.expand_path(__dir__))
rackup_path File.expand_path("http_config.ru", __dir__)

uses_provider
default_settings :use_provider => 'puppetca_hostname_whitelisting'
Expand Down
3 changes: 1 addition & 2 deletions modules/realm/realm_plugin.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module Proxy::Realm
class Plugin < ::Proxy::Plugin
http_rackup_path File.expand_path("http_config.ru", File.expand_path(__dir__))
https_rackup_path File.expand_path("http_config.ru", File.expand_path(__dir__))
rackup_path File.expand_path("http_config.ru", __dir__)

default_settings :use_provider => 'realm_freeipa'

Expand Down
3 changes: 1 addition & 2 deletions modules/root/root_plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ class ::Proxy::RootPlugin < ::Proxy::Plugin
plugin :foreman_proxy, ::Proxy::VERSION
default_settings :enabled => true

http_rackup_path File.expand_path("http_config.ru", File.expand_path(__dir__))
https_rackup_path File.expand_path("http_config.ru", File.expand_path(__dir__))
rackup_path File.expand_path("http_config.ru", __dir__)

override_module_loader_class ::Proxy::RootPluginLoader
end
3 changes: 1 addition & 2 deletions modules/templates/templates_plugin.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module Proxy::Templates
class Plugin < ::Proxy::Plugin
http_rackup_path File.expand_path("http_config.ru", File.expand_path(__dir__))
https_rackup_path File.expand_path("http_config.ru", File.expand_path(__dir__))
rackup_path File.expand_path("http_config.ru", __dir__)

plugin :templates, ::Proxy::VERSION

Expand Down
3 changes: 1 addition & 2 deletions modules/tftp/tftp_plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ module Proxy::TFTP
class Plugin < ::Proxy::Plugin
plugin :tftp, ::Proxy::VERSION

http_rackup_path File.expand_path("http_config.ru", File.expand_path(__dir__))
https_rackup_path File.expand_path("http_config.ru", File.expand_path(__dir__))
rackup_path File.expand_path("http_config.ru", __dir__)

default_settings :tftproot => '/var/lib/tftpboot',
:tftp_read_timeout => 60,
Expand Down
10 changes: 10 additions & 0 deletions test/plugins/plugin_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ def test_http_rackup_returns_empty_string_with_missing_rackup_path
assert_equal "", TestPlugin2.https_rackup
end

class TestPluginSingleRackupPath < Proxy::Plugin
plugin :test2, '1.0'
rackup_path '/dev/null'
end

def test_combined_rackup_path_returns_http_and_https
assert_equal '/dev/null', TestPluginSingleRackupPath.get_http_rackup_path
assert_equal '/dev/null', TestPluginSingleRackupPath.get_https_rackup_path
end

class TestBundlerGroupPlugin < ::Proxy::Plugin
plugin :test_bundler_group, '1.0'
bundler_group :test_group
Expand Down

0 comments on commit 88fbc8e

Please sign in to comment.