Skip to content
This repository has been archived by the owner on Dec 31, 2024. It is now read-only.

Commit

Permalink
add nssdb base class to ensure package deps
Browse files Browse the repository at this point in the history
This will prevent duplicate package type declarations when using one of
the defined types multiple times in the same manifest.
  • Loading branch information
Joshua Hoblitt committed Jan 14, 2014
1 parent 041e0e1 commit 6fc4ead
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ fixtures:
repositories:
'stdlib':
repo: 'git://github.com/puppetlabs/puppetlabs-stdlib.git'
ref: '3.0.0'
ref: '4.0.0'
symlinks:
nssdb: "#{source_dir}"
2 changes: 1 addition & 1 deletion Modulefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ summary 'NSS database Puppet Module'
description 'This module manages NSS databases.'
project_page 'https://github.com/rcritten/puppet-nssdb'

dependency 'puppetlabs/stdlib', '>= 3.0.0'
dependency 'puppetlabs/stdlib', '>= 4.0.0'
6 changes: 3 additions & 3 deletions manifests/add_cert_and_key.pp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
$key,
$certdir = $title
) {
package { 'openssl': ensure => present }
include nssdb

# downcase and change spaces into _s
$pkcs12_name = downcase(regsubst("${nickname}.p12", '[\s]', '_', 'GM'))
Expand All @@ -38,7 +38,7 @@
require => [
File["${certdir}/password.conf"],
File["${certdir}/cert8.db"],
Package['openssl'],
Class['nssdb'],
],
before => Exec['load_pkcs12'],
notify => Exec['load_pkcs12'],
Expand All @@ -50,7 +50,7 @@
command => "/usr/bin/pk12util -i '${certdir}/${pkcs12_name}' -d '${certdir}' -w '${certdir}/password.conf' -k '${certdir}/password.conf'",
require => [
Exec['generate_pkcs12'],
Package['nss-tools'],
Class['nssdb'],
],
refreshonly => true,
}
Expand Down
6 changes: 3 additions & 3 deletions manifests/create.pp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
$canickname = 'CA',
$catrust = 'CT,CT,'
) {
package { 'nss-tools': ensure => present }
include nssdb

if $manage_certdir {
file { $certdir:
Expand Down Expand Up @@ -83,7 +83,7 @@
require => [
File[$certdir],
File["${certdir}/password.conf"],
Package['nss-tools'],
Class['nssdb'],
],
notify => [
Exec['add_ca_cert'],
Expand All @@ -93,7 +93,7 @@
exec {'add_ca_cert':
command => "/usr/bin/certutil -A -n ${canickname} -d ${certdir} -t ${catrust} -a -i ${cacert}",
require => [
Package['nss-tools'],
Class['nssdb'],
],
refreshonly => true,
onlyif => "/usr/bin/test -e ${cacert}",
Expand Down
10 changes: 10 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# utility class
class nssdb {
include nssdb::params

ensure_packages($::nssdb::params::package_name)

anchor{ 'nssdb::begin': } ->
Package[$::nssdb::params::package_name] ->
anchor{ 'nssdb::end': }
}
4 changes: 4 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# this class should be considered private
class nssdb::params {
$package_name = ['nss-tools', 'openssl']
}
6 changes: 6 additions & 0 deletions spec/classes/nssdb_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require 'spec_helper'

describe 'nssdb', :type => :class do
it { should contain_package('nss-tools') }
it { should contain_package('openssl') }
end
8 changes: 6 additions & 2 deletions spec/defines/nssdb_add_cert_and_key_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
:require => [
'File[/dne/password.conf]',
'File[/dne/cert8.db]',
'Package[openssl]'
'Class[Nssdb]'
],
:subscribe => 'File[/dne/password.conf]'
)
Expand All @@ -27,7 +27,11 @@
context 'load_pkcs12' do
it do
contain_exec('load_pkcs12').with(
:command => "/usr/bin/pk12util -i '/dne/${pkcs12_name}' -d '/dne' -w '/dne/password.conf' -k '/dne/password.conf'"
:command => "/usr/bin/pk12util -i '/dne/${pkcs12_name}' -d '/dne' -w '/dne/password.conf' -k '/dne/password.conf'",
:require => [
'Exec[generate_pkcs12]',
'Class[Nssdb]'
]
)
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/defines/nssdb_create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
:require => [
'File[/obsolete]',
'File[/obsolete/password.conf]',
'Package[nss-tools]'
'Class[Nssdb]'
]
)
end
Expand Down Expand Up @@ -133,7 +133,7 @@
:require => [
'File[/obsolete]',
'File[/obsolete/password.conf]',
'Package[nss-tools]'
'Class[Nssdb]'
]
)
end
Expand Down

0 comments on commit 6fc4ead

Please sign in to comment.