<commit_before>define :app_vhost, :server_type => nil, :site => {} do

  type = params[:server_type] || site['server_type']

  Chef::Application.fatal!("Unsupported vhost type (#{type})") unless ['nginx', 'apache'].include? type

  site = ConfigDrivenHelper::Util::immutablemash_to_hash(params[:site])

  if site['inherits']
    site = ::Chef::Mixin::DeepMerge.hash_only_merge(
      ConfigDrivenHelper::Util::immutablemash_to_hash(node[type]['shared_config'][site['inherits']]),
      site)
  end

  site = ::Chef::Mixin::DeepMerge.hash_only_merge(ConfigDrivenHelper::Util::immutablemash_to_hash(node["#{type}-sites"]), site)
  site['server_name'] ||= params[:name]

  [(site['protocols'] || ['http'])].flatten.each do |protocol|

    Chef::Application.fatal!("Unsupported vhost protocol (#{protocol}) for #{params[:name]}") unless ['http', 'https'].include? protocol

    service_name = type == 'nginx' ? type : 'apache2'
    name = protocol == 'https' ? "#{params[:name]}.ssl" : params[:name]

    template "#{node[type]['dir']}/sites-available/#{name}" do
      source site["template"]
      cookbook site["cookbook"]

      variables({
        :params => site,
        :protocol => protocol
      })
      notifies :reload, "service[#{service_name}]", :delayed
    end

    [ site['ssl']['certfile'], site['ssl']['keyfile'] ].each do |f|
      next if f.nil?

      Chef::Application.fatal!("node['ssl_certs']['#{f}'] is not set but is used by the #{name} #{type} vhost") unless node['ssl_certs'][f]

      file f do
        owner 'root'
        group 'root'
        mode (f == site['ssl']['keyfile'] ? 0600 : 0644)
        content node['ssl_certs'][f]
        notifies :reload, "service[#{service_name}]", :delayed
      end
    end if protocol == 'https'

    self.send "#{type}_site", name do
      enable (defined? site['enable'] ? site['enable'] : true)
    end
  end
<commit_msg>Fix apache 2.4 compatibility by ensuring the configuration as a .conf suffix.<commit_after>define :app_vhost, :server_type => nil, :site => {} do

  type = params[:server_type] || site['server_type']

  Chef::Application.fatal!("Unsupported vhost type (#{type})") unless ['nginx', 'apache'].include? type

  site = ConfigDrivenHelper::Util::immutablemash_to_hash(params[:site])

  if site['inherits']
    site = ::Chef::Mixin::DeepMerge.hash_only_merge(
      ConfigDrivenHelper::Util::immutablemash_to_hash(node[type]['shared_config'][site['inherits']]),
      site)
  end

  site = ::Chef::Mixin::DeepMerge.hash_only_merge(ConfigDrivenHelper::Util::immutablemash_to_hash(node["#{type}-sites"]), site)
  site['server_name'] ||= params[:name]

  [(site['protocols'] || ['http'])].flatten.each do |protocol|

    Chef::Application.fatal!("Unsupported vhost protocol (#{protocol}) for #{params[:name]}") unless ['http', 'https'].include? protocol

    service_name = type == 'nginx' ? type : 'apache2'
    name = protocol == 'https' ? "#{params[:name]}.ssl" : params[:name]
    name = "#{name}.conf" if type == 'apache' && node[type]['version'] == '2.4'

    template "#{node[type]['dir']}/sites-available/#{name}" do
      source site["template"]
      cookbook site["cookbook"]

      variables({
        :params => site,
        :protocol => protocol
      })
      notifies :reload, "service[#{service_name}]", :delayed
    end

    [ site['ssl']['certfile'], site['ssl']['keyfile'] ].each do |f|
      next if f.nil?

      Chef::Application.fatal!("node['ssl_certs']['#{f}'] is not set but is used by the #{name} #{type} vhost") unless node['ssl_certs'][f]

      file f do
        owner 'root'
        group 'root'
        mode (f == site['ssl']['keyfile'] ? 0600 : 0644)
        content node['ssl_certs'][f]
        notifies :reload, "service[#{service_name}]", :delayed
      end
    end if protocol == 'https'

    self.send "#{type}_site", name do
      enable (defined? site['enable'] ? site['enable'] : true)
    end
  end

{'fraction_non_alphanumeric': 0.1898572884811417, 'fraction_numerical': 0.0056065239551478085, 'mean_word_length': 4.044987146529563, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '204640', 'n_tokens_mistral': 1296, 'n_tokens_neox': 1277, 'n_words': 274}