diff --git a/manifests/config/resource.pp b/manifests/config/resource.pp index 7327060..1416634 100644 --- a/manifests/config/resource.pp +++ b/manifests/config/resource.pp @@ -1,115 +1,120 @@ # == Define: icingaweb2::config::resource # # Create and remove Icinga Web 2 resources. Resources may be referenced in other configuration sections. # # === Parameters # # [*resource_name*] # Name of the resources. Resources are referenced by their name in other configuration sections. # # [*type*] # Supported resource types are `db` and `ldap`. # # [*host*] # Connect to the database or ldap server on the given host. For using unix domain sockets, specify 'localhost' for # MySQL and the path to the unix domain socket directory for PostgreSQL. When using the 'ldap' type you can also # provide multiple hosts separated by a space. # # [*port*] # Port number to use. # # [*db_type*] # Supported DB types are `mysql` and `pgsql`. # # [*db_name*] # The database to use. Only valid if `type` is `db`. # # [*db_username*] # The username to use when connecting to the server. Only valid if `type` is `db`. # # [*db_password*] # The password to use when connecting to the server. Only valid if `type` is `db`. # # [*db_charset*] # The character set to use for the database connection. Only valid if `type` is `db`. # # [*ldap_root_dn*] # Root object of the tree, e.g. 'ou=people,dc=icinga,dc=com'. Only valid if `type` is `ldap`. # # [*ldap_bind_dn*] # The user to use when connecting to the server. Only valid if `type` is `ldap`. # # [*ldap_bind_pw*] # The password to use when connecting to the server. Only valid if `type` is `ldap`. # # [*ldap_encryption*] # Type of encryption to use: none (default), starttls, ldaps. Only valid if `type` is `ldap`. # +# [*ldap_timeout*] +# Timeout for the ldap connection, defaults to 5. +# # === Examples # # Create a 'db' resource: # # icingaweb2::config::resource{'my-sql': # type => 'db', # db_type => 'mysql', # host => 'localhost', # port => '3306', # db_name => 'icingaweb2', # db_username => 'root', # db_password => 'supersecret', # } # # define icingaweb2::config::resource( String $resource_name = $title, Enum['db', 'ldap'] $type = undef, String $host = undef, Optional[Integer[1,65535]] $port = undef, Optional[Enum['mysql', 'pgsql']] $db_type = undef, Optional[String] $db_name = undef, Optional[String] $db_username = undef, Optional[String] $db_password = undef, Optional[String] $db_charset = undef, Optional[String] $ldap_root_dn = undef, Optional[String] $ldap_bind_dn = undef, Optional[String] $ldap_bind_pw = undef, Optional[Enum['none', 'starttls', 'ldaps']] $ldap_encryption = 'none', + Optional[Integer] $ldap_timeout = 5, ) { $conf_dir = $::icingaweb2::params::conf_dir case $type { 'db': { $settings = { 'type' => $type, 'db' => $db_type, 'host' => $host, 'port' => $port, 'dbname' => $db_name, 'username' => $db_username, 'password' => $db_password, 'charset' => $db_charset, } } 'ldap': { $settings = { 'type' => $type, 'hostname' => $host, 'port' => $port, 'root_dn' => $ldap_root_dn, 'bind_dn' => $ldap_bind_dn, 'bind_pw' => $ldap_bind_pw, 'encryption' => $ldap_encryption, + 'timeout' => $ldap_timeout, } } default: { fail('The resource type you provided is not supported.') } } icingaweb2::inisection { "resource-${resource_name}": section_name => $resource_name, target => "${conf_dir}/resources.ini", settings => delete_undef_values($settings), } } diff --git a/spec/defines/resource_spec.rb b/spec/defines/resource_spec.rb index 102a9cd..86a2c3e 100644 --- a/spec/defines/resource_spec.rb +++ b/spec/defines/resource_spec.rb @@ -1,56 +1,70 @@ require 'spec_helper' describe('icingaweb2::config::resource', :type => :define) do let(:title) { 'myresource' } let(:pre_condition) { [ "class { 'icingaweb2': }" ] } on_supported_os.each do |os, facts| context "on #{os}" do let :facts do facts end context "#{os} with type db" do let(:params) { { :type => 'db', :host => 'localhost', :port => 3306, :db_type => 'mysql', :db_name => 'foo', :db_username => 'bar', :db_password => 'secret' } } it { is_expected.to contain_icingaweb2__inisection('resource-myresource') .with_target('/etc/icingaweb2/resources.ini') .with_settings({'type'=>'db', 'db'=>'mysql', 'host'=>'localhost', 'port'=>'3306', 'dbname'=>'foo', 'username'=>'bar', 'password'=>'secret'}) } end context "#{os} with type ldap" do let(:params) { { :type => 'ldap', :host => 'localhost', :port => 389, :ldap_root_dn => 'cn=foo,dc=bar', :ldap_bind_dn => 'cn=root,dc=bar', :ldap_bind_pw => 'secret' } } it { is_expected.to contain_icingaweb2__inisection('resource-myresource') .with_target('/etc/icingaweb2/resources.ini') - .with_settings({'type'=>'ldap', 'hostname'=>'localhost', 'port'=>'389', 'root_dn'=>'cn=foo,dc=bar', 'bind_dn'=>'cn=root,dc=bar', 'bind_pw'=>'secret', 'encryption'=>'none'})} + .with_settings({'type'=>'ldap', 'hostname'=>'localhost', 'port'=>'389', 'root_dn'=>'cn=foo,dc=bar', 'bind_dn'=>'cn=root,dc=bar', 'bind_pw'=>'secret', 'encryption'=>'none', 'timeout' => '5'})} + end + context "#{os} with type ldap and changed ldap timeout" do + let(:params) { { + :type => 'ldap', + :host => 'localhost', + :port => 389, + :ldap_root_dn => 'cn=foo,dc=bar', + :ldap_bind_dn => 'cn=root,dc=bar', + :ldap_bind_pw => 'secret', + :ldap_timeout => 60 } } + + it { is_expected.to contain_icingaweb2__inisection('resource-myresource') + .with_target('/etc/icingaweb2/resources.ini') + .with_settings({'type'=>'ldap', 'hostname'=>'localhost', 'port'=>'389', 'root_dn'=>'cn=foo,dc=bar', 'bind_dn'=>'cn=root,dc=bar', 'bind_pw'=>'secret', 'encryption'=>'none', 'timeout' => '60'})} end context "#{os} with invalid type" do let(:params) { { :type => 'foobar', :host => 'localhost', :port => 3306 } } it { is_expected.to raise_error(Puppet::Error, /expects a match for Enum\['db', 'ldap'\]/) } end end end end