Skip to content

Commit 10fd1e8

Browse files
author
Phil Friderici
committed
Remove validations, use stricter data types instead
1 parent 3e1c82a commit 10fd1e8

File tree

4 files changed

+11
-26
lines changed

4 files changed

+11
-26
lines changed

manifests/init.pp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,22 +60,14 @@
6060
Variant[Enum['true', 'false'], Boolean] $run_in_noop = true, #lint:ignore:quoted_booleans
6161
String $cron_command = '/opt/puppetlabs/bin/puppet agent --onetime --no-daemonize --no-usecacheonfailure --detailed-exitcodes --no-splay', #lint:ignore:140chars
6262
Variant[Enum['true', 'false'], Boolean] $run_at_boot = true, #lint:ignore:quoted_booleans
63-
String $config_path = '/etc/puppetlabs/puppet/puppet.conf',
63+
Stdlib::Absolutepath $config_path = '/etc/puppetlabs/puppet/puppet.conf',
6464
String $server = 'puppet',
6565
String $ca_server = 'puppet',
6666
String $env = $environment,
6767
Variant[Enum['true', 'false'], Boolean] $graph = false, #lint:ignore:quoted_booleans
68-
String $agent_sysconfig_path = '/etc/sysconfig/puppet',
68+
Stdlib::Absolutepath $agent_sysconfig_path = '/etc/sysconfig/puppet',
6969
Hash $custom_settings = {},
7070
) {
71-
if $config_path != undef {
72-
validate_absolute_path($config_path)
73-
}
74-
75-
if $agent_sysconfig_path != undef {
76-
validate_absolute_path($agent_sysconfig_path)
77-
}
78-
7971
if is_string($run_every_thirty) == true {
8072
$run_every_thirty_bool = str2bool($run_every_thirty)
8173
} else {

manifests/server.pp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,13 @@
2828
class puppet::server (
2929
Variant[Enum['true', 'false'], Boolean] $ca = false, #lint:ignore:quoted_booleans
3030
Variant[Array[String, 1], Undef] $autosign_entries = undef,
31-
String $sysconfig_path = '/etc/sysconfig/puppetserver',
32-
String $memory_size = '2g', # only m and g are appropriate for unit
33-
Optional[String] $enc = undef,
31+
Stdlib::Absolutepath $sysconfig_path = '/etc/sysconfig/puppetserver',
32+
Pattern[/^\d+(m|g)$/] $memory_size = '2g', # only m and g are appropriate for unit
33+
Optional[Stdlib::Absolutepath] $enc = undef,
3434
Optional[String] $dns_alt_names = undef,
3535
) {
3636
include puppet
3737

38-
if $sysconfig_path != undef {
39-
validate_absolute_path($sysconfig_path)
40-
}
41-
42-
validate_re($memory_size, '^\d+(m|g)$', "puppet::memory_size is <${memory_size}> and must be an integer following by the unit 'm' or 'g'.") #lint:ignore:140chars
43-
4438
$ini_defaults = {
4539
ensure => 'present',
4640
path => $puppet::config_path,
@@ -59,7 +53,6 @@
5953
}
6054

6155
if $enc != undef {
62-
validate_absolute_path($enc)
6356
$ini_enc_settings = {
6457
'node_terminus' => { setting => 'node_terminus', value => 'exec' },
6558
'external_nodes' => { setting => 'external_nodes', value => $enc },

spec/classes/init_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,11 +312,11 @@
312312

313313
describe 'parameter type and content validations' do
314314
validations = {
315-
'absolute paths' => {
315+
'Stdlib::Absolutepath' => {
316316
name: ['config_path', 'agent_sysconfig_path'],
317317
valid: ['/absolute/path'],
318318
invalid: ['not/an/absolute/path'],
319-
message: 'is not an absolute path',
319+
message: 'expects a Stdlib::Absolutepath',
320320
},
321321
'booleans' => {
322322
name: ['run_every_thirty', 'run_in_noop', 'run_at_boot', 'graph'],

spec/classes/server_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,11 @@
183183

184184
describe 'parameter type and content validations' do
185185
validations = {
186-
'absolute paths' => {
186+
'Stdlib::Absolutepath' => {
187187
name: ['sysconfig_path', 'enc'],
188188
valid: ['/absolute/path'],
189189
invalid: ['not/an/absolute/path'],
190-
message: 'is not an absolute path',
190+
message: 'expects a Stdlib::Absolutepath',
191191
},
192192
'booleans' => {
193193
name: ['ca'],
@@ -207,11 +207,11 @@
207207
invalid: [[], [1, 'not_all', 'string'], true, 'string', { 'ha' => 'sh' }, 3, 2.42],
208208
message: 'Error while evaluating a Resource Statement',
209209
},
210-
'memory size regex' => {
210+
'Pattern[/^\d+(m|g)$/]' => {
211211
name: ['memory_size'],
212212
valid: ['1g', '1m', '1500m', '3g'],
213213
invalid: ['1g1', 'm', '1k', '2t', 'g3', '1.2g'],
214-
message: 'must be an integer following by the unit',
214+
message: 'expects a match for Pattern',
215215
},
216216
}
217217

0 commit comments

Comments
 (0)