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

Type aliases for all the things #94

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
73 changes: 1 addition & 72 deletions lib/puppet/parser/functions/bareos_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,88 +35,17 @@ module Puppet::Parser::Functions
# defaults:
# quote value
quote = false
# check regex
regex = nil
# check in array
value_in_array = nil
# required for addresses/hashes
hash_separator = ' '

# validation by type
case type
# maybe check more than it is an int
when 'int32', 'pint16', 'pint32', 'port', 'max_blocksize'
# type casting raise error
Integer(value)
when 'name', 'res', 'resource'
when 'name', 'res', 'resource', 'audit_command', 'runscript_short', 'autopassword', 'md5password', 'directory', 'string', 'strname', 'device', 'plugin_names'
quote = true
regex = %r{^[a-z][a-z0-9.\-_ $]{0,126}$}i
when 'acl', 'messages', 'type', 'string_noquote', 'schedule_run_command'
raise 'Value need to be an string' unless value.is_a?(String)
# type md5password is missleading, it is an plain password and not md5 hashed
when 'audit_command', 'runscript_short', 'autopassword', 'md5password', 'directory', 'string', 'strname', 'device', 'plugin_names'
# array
quote = true
raise 'Value need to be an string' unless value.is_a?(String)
when 'speed'
regex = %r{^\d+\W*(k|kb|m|mb)/s$}i
when 'size64'
regex = %r{^(\d+(\.\d+)?)\W*(k|kb|m|mb|g|gb)$}i
when 'time'
regex = %r{^(\d+|(\d+\W+(seconds|sec|s|minutes|min|hours|h|days|d|weeks|w|months|m|quarters|q|years|y)\W*)+)$}i
when 'boolean', 'bit'
value_in_array = %w[yes no on off true false]
when 'address'
raise 'Value need to be an string' unless value.is_a?(String)

# validate net-address for domain name or ip
regex_hostname = %r{^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$}i
raise 'Value needs to be an ip or host address' unless value =~ Resolv::IPv4::Regex || value =~ Resolv::IPv6::Regex || value =~ Regexp.compile(regex_hostname)
when 'addresses'
hash_separator = ' = '
raise 'Please specify as Hash' unless value.is_a?(Hash)
when 'include_exclude_item', 'runscript', 'hash'
raise 'Please specify as Hash' unless value.is_a?(Hash)
when 'include_exclude_item_nested'
raise 'Nested elements need to be hashes or strings' unless value.is_a?(Hash) || value.is_a?(String)
when 'backup_level'
value_in_array = %w[full incremental differential virtualfull initcatalog catalog volumetocatalog disktocatalog]
when 'io_direction'
value_in_array = %w[in out both]
when 'action_on_purge'
value_in_array = %w[truncate]
when 'encryption_cipher'
value_in_array = %w[aes128 aes192 aes256 camellia128 camellia192 camellia256 aes128hmacsha1 aes256hmacsha1 blowfish]
when 'auth_type'
value_in_array = %w[clear md5]
when 'auth_protocol_type', 'protocol_type'
value_in_array = %w[native ndmp]
when 'pooltype'
value_in_array = %w[backup archive cloned migration copy save scratch]
when 'label'
value_in_array = %w[ansi ibm bareos]
when 'migration_type'
value_in_array = %w[smallestvolume oldestvolume client volume job sqlquery pooloccupancy pooltime pooluncopiedjobs]
when 'job_type'
value_in_array = %w[backup restore verify admin migrate copy consolidate]
when 'replace_option'
value_in_array = %w[always ifnewer ifolder never]
when 'device_type'
value_in_array = %w[tape file fifo gfapi rados]
when 'compression_algorithm'
value_in_array = %w[gzip lzo lzfast lz4 lz4hc]
else
raise "Invalid setting type '#{type}'"
end

# rubocop:disable Style/SoleNestedConditional
unless value_in_array.nil?
raise "Value '#{value}' needs to be one of #{value_in_array.inspect}" unless value_in_array.include? value.to_s.downcase
end
unless regex.nil?
raise "Value '#{value}' does not match regex #{regex}" unless value =~ Regexp.compile(regex)
end
# rubocop:enable Style/SoleNestedConditional

if value.is_a?(Hash)
final_settings.push "#{indent}#{directive}#{hash_separator}{"
Expand Down
16 changes: 8 additions & 8 deletions manifests/client.pp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
# This class will be automatically included when a resource is defined.
# It is not intended to be used directly by external resources like node definitions or other modules.
class bareos::client (
$manage_service = $bareos::manage_service,
$manage_package = $bareos::manage_package,
$package_name = $bareos::client_package_name,
$package_ensure = $bareos::package_ensure,
$service_name = $bareos::client_service_name,
$service_ensure = $bareos::service_ensure,
$service_enable = $bareos::service_enable,
$config_dir = "${bareos::config_dir}/bareos-fd.d"
Boolean $manage_service = $bareos::manage_service,
Boolean $manage_package = $bareos::manage_package,
Variant[String, Array[String]] $package_name = $bareos::client_package_name,
String $package_ensure = $bareos::package_ensure,
String $service_name = $bareos::client_service_name,
Copy link
Member

Choose a reason for hiding this comment

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

You probably want String[1] unless the code specifically is meant to handle empty strings ''

String $service_ensure = $bareos::service_ensure,
Boolean $service_enable = $bareos::service_enable,
String $config_dir = "${bareos::config_dir}/bareos-fd.d"
Copy link
Member

Choose a reason for hiding this comment

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

You probably want Stdlib::Absolutepath if this will also be an absolute path.

) inherits bareos {
include bareos::client::client

Expand Down
109 changes: 55 additions & 54 deletions manifests/client/client.pp
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,9 @@
# Required: false
#
# [*tls_dh_file*]
# Tls Dh File: Path to PEM encoded Diffie-Hellman parameter file. If this directive is specified, DH key exchange will be used for the ephemeral keying, allowing for forward secrecy of communications.
# Tls Dh File: Path to PEM encoded Diffie-Hellman parameter file. If this
# directive is specified, DH key exchange will be used for the ephemeral
# keying, allowing for forward secrecy of communications.
#
# Bareos Datatype: directory
# Bareos Default: Not set
Expand All @@ -307,14 +309,17 @@
# Required: false
#
# [*tls_require*]
# Tls Require: Without setting this to yes, Bareos can fall back to use unencryption connections. Enabling this implicietly sets "TLS Enable = yes".
# Tls Require: Without setting this to yes, Bareos can fall back to use
# unencryption connections. Enabling this implicietly sets "TLS Enable = yes".
#
# Bareos Datatype: boolean
# Bareos Default: false
# Required: false
#
# [*tls_verify_peer*]
# Tls Verify Peer: If disabled, all certificates signed by a known CA will be accepted. If enabled, the CN of a certificate must the Address or in the "TLS Allowed CN" list.
# Tls Verify Peer: If disabled, all certificates signed by a known CA will be
# accepted. If enabled, the CN of a certificate must the Address or in the
# "TLS Allowed CN" list.
#
# Bareos Datatype: boolean
# Bareos Default: true
Expand All @@ -335,63 +340,59 @@
# Required: false
#
class bareos::client::client (
$ensure = present,
$absolute_job_timeout = undef,
$allow_bandwidth_bursting = undef,
$allowed_job_command = undef,
$allowed_script_dir = undef,
$always_use_lmdb = undef,
$compatible = undef,
$description = undef,
$fd_address = undef,
$fd_addresses = undef,
$fd_port = undef,
$fd_source_address = undef,
$heartbeat_interval = undef,
$lmdb_threshold = undef,
$log_timestamp_format = undef,
$maximum_bandwidth_per_job = undef,
$maximum_concurrent_jobs = undef,
$maximum_connections = undef,
$maximum_network_buffer_size = undef,
$messages = undef,
$name_client = 'bareos-fd',
$pid_directory = undef,
$pki_cipher = undef,
$pki_encryption = undef,
$pki_key_pair = undef,
$pki_master_key = undef,
$pki_signatures = undef,
$pki_signer = undef,
$plugin_directory = undef,
$plugin_names = undef,
$scripts_directory = undef,
$sd_connect_timeout = undef,
$secure_erase_command = undef,
$tls_allowed_cn = undef,
$tls_authenticate = undef,
$tls_ca_certificate_dir = undef,
$tls_ca_certificate_file = undef,
$tls_certificate = undef,
$tls_certificate_revocation_list = undef,
$tls_cipher_list = undef,
$tls_dh_file = undef,
$tls_enable = undef,
$tls_key = undef,
$tls_require = undef,
$tls_verify_peer = undef,
$ver_id = undef,
$working_directory = undef,
Bareos::Resource $name_client = 'bareos-fd',
Bareos::Module::Ensure $ensure = present,
Optional[Integer[0]] $absolute_job_timeout = undef,
Optional[Boolean] $allow_bandwidth_bursting = undef,
Optional[Bareos::List::String] $allowed_job_command = undef,
Optional[Bareos::List::Directory] $allowed_script_dir = undef,
Optional[Boolean] $always_use_lmdb = undef,
Optional[Boolean] $compatible = undef,
Optional[String] $description = undef,
Optional[Bareos::Address] $fd_address = undef,
Optional[Bareos::Addresses] $fd_addresses = undef,
Optional[Stdlib::Port] $fd_port = undef,
Optional[Bareos::Address] $fd_source_address = undef,
Optional[Bareos::Time] $heartbeat_interval = undef,
Optional[Integer[0]] $lmdb_threshold = undef,
Optional[String] $log_timestamp_format = undef,
Optional[Bareos::Speed] $maximum_bandwidth_per_job = undef,
Optional[Integer[0]] $maximum_concurrent_jobs = undef,
Optional[Integer[0]] $maximum_connections = undef,
Optional[Integer[0]] $maximum_network_buffer_size = undef,
Optional[Bareos::Resource] $messages = undef,
Optional[String] $pid_directory = undef,
Optional[Bareos::EncryptionCipher] $pki_cipher = undef,
Optional[Bareos::Boolean] $pki_encryption = undef,
Optional[String] $pki_key_pair = undef,
Optional[Bareos::List::Directory] $pki_master_key = undef,
Optional[Bareos::Boolean] $pki_signatures = undef,
Optional[Bareos::List::Directory] $pki_signer = undef,
Optional[String] $plugin_directory = undef,
Optional[String] $plugin_names = undef,
Optional[String] $scripts_directory = undef,
Optional[Bareos::Time] $sd_connect_timeout = undef,
Optional[String] $secure_erase_command = undef,
Optional[Bareos::List::String] $tls_allowed_cn = undef,
Optional[Bareos::Boolean] $tls_authenticate = undef,
Optional[String] $tls_ca_certificate_dir = undef,
Optional[String] $tls_ca_certificate_file = undef,
Optional[String] $tls_certificate = undef,
Optional[String] $tls_certificate_revocation_list = undef,
Optional[String] $tls_cipher_list = undef,
Optional[String] $tls_dh_file = undef,
Optional[Bareos::Boolean] $tls_enable = undef,
Optional[String] $tls_key = undef,
Optional[Bareos::Boolean] $tls_require = undef,
Optional[Bareos::Boolean] $tls_verify_peer = undef,
Optional[String] $ver_id = undef,
Optional[String] $working_directory = undef,
) {
include bareos::client

$_resource = 'Client'
$_resource_dir = 'client'

unless $ensure in ['present', 'absent'] {
fail('Invalid value for ensure')
}

if $ensure == 'present' {
$_require_res_messages = $messages ? { undef => undef, default => Bareos::Client::Messages[$messages] }

Expand Down
50 changes: 23 additions & 27 deletions manifests/client/director.pp
Original file line number Diff line number Diff line change
Expand Up @@ -163,39 +163,35 @@
# Required: false
#
define bareos::client::director (
$ensure = present,
$address = undef,
$allowed_job_command = undef,
$allowed_script_dir = undef,
$connection_from_client_to_director = undef,
$connection_from_director_to_client = undef,
$description = undef,
$maximum_bandwidth_per_job = undef,
$monitor = undef,
$password = undef,
$port = undef,
$tls_allowed_cn = undef,
$tls_authenticate = undef,
$tls_ca_certificate_dir = undef,
$tls_ca_certificate_file = undef,
$tls_certificate = undef,
$tls_certificate_revocation_list = undef,
$tls_cipher_list = undef,
$tls_dh_file = undef,
$tls_enable = undef,
$tls_key = undef,
$tls_require = undef,
$tls_verify_peer = undef,
Bareos::Module::Ensure $ensure = present,
Optional[String] $address = undef,
Optional[Bareos::List::String] $allowed_job_command = undef,
Optional[Bareos::List::Directory] $allowed_script_dir = undef,
Optional[Bareos::Boolean] $connection_from_client_to_director = undef,
Optional[Bareos::Boolean] $connection_from_director_to_client = undef,
Optional[String] $description = undef,
Optional[Bareos::Speed] $maximum_bandwidth_per_job = undef,
Optional[Bareos::Boolean] $monitor = undef,
Optional[String] $password = undef,
Optional[Stdlib::Port] $port = undef,
Optional[Bareos::List::String] $tls_allowed_cn = undef,
Optional[Bareos::Boolean] $tls_authenticate = undef,
Optional[String] $tls_ca_certificate_dir = undef,
Optional[String] $tls_ca_certificate_file = undef,
Optional[String] $tls_certificate = undef,
Optional[String] $tls_certificate_revocation_list = undef,
Optional[String] $tls_cipher_list = undef,
Optional[String] $tls_dh_file = undef,
Optional[Bareos::Boolean] $tls_enable = undef,
Optional[String] $tls_key = undef,
Optional[Bareos::Boolean] $tls_require = undef,
Optional[Bareos::Boolean] $tls_verify_peer = undef,
) {
include bareos::client

$_resource = 'Director'
$_resource_dir = 'director'

unless $ensure in ['present', 'absent'] {
fail('Invalid value for ensure')
}

if $ensure == 'present' {
$_settings = bareos_settings( [$name, 'Name', 'name', true],
[$description, 'Description', 'string', false],
Expand Down
38 changes: 17 additions & 21 deletions manifests/client/messages.pp
Original file line number Diff line number Diff line change
Expand Up @@ -130,33 +130,29 @@
# Required: false
#
define bareos::client::messages (
$ensure = present,
$append = undef,
$catalog = undef,
$console = undef,
$description = undef,
$director = undef,
$file = undef,
$mail = undef,
$mail_command = undef,
$mail_on_error = undef,
$mail_on_success = undef,
$operator = undef,
$operator_command = undef,
$stderr = undef,
$stdout = undef,
$syslog = undef,
$timestamp_format = undef,
Bareos::Module::Ensure $ensure = present,
Optional[Bareos::List::String] $append = undef,
Optional[Bareos::List::String] $catalog = undef,
Optional[Bareos::List::String] $console = undef,
Optional[String] $description = undef,
Optional[Bareos::List::String] $director = undef,
Optional[Bareos::List::String] $file = undef,
Optional[Bareos::List::String] $mail = undef,
Optional[String] $mail_command = undef,
Optional[Bareos::List::String] $mail_on_error = undef,
Optional[Bareos::List::String] $mail_on_success = undef,
Optional[Bareos::List::String] $operator = undef,
Optional[String] $operator_command = undef,
Optional[Bareos::List::String] $stderr = undef,
Optional[Bareos::List::String] $stdout = undef,
Optional[Bareos::List::String] $syslog = undef,
Optional[String] $timestamp_format = undef,
) {
include bareos::client

$_resource = 'Messages'
$_resource_dir = 'messages'

unless $ensure in ['present', 'absent'] {
fail('Invalid value for ensure')
}

if $ensure == 'present' {
$_settings = bareos_settings( [$name, 'Name', 'name', true],
[$description, 'Description', 'string', false],
Expand Down
8 changes: 4 additions & 4 deletions manifests/console.pp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
# This class will be automatically included when a resource is defined.
# It is not intended to be used directly by external resources like node definitions or other modules.
class bareos::console (
$manage_package = $bareos::manage_package,
$package_name = $bareos::console_package_name,
$package_ensure = $bareos::package_ensure,
$config_dir = "${bareos::config_dir}/bconsole.d"
Boolean $manage_package = $bareos::manage_package,
Variant[String, Array[String]] $package_name = $bareos::console_package_name,
String $package_ensure = $bareos::package_ensure,
String $config_dir = "${bareos::config_dir}/bconsole.d"
) inherits bareos {
if $manage_package {
package { $package_name:
Expand Down
Loading