Defined Type: tomcat::config::server::valve

Defined in:
manifests/config/server/valve.pp

Summary

Configure a Valve element in $CATALINA_BASE/conf/server.xml

Overview

Parameters:

  • catalina_base (Any) (defaults to: undef)

    Specifies the base directory of the Tomcat installation. Valid options: a string containing an absolute path. ‘$::tomcat::catalina_home`.

  • class_name (Any) (defaults to: undef)

    Specifies the Java class name of a server implementation to use. Maps to the [className XML attribute](tomcat.apache.org/tomcat-8.0-doc/config/valve.html#Access_Logging/Attributes). Valid options: a string containing a Java class name.

  • parent_host (Any) (defaults to: undef)

    Specifies which virtual host the Valve should nest under. Valid options: a string containing the name of a Host element.

  • parent_service (Any) (defaults to: 'Catalina')

    Specifies which Service element the Valve should nest under. Valid options: a string containing the name of a Service element.

  • parent_context (Any) (defaults to: undef)

    Specifies which Context element the Valve should nest under. Valid options: a string containing the name of a Context element (matching the docbase attribute).

  • valve_ensure (Enum['present','absent']) (defaults to: 'present')

    Specifies whether the Valve should exist in the configuration file. Maps to the [Valve XML element](tomcat.apache.org/tomcat-8.0-doc/config/valve.html#Introduction).

  • additional_attributes (Hash) (defaults to: {})

    Specifies any further attributes to add to the Valve. Valid options: a hash of ‘< attribute >’ => ‘< value >’ pairs.

  • attributes_to_remove (Array) (defaults to: [])

    Specifies an array of attributes to remove from the element. Valid options: an array of strings.

  • uniqueness_attributes (Array) (defaults to: [])

    Specifies an array of attribute names that Pupet use to uniquely idetify valves. Valid options: an array of strings. ‘[’className’]‘.

  • server_config (Any) (defaults to: undef)

    Specifies a server.xml file to manage. Valid options: a string containing an absolute path.

  • show_diff (Boolean) (defaults to: true)

    Specifies display differences when augeas changes files, defaulting to true. Valid options: true or false.



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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'manifests/config/server/valve.pp', line 26

define tomcat::config::server::valve (
  $catalina_base                         = undef,
  $class_name                            = undef,
  $parent_host                           = undef,
  $parent_service                        = 'Catalina',
  $parent_context                        = undef,
  Enum['present','absent'] $valve_ensure = 'present',
  Hash $additional_attributes            = {},
  Array $attributes_to_remove            = [],
  Array $uniqueness_attributes           = [],
  $server_config                         = undef,
  Boolean $show_diff                     = true,
) {
  include ::tomcat
  $_catalina_base = pick($catalina_base, $::tomcat::catalina_home)
  tag(sha1($_catalina_base))

  if versioncmp($::augeasversion, '1.0.0') < 0 {
    fail('Valve configurations require Augeas >= 1.0.0')
  }

  if member($additional_attributes.keys, 'className') {
    fail('\'additional_attributes\' contains \'className\'. Please use parameter \'class_name\'')
  }

  if $class_name {
    $_class_name = $class_name
  } else {
    $_class_name = $name
  }

  if !member($uniqueness_attributes, 'className') {
    $_uniqueness_attributes = ['className'] + $uniqueness_attributes
  } else {
    $_uniqueness_attributes = $uniqueness_attributes
  }

  $attributes = {'className' => $_class_name} + $additional_attributes

  $augeas_filter = $_uniqueness_attributes.map |$attr| {
    "[#attribute/${attr}='${attributes[$attr]}']"
  }

  # lint:ignore:140chars
  if $parent_host {
    if $parent_context {
      $base_path = "Server/Service[#attribute/name='${parent_service}']/Engine/Host[#attribute/name='${parent_host}']/Context[#attribute/docBase='${parent_context}']/Valve${join($augeas_filter)}"
    } else {
      $base_path = "Server/Service[#attribute/name='${parent_service}']/Engine/Host[#attribute/name='${parent_host}']/Valve${join($augeas_filter)}"
    }
  } else {
    $base_path = "Server/Service[#attribute/name='${parent_service}']/Engine/Valve${join($augeas_filter)}"
  }
  # lint:endignore

  if $server_config {
    $_server_config = $server_config
  } else {
    $_server_config = "${_catalina_base}/conf/server.xml"
  }

  if $valve_ensure == 'absent' {
    $changes = "rm ${base_path}"
  } else {
    $defnode_valve = "defnode valve ${base_path} ''"
    $set_attributes = join_keys_to_values($attributes, " '").map |$attr| {
      "set \$valve/#attribute/${attr}'"
    }
    if ! empty(any2array($attributes_to_remove)) {
      $rm_attributes = any2array($attributes_to_remove).map |$attr| {
        "rm \$valve/#attribute/${attr}"
      }
    } else {
      $rm_attributes = undef
    }

    $changes = delete_undef_values(flatten([
      $defnode_valve,
      $set_attributes,
      $rm_attributes,
    ]))
  }

  augeas { "${_catalina_base}-${parent_service}-${parent_host}-valve-${name}":
    lens      => 'Xml.lns',
    incl      => $_server_config,
    changes   => $changes,
    show_diff => $show_diff,
  }
}