Skip to content

Commit 5268851

Browse files
committed
Refactor pam template
1 parent 09e9f9b commit 5268851

File tree

2 files changed

+75
-65
lines changed

2 files changed

+75
-65
lines changed

manifests/service/pam.pp

Lines changed: 72 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,25 +61,81 @@
6161
},
6262
)
6363
} else {
64+
# Build configuration content for the PAM service
65+
$_base_content = [
66+
'# sssd::service::pam',
67+
]
68+
69+
# Add conditional parameters if defined
70+
if $description {
71+
$_description_entries = ["description = ${description}"]
72+
} else {
73+
$_description_entries = []
74+
}
75+
76+
if $debug_level {
77+
$_debug_level_entries = ["debug_level = ${debug_level}"]
78+
} else {
79+
$_debug_level_entries = []
80+
}
81+
82+
$_debug_timestamps_entries = $debug_timestamps ? {
83+
true => ['debug_timestamps = true'],
84+
false => ['debug_timestamps = false'],
85+
}
86+
87+
$_debug_microseconds_entries = $debug_microseconds ? {
88+
true => ['debug_microseconds = true'],
89+
false => ['debug_microseconds = false'],
90+
}
91+
92+
$_reconnection_retries_entries = ["reconnection_retries = ${reconnection_retries}"]
93+
94+
if $command {
95+
$_command_entries = ["command = ${command}"]
96+
} else {
97+
$_command_entries = []
98+
}
99+
100+
$_offline_credentials_expiration_entries = ["offline_credentials_expiration = ${offline_credentials_expiration}"]
101+
$_offline_failed_login_attempts_entries = ["offline_failed_login_attempts = ${offline_failed_login_attempts}"]
102+
$_offline_failed_login_delay_entries = ["offline_failed_login_delay = ${offline_failed_login_delay}"]
103+
$_pam_verbosity_entries = ["pam_verbosity = ${pam_verbosity}"]
104+
$_pam_id_timeout_entries = ["pam_id_timeout = ${pam_id_timeout}"]
105+
$_pam_pwd_expiration_warning_entries = ["pam_pwd_expiration_warning = ${pam_pwd_expiration_warning}"]
106+
107+
if $get_domains_timeout {
108+
$_get_domains_timeout_entries = ["get_domains_timeout = ${get_domains_timeout}"]
109+
} else {
110+
$_get_domains_timeout_entries = []
111+
}
112+
113+
if $pam_trusted_users {
114+
$_pam_trusted_users_entries = ["pam_trusted_users = ${pam_trusted_users}"]
115+
} else {
116+
$_pam_trusted_users_entries = []
117+
}
118+
119+
if $pam_public_domains {
120+
$_pam_public_domains_entries = ["pam_public_domains = ${pam_public_domains}"]
121+
} else {
122+
$_pam_public_domains_entries = []
123+
}
124+
125+
$_pam_cert_auth_entries = $pam_cert_auth ? {
126+
true => ['pam_cert_auth = True'],
127+
false => [],
128+
}
129+
130+
# Combine all configuration entries in the expected order
131+
$_all_entries = $_base_content + $_description_entries + $_debug_level_entries + $_debug_timestamps_entries + $_debug_microseconds_entries + $_reconnection_retries_entries + $_command_entries + $_offline_credentials_expiration_entries + $_offline_failed_login_attempts_entries + $_offline_failed_login_delay_entries + $_pam_verbosity_entries + $_pam_id_timeout_entries + $_pam_pwd_expiration_warning_entries + $_get_domains_timeout_entries + $_pam_trusted_users_entries + $_pam_public_domains_entries + $_pam_cert_auth_entries
132+
133+
$_final_content = $_all_entries.join("\n")
134+
64135
$_content = epp(
65136
"${module_name}/service/pam.epp",
66137
{
67-
'description' => $description,
68-
'debug_level' => $debug_level,
69-
'debug_timestamps' => $debug_timestamps,
70-
'debug_microseconds' => $debug_microseconds,
71-
'pam_cert_auth' => $pam_cert_auth,
72-
'reconnection_retries' => $reconnection_retries,
73-
'command' => $command,
74-
'offline_credentials_expiration' => $offline_credentials_expiration,
75-
'offline_failed_login_attempts' => $offline_failed_login_attempts,
76-
'offline_failed_login_delay' => $offline_failed_login_delay,
77-
'pam_verbosity' => $pam_verbosity,
78-
'pam_id_timeout' => $pam_id_timeout,
79-
'pam_pwd_expiration_warning' => $pam_pwd_expiration_warning,
80-
'get_domains_timeout' => $get_domains_timeout,
81-
'pam_trusted_users' => $pam_trusted_users,
82-
'pam_public_domains' => $pam_public_domains,
138+
'content' => $_final_content,
83139
},
84140
)
85141
}

templates/service/pam.epp

Lines changed: 3 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,5 @@
1-
<% |
2-
Optional[String] $description,
3-
Optional[Sssd::DebugLevel] $debug_level,
4-
Boolean $debug_timestamps,
5-
Boolean $debug_microseconds,
6-
Boolean $pam_cert_auth,
7-
Integer $reconnection_retries,
8-
Optional[String] $command,
9-
Integer $offline_credentials_expiration,
10-
Integer $offline_failed_login_attempts,
11-
Integer $offline_failed_login_delay,
12-
Integer $pam_verbosity,
13-
Integer $pam_id_timeout,
14-
Integer $pam_pwd_expiration_warning,
15-
Optional[Integer] $get_domains_timeout,
16-
Optional[String] $pam_trusted_users,
17-
Optional[String] $pam_public_domains,
1+
<%- |
2+
String $content,
183
| -%>
19-
20-
# sssd::service::pam
214
[pam]
22-
<% if $description { -%>
23-
description = <%= $description %>
24-
<% } -%>
25-
<% if $debug_level { -%>
26-
debug_level = <%= $debug_level %>
27-
<% } -%>
28-
debug_timestamps = <%= $debug_timestamps %>
29-
debug_microseconds = <%= $debug_microseconds %>
30-
reconnection_retries = <%= $reconnection_retries %>
31-
<% if $command { -%>
32-
command = <%= $command %>
33-
<% } -%>
34-
offline_credentials_expiration = <%= $offline_credentials_expiration %>
35-
offline_failed_login_attempts = <%= $offline_failed_login_attempts %>
36-
offline_failed_login_delay = <%= $offline_failed_login_delay %>
37-
pam_verbosity = <%= $pam_verbosity %>
38-
pam_id_timeout = <%= $pam_id_timeout %>
39-
pam_pwd_expiration_warning = <%= $pam_pwd_expiration_warning %>
40-
<% if $get_domains_timeout { -%>
41-
get_domains_timeout = <%= $get_domains_timeout %>
42-
<% } -%>
43-
<% if $pam_trusted_users { -%>
44-
pam_trusted_users = <%= $pam_trusted_users %>
45-
<% } -%>
46-
<% if $pam_public_domains { -%>
47-
pam_public_domains = <%= $pam_public_domains %>
48-
<% } -%>
49-
<% if $pam_cert_auth { -%>
50-
pam_cert_auth = True
51-
<% } -%>
5+
<%= $content %>

0 commit comments

Comments
 (0)