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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
# File 'manifests/config/server/realm.pp', line 30
define tomcat::config::server::realm (
Optional[String[1]] $catalina_base = undef,
String[1] $class_name = $name,
Enum['present','absent'] $realm_ensure = 'present',
String $parent_service = 'Catalina',
String $parent_engine = 'Catalina',
Optional[String[1]] $parent_host = undef,
Optional[String[1]] $parent_realm = undef,
Hash $additional_attributes = {},
Array $attributes_to_remove = [],
Optional[Boolean] $purge_realms = undef,
Optional[String[1]] $server_config = undef,
Boolean $show_diff = true,
) {
include tomcat
$_catalina_base = pick($catalina_base, $tomcat::catalina_home)
tag(sha1($_catalina_base))
$_purge_realms = pick($purge_realms, $tomcat::purge_realms)
if versioncmp($facts['augeas']['version'], '1.0.0') < 0 {
fail('Server configurations require Augeas >= 1.0.0')
}
if $_purge_realms and ($realm_ensure == 'absent') {
fail('$realm_ensure must be set to \'present\' to use $purge_realms')
}
if $_purge_realms {
# Perform deletions in reverse depth order as workaround for
# https://github.com/hercules-team/augeas/issues/319
$__purge_realms = [
'rm //Realm//Realm',
'rm //Context//Realm',
'rm //Host//Realm',
'rm //Engine//Realm',
'rm //Server//Realm',
]
} else {
$__purge_realms = undef
}
$engine_path = "Server/Service[#attribute/name='${parent_service}']/Engine[#attribute/name='${parent_engine}']"
# The Realm may be nested under a Host element.
if $parent_host {
$host_path = "${engine_path}/Host[#attribute/name='${parent_host}']"
} else {
$host_path = $engine_path
}
# The Realm could also be nested under another Realm element if the parent realm is a CombinedRealm.
if $parent_realm {
$path = "${host_path}/Realm[#attribute/className='${parent_realm}']/Realm"
} else {
$path = "${host_path}/Realm"
}
if $server_config {
$_server_config = $server_config
} else {
$_server_config = "${_catalina_base}/conf/server.xml"
}
# For backwards-compatible reasons, match previously managed realms that do
# not have puppetName but have a known className. Either we match puppetName
# or className; puppet could not have created a state in which two realms
# match.
$path_expression = "#attribute/puppetName='${name}' or (count(#attribute/puppetName)=0 and #attribute/className='${class_name}')"
if $realm_ensure == 'absent' {
$changes = "rm ${path}[${path_expression}]"
} else {
# This will create the node if there are no matches
$_class_name = "set ${path}[${path_expression}]/#attribute/className '${class_name}'"
$puppet_name = "set ${path}[${path_expression}]/#attribute/puppetName '${name}'"
if ! empty($additional_attributes) {
$_additional_attributes = suffix(prefix(join_keys_to_values($additional_attributes, " '"),
"set ${path}[${path_expression}]/#attribute/"), "'")
} else {
$_additional_attributes = undef
}
if ! empty(any2array($attributes_to_remove)) {
$_attributes_to_remove = prefix(any2array($attributes_to_remove), "rm ${path}[${path_expression}]/#attribute/")
} else {
$_attributes_to_remove = undef
}
$changes = delete_undef_values(flatten([
$__purge_realms,
$puppet_name,
$_class_name,
$_additional_attributes,
$_attributes_to_remove,
]))
}
augeas { "${_catalina_base}-${parent_service}-${parent_engine}-${parent_host}-${parent_realm}-realm-${name}":
lens => 'Xml.lns',
incl => $_server_config,
changes => $changes,
show_diff => $show_diff,
}
}
|