Defined Type: tomcat::config::server::connector

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

Summary

Configure Connector elements in $CATALINA_BASE/conf/server.xml

Overview

Parameters:

  • catalina_base (Any) (defaults to: undef)

    Specifies the base directory of the Tomcat installation to manage. Valid options: a string containing an absolute path.

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

    Specifies whether the [Connector XML element](tomcat.apache.org/tomcat-8.0-doc/connectors.html) should exist in the configuration file.

  • port (Any) (defaults to: undef)

    Sets a TCP port on which to create a server socket. Maps to the [port XML attribute](tomcat.apache.org/tomcat-8.0-doc/config/http.html#Common_Attributes). Valid options: a string.

  • protocol (Any) (defaults to: $name)

    Specifies a protocol to use for handling incoming traffic. Maps to the [protocol XML attribute](tomcat.apache.org/tomcat-8.0-doc/config/http.html#Common_Attributes). Valid options: a string. ‘$name`.

  • name

    ‘$protocol`

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

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

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

    Specifies any further attributes to add to the Connector. 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.

  • purge_connectors (Optional[Boolean]) (defaults to: undef)

    Specifies whether to purge any unmanaged Connector elements that match defined protocol but have a different port from the configuration file.

  • 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
# File 'manifests/config/server/connector.pp', line 26

define tomcat::config::server::connector (
  $catalina_base                             = undef,
  Enum['present','absent'] $connector_ensure = 'present',
  $port                                      = undef,
  $protocol                                  = $name,
  $parent_service                            = 'Catalina',
  Hash $additional_attributes                = {},
  Array $attributes_to_remove                = [],
  Optional[Boolean] $purge_connectors        = undef,
  $server_config                             = undef,
  Boolean $show_diff                         = true,
) {
  include ::tomcat
  $_catalina_base = pick($catalina_base, $::tomcat::catalina_home)
  tag(sha1($_catalina_base))
  $_purge_connectors = pick($purge_connectors, $::tomcat::purge_connectors)
  if versioncmp($::augeasversion, '1.0.0') < 0 {
    fail('Server configurations require Augeas >= 1.0.0')
  }

  if $_catalina_base !~ /^.*[^\/]$/ {
    fail('$catalina_base must not end in a /!')
  }

  $path = "Server/Service[#attribute/name='${parent_service}']"

  if $_purge_connectors {
    $__purge_connectors = "rm Server//Connector[#attribute/protocol='${protocol}'][#attribute/port!='${port}']"
  } else {
    $__purge_connectors = undef
  }

  if $_purge_connectors and ($connector_ensure == 'absent') {
    fail('$connector_ensure must be set to \'true\' or \'present\' to use $purge_connectors')
  }

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

  if $connector_ensure == 'absent' {
    if ! $port {
      $base_path = "${path}/Connector[#attribute/protocol='${protocol}']"
    } else {
      $base_path = "${path}/Connector[#attribute/port='${port}']"
    }
    $changes = "rm ${base_path}"
  } else {
    if ! $port {
      fail('$port must be specified unless $connector_ensure is set to \'absent\'')
    }

    $base_path = "${path}/Connector[#attribute/port='${port}']"
    $_port = "set ${base_path}/#attribute/port ${port}"
    $_protocol_change = "set ${base_path}/#attribute/protocol ${protocol}"
    if ! empty($additional_attributes) {
      $_additional_attributes = suffix(prefix(join_keys_to_values($additional_attributes, " '"), "set ${base_path}/#attribute/"), "'")
    } else {
      $_additional_attributes = undef
    }
    if ! empty(any2array($attributes_to_remove)) {
      $_attributes_to_remove = prefix(any2array($attributes_to_remove), "rm ${base_path}/#attribute/")
    } else {
      $_attributes_to_remove = undef
    }

    $changes = delete_undef_values(flatten([
      $__purge_connectors,
      $_port,
      $_protocol_change,
      $_additional_attributes,
      $_attributes_to_remove,
    ]))
  }

  augeas { "server-${_catalina_base}-${parent_service}-connector-${port}":
    lens      => 'Xml.lns',
    incl      => $_server_config,
    changes   => $changes,
    show_diff => $show_diff,
  }
}