#
# Cookbook:: irrigate-memcached
# Recipe:: default
#
# Copyright:: 2017, The Orchard, All Rights Reserved.

include_recipe 'memcached::default'

# Make sure the firewall is installed and enabled
firewall 'default' do
  log_level :high
  action :install
end

firewall_rule 'established' do
  stateful [:related, :established]
  protocol :none
  position 2
  command :allow
end

firewall_rule 'ssh' do
  port 22
  protocol :tcp
  position 3
  command :allow
end

memcached_source_ip_addresses = node['memcached']['source_ip_addresses']
memcached_source_ip_addresses.each_with_index do |source_ip, index|
  firewall_rule "memcached-#{index}" do
    port node['memcached']['port']
    protocol :tcp
    position 4 + index
    source source_ip
    command :allow
  end
end
