Skip to content

Commit

Permalink
move the conversion of listen_addresses and listen_ports out of ports…
Browse files Browse the repository at this point in the history
….conf.erb and print a deprecation warning.
  • Loading branch information
b-dean committed Oct 14, 2015
1 parent c712650 commit 4fd928f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 11 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -710,13 +710,15 @@ License and Authors
* Author:: Gilles Devaux <gilles@peerpong.com>
* Author:: Sander van Zoest <sander+cookbooks@vanzoest.com>
* Author:: Taylor Price <tayworm@gmail.com>
* Author:: Ben Dean <ben.dean@ontariosystems.com>

* Copyright:: 2009-2012, Chef Software, Inc
* Copyright:: 2011, Atriso
* Copyright:: 2011, CustomInk, LLC.
* Copyright:: 2013-2014, OneHealth Solutions, Inc.
* Copyright:: 2014, Viverae, Inc.
* Copyright:: 2015, Alexander van Zoest
* Copyright:: 2015, Ontario Systems, LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
42 changes: 42 additions & 0 deletions libraries/listen.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# encoding: utf-8
#
# Cookbook Name:: apache2
# Libraries:: listen
#
# Copyright 2015, Ontario Systems, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
module Apache2
# Provides method to convert node['apache']['listen_ports'] and node['apache']['listen_addresses'] into new node['apache']['listen']
module Listen
# @param node [Chef::Node] the chef node
# @return [Hash] a hash indexed by address where the values are arrays of ports to listen to
def listen_ports_by_address(node)
node['apache']['listen'].to_hash.merge(Apache2::Listen.converted_listen_ports_and_addresses(node))
end

module_function :listen_ports_by_address

private

def self.converted_listen_ports_and_addresses(node)
return {} unless node['apache']['listen_ports'] && node['apache']['listen_addresses']
Chef::Log.warn "node['apache']['listen_ports'] and node['apache']['listen_addresses'] are deprecated in favor of node['apache']['listen']. Please adjust your cookbooks"

node['apache']['listen_addresses'].uniq.each_with_object({}) do |address, listen|
listen[address] = node['apache']['listen_ports'].map(&:to_i)
end
end
end
end
13 changes: 2 additions & 11 deletions templates/default/ports.conf.erb
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
# This file was generated by Chef for <%= node['fqdn'] %>.
# Do NOT modify this file by hand!

<% listen = Hash[node['apache']['listen'].map {|address, ports| [address, ports.map(&:to_i)]}] -%>
<% if node['apache']['listen_ports'] && node['apache']['listen_addresses'] -%>
<% node['apache']['listen_addresses'].uniq.each do |address| -%>
<% listen[address] ||= [] -%>
<% node['apache']['listen_ports'].map(&:to_i).uniq.each do |port| -%>
<% listen[address] = (listen[address] + [port]).uniq -%>
<% end -%>
<% end -%>
<% end -%>
<% listen.each do |address, ports| -%>
<% ports.each do |port| -%>
<% Apache2::Listen.listen_ports_by_address(node).each do |address, ports| -%>
<% ports.map(&:to_i).uniq.each do |port| -%>
<% if address.empty? -%>
Listen <%= port %>
<% else -%>
Expand Down

0 comments on commit 4fd928f

Please sign in to comment.