Skip to content

Commit

Permalink
Puppet >= 4 validations
Browse files Browse the repository at this point in the history
  • Loading branch information
edestecd committed Aug 26, 2020
1 parent c3cf761 commit c34e138
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 59 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file.

## 2020-08-25 (2.0.0) Chris Edester
* PDK support at 1.18.0
* Puppet 5/6ish support
* Drop Puppet 3 support
* Update puppetlabs/stdlib dependency
* Switch to puppet/epel dependency

## 2016-08-10 (1.0.0) Chris Edester
* WARNING: Major revision, will most likely change your configs, especially on RedHat (Please test first)
* Refactor private class params and specs
Expand Down
84 changes: 27 additions & 57 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,40 @@
#

class clamav (
$manage_user = $clamav::params::manage_user,
$manage_repo = $clamav::params::manage_repo,
$manage_clamd = $clamav::params::manage_clamd,
$manage_freshclam = $clamav::params::manage_freshclam,
$manage_clamav_milter = $clamav::params::manage_clamav_milter,
$clamav_package = $clamav::params::clamav_package,
$clamav_version = $clamav::params::clamav_version,
Boolean $manage_user = $clamav::params::manage_user,
Boolean $manage_repo = $clamav::params::manage_repo,
Boolean $manage_clamd = $clamav::params::manage_clamd,
Boolean $manage_freshclam = $clamav::params::manage_freshclam,
Boolean $manage_clamav_milter = $clamav::params::manage_clamav_milter,
String $clamav_package = $clamav::params::clamav_package,
String $clamav_version = $clamav::params::clamav_version,

$user = $clamav::params::user,
$comment = $clamav::params::comment,
Optional[String] $comment = $clamav::params::comment,
$uid = $clamav::params::uid,
$gid = $clamav::params::gid,
$home = $clamav::params::home,
$shell = $clamav::params::shell,
Stdlib::Absolutepath $home = $clamav::params::home,
Stdlib::Absolutepath $shell = $clamav::params::shell,
$group = $clamav::params::group,
$groups = $clamav::params::groups,

$clamd_package = $clamav::params::clamd_package,
$clamd_version = $clamav::params::clamd_version,
$clamd_config = $clamav::params::clamd_config,
$clamd_service = $clamav::params::clamd_service,
String $clamd_package = $clamav::params::clamd_package,
String $clamd_version = $clamav::params::clamd_version,
Stdlib::Absolutepath $clamd_config = $clamav::params::clamd_config,
String $clamd_service = $clamav::params::clamd_service,
$clamd_service_ensure = $clamav::params::clamd_service_ensure,
$clamd_service_enable = $clamav::params::clamd_service_enable,
$clamd_options = $clamav::params::clamd_options,
Boolean $clamd_service_enable = $clamav::params::clamd_service_enable,
Hash $clamd_options = $clamav::params::clamd_options,

$freshclam_package = $clamav::params::freshclam_package,
$freshclam_version = $clamav::params::freshclam_version,
$freshclam_config = $clamav::params::freshclam_config,
Stdlib::Absolutepath $freshclam_config = $clamav::params::freshclam_config,
$freshclam_service = $clamav::params::freshclam_service,
$freshclam_service_ensure = $clamav::params::freshclam_service_ensure,
$freshclam_service_enable = $clamav::params::freshclam_service_enable,
$freshclam_options = $clamav::params::freshclam_options,
$freshclam_sysconfig = $clamav::params::freshclam_sysconfig,
$freshclam_delay = $clamav::params::freshclam_delay,
Boolean $freshclam_service_enable = $clamav::params::freshclam_service_enable,
Hash $freshclam_options = $clamav::params::freshclam_options,
Optional[Stdlib::Absolutepath] $freshclam_sysconfig = $clamav::params::freshclam_sysconfig,
Optional[String] $freshclam_delay = $clamav::params::freshclam_delay,

$clamav_milter_package = $clamav::params::clamav_milter_package,
$clamav_milter_version = $clamav::params::clamav_milter_version,
Expand All @@ -51,50 +51,20 @@
$clamav_milter_options = $clamav::params::clamav_milter_options,
) inherits clamav::params {

# Input validation
$valid_service_statuses = '^(stopped|false|running|true)$'

validate_bool($manage_user, $manage_repo, $manage_clamd, $manage_freshclam, $manage_clamav_milter)
validate_string($clamav_package)
validate_string($clamav_version)

# user
validate_string($comment)
validate_absolute_path($home)
validate_absolute_path($shell)

# clamd
validate_string($clamd_package)
validate_string($clamd_version)
validate_absolute_path($clamd_config)
validate_string($clamd_service)
validate_re($clamd_service_ensure, $valid_service_statuses)
validate_bool($clamd_service_enable)
validate_hash($clamd_options)
$_clamd_options = merge($clamav::params::clamd_default_options, $clamd_options)

# freshclam
validate_absolute_path($freshclam_config)
validate_re($freshclam_service_ensure, $valid_service_statuses)
validate_bool($freshclam_service_enable)
validate_hash($freshclam_options)
$_freshclam_options = merge($clamav::params::freshclam_default_options, $freshclam_options)
if $freshclam_sysconfig {
validate_absolute_path($freshclam_sysconfig)
}
if $freshclam_delay {
validate_string($freshclam_delay)
}

# clamav_milter
if $manage_clamav_milter {
validate_string($clamav_milter_package)
validate_string($clamav_milter_version)
validate_absolute_path($clamav_milter_config)
validate_string($clamav_milter_service)
validate_re($clamav_milter_service_ensure, $valid_service_statuses)
validate_bool($clamav_milter_service_enable)
validate_hash($clamav_milter_options)
assert_type(String, $clamav_milter_package)
assert_type(String, $clamav_milter_version)
assert_type(Stdlib::Absolutepath, $clamav_milter_config)
assert_type(String, $clamav_milter_service)
assert_type(Boolean, $clamav_milter_service_enable)
assert_type(Hash, $clamav_milter_options)
$_clamav_milter_options = merge($clamav::params::clamav_milter_default_options, $clamav_milter_options)
}

Expand Down
4 changes: 2 additions & 2 deletions metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "edestecd-clamav",
"version": "1.0.0",
"version": "2.0.0",
"author": "Chris Edester",
"summary": "Puppet Module for managing ClamAV",
"license": "GPL-3.0+",
Expand All @@ -10,7 +10,7 @@
"dependencies": [
{
"name": "puppetlabs/stdlib",
"version_requirement": ">= 4.1.0 < 7.0.0"
"version_requirement": ">= 4.13.0 < 7.0.0"
},
{
"name": "puppet/epel",
Expand Down
8 changes: 8 additions & 0 deletions spec/classes/clamav_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@
it { is_expected.to contain_class('clamav::freshclam') }
end

context 'manage manage_clamav_milter' do
if facts[:osfamily] == 'RedHat' && facts[:operatingsystemrelease] >= '7.0'
let(:params) { { manage_clamav_milter: true } }

it { is_expected.to contain_class('clamav::clamav_milter') }
end
end

context 'clamav::user' do
let(:params) { { manage_user: true } }

Expand Down

0 comments on commit c34e138

Please sign in to comment.