Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace validate_apache_loglevel() with data type #2023

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Configures the apache [LogLevel](https://httpd.apache.org/docs/current/mod/core.html#loglevel) directive
# 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

[
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about xemerg to test if ^ at the start is needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regex is copied from the the function and is very lax and could be better. I thought about trying to make it stricter, but decided that a change like that might be suited to a separate PR.

As things stand a ^ at the beginning would be bad. The apache docs describe the allowed syntax as...

Syntax
LogLevel [module:]level [module:level] ...

I think in a perfect world, $log_level would have actually accepted an Array. I doubt it's worth introducing that sort of change now though.

'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])/]