Skip to content

Commit

Permalink
change the {user,group} params to nsstools::create
Browse files Browse the repository at this point in the history
To be optional and and default to `undef`.
  • Loading branch information
Joshua Hoblitt committed Feb 13, 2014
1 parent 8cb0ab0 commit c4d4c89
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 26 deletions.
45 changes: 27 additions & 18 deletions manifests/create.pp
Original file line number Diff line number Diff line change
@@ -1,50 +1,59 @@
# Create an empty NSS database with a password file.
#
# Parameters:
# $owner - required - the file/directory user
# $group - required - the file/directory group
# $password - required - password to set on the database
# $certdir - optional - defaults to title
# $mode - optional - defaults to '0600'
# $certdir_mode - optional - defaults to '0700'
# $password - required - password to set on the database
# $certdir - optional - defaults to title
# $owner - optional - the file/directory user
# $group - optional - the file/directory group
# $mode - optional - defaults to '0600'
# $certdir_mode - optional - defaults to '0700'
# $manage_certdir - optional - defaults to true
#
# Actions:
# creates a new NSS database, consisting of 4 files:
# cert8.db, key3.db, secmod.db and a password file, nss-password.txt
#
# Requires:
# $owner must be set
# $group must be set
# $password must be set
#
# Sample Usage:
#
# nsstools::create {'test':
# owner => 'qpidd',
# group => 'qpidd',
# password => 'test'}
# nsstools::create { '/tmp/mydb':
# password => 'password',
# certdir => '/tmp/mydb', # defaults to $title
# owner => 'root',
# group => 'root',
# mode => '0600',
# certdir_mode => '0700',
# manage_certdir => true
# }
#
# This will create an NSS database in /etc/pki/test
#
define nsstools::create (
$owner,
$group,
$password,
$certdir = $title,
$owner = undef,
$group = undef,
$mode = '0600',
$certdir_mode = '0700',
$manage_certdir = true
) {
include nsstools

validate_string($password)
validate_absolute_path($certdir)
validate_string($owner)
validate_string($group)
validate_string($mode)
validate_string($certdir_mode)
validate_bool($manage_certdir)

if $manage_certdir {
file { $certdir:
ensure => directory,
mode => $certdir_mode,
owner => $owner,
group => $group,
mode => $certdir_mode,
}

$require_certdir = File[$certdir]
Expand All @@ -55,10 +64,10 @@

file { "${certdir}/nss-password.txt":
ensure => file,
mode => $mode,
owner => $owner,
group => $group,
content => $password,
mode => $mode,
require => $require_certdir,
}

Expand All @@ -68,9 +77,9 @@
"${certdir}/secmod.db"
]:
ensure => file,
mode => $mode,
owner => $owner,
group => $group,
mode => $mode,
require => [
File["${certdir}/nss-password.txt"],
Exec["create_nss_db_${title}"],
Expand Down
8 changes: 0 additions & 8 deletions spec/defines/nsstools_create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,13 @@
let(:title) { '/obsolete' }
let(:params) do
{
:owner => 'nobody',
:group => 'nobody',
:password => 'secret',
}
end

context 'nsstools directory' do
it do
should contain_file('/obsolete').with(
:owner => 'nobody',
:group => 'nobody',
:mode => '0700'
)
end
Expand All @@ -26,8 +22,6 @@
context 'password file' do
it do
should contain_file('/obsolete/nss-password.txt').with(
:owner => 'nobody',
:group => 'nobody',
:mode => '0600',
:content => 'secret',
:require => 'File[/obsolete]'
Expand All @@ -40,8 +34,6 @@
databases.each do |db|
it do
should contain_file('/obsolete/' + db).with(
:owner => 'nobody',
:group => 'nobody',
:mode => '0600',
:require => [
'File[/obsolete/nss-password.txt]',
Expand Down

0 comments on commit c4d4c89

Please sign in to comment.