|
| 1 | +# @summary Configure Resources elements in $CATALINA_BASE/conf/context.xml |
| 2 | +# |
| 3 | +# @param ensure |
| 4 | +# Specifies whether you are trying to add or remove the Resources element. |
| 5 | +# @param resources_name |
| 6 | +# The name of the Resources to be created, relative to the `java:comp/env` context. `$name`. |
| 7 | +# @param name |
| 8 | +# `$resources_name` |
| 9 | +# @param resources_type |
| 10 | +# The fully qualified Java class name expected by the web application when it performs a lookup for this resources. Required to create the resource. |
| 11 | +# @param catalina_base |
| 12 | +# Specifies the root of the Tomcat installation. |
| 13 | +# @param additional_attributes |
| 14 | +# Specifies any additional attributes to add to the Valve. Should be a hash of the format 'attribute' => 'value'. Optional |
| 15 | +# @param attributes_to_remove |
| 16 | +# Specifies an array of attributes to remove from the element. Valid options: an array of strings. `[]`. |
| 17 | +# @param show_diff |
| 18 | +# Specifies display differences when augeas changes files, defaulting to true. Valid options: true or false. |
| 19 | +# |
| 20 | +define tomcat::config::context::resources ( |
| 21 | + Enum['present','absent'] $ensure = 'present', |
| 22 | + $resources_name = $name, |
| 23 | + $resources_type = undef, |
| 24 | + $catalina_base = $::tomcat::catalina_home, |
| 25 | + Hash $additional_attributes = {}, |
| 26 | + Array $attributes_to_remove = [], |
| 27 | + Boolean $show_diff = true, |
| 28 | +) { |
| 29 | + if versioncmp($::augeasversion, '1.0.0') < 0 { |
| 30 | + fail('Server configurations require Augeas >= 1.0.0') |
| 31 | + } |
| 32 | + |
| 33 | + if $resources_name { |
| 34 | + $_resources_name = $resources_name |
| 35 | + } else { |
| 36 | + $_resources_name = $name |
| 37 | + } |
| 38 | + |
| 39 | + $base_path = "Context/Resources[#attribute/name='${_resources_name}']" |
| 40 | + |
| 41 | + if $ensure == 'absent' { |
| 42 | + $changes = "rm ${base_path}" |
| 43 | + } else { |
| 44 | + # (MODULES-3353) does this need to be quoted? |
| 45 | + $set_name = "set ${base_path}/#attribute/name ${_resources_name}" |
| 46 | + if $resources_type { |
| 47 | + $set_type = "set ${base_path}/#attribute/type ${resources_type}" |
| 48 | + } else { |
| 49 | + $set_type = undef |
| 50 | + } |
| 51 | + |
| 52 | + if ! empty($additional_attributes) { |
| 53 | + $set_additional_attributes = suffix(prefix(join_keys_to_values($additional_attributes, " '"), "set ${base_path}/#attribute/"), "'") |
| 54 | + } else { |
| 55 | + $set_additional_attributes = undef |
| 56 | + } |
| 57 | + if ! empty(any2array($attributes_to_remove)) { |
| 58 | + $rm_attributes_to_remove = prefix(any2array($attributes_to_remove), "rm ${base_path}/#attribute/") |
| 59 | + } else { |
| 60 | + $rm_attributes_to_remove = undef |
| 61 | + } |
| 62 | + |
| 63 | + $changes = delete_undef_values(flatten([ |
| 64 | + $set_name, |
| 65 | + $set_type, |
| 66 | + $set_additional_attributes, |
| 67 | + $rm_attributes_to_remove, |
| 68 | + ])) |
| 69 | + } |
| 70 | + |
| 71 | + augeas { "context-${catalina_base}-resources-${name}": |
| 72 | + lens => 'Xml.lns', |
| 73 | + incl => "${catalina_base}/conf/context.xml", |
| 74 | + changes => $changes, |
| 75 | + show_diff => $show_diff, |
| 76 | + } |
| 77 | +} |
0 commit comments