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

adding ability to store rabbitmq cert/keys in hiera/vars instead of just... #337

Merged
merged 1 commit into from
Apr 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,17 @@
# Valid values: true, false
#
# [*rabbitmq_ssl_private_key*]
# String. Private key to be used by sensu to connect to rabbitmq
# If the value starts with 'puppet://' the file will be copied and used. Absolute paths will just be used
# String. Private key to be used by sensu to connect to rabbitmq. If the value starts with
# 'puppet://' the file will be copied and used. Also the key itself can be given as the
# parameter value, or a variable, or using hiera. Absolute paths will just be used as
# a file reference, as you'd normally configure sensu.
# Default: undef
#
# [*rabbitmq_ssl_cert_chain*]
# String. Private SSL cert chain to be used by sensu to connect to rabbitmq
# If the value starts with 'puppet://' the file will be copied and used. Absolute paths will just be used
# If the value starts with 'puppet://' the file will be copied and used. Also the key itself can
# be given as the parameter value, or a variable, or using hiera. Absolute paths will just be used
# as a file reference, as you'd normally configure sensu.
# Default: undef
#
# [*rabbitmq_reconnect_on_error*]
Expand Down
37 changes: 37 additions & 0 deletions manifests/rabbitmq/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
require => Package['sensu'],
}

# if provided a cert chain, and its a puppet:// URI, source file form the
# the URI provided
if $sensu::rabbitmq_ssl_cert_chain and $sensu::rabbitmq_ssl_cert_chain =~ /^puppet:\/\// {
file { '/etc/sensu/ssl/cert.pem':
ensure => present,
Expand All @@ -35,10 +37,28 @@
}

$ssl_cert_chain = '/etc/sensu/ssl/cert.pem'
# else provided a cert chain, and the variable actually contains the cert,
# create the file with conents of the variable
} elsif $sensu::rabbitmq_ssl_cert_chain and $sensu::rabbitmq_ssl_cert_chain =~ /BEGIN CERTIFICATE/ {
file { '/etc/sensu/ssl/cert.pem':
ensure => present,
content => $sensu::rabbitmq_ssl_cert_chain,
owner => 'sensu',
group => 'sensu',
mode => '0444',
require => File['/etc/sensu/ssl'],
before => Sensu_rabbitmq_config[$::fqdn],
}

$ssl_cert_chain = '/etc/sensu/ssl/cert.pem'
# else set the cert to value passed in wholesale, usually this is
# a raw file path
} else {
$ssl_cert_chain = $sensu::rabbitmq_ssl_cert_chain
}

# if provided private key, and its a puppet:// URI, source file from the
# URI provided
if $sensu::rabbitmq_ssl_private_key and $sensu::rabbitmq_ssl_private_key =~ /^puppet:\/\// {
file { '/etc/sensu/ssl/key.pem':
ensure => present,
Expand All @@ -51,9 +71,26 @@
}

$ssl_private_key = '/etc/sensu/ssl/key.pem'
# else provided private key, and the variable actually contains the key,
# create file with contents of the variable
} elsif $sensu::rabbitmq_ssl_private_key and $sensu::rabbitmq_ssl_private_key =~ /BEGIN RSA PRIVATE KEY/ {
file { '/etc/sensu/ssl/key.pem':
ensure => present,
content => $sensu::rabbitmq_ssl_private_key,
owner => 'sensu',
group => 'sensu',
mode => '0440',
require => File['/etc/sensu/ssl'],
before => Sensu_rabbitmq_config[$::fqdn],
}

$ssl_private_key = '/etc/sensu/ssl/key.pem'
# else set the private key to value passed in wholesale, usually this is
# a raw file path
} else {
$ssl_private_key = $sensu::rabbitmq_ssl_private_key
}

$enable_ssl = true
} else {
$ssl_cert_chain = undef
Expand Down
73 changes: 73 additions & 0 deletions spec/classes/sensu_rabbitmq_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,52 @@
require 'spec_helper'

rabbitmq_ssl_cert_chain_test = "-----BEGIN CERTIFICATE-----
MIIC3TCCAcWgAwIBAgIBAjANBgkqhkiG9w0BAQUFADASMRAwDgYDVQQDDAdTZW5z
dUNBMB4XDTE1MDMyNjE4MDMyM1oXDTIwMDM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5t8NvafXnilQx5KoeRqelr+5wton9y+N3xs
P2LcqWVZP6Vsc66pVqgc8wKBgQDCkSF4qhxVwINL/7QCwO78KfuuiDN3SlaW4nZ3
q1Olv1vE93jChySY5go0z9hxnxFJcXueToaV9xP0EY1TFG4RzzAfoP46xKRH2gLW
sLhIsniLs20MW7TNYS6/k3Gj0atfTYjAT0vUhl8sWLS6M1+ifXrfP3HAUKM2tQts
D1OVAQKBgCxcbeztUxD4b6V1a9xnC6SsiZirrVdZRFI8Xe1dUyL0jEPf5mH3eF0x
BpIpKUvLh4TsmgcezGV5512sm+K/TNNDynKY8vhVA8v9PNGiq6UJJkVRow5Ptes0
Pj3BM+E9hNMOQ6N7H87G4rbDz4T/kswNSiyF3v5Vlm0U5nGWWbk7
-----END RSA PRIVATE KEY-----"

describe 'sensu', :type => :class do
let(:facts) { { :fqdn => 'hostname.domain.com', :osfamily => 'RedHat' } }
let(:params) { { :client => true } }
Expand Down Expand Up @@ -74,6 +121,32 @@
) }
end # when using key in puppet

context 'when using key in variable' do
let(:params) { {
:rabbitmq_ssl_cert_chain => rabbitmq_ssl_cert_chain_test,
:rabbitmq_ssl_private_key => rabbitmq_ssl_private_key_test,
:rabbitmq_port => '1234',
:rabbitmq_host => 'myhost',
:rabbitmq_user => 'sensuuser',
:rabbitmq_password => 'sensupass',
:rabbitmq_vhost => '/myvhost',
} }

it { should contain_file('/etc/sensu/ssl').with_ensure('directory') }
it { should contain_file('/etc/sensu/ssl/cert.pem').with_content(rabbitmq_ssl_cert_chain_test) }
it { should contain_file('/etc/sensu/ssl/key.pem').with_content(rabbitmq_ssl_private_key_test) }

it { should contain_sensu_rabbitmq_config('hostname.domain.com').with(
:port => '1234',
:host => 'myhost',
:user => 'sensuuser',
:password => 'sensupass',
:vhost => '/myvhost',
:ssl_cert_chain => '/etc/sensu/ssl/cert.pem',
:ssl_private_key => '/etc/sensu/ssl/key.pem'
) }
end # when using key in variable

context 'purge config' do
let(:params) { {
:purge_config => true,
Expand Down