% This file managed by Puppet
% Template Path: <%= @module_name %>/templates/rabbitmq.config
[
<%- if @ssl and @ssl_versions -%>
  {ssl, [{versions, [<%= @ssl_versions.sort.map { |v| "'#{v}'" }.join(', ') %>]}]},
<%- end -%>
  {rabbit, [
<% if @ldap_auth -%>
    {auth_backends, [rabbit_auth_backend_internal, rabbit_auth_backend_ldap]},
<% end -%>
<% if @config_cluster -%>
    {cluster_nodes, {[<%= @cluster_nodes.map { |n| "\'rabbit@#{n}\'" }.join(', ') %>], <%= @cluster_node_type %>}},
    {cluster_partition_handling, <%= @cluster_partition_handling %>},
<% end -%>
    {tcp_listen_options,
         [binary,
         <%- if @tcp_keepalive -%>
         {keepalive,     true},
         <%- end -%>
         {packet,        raw},
         {reuseaddr,     true},
         {backlog,       128},
         {nodelay,       true},
         {exit_on_close, false}]
    },
<%- if @ssl_only -%>
    {tcp_listeners, []},
<%- elsif @interface != 'UNSET' -%>
    {tcp_listeners, [{"<%= @interface%>", <%= @port %>}]},
<%- end -%>
<%- if @ssl -%>
  <%- if @ssl_interface != 'UNSET' -%>
    {ssl_listeners, [{"<%= @ssl_interface%>", <%= @ssl_port %>}]},
  <%- else -%>
    {ssl_listeners, [<%= @ssl_port %>]},
  <%- end -%>
    {ssl_options, [
                   <%- if @ssl_cacert != 'UNSET' -%>
                   {cacertfile,"<%= @ssl_cacert %>"},
                   <%- end -%>
                   {certfile,"<%= @ssl_cert %>"},
                   {keyfile,"<%= @ssl_key %>"},
                   {verify,<%= @ssl_verify %>},
                   {fail_if_no_peer_cert,<%= @ssl_fail_if_no_peer_cert %>}
                   <%- if @ssl_versions -%>
                   ,{versions, [<%= @ssl_versions.sort.map { |v| "'#{v}'" }.join(', ') %>]}
                   <%- end -%>
                   <%- if @ssl_ciphers and @ssl_ciphers.size > 0 -%>
                   ,{ciphers,[
                     <%= @ssl_ciphers.sort.map{|k| "{#{k}}"}.join(",\n                     ") %>
                   ]}
                   <%- end -%>
                  ]},
<%- end -%>
<% if @config_variables -%>
<%- @config_variables.keys.sort.each do |key| -%>
    {<%= key %>, <%= @config_variables[key] %>},
<%- end -%>
<%- end -%>
    {default_user, <<"<%= @default_user %>">>},
    {default_pass, <<"<%= @default_pass %>">>}
  ]}<% if @config_kernel_variables -%>,
  {kernel, [
    <%= @config_kernel_variables.sort.map{|k,v| "{#{k}, #{v}}"}.join(",\n    ") %>
  ]}
<%- end -%>
<%- if @admin_enable -%>,
  {rabbitmq_management, [
    {listener, [
<%- if @ssl && @management_ssl -%>
      {port, <%= @ssl_management_port %>},
      {ssl, true},
      {ssl_opts, [<%- if @ssl_cacert != 'UNSET' %>
                  {cacertfile, "<%= @ssl_cacert %>"},
                  <%- end -%>

                  {certfile, "<%= @ssl_cert %>"},
                  {keyfile, "<%= @ssl_key %>"}
                   <%- if @ssl_versions -%>
                     ,{versions, [<%= @ssl_versions.sort.map { |v| "'#{v}'" }.join(', ') %>]}
                   <%- end -%>
                  <%- if @ssl_ciphers and @ssl_ciphers.size > 0 -%>
                  ,{ciphers,[
                      <%= @ssl_ciphers.sort.map{|k| "{#{k}}"}.join(",\n                      ") %>
                  ]}
                  <%- end -%>
                 ]}
<%- else -%>
      {port, <%= @management_port %>}
<%- end -%>
    ]}
  ]}
<%- end -%>
<% if @config_stomp -%>,
% Configure the Stomp Plugin listening port
  {rabbitmq_stomp, [
  <%- if @stomp_ssl_only -%>
    {tcp_listeners, []}
  <%- else -%>
    {tcp_listeners, [<%= @stomp_port %>]}
  <%- end -%>
  <%- if @ssl && @ssl_stomp_port -%>
    ,
    {ssl_listeners, [<%= @ssl_stomp_port %>]}
  <%- end -%>
  ]}
<% end -%>
<%- if @ldap_auth -%>,
% Configure the LDAP authentication plugin
  {rabbitmq_auth_backend_ldap, [
    {other_bind, <%= @ldap_other_bind %>},
    {servers, ["<%= @ldap_server %>"]},
    {user_dn_pattern, "<%= @ldap_user_dn_pattern %>"},
    {use_ssl, <%= @ldap_use_ssl %>},
    {port, <%= @ldap_port %>},
<% if @ldap_config_variables -%>
<%- @ldap_config_variables.keys.sort.each do |key| -%>
    {<%= key %>, <%= @ldap_config_variables[key] %>},
<%- end -%>
<%- end -%>
    {log, <%= @ldap_log %>}
  ]}
<%- end -%>
].
% EOF
