Skip to content

Commit b7ebd93

Browse files
committed
Refactor sssd.conf template
1 parent 1d215ea commit b7ebd93

File tree

2 files changed

+65
-80
lines changed

2 files changed

+65
-80
lines changed

manifests/config.pp

Lines changed: 63 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -68,31 +68,73 @@
6868
}
6969
}
7070

71+
# Build configuration lines in order (matching expected test output)
72+
# Services configuration - sudo has to be started by the socket
73+
$filtered_services = Array($_services) - ['sudo']
74+
$services_line = $_services.empty ? {
75+
true => [],
76+
false => $filtered_services.empty ? { true => [], false => ["services = ${filtered_services.join(',')}"] }
77+
}
78+
79+
# Basic configuration
80+
$description_line = $_description ? { undef => [], default => ["description = ${_description}"] }
81+
82+
# Domains configuration
83+
$domains_line = $_domains.empty ? { true => [], false => ["domains = ${Array($_domains).join(', ')}"] }
84+
85+
# Required configuration parameters
86+
$config_file_version_line = ["config_file_version = ${_config_file_version}"]
87+
$reconnection_retries_line = ["reconnection_retries = ${_reconnection_retries}"]
88+
89+
# Optional string parameters
90+
$re_expression_line = $_re_expression ? { undef => [], default => ["re_expression = ${_re_expression}"] }
91+
$full_name_format_line = $_full_name_format ? { undef => [], default => ["full_name_format = ${_full_name_format}"] }
92+
93+
# Optional boolean parameters (special undef checking)
94+
$try_inotify_line = $_try_inotify ? { undef => [], default => ["try_inotify = ${_try_inotify}"] }
95+
$enable_files_domain_line = $_enable_files_domain ? { undef => [], default => ["enable_files_domain = ${_enable_files_domain}"] }
96+
97+
# Optional directory and user parameters
98+
$krb5_rcache_dir_line = $_krb5_rcache_dir ? { undef => [], default => ["krb5_rcache_dir = ${_krb5_rcache_dir}"] }
99+
$user_line = $_user ? { undef => [], default => ["user = ${_user}"] }
100+
$default_domain_suffix_line = $_default_domain_suffix ? { undef => [], default => ["default_domain_suffix = ${_default_domain_suffix}"] }
101+
$override_space_line = $_override_space ? { undef => [], default => ["override_space = ${_override_space}"] }
102+
103+
# Debug configuration
104+
$debug_level_line = $_debug_level ? { undef => [], default => ["debug_level = ${_debug_level}"] }
105+
$debug_timestamps_line = ["debug_timestamps = ${_debug_timestamps}"]
106+
$debug_microseconds_line = ["debug_microseconds = ${_debug_microseconds}"]
107+
108+
# Combine all lines in order
109+
$config_lines = (
110+
$services_line +
111+
$description_line +
112+
$domains_line +
113+
$config_file_version_line +
114+
$reconnection_retries_line +
115+
$re_expression_line +
116+
$full_name_format_line +
117+
$try_inotify_line +
118+
$krb5_rcache_dir_line +
119+
$user_line +
120+
$default_domain_suffix_line +
121+
$override_space_line +
122+
$enable_files_domain_line +
123+
$debug_level_line +
124+
$debug_timestamps_line +
125+
$debug_microseconds_line
126+
)
127+
128+
# Join all configuration lines
129+
$content = $config_lines.join("\n")
130+
71131
file { '/etc/sssd/sssd.conf':
72132
owner => 'root',
73133
group => 'root',
74134
mode => '0600',
75-
content => epp(
76-
"${module_name}/sssd.conf.epp",
77-
{
78-
'_domains' => $_domains,
79-
'_debug_level' => $_debug_level,
80-
'_debug_timestamps' => $_debug_timestamps,
81-
'_debug_microseconds' => $_debug_microseconds,
82-
'_description' => $_description,
83-
'_enable_files_domain' => $_enable_files_domain,
84-
'_config_file_version' => $_config_file_version,
85-
'_services' => $_services,
86-
'_reconnection_retries' => $_reconnection_retries,
87-
'_re_expression' => $_re_expression,
88-
'_full_name_format' => $_full_name_format,
89-
'_try_inotify' => $_try_inotify,
90-
'_krb5_rcache_dir' => $_krb5_rcache_dir,
91-
'_user' => $_user,
92-
'_default_domain_suffix' => $_default_domain_suffix,
93-
'_override_space' => $_override_space,
94-
},
95-
),
135+
content => epp("${module_name}/sssd.conf.epp", {
136+
'content' => $content,
137+
}),
96138
notify => Class["${module_name}::service"],
97139
}
98140
}

templates/sssd.conf.epp

Lines changed: 2 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,6 @@
11
<% |
2-
Optional[String] $_description,
3-
Optional[Array[String]] $_services,
4-
Optional[Array[String]] $_domains,
5-
Integer[1] $_config_file_version,
6-
Integer[0] $_reconnection_retries,
7-
Optional[String] $_re_expression,
8-
Optional[String] $_full_name_format,
9-
Optional[Boolean] $_try_inotify,
10-
Optional[String] $_krb5_rcache_dir,
11-
Optional[String] $_user,
12-
Optional[String] $_default_domain_suffix,
13-
Optional[String] $_override_space,
14-
Optional[Boolean] $_enable_files_domain,
15-
Optional[Sssd::DebugLevel] $_debug_level,
16-
Boolean $_debug_timestamps,
17-
Boolean $_debug_microseconds,
2+
String[1] $content,
183
| -%>
194
# sssd::config
205
[sssd]
21-
<%
22-
# sudo has to be started by the socket
23-
unless Array($_services).empty {
24-
-%>
25-
services = <%= (Array($_services) - ['sudo']).join(',') %>
26-
<% } -%>
27-
<% if $_description { -%>
28-
description = <%= $_description %>
29-
<% } -%>
30-
<% unless $_domains.empty { -%>
31-
domains = <%= Array($_domains).join(', ') %>
32-
<% } -%>
33-
config_file_version = <%= $_config_file_version %>
34-
reconnection_retries = <%= $_reconnection_retries %>
35-
<% if $_re_expression { -%>
36-
re_expression = <%= $_re_expression %>
37-
<% } -%>
38-
<% if $_full_name_format { -%>
39-
full_name_format = <%= $_full_name_format %>
40-
<% } -%>
41-
<% unless $_try_inotify =~ Undef { -%>
42-
try_inotify = <%= $_try_inotify %>
43-
<% } -%>
44-
<% if $_krb5_rcache_dir { -%>
45-
krb5_rcache_dir = <%= $_krb5_rcache_dir %>
46-
<% } -%>
47-
<% if $_user { -%>
48-
user = <%= $_user %>
49-
<% } -%>
50-
<% if $_default_domain_suffix { -%>
51-
default_domain_suffix = <%= $_default_domain_suffix %>
52-
<% } -%>
53-
<% if $_override_space { -%>
54-
override_space = <%= $_override_space %>
55-
<% } -%>
56-
<% unless $_enable_files_domain =~ Undef { -%>
57-
enable_files_domain = <%= $_enable_files_domain %>
58-
<% } -%>
59-
<% unless $_debug_level =~ Undef { -%>
60-
debug_level = <%= $_debug_level %>
61-
<% } -%>
62-
debug_timestamps = <%= $_debug_timestamps %>
63-
debug_microseconds = <%= $_debug_microseconds %>
6+
<%= $content %>

0 commit comments

Comments
 (0)