Skip to content
This repository has been archived by the owner on Feb 1, 2022. It is now read-only.

Commit

Permalink
Updates validate_* functions to validate_legacy. Fixes ajcrowe#118
Browse files Browse the repository at this point in the history
  • Loading branch information
jtreminio committed Jan 21, 2018
1 parent db8e767 commit 8bfbcc7
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 136 deletions.
2 changes: 1 addition & 1 deletion manifests/ctlplugin.pp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
include supervisord

# parameter validation
validate_string($ctl_factory)
validate_legacy(String, 'validate_string', $ctl_factory)

concat::fragment { "ctlplugin:${name}":
target => $supervisord::config_file,
Expand Down
62 changes: 31 additions & 31 deletions manifests/eventlistener.pp
Original file line number Diff line number Diff line change
Expand Up @@ -47,36 +47,36 @@
include supervisord

# parameter validation
validate_string($command)
validate_re($ensure_process, ['running', 'stopped', 'removed', 'unmanaged'])
if !is_integer($buffer_size) { validate_re($buffer_size, '^\d+')}
if $events { validate_array($events) }
if $result_handler { validate_string($result_handler) }
if $numprocs { if !is_integer($numprocs) { validate_re($numprocs, '^\d+')} }
if $numprocs_start { if !is_integer($numprocs_start) { validate_re($numprocs_start, '^\d+')} }
if $priority { if !is_integer($priority) { validate_re($priority, '^\d+') } }
if $autostart { if !is_bool($autostart) { validate_re($autostart, ['true', 'false']) } }
if $autorestart { if !is_bool($autorestart) { validate_re($autorestart, ['true', 'false', 'unexpected']) } }
if $startsecs { if !is_integer($startsecs) { validate_re($startsecs, '^\d+')} }
if $startretries { if !is_integer($startretries) { validate_re($startretries, '^\d+')} }
if $exitcodes { validate_string($exitcodes)}
if $stopsignal { validate_re($stopsignal, ['TERM', 'HUP', 'INT', 'QUIT', 'KILL', 'USR1', 'USR2']) }
if $stopwaitsecs { if !is_integer($stopwaitsecs) { validate_re($stopwaitsecs, '^\d+')} }
if $stopasgroup { validate_bool($stopasgroup) }
if $killasgroup { validate_bool($killasgroup) }
if $user { validate_string($user) }
if $redirect_stderr { validate_bool($redirect_stderr) }
validate_string($stdout_logfile)
if $stdout_logfile_maxbytes { validate_string($stdout_logfile_maxbytes) }
if $stdout_logfile_backups { if !is_integer($stdout_logfile_backups) { validate_re($stdout_logfile_backups, '^\d+')} }
if $stdout_events_enabled { validate_bool($stdout_events_enabled) }
validate_string($stderr_logfile)
if $stderr_logfile_maxbytes { validate_string($stderr_logfile_maxbytes) }
if $stderr_logfile_backups { if !is_integer($stderr_logfile_backups) { validate_re($stderr_logfile_backups, '^\d+')} }
if $stderr_events_enabled { validate_bool($stderr_events_enabled) }
validate_legacy(String, 'validate_string', $command)
validate_legacy('Optional[String]', 'validate_re', $ensure_process, ['running', 'stopped', 'removed', 'unmanaged'])
if $buffer_size !~ Integer { validate_legacy('Optional[String]', 'validate_re', $buffer_size, ['^\d+'])}
if $events { validate_legacy(Array, 'validate_array', $events) }
if $result_handler { validate_legacy(String, 'validate_string', $result_handler) }
if $numprocs { if $numprocs !~ Integer { validate_legacy('Optional[String]', 'validate_re', $numprocs, ['^\d+'])} }
if $numprocs_start { if $numprocs_start !~ Integer { validate_legacy('Optional[String]', 'validate_re', $numprocs_start, ['^\d+'])} }
if $priority { if $priority !~ Integer { validate_legacy('Optional[String]', 'validate_re', $priority, ['^\d+']) } }
if $autostart { if $autostart !~ Boolean { validate_legacy('Optional[String]', 'validate_re', $autostart, ['true', 'false']) } }
if $autorestart { if $autorestart !~ Boolean { validate_legacy('Optional[String]', 'validate_re', $autorestart, ['true', 'false', 'unexpected']) } }
if $startsecs { if $startsecs !~ Integer { validate_legacy('Optional[String]', 'validate_re', $startsecs, ['^\d+'])} }
if $startretries { if $startretries !~ Integer { validate_legacy('Optional[String]', 'validate_re', $startretries, ['^\d+'])} }
if $exitcodes { validate_legacy(String, 'validate_string', $exitcodes)}
if $stopsignal { validate_legacy('Optional[String]', 'validate_re', $stopsignal, ['TERM', 'HUP', 'INT', 'QUIT', 'KILL', 'USR1', 'USR2']) }
if $stopwaitsecs { if $stopwaitsecs !~ Integer { validate_legacy('Optional[String]', 'validate_re', $stopwaitsecs, ['^\d+'])} }
if $stopasgroup { validate_legacy(Boolean, 'validate_bool', $stopasgroup) }
if $killasgroup { validate_legacy(Boolean, 'validate_bool', $killasgroup) }
if $user { validate_legacy(String, 'validate_string', $user) }
if $redirect_stderr { validate_legacy(Boolean, 'validate_bool', $redirect_stderr) }
validate_legacy(String, 'validate_string', $stdout_logfile)
if $stdout_logfile_maxbytes { validate_legacy(String, 'validate_string', $stdout_logfile_maxbytes) }
if $stdout_logfile_backups { if $stdout_logfile_backups !~ Integer { validate_legacy('Optional[String]', 'validate_re', $stdout_logfile_backups, ['^\d+'])} }
if $stdout_events_enabled { validate_legacy(Boolean, 'validate_bool', $stdout_events_enabled) }
validate_legacy(String, 'validate_string', $stderr_logfile)
if $stderr_logfile_maxbytes { validate_legacy(String, 'validate_string', $stderr_logfile_maxbytes) }
if $stderr_logfile_backups { if $stderr_logfile_backups !~ Integer { validate_legacy('Optional[String]', 'validate_re', $stderr_logfile_backups, ['^\d+'])} }
if $stderr_events_enabled { validate_legacy(Boolean, 'validate_bool', $stderr_events_enabled) }
if $directory { validate_absolute_path($directory) }
if $umask { validate_re($umask, '^[0-7][0-7][0-7]$') }
validate_re($config_file_mode, '^0[0-7][0-7][0-7]$')
if $umask { validate_legacy('Optional[String]', 'validate_re', $umask, ['^[0-7][0-7][0-7]$']) }
validate_legacy('Optional[String]', 'validate_re', $config_file_mode, ['^0[0-7][0-7][0-7]$'])

# create the correct log variables
$stdout_logfile_path = $stdout_logfile ? {
Expand All @@ -101,11 +101,11 @@
# convert environment data into a csv
if $env_var {
$env_hash = hiera_hash($env_var)
validate_hash($env_hash)
validate_legacy(Hash, 'validate_hash', $env_hash)
$env_string = hash2csv($env_hash)
}
elsif $_event_environment {
validate_hash($_event_environment)
validate_legacy(Hash, 'validate_hash', $_event_environment)
$env_string = hash2csv($_event_environment)
}

Expand Down
64 changes: 32 additions & 32 deletions manifests/fcgi_program.pp
Original file line number Diff line number Diff line change
Expand Up @@ -49,37 +49,37 @@
include supervisord

# parameter validation
validate_string($command)
validate_re($ensure_process, ['running', 'stopped', 'removed', 'unmanaged'])
validate_re($socket, ['^tcp:\/\/.*:\d+$', '^unix:\/\/\/'])
if $process_name { validate_string($process_name) }
if $numprocs { if !is_integer($numprocs) { validate_re($numprocs, '^\d+')} }
if $numprocs_start { if !is_integer($numprocs_start) { validate_re($numprocs_start, '^\d+')} }
if $priority { if !is_integer($priority) { validate_re($priority, '^\d+') } }
if $autostart { if !is_bool($autostart) { validate_re($autostart, ['true', 'false']) } }
if $autorestart { if !is_bool($autorestart) { validate_re($autorestart, ['true', 'false', 'unexpected']) } }
if $startsecs { if !is_integer($startsecs) { validate_re($startsecs, '^\d+')} }
if $startretries { if !is_integer($startretries) { validate_re($startretries, '^\d+')} }
if $exitcodes { validate_string($exitcodes)}
if $stopsignal { validate_re($stopsignal, ['TERM', 'HUP', 'INT', 'QUIT', 'KILL', 'USR1', 'USR2']) }
if $stopwaitsecs { if !is_integer($stopwaitsecs) { validate_re($stopwaitsecs, '^\d+')} }
if $stopasgroup { validate_bool($stopasgroup) }
if $killasgroup { validate_bool($killasgroup) }
if $user { validate_string($user) }
if $redirect_stderr { validate_bool($redirect_stderr) }
validate_string($stdout_logfile)
if $stdout_logfile_maxbytes { validate_string($stdout_logfile_maxbytes) }
if $stdout_logfile_backups { if !is_integer($stdout_logfile_backups) { validate_re($stdout_logfile_backups, '^\d+')} }
if $stdout_capture_maxbytes { validate_string($stdout_capture_maxbytes) }
if $stdout_events_enabled { validate_bool($stdout_events_enabled) }
validate_string($stderr_logfile)
if $stderr_logfile_maxbytes { validate_string($stderr_logfile_maxbytes) }
if $stderr_logfile_backups { if !is_integer($stderr_logfile_backups) { validate_re($stderr_logfile_backups, '^\d+')} }
if $stderr_capture_maxbytes { validate_string($stderr_capture_maxbytes) }
if $stderr_events_enabled { validate_bool($stderr_events_enabled) }
validate_legacy(String, 'validate_string', $command)
validate_legacy('Optional[String]', 'validate_re', $ensure_process, ['running', 'stopped', 'removed', 'unmanaged'])
validate_legacy('Optional[String]', 'validate_re', $socket, ['^tcp:\/\/.*:\d+$', '^unix:\/\/\/'])
if $process_name { validate_legacy(String, 'validate_string', $process_name) }
if $numprocs { if $numprocs !~ Integer { validate_legacy('Optional[String]', 'validate_re', $numprocs, ['^\d+'])} }
if $numprocs_start { if $numprocs_start !~ Integer { validate_legacy('Optional[String]', 'validate_re', $numprocs_start, ['^\d+'])} }
if $priority { if $priority !~ Integer { validate_legacy('Optional[String]', 'validate_re', $priority, ['^\d+']) } }
if $autostart { if $autostart !~ Boolean { validate_legacy('Optional[String]', 'validate_re', $autostart, ['true', 'false']) } }
if $autorestart { if $autorestart !~ Boolean { validate_legacy('Optional[String]', 'validate_re', $autorestart, ['true', 'false', 'unexpected']) } }
if $startsecs { if $startsecs !~ Integer { validate_legacy('Optional[String]', 'validate_re', $startsecs, ['^\d+'])} }
if $startretries { if $startretries !~ Integer { validate_legacy('Optional[String]', 'validate_re', $startretries, ['^\d+'])} }
if $exitcodes { validate_legacy(String, 'validate_string', $exitcodes)}
if $stopsignal { validate_legacy('Optional[String]', 'validate_re', $stopsignal, ['TERM', 'HUP', 'INT', 'QUIT', 'KILL', 'USR1', 'USR2']) }
if $stopwaitsecs { if $stopwaitsecs !~ Integer { validate_legacy('Optional[String]', 'validate_re', $stopwaitsecs, ['^\d+'])} }
if $stopasgroup { validate_legacy(Boolean, 'validate_bool', $stopasgroup) }
if $killasgroup { validate_legacy(Boolean, 'validate_bool', $killasgroup) }
if $user { validate_legacy(String, 'validate_string', $user) }
if $redirect_stderr { validate_legacy(Boolean, 'validate_bool', $redirect_stderr) }
validate_legacy(String, 'validate_string', $stdout_logfile)
if $stdout_logfile_maxbytes { validate_legacy(String, 'validate_string', $stdout_logfile_maxbytes) }
if $stdout_logfile_backups { if $stdout_logfile_backups !~ Integer { validate_legacy('Optional[String]', 'validate_re', $stdout_logfile_backups, ['^\d+'])} }
if $stdout_capture_maxbytes { validate_legacy(String, 'validate_string', $stdout_capture_maxbytes) }
if $stdout_events_enabled { validate_legacy(Boolean, 'validate_bool', $stdout_events_enabled) }
validate_legacy(String, 'validate_string', $stderr_logfile)
if $stderr_logfile_maxbytes { validate_legacy(String, 'validate_string', $stderr_logfile_maxbytes) }
if $stderr_logfile_backups { if $stderr_logfile_backups !~ Integer { validate_legacy('Optional[String]', 'validate_re', $stderr_logfile_backups, ['^\d+'])} }
if $stderr_capture_maxbytes { validate_legacy(String, 'validate_string', $stderr_capture_maxbytes) }
if $stderr_events_enabled { validate_legacy(Boolean, 'validate_bool', $stderr_events_enabled) }
if $directory { validate_absolute_path($directory) }
if $umask { validate_re($umask, '^[0-7][0-7][0-7]$') }
validate_re($config_file_mode, '^0[0-7][0-7][0-7]$')
if $umask { validate_legacy('Optional[String]', 'validate_re', $umask, ['^[0-7][0-7][0-7]$']) }
validate_legacy('Optional[String]', 'validate_re', $config_file_mode, ['^0[0-7][0-7][0-7]$'])

# create the correct log variables
$stdout_logfile_path = $stdout_logfile ? {
Expand All @@ -104,11 +104,11 @@
# convert environment data into a csv
if $env_var {
$env_hash = hiera_hash($env_var)
validate_hash($env_hash)
validate_legacy(Hash, 'validate_hash', $env_hash)
$env_string = hash2csv($env_hash)
}
elsif $_program_environment {
validate_hash($_program_environment)
validate_legacy(Hash, 'validate_hash', $_program_environment)
$env_string = hash2csv($_program_environment)
}

Expand Down
6 changes: 3 additions & 3 deletions manifests/group.pp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
include supervisord

# parameter validation
validate_array($programs)
if $priority { if !is_integer($priority) { validate_re($priority, '^\d+', "invalid priority value of: ${priority}") } }
validate_re($config_file_mode, '^0[0-7][0-7][0-7]$')
validate_legacy(Array, 'validate_array', $programs)
if $priority { if $priority !~ Integer { validate_legacy('Optional[String]', 'validate_re', $priority, ['^\d+']) } }
validate_legacy('Optional[String]', 'validate_re', $config_file_mode, ['^0[0-7][0-7][0-7]$'])

$progstring = array2csv($programs)
$conf = "${supervisord::config_include}/group_${name}.conf"
Expand Down
65 changes: 32 additions & 33 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,20 @@

) inherits supervisord::params {

validate_bool($install_pip)
validate_bool($install_init)
validate_bool($nodaemon)
validate_bool($unix_socket)
validate_bool($unix_auth)
validate_bool($inet_server)
validate_bool($inet_auth)
validate_bool($strip_ansi)
validate_bool($nocleanup)

validate_hash($eventlisteners)
validate_hash($fcgi_programs)
validate_hash($groups)
validate_hash($programs)
validate_legacy(Boolean, 'validate_bool', $install_pip)
validate_legacy(Boolean, 'validate_bool', $install_init)
validate_legacy(Boolean, 'validate_bool', $nodaemon)
validate_legacy(Boolean, 'validate_bool', $unix_socket)
validate_legacy(Boolean, 'validate_bool', $unix_auth)
validate_legacy(Boolean, 'validate_bool', $inet_server)
validate_legacy(Boolean, 'validate_bool', $inet_auth)
validate_legacy(Boolean, 'validate_bool', $strip_ansi)
validate_legacy(Boolean, 'validate_bool', $nocleanup)

validate_legacy(Hash, 'validate_hash', $eventlisteners)
validate_legacy(Hash, 'validate_hash', $fcgi_programs)
validate_legacy(Hash, 'validate_hash', $groups)
validate_legacy(Hash, 'validate_hash', $programs)

validate_absolute_path($config_include)
validate_absolute_path($log_path)
Expand All @@ -105,18 +105,17 @@
if $directory { validate_absolute_path($directory) }

$log_levels = ['^critical$', '^error$', '^warn$', '^info$', '^debug$', '^trace$', '^blather$']
validate_re($log_level, $log_levels, "invalid log_level: ${log_level}")
validate_re($logfile_maxbytes,'^[0-9]*(?:KB|MB|GB)?', "invalid logfile_maxbytes: ${$logfile_maxbytes}")
validate_re($umask, '^0[0-7][0-7]$', "invalid umask: ${umask}.")
validate_re($unix_socket_mode, '^[0-7][0-7][0-7][0-7]$', "invalid unix_socket_mode: ${unix_socket_mode}")
validate_re($ctl_socket, ['^unix$', '^inet$'], "invalid ctl_socket: ${ctl_socket}")
validate_re($config_file_mode, '^0[0-7][0-7][0-7]$')
if $pip_proxy { validate_re($pip_proxy, ['^https?:\/\/.*$'], "invalid pip_proxy: ${pip_proxy}") }

if ! is_integer($logfile_backups) { fail("invalid logfile_backups: ${logfile_backups}.")}
if ! is_integer($minfds) { fail("invalid minfds: ${minfds}.")}
if ! is_integer($minprocs) { fail("invalid minprocs: ${minprocs}.")}
if ! is_integer($inet_server_port) { fail("invalid inet_server_port: ${inet_server_port}.")}
validate_legacy('Optional[String]', 'validate_re', $log_level, $log_levels)
validate_legacy('Optional[String]', 'validate_re', $logfile_maxbytes, ['^[0-9]*(?:KB|MB|GB)?'])
validate_legacy('Optional[String]', 'validate_re', $umask, ['^0[0-7][0-7]$'])
validate_legacy('Optional[String]', 'validate_re', $unix_socket_mode, ['^[0-7][0-7][0-7][0-7]$'])
validate_legacy('Optional[String]', 'validate_re', $ctl_socket, ['^unix$', '^inet$'])
validate_legacy('Optional[String]', 'validate_re', $config_file_mode, ['^0[0-7][0-7][0-7]$'])
if $pip_proxy { validate_legacy('Optional[String]', 'validate_re', $pip_proxy, ['^https?:\/\/.*$']) }
if $logfile_backups !~ Integer { validate_legacy('Optional[String]', 'validate_re', $logfile_backups, ['^\d+'])}
if $minfds !~ Integer { validate_legacy('Optional[String]', 'validate_re', $minfds, ['^\d+'])}
if $minprocs !~ Integer { validate_legacy('Optional[String]', 'validate_re', $minprocs, ['^\d+'])}
if $inet_server_port !~ Integer { validate_legacy('Optional[String]', 'validate_re', $inet_server_port, ['^\d+'])}

if $unix_socket and $inet_server {
$use_ctl_socket = $ctl_socket
Expand All @@ -142,13 +141,13 @@
}

if $unix_auth {
validate_string($unix_username)
validate_string($unix_password)
validate_legacy(String, 'validate_string', $unix_username)
validate_legacy(String, 'validate_string', $unix_password)
}

if $inet_auth {
validate_string($inet_username)
validate_string($inet_password)
validate_legacy(String, 'validate_string', $inet_username)
validate_legacy(String, 'validate_string', $inet_password)
}

# Handle deprecated $environment variable
Expand All @@ -159,17 +158,17 @@
}

if $env_var {
validate_hash($env_var)
validate_legacy(Hash, 'validate_hash', $env_var)
$env_hash = hiera($env_var)
$env_string = hash2csv($env_hash)
}
elsif $_global_environment {
validate_hash($_global_environment)
validate_legacy(Hash, 'validate_hash', $_global_environment)
$env_string = hash2csv($_global_environment)
}

if $config_dirs {
validate_array($config_dirs)
validate_legacy(Array, 'validate_array', $config_dirs)
$config_include_string = join($config_dirs, ' ')
}
else {
Expand Down
Loading

0 comments on commit 8bfbcc7

Please sign in to comment.