From 2683e2f4e4d8fd3572ba70dc1b02d9f3464e2c79 Mon Sep 17 00:00:00 2001 From: Lennart Betz Date: Fri, 22 Dec 2023 07:39:49 +0100 Subject: [PATCH] replace newline function against icinga::newline --- REFERENCE.md | 19 ------------------- functions/newline.pp | 25 ------------------------- manifests/config.pp | 8 ++------ manifests/config/fragment.pp | 2 +- manifests/feature/api.pp | 6 +++--- manifests/object.pp | 7 +------ manifests/pki/ca.pp | 4 ++-- manifests/tls/client.pp | 6 +++--- 8 files changed, 12 insertions(+), 65 deletions(-) delete mode 100644 functions/newline.pp diff --git a/REFERENCE.md b/REFERENCE.md index 141be7dd..8d2ae0e1 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -80,7 +80,6 @@ with or without TLS information. * [`icinga2::icinga2_attributes`](#icinga2--icinga2_attributes): Calls the simple parser to decide what to quote. For more information, see lib/puppet_x/icinga2/utils.rb. * [`icinga2::icinga2_ticket_id`](#icinga2--icinga2_ticket_id): Summarise what the function does here -* [`icinga2::newline`](#icinga2--newline): Replace newlines for Windows systems. * [`icinga2::parse`](#icinga2--parse) * [`icinga2::unwrap`](#icinga2--unwrap): This function returns an unwrap string if necessary. @@ -5699,24 +5698,6 @@ Data type: `Variant[String, Sensitive[String]]` The ticket salt of the Icinga CA. -### `icinga2::newline` - -Type: Puppet Language - -Replace newlines for Windows systems. - -#### `icinga2::newline(Optional[String] $text)` - -The icinga2::newline function. - -Returns: `String` Text with correct newlines. - -##### `text` - -Data type: `Optional[String]` - - - ### `icinga2::parse` Type: Puppet Language diff --git a/functions/newline.pp b/functions/newline.pp deleted file mode 100644 index 972e6d2c..00000000 --- a/functions/newline.pp +++ /dev/null @@ -1,25 +0,0 @@ -# @summary -# Replace newlines for Windows systems. -# -# @return -# Text with correct newlines. -# -function icinga2::newline( - Optional[String] $text, -) >> String { - # @param text - # Text to replace the newlines. - # - - if $text { - $result = if $facts['os']['family'] != 'windows' { - $text - } else { - regsubst($text, '\n', "\r\n", 'EMG') - } - } else { - $result = undef - } - - return $result -} diff --git a/manifests/config.pp b/manifests/config.pp index 63760e69..58c01af3 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -18,12 +18,8 @@ ) if $facts['kernel'] != 'windows' { - $template_constants = icinga2::parse($constants) - $template_mainconfig = $_mainconfig $file_permissions = '0640' } else { - $template_constants = regsubst(icinga2::parse($constants), '\n', "\r\n", 'EMG') - $template_mainconfig = regsubst($_mainconfig, '\n', "\r\n", 'EMG') $file_permissions = undef } @@ -35,12 +31,12 @@ file { "${conf_dir}/constants.conf": ensure => file, - content => $template_constants, + content => icinga::newline(icinga2::parse($constants)), } file { "${conf_dir}/icinga2.conf": ensure => file, - content => $template_mainconfig, + content => icinga::newline($_mainconfig), } file { "${conf_dir}/features-enabled": diff --git a/manifests/config/fragment.pp b/manifests/config/fragment.pp index 1743da6d..c68eefd3 100644 --- a/manifests/config/fragment.pp +++ b/manifests/config/fragment.pp @@ -52,7 +52,7 @@ ) { case $facts['os']['family'] { 'windows': { - $_content = regsubst($content, '\n', "\r\n", 'EMG') + $_content = icinga::newline($content) } # windows default: { Concat { diff --git a/manifests/feature/api.pp b/manifests/feature/api.pp index 9e360195..32ac30e4 100644 --- a/manifests/feature/api.pp +++ b/manifests/feature/api.pp @@ -252,7 +252,7 @@ file { $_ssl_key_path: ensure => file, mode => $_ssl_key_mode, - content => icinga2::newline($ssl_key), + content => icinga::newline($ssl_key), tag => 'icinga2::config::file', show_diff => false, backup => false, @@ -262,7 +262,7 @@ if $ssl_cert { file { $_ssl_cert_path: ensure => file, - content => icinga2::newline($ssl_cert), + content => icinga::newline($ssl_cert), tag => 'icinga2::config::file', } } @@ -270,7 +270,7 @@ if $ssl_cacert { file { $_ssl_cacert_path: ensure => file, - content => icinga2::newline($ssl_cacert), + content => icinga::newline($ssl_cacert), tag => 'icinga2::config::file', } } diff --git a/manifests/object.pp b/manifests/object.pp index 8c433003..e3d238e1 100644 --- a/manifests/object.pp +++ b/manifests/object.pp @@ -98,11 +98,6 @@ } ) - $_content = $facts['os']['family'] ? { - 'windows' => regsubst($_object, '\n', "\r\n", 'EMG'), - default => $_object, - } - if !defined(Concat[$target]) { concat { $target: ensure => present, @@ -114,7 +109,7 @@ if $ensure != 'absent' { concat::fragment { $title: target => $target, - content => $_content, + content => icinga::newline($_object), order => $order, } } diff --git a/manifests/pki/ca.pp b/manifests/pki/ca.pp index 30ae0260..ba1846dd 100644 --- a/manifests/pki/ca.pp +++ b/manifests/pki/ca.pp @@ -64,7 +64,7 @@ file { "${ca_dir}/ca.crt": ensure => file, - content => icinga2::newline($ca_cert), + content => icinga::newline($ca_cert), tag => 'icinga2::config::file', before => File[$_ssl_cacert_path], } @@ -72,7 +72,7 @@ file { "${ca_dir}/ca.key": ensure => file, mode => $_ca_key_mode, - content => icinga2::newline($ca_key), + content => icinga::newline($ca_key), tag => 'icinga2::config::file', show_diff => false, backup => false, diff --git a/manifests/tls/client.pp b/manifests/tls/client.pp index 89d66ae0..9aadace8 100644 --- a/manifests/tls/client.pp +++ b/manifests/tls/client.pp @@ -29,7 +29,7 @@ if icinga2::unwrap($args[key]) { file { $args['key_file']: ensure => file, - content => icinga2::newline(icinga2::unwrap($args['key'])), + content => icinga::newline(icinga2::unwrap($args['key'])), mode => $key_mode, show_diff => false, } @@ -38,14 +38,14 @@ if $args['cert'] { file { $args['cert_file']: ensure => file, - content => icinga2::newline($args['cert']), + content => icinga::newline($args['cert']), } } if $args['cacert'] { file { $args['cacert_file']: ensure => file, - content => icinga2::newline($args['cacert']), + content => icinga::newline($args['cacert']), } } }