Skip to content

Commit

Permalink
Replace validate_apache_loglevel() with data type
Browse files Browse the repository at this point in the history
The function was introduced before Puppet 4 was released.  It was
originally created to reduce duplicated use of stdlib's `validate_re`.

See #1097
  • Loading branch information
alexjfisher committed May 2, 2020
1 parent e8465d2 commit 426099e
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 119 deletions.
28 changes: 0 additions & 28 deletions lib/puppet/functions/apache/validate_apache_log_level.rb

This file was deleted.

31 changes: 0 additions & 31 deletions lib/puppet/parser/functions/validate_apache_log_level.rb

This file was deleted.

8 changes: 3 additions & 5 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@
# > **Note**: Do not configure this parameter manually without special reason.
#
# @param log_level
# Changes the error log's verbosity. Valid options are: `alert`, `crit`, `debug`, `emerg`, `error`,
# `info`, `notice` and `warn`.
# Configures the apache [LogLevel](https://httpd.apache.org/docs/current/mod/core.html#loglevel) directive
# which adjusts the verbosity of the messages recorded in the error logs.
#
# @param log_formats
# Define additional `LogFormat` directives. Values: A hash, such as:
Expand Down Expand Up @@ -520,7 +520,7 @@
$limitreqfields = '100',
$logroot = $::apache::params::logroot,
$logroot_mode = $::apache::params::logroot_mode,
$log_level = $::apache::params::log_level,
Apache::LogLevel $log_level = $::apache::params::log_level,
$log_formats = {},
$ssl_file = undef,
$ports_file = $::apache::params::ports_file,
Expand Down Expand Up @@ -602,8 +602,6 @@
}
}

apache::validate_apache_log_level($log_level)

class { '::apache::service':
service_name => $service_name,
service_enable => $service_enable,
Expand Down
6 changes: 1 addition & 5 deletions manifests/vhost.pp
Original file line number Diff line number Diff line change
Expand Up @@ -1735,7 +1735,7 @@
$logroot_mode = undef,
$logroot_owner = undef,
$logroot_group = undef,
$log_level = undef,
Optional[Apache::LogLevel] $log_level = undef,
Boolean $access_log = true,
$access_log_file = false,
$access_log_pipe = false,
Expand Down Expand Up @@ -1940,10 +1940,6 @@

# Input validation begins

if $log_level {
apache::validate_apache_log_level($log_level)
}

if $access_log_file and $access_log_pipe {
fail("Apache::Vhost[${name}]: 'access_log_file' and 'access_log_pipe' cannot be defined at the same time")
}
Expand Down
12 changes: 0 additions & 12 deletions spec/functions/validate_apache_log_level_spec.rb

This file was deleted.

23 changes: 23 additions & 0 deletions spec/type_aliases/loglevel_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require 'spec_helper'

describe 'Apache::LogLevel' do
[
'info',
'warn ssl:info',
'warn mod_ssl.c:info',
'warn mod_ssl.c:info',
'warn ssl_module:info',
'trace4',
].each do |allowed_value|
it { is_expected.to allow_value(allowed_value) }
end

[
'garbage',
'',
[],
['info'],
].each do |invalid_value|
it { is_expected.not_to allow_value(invalid_value) }
end
end
38 changes: 0 additions & 38 deletions spec/unit/puppet/parser/functions/validate_apache_log_level.rb

This file was deleted.

27 changes: 27 additions & 0 deletions types/loglevel.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# @summary A string that conforms to the Apache `LogLevel` syntax.
#
# A string that conforms to the Apache `LogLevel` syntax.
# Different levels can be specified for individual apache modules.
#
# ie. `[module:]level [module:level] ...`
#
# The levels are (in order of decreasing significance):
# * `emerg`
# * `alert`
# * `crit`
# * `error`
# * `warn`
# * `notice`
# * `info`
# * `debug`
# * `trace1`
# * `trace2`
# * `trace3`
# * `trace4`
# * `trace5`
# * `trace6`
# * `trace7`
# * `trace8`
#
# @see https://httpd.apache.org/docs/current/mod/core.html#loglevel
type Apache::LogLevel = Pattern[/(emerg|alert|crit|error|warn|notice|info|debug|trace[1-8])/]

0 comments on commit 426099e

Please sign in to comment.