-
-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #714 from Icinga/tls
Rewrite some feature classes
- Loading branch information
Showing
25 changed files
with
622 additions
and
851 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
include icinga2 | ||
|
||
class { 'icinga2::feature::elasticsearch': | ||
password => Sensitive('super(secret'), | ||
# password => Sensitive('super(secret'), | ||
password => 'super(secret', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# @summary | ||
# This function returns a string to connect databases | ||
# with or without TLS information. | ||
# | ||
# @return | ||
# Connection string to connect database. | ||
# | ||
function icinga2::db::connect( | ||
Struct[{ | ||
type => Enum['pgsql','mysql','mariadb'], | ||
host => Stdlib::Host, | ||
port => Optional[Stdlib::Port], | ||
database => String, | ||
username => String, | ||
password => Optional[Variant[String, Sensitive[String]]], | ||
}] $db, | ||
Hash[String, Any] $tls, | ||
Optional[Boolean] $use_tls = undef, | ||
) >> String { | ||
# @param db | ||
# Data hash with database information. | ||
# | ||
# @param tls | ||
# Data hash with TLS connection information. | ||
# | ||
# @param use_tls | ||
# Wether or not to use TLS encryption. | ||
# | ||
if $use_tls { | ||
case $db['type'] { | ||
'pgsql': { | ||
$tls_options = regsubst(join(any2array(delete_undef_values({ | ||
'sslmode=' => if $tls['noverify'] { 'require' } else { 'verify-full' }, | ||
'sslcert=' => $tls['cert_file'], | ||
'sslkey=' => $tls['key_file'], | ||
'sslrootcert=' => $tls['cacert_file'], | ||
})), ' '), '= ', '=', 'G') | ||
} | ||
'mariadb': { | ||
$tls_options = join(any2array(delete_undef_values({ | ||
'--ssl' => '', | ||
'--ssl-ca' => $tls['cacert_file'], | ||
'--ssl-cert' => $tls['cert_file'], | ||
'--ssl-key' => $tls['key_file'], | ||
'--ssl-capath' => $tls['capath'], | ||
'--ssl-cipher' => $tls['cipher'], | ||
})), ' ') | ||
} | ||
'mysql': { | ||
$tls_options = join(any2array(delete_undef_values({ | ||
'--ssl-mode' => 'required', | ||
'--ssl-ca' => $tls['cacert_file'], | ||
'--ssl-cert' => $tls['cert_file'], | ||
'--ssl-key' => $tls['key_file'], | ||
'--ssl-capath' => $tls['capath'], | ||
'--ssl-cipher' => $tls['cipher'], | ||
})), ' ') | ||
} | ||
default: { | ||
fail('The database type you provided is not supported.') | ||
} | ||
} | ||
} else { | ||
$tls_options = '' | ||
} | ||
|
||
if $db['type'] == 'pgsql' { | ||
$options = regsubst(join(any2array(delete_undef_values({ | ||
'host=' => $db['host'], | ||
'user=' => $db['username'], | ||
'port=' => $db['port'], | ||
'dbname=' => $db['database'], | ||
})), ' '), '= ', '=', 'G') | ||
} else { | ||
$_password = icinga2::unwrap($db['password']) | ||
$options = join(any2array(delete_undef_values({ | ||
'-h' => $db['host'] ? { | ||
/localhost/ => undef, | ||
default => $db['host'], | ||
}, | ||
'-P' => $db['port'], | ||
'-u' => $db['username'], | ||
"-p'${_password}'" => '', | ||
'-D' => $db['database'], | ||
})), ' ') | ||
} | ||
|
||
"${options} ${tls_options}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# @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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.