diff --git a/data/common.yaml b/data/common.yaml index 331cd14..fbf53c7 100644 --- a/data/common.yaml +++ b/data/common.yaml @@ -61,6 +61,8 @@ prosody::user: prosody prosody::virtualhost_defaults: {} prosody::virtualhosts: {} +prosody::config_directory: '/etc/prosody' + prosody::community_modules::ensure: present prosody::community_modules::path: /var/lib/prosody/modules prosody::community_modules::source: https://hg.prosody.im/prosody-modules/ diff --git a/data/os/Gentoo.yaml b/data/os/Gentoo.yaml new file mode 100644 index 0000000..b4fba30 --- /dev/null +++ b/data/os/Gentoo.yaml @@ -0,0 +1,14 @@ +--- +prosody::error_log: /var/log/jabber/prosody.err +prosody::group: jabber +prosody::info_log: /var/log/jabber/prosody.log +prosody::pidfile: /run/jabber/prosody.pid +prosody::user: jabber + +prosody::config_directory: '/etc/jabber' + +prosody::community_package_name: 'net-im/prosody-modules' + +prosody::community_modules::ensure: present +prosody::community_modules::path: /usr/lib64/prosody/community-modules +prosody::community_modules::type: os diff --git a/manifests/community_modules.pp b/manifests/community_modules.pp index 06e65c1..bb4fffa 100644 --- a/manifests/community_modules.pp +++ b/manifests/community_modules.pp @@ -4,20 +4,28 @@ Enum[present, latest] $ensure, Stdlib::Absolutepath $path, String $source, - Enum['hg', 'git'] $type, + Enum['hg', 'git', 'os'] $type, Optional[String] $revision = undef, ) { + include prosody + if $type == 'hg' { $_packages = ['mercurial'] } elsif $type == 'git' { $_packages = ['git'] + } elsif $type == 'os' { + package { $prosody::community_package_name: + ensure => present, + } } - ensure_packages($_packages) - -> vcsrepo { $path: - ensure => $ensure, - provider => $type, - source => $source, - revision => $revision, + if $type != 'os' { + ensure_packages($_packages) + -> vcsrepo { $path: + ensure => $ensure, + provider => $type, + source => $source, + revision => $revision, + } } } diff --git a/manifests/config.pp b/manifests/config.pp index 4c36c74..2fcbecf 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -1,14 +1,16 @@ # == Class: prosody::config class prosody::config { - file { '/etc/prosody/conf.avail': + include prosody + + file { "${prosody::config_directory}/conf.avail": ensure => directory, } - file { '/etc/prosody/conf.d': + file { "${prosody::config_directory}/conf.d": ensure => directory, } - file { '/etc/prosody/prosody.cfg.lua': + file { "${prosody::config_directory}/prosody.cfg.lua": content => template('prosody/prosody.cfg.erb'), require => Class['prosody::package'], notify => Class['prosody::service'], diff --git a/manifests/init.pp b/manifests/init.pp index 0ccfaf9..4f32cd4 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -43,6 +43,8 @@ Optional[Stdlib::Absolutepath] $ssl_cert = undef, Optional[Stdlib::Absolutepath] $ssl_key = undef, Optional[String] $ssl_protocol = undef, + Optional[Stdlib::Absolutepath] $config_directory = undef, + Optional[String[1]] $community_package_name = undef, ) { if ($community_modules != []) { class { 'prosody::community_modules': diff --git a/manifests/virtualhost.pp b/manifests/virtualhost.pp index 3682dbd..c3b5053 100644 --- a/manifests/virtualhost.pp +++ b/manifests/virtualhost.pp @@ -1,14 +1,14 @@ # == Type: prosody::virtualhost define prosody::virtualhost ( - Hash $custom_options = {}, - Enum[present, absent] $ensure = present, - Optional[Stdlib::Absolutepath] $ssl_key = undef, - Optional[Stdlib::Absolutepath] $ssl_cert = undef, - Boolean $ssl_copy = true, - Optional[String] $user = undef, - Optional[String] $group = undef, - Hash $components = {}, - Array[String[1]] $disco_items = [], + Hash $custom_options = {}, + Enum[present, absent] $ensure = present, + Optional[Stdlib::Absolutepath] $ssl_key = undef, + Optional[Stdlib::Absolutepath] $ssl_cert = undef, + Boolean $ssl_copy = true, + Optional[String] $user = undef, + Optional[String] $group = undef, + Hash $components = {}, + Array[String[1]] $disco_items = [], ) { # Check if SSL set correctly if (($ssl_key != undef) and ($ssl_cert == undef)) { @@ -18,10 +18,12 @@ fail('The prosody::virtualhost type needs both ssl_key *and* ssl_cert set') } + include prosody + if (($ssl_key != undef) and ($ssl_cert != undef) and ($ssl_copy == true)) { # Copy the provided sources to prosody certs folder - $prosody_ssl_key = "/etc/prosody/certs/${name}.key" - $prosody_ssl_cert = "/etc/prosody/certs/${name}.crt" + $prosody_ssl_key = "${prosody::config_directory}/certs/${name}.key" + $prosody_ssl_cert = "${prosody::config_directory}/certs/${name}.crt" $file_user = pick_default($user, 'prosody') $file_group = pick_default($group, 'prosody') @@ -53,7 +55,7 @@ $config_requires = Class['prosody::package'] } - $conf_avail_fn = "/etc/prosody/conf.avail/${name}.cfg.lua" + $conf_avail_fn = "${prosody::config_directory}/conf.avail/${name}.cfg.lua" file { $conf_avail_fn: ensure => $ensure, @@ -67,7 +69,7 @@ 'absent' => absent, } - file { "/etc/prosody/conf.d/${name}.cfg.lua": + file { "${prosody::config_directory}/conf.d/${name}.cfg.lua": ensure => $cfg_ensure, target => $conf_avail_fn, notify => Class['prosody::service'], diff --git a/metadata.json b/metadata.json index e3ed67a..cd1a9f4 100644 --- a/metadata.json +++ b/metadata.json @@ -22,6 +22,9 @@ "10", "11" ] + }, + { + "operatingsystem": "Gentoo" } ], "dependencies": [ diff --git a/spec/classes/prosody_spec.rb b/spec/classes/prosody_spec.rb index 37f419d..54f7f5e 100644 --- a/spec/classes/prosody_spec.rb +++ b/spec/classes/prosody_spec.rb @@ -7,14 +7,27 @@ os_facts end + context 'on every platform' do it { is_expected.to contain_class 'prosody::package' } it { is_expected.to contain_class 'prosody::config' } it { is_expected.to contain_class 'prosody::service' } it { is_expected.to contain_package('prosody').with(ensure: 'present') } - it { is_expected.to contain_file('/etc/prosody/conf.avail').with(ensure: 'directory') } - it { is_expected.to contain_file('/etc/prosody/conf.d').with(ensure: 'directory') } + it { + config_directory = case facts[:osfamily] + when 'Gentoo' then '/etc/jabber' + else '/etc/prosody' + end + is_expected.to contain_file("#{config_directory}/conf.a'ail").with(ensure: 'directory') + } + it { + config_directory = case facts[:osfamily] + when 'Gentoo' then '/etc/jabber' + else '/etc/prosody' + end + is_expected.to contain_file("#{config_directory}/conf.d").with(ensure: 'directory') + } end context 'with daemonize => true' do @@ -41,7 +54,11 @@ let(:params) { { custom_options: { 'foo' => 'bar', 'baz' => 'quux' } } } it { - is_expected.to contain_file('/etc/prosody/prosody.cfg.lua'). \ + config_directory = case facts[:osfamily] + when 'Gentoo' then '/etc/jabber' + else '/etc/prosody' + end + is_expected.to contain_file("#{config_directory}/prosody.cfg.lua"). \ with_content(%r{^foo = "bar"$}, %r{^baz = "quux"$}) } end @@ -50,7 +67,11 @@ let(:params) { { custom_options: { 'foo' => { 'fnord' => '23', 'xyzzy' => '42' }, 'bar' => %w[cool elements], 'baz' => 'quux' } } } it { - is_expected.to contain_file('/etc/prosody/prosody.cfg.lua'). \ + config_directory = case facts[:osfamily] + when 'Gentoo' then '/etc/jabber' + else '/etc/prosody' + end + is_expected.to contain_file("#{config_directory}/prosody.cfg.lua"). \ with_content(%r{^foo = {\n fnord = "23";\n xyzzy = "42";\n}$}, %r{^baz = "quux"$}, %r{^bar = [ "cool"; "elements" ]$}) } end diff --git a/spec/defines/virtualhost_spec.rb b/spec/defines/virtualhost_spec.rb index bcb9e3d..9592566 100644 --- a/spec/defines/virtualhost_spec.rb +++ b/spec/defines/virtualhost_spec.rb @@ -14,8 +14,13 @@ let(:title) { 'mockvirtualhost' } - let(:path_avail) { "/etc/prosody/conf.avail/#{title}.cfg.lua" } - let(:path_link) { "/etc/prosody/conf.d/#{title}.cfg.lua" } + let(:path_avail) { "#{config_directory}/conf.avail/#{title}.cfg.lua" } + let(:path_link) { "#{config_directory}/conf.d/#{title}.cfg.lua" } + + config_directory = case facts[:osfamily] + when 'Gentoo' then '/etc/jabber' + else '/etc/prosody' + end context 'with no parameters' do it { @@ -38,31 +43,31 @@ end context 'with ssl_key but no ssl_cert' do - let(:params) { { ssl_key: '/etc/prosody/certs/rspec-puppet.com.key' } } + let(:params) { { ssl_key: "#{config_directory}/certs/rspec-puppet.com.key" } } it { is_expected.to compile.and_raise_error(%r{The prosody::virtualhost type needs both ssl_key \*and\* ssl_cert set}) } end context 'with ssl_cert but no ssl_key' do - let(:params) { { ssl_cert: '/etc/prosody/certs/rspec-puppet.com.crt' } } + let(:params) { { ssl_cert: "#{config_directory}/certs/rspec-puppet.com.crt" } } it { is_expected.to compile.and_raise_error(%r{The prosody::virtualhost type needs both ssl_key \*and\* ssl_cert set}) } end context 'with ssl keys and certs' do - let(:ssl_key) { '/etc/prosody/certs/rspec-puppet.com.key' } - let(:ssl_cert) { '/etc/prosody/certs/rspec-puppet.com.crt' } + let(:ssl_key) { "#{config_directory}/certs/rspec-puppet.com.key" } + let(:ssl_cert) { "#{config_directory}/certs/rspec-puppet.com.crt" } let(:params) { { ssl_key: ssl_key, ssl_cert: ssl_cert } } it { # This require statment is bananas is_expected.to contain_file(path_avail).with( ensure: 'present', - require: ['File[/etc/prosody/certs/mockvirtualhost.key]', 'File[/etc/prosody/certs/mockvirtualhost.crt]', 'Class[Prosody::Package]'] + require: ["File[#{config_directory}/certs/mockvirtualhost.key]", "File[#{config_directory}/certs/mockvirtualhost.crt]", 'Class[Prosody::Package]'] ) - is_expected.to contain_file('/etc/prosody/certs/mockvirtualhost.key').with_source(ssl_key) - is_expected.to contain_file('/etc/prosody/certs/mockvirtualhost.crt').with_source(ssl_cert) + is_expected.to contain_file("#{config_directory}/certs/mockvirtualhost.key").with_source(ssl_key) + is_expected.to contain_file("#{config_directory}/certs/mockvirtualhost.crt").with_source(ssl_cert) } end