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

Introduce support for Gentoo #79

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
2 changes: 2 additions & 0 deletions data/common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
14 changes: 14 additions & 0 deletions data/os/Gentoo.yaml
Original file line number Diff line number Diff line change
@@ -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
22 changes: 15 additions & 7 deletions manifests/community_modules.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
}
8 changes: 5 additions & 3 deletions manifests/config.pp
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# == Class: prosody::config
class prosody::config {
file { '/etc/prosody/conf.avail':
include prosody

file { "${prosody::config_directory}/conf.avail":
smortex marked this conversation as resolved.
Show resolved Hide resolved
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'],
Expand Down
2 changes: 2 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
28 changes: 15 additions & 13 deletions manifests/virtualhost.pp
Original file line number Diff line number Diff line change
@@ -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)) {
Expand All @@ -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"
smortex marked this conversation as resolved.
Show resolved Hide resolved
$prosody_ssl_cert = "${prosody::config_directory}/certs/${name}.crt"

$file_user = pick_default($user, 'prosody')
$file_group = pick_default($group, 'prosody')
Expand Down Expand Up @@ -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,
Expand All @@ -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'],
Expand Down
3 changes: 3 additions & 0 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
"10",
"11"
]
},
{
"operatingsystem": "Gentoo"
}
],
"dependencies": [
Expand Down
29 changes: 25 additions & 4 deletions spec/classes/prosody_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,27 @@
os_facts
end


Copy link
Member

Choose a reason for hiding this comment

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

This blank line makes rubocop unhappy 😉

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
Expand All @@ -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
Expand All @@ -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
Expand Down
23 changes: 14 additions & 9 deletions spec/defines/virtualhost_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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

Expand Down