Make logrotate::file more resilient

Validate that the first option is a string.
Mutate the path to remove /'s, allowing full paths to be passed.

Change-Id: I341290c430023e5e9a24bf2247482ed818ea4a26
This commit is contained in:
Spencer Krum 2015-06-08 10:32:07 -07:00
parent 385a1a5031
commit df4961a081
2 changed files with 26 additions and 3 deletions

View File

@ -1,3 +1,20 @@
# OpenStack Logrotate Module # OpenStack Logrotate Module
This module installs and configures Logrotate This module installs and configures Logrotate
Rotate logfiles using the logrotate::file defined type:
include logrotate
logrotate::file { 'manage_projects.log':
log => '/var/log/manage_projects.log',
options => [
'compress',
'missingok',
'rotate 30',
'daily',
'notifempty',
'copytruncate',
],
}

View File

@ -1,19 +1,24 @@
# == Define: logrotate::file # == Define: logrotate::file
# #
define logrotate::file( $log, define logrotate::file (
$log,
$options, $options,
$ensure=present, $ensure=present,
$prerotate='undef', $prerotate='undef',
$postrotate='undef', $postrotate='undef',
$firstaction='undef', $firstaction='undef',
$lastaction='undef') { $lastaction='undef',
) {
# $options should be an array containing 1 or more logrotate # $options should be an array containing 1 or more logrotate
# directives (e.g. missingok, compress). # directives (e.g. missingok, compress).
validate_string($options[0])
include logrotate include logrotate
# This allows us to handle fully pathed files
$escaped_path = regsubst($name, '/', '_', 'G')
file { "/etc/logrotate.d/${name}": file { "/etc/logrotate.d/${escaped_path}":
ensure => $ensure, ensure => $ensure,
owner => 'root', owner => 'root',
group => 'root', group => 'root',
@ -21,4 +26,5 @@ define logrotate::file( $log,
content => template('logrotate/config.erb'), content => template('logrotate/config.erb'),
require => File['/etc/logrotate.d'], require => File['/etc/logrotate.d'],
} }
} }