#
# Cookbook:: irrigate-filemaker
# Attributes:: default
#
# Copyright:: (C) 2021 The Orchard
#

include_recipe 'firewall'

if platform_family?('rhel')
  # Get data bag with filemaker credentials
  data_bag = node['filemaker']['filemaker_credentials_data_bag_name']
  filemaker_credentials = data_bag_item('secrets', data_bag)
  packagecloud_read_token = filemaker_credentials['packagecloud_read_token'].chomp

  yum_repository 'orchard-filemaker' do
    description 'Orchard Filemaker Repository'
    baseurl "https://packagecloud.io/priv/#{packagecloud_read_token}" \
    '/orchardit/filemaker/el/7/$basearch/'
    gpgcheck false
    gpgkey "https://#{packagecloud_read_token}@packagecloud.io/" \
    'orchardit/filemaker/gpgkey'
    repo_gpgcheck true
    action :create
    not_if { ::File.exist?('/etc/yum.repos.d/orchard-filemaker.repo') }
  end

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

  # Firewall rules
  firewall_rule 'ssh' do
    port 22
    protocol :tcp
    command :allow
  end

  firewall_rule 'http' do
    port 80
    protocol :tcp
    command :allow
  end

  firewall_rule 'https' do
    port 443
    protocol :tcp
    command :allow
  end

  firewall_rule 'filemaker_port_req_1' do
    port 2399
    protocol :tcp
    command :allow
  end

  firewall_rule 'filemaker_port_req_2' do
    port 5003
    protocol :tcp
    command :allow
  end

  firewall_rule 'filemaker_admin_console' do
    port 16000
    protocol :tcp
    command :allow
  end
end
