Puppet Function: apache::authz_core_config

Defined in:
lib/puppet/functions/apache/authz_core_config.rb
Function type:
Ruby 4.x API

Summary

Function to generate the authz_core configuration directives.

Overview

apache::authz_core_config(Hash $config)Array

Examples:


arg = {
  require_all => {
   'require_any' => {
     'require' => ['user superadmin'],
     'require_all' => {
       'require' => ['group admins'],
     },
    },
   'require_none' => {
     'require' => ['group temps']
   }
  }
}

apache::bool2httpd(arg)
returns :
[
  "  <RequireAll>",
  "    <RequireAny>",
  "      Require user superadmin",
  "      <RequireAll>",
  "        Require group admins",
  "        Require ldap-group \"cn=Administrators,o=Airius\"",
  "      </RequireAll>",
  "    </RequireAny>",
  "    <RequireNone>",
  "      Require group temps",
  "      Require ldap-group \"cn=Temporary Employees,o=Airius\"",
  "    </RequireNone>",
  "  </RequireAll>"
]

Parameters:

  • config (Hash)

    The input as JSON format.

Returns:

  • (Array)

    Returns the authz_core config directives in array.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/puppet/functions/apache/authz_core_config.rb', line 6

Puppet::Functions.create_function(:'apache::authz_core_config') do
  # @param config
  #   The input as JSON format.
  #
  # @return
  #   Returns the authz_core config directives in array.
  #
  # @example
  #
  #    arg = {
  #      require_all => {
  #       'require_any' => {
  #         'require' => ['user superadmin'],
  #         'require_all' => {
  #           'require' => ['group admins'],
  #         },
  #        },
  #       'require_none' => {
  #         'require' => ['group temps']
  #       }
  #      }
  #    }
  #
  #    apache::bool2httpd(arg)
  #    returns :
  #    [
  #      "  <RequireAll>",
  #      "    <RequireAny>",
  #      "      Require user superadmin",
  #      "      <RequireAll>",
  #      "        Require group admins",
  #      "        Require ldap-group \"cn=Administrators,o=Airius\"",
  #      "      </RequireAll>",
  #      "    </RequireAny>",
  #      "    <RequireNone>",
  #      "      Require group temps",
  #      "      Require ldap-group \"cn=Temporary Employees,o=Airius\"",
  #      "    </RequireNone>",
  #      "  </RequireAll>"
  #    ]
  #
  dispatch :authz_core_config do
    param 'Hash', :config
    return_type 'Array'
  end

  private

  def build_directive(value)
    value.split('_').map(&:capitalize).join
  end

  def authz_core_config(config, count = 1)
    result_string = []
    config.map do |key, value|
      directive = build_directive(key)
      if value.is_a?(Hash)
        result_string << spacing("<#{directive}>", count)
        result_string << authz_core_config(value, count + 1)
        result_string << spacing("</#{directive}>", count)
      else
        value.map do |v|
          result_string << spacing("#{directive} #{v}", count)
        end
      end
    end
    result_string.flatten
  end

  def spacing(string, count)
    ('  ' * count) + string
  end
end