|
2 | 2 | # |
3 | 3 | # @param catalina_base |
4 | 4 | # Specifies the root of the Tomcat installation. |
| 5 | +# @param additional_attributes |
| 6 | +# Specifies any additional attributes to add to the Context. Should be a hash of the format 'attribute' => 'value'. Optional |
| 7 | +# @param attributes_to_remove |
| 8 | +# Specifies an array of attributes to remove from the element. Valid options: an array of strings. `[]`. |
5 | 9 | # @param show_diff |
6 | 10 | # Specifies display differences when augeas changes files, defaulting to true. Valid options: true or false. |
7 | 11 | # |
8 | 12 | define tomcat::config::context ( |
9 | | - Optional[Stdlib::Absolutepath] $catalina_base = undef, |
10 | | - Boolean $show_diff = true, |
| 13 | + Optional[Stdlib::Absolutepath] $catalina_base = undef, |
| 14 | + Hash $additional_attributes = {}, |
| 15 | + Array $attributes_to_remove = [], |
| 16 | + Boolean $show_diff = true, |
11 | 17 | ) { |
12 | 18 | include tomcat |
13 | 19 | $_catalina_base = pick($catalina_base, $tomcat::catalina_home) |
|
17 | 23 | fail('Server configurations require Augeas >= 1.0.0') |
18 | 24 | } |
19 | 25 |
|
| 26 | + $base_path = 'Context' |
| 27 | + |
| 28 | + if ! empty($additional_attributes) { |
| 29 | + $set_additional_attributes = suffix(prefix(join_keys_to_values($additional_attributes, " '"), "set ${base_path}/#attribute/"), "'") |
| 30 | + |
| 31 | + # Extra augeas to add atttibutes if there are currently no attrributes in <Context> element |
| 32 | + augeas { "context-add_attribute_${_catalina_base}": |
| 33 | + incl => "${catalina_base}/conf/context.xml", |
| 34 | + lens => 'Xml.lns', |
| 35 | + context => "/files/${catalina_base}/conf/context.xml", |
| 36 | + changes => ['ins #attribute before Context/#text[1]'] + $set_additional_attributes, |
| 37 | + onlyif => 'match Context/#attribute size == 0', |
| 38 | + } |
| 39 | + } else { |
| 40 | + $set_additional_attributes = undef |
| 41 | + } |
| 42 | + if ! empty(any2array($attributes_to_remove)) { |
| 43 | + $rm_attributes_to_remove = prefix(any2array($attributes_to_remove), "rm ${base_path}/#attribute/") |
| 44 | + } else { |
| 45 | + $rm_attributes_to_remove = undef |
| 46 | + } |
| 47 | + |
20 | 48 | $_watched_resource = 'set Context/WatchedResource/#text "WEB-INF/web.xml"' |
21 | 49 |
|
22 | | - $changes = delete_undef_values([$_watched_resource]) |
| 50 | + $changes = delete_undef_values(flatten([ |
| 51 | + $_watched_resource, |
| 52 | + $set_additional_attributes, |
| 53 | + $rm_attributes_to_remove, |
| 54 | + ])) |
23 | 55 |
|
24 | 56 | if ! empty($changes) { |
25 | 57 | augeas { "context-${_catalina_base}": |
|
0 commit comments