This repository has been archived by the owner on Dec 31, 2024. It is now read-only.
forked from jhoblitt/puppet-nsstools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Imported and renamed the port389_nsstools_add_cert() function from: https://github.com/jhoblitt/puppet-port389/tree/93e211f0ef862659523f37ef638f23e127198a94
- Loading branch information
Joshua Hoblitt
committed
Feb 11, 2014
1 parent
2030ca5
commit 58cf67d
Showing
3 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
module Puppet::Parser::Functions | ||
newfunction(:nsstools_add_cert, :doc => <<-EOS | ||
Iterates over a hash of cert nickname/path pairs (key/value) and creates | ||
nsstools::add_cert resources. | ||
*Example:* | ||
nsstools_add_cert( | ||
'/etc/dirsrv/slapd-ldap1', | ||
{ | ||
'AlphaSSL CA' => '/tmp/alphassl_intermediate.pem', | ||
'GlobalSign Root CA' => '/tmp/globalsign_root.pem', | ||
} | ||
) | ||
Would effectively define these resources: | ||
nsstools::add_cert { 'AlphaSSL CA': | ||
certdir => '/etc/dirsrv/slapd-ldap1', | ||
nickname => 'AlphaSSL CA', | ||
cert => '/tmp/alphassl_intermediate.pem', | ||
} | ||
nsstools::add_cert { 'GlobalSign Root CA': | ||
certdir => '/etc/dirsrv/slapd-ldap1', | ||
nickname => 'GlobalSign Root CA', | ||
cert => '/tmp/globalsign_root.pem', | ||
} | ||
EOS | ||
) do |args| | ||
unless args.size == 2 | ||
raise(Puppet::ParseError, ":nsstools_add_cert(): " + | ||
"Wrong number of arguments given #{args.size} for 2") | ||
end | ||
|
||
certdir = args[0] | ||
certs = args[1] | ||
|
||
unless certdir.is_a?(String) | ||
raise(Puppet::ParseError, ":nsstools_add_cert(): " + | ||
"First argument must be a string") | ||
end | ||
|
||
unless certs.is_a?(Hash) | ||
raise(Puppet::ParseError, ":nsstools_add_cert(): " + | ||
"Second argument must be a hash") | ||
end | ||
|
||
# we need to managle the resource name so multiple instances (and/or the | ||
# admin server) can reuse the same certs | ||
certs.each_pair do |nickname, cert| | ||
function_create_resources(['nsstools::add_cert', { | ||
"#{certdir}-#{nickname}" => { | ||
'certdir' => certdir, | ||
'nickname' => nickname, | ||
'cert' => cert, | ||
} | ||
}]) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
require 'spec_helper' | ||
|
||
describe 'nsstools_add_cert', :type => :puppet_function do | ||
it 'should fail with < 2 param' do | ||
expect { subject.call([1]) }.to raise_error(/Wrong number of arguments/) | ||
end | ||
|
||
it 'should fail with > 2 param' do | ||
expect { subject.call([1, 2, 3]) }.to raise_error(/Wrong number of arguments/) | ||
end | ||
|
||
it 'should require first arg to be a string' do | ||
expect { subject.call([1, 2]) }.to raise_error(/First argument must be a string/) | ||
end | ||
|
||
it 'should require second arg to be a hash' do | ||
expect { subject.call(['1', 2]) }.to raise_error(/Second argument must be a hash/) | ||
end | ||
|
||
it 'should work with reasonable input' do | ||
should run.with_params( | ||
'/etc/dirsrv/slapd-ldap1', | ||
{ | ||
'AlphaSSL CA' => '/tmp/alphassl_intermediate.pem', | ||
'GlobalSign Root CA' => '/tmp/globalsign_root.pem', | ||
} | ||
) | ||
|
||
alpha = catalogue.resource('Nsstools::Add_cert', '/etc/dirsrv/slapd-ldap1-AlphaSSL CA') | ||
alpha[:nickname].should eq 'AlphaSSL CA' | ||
alpha[:certdir].should eq '/etc/dirsrv/slapd-ldap1' | ||
alpha[:cert].should eq '/tmp/alphassl_intermediate.pem' | ||
|
||
global = catalogue.resource('Nsstools::Add_cert', '/etc/dirsrv/slapd-ldap1-GlobalSign Root CA') | ||
global[:nickname].should eq 'GlobalSign Root CA' | ||
global[:certdir].should eq '/etc/dirsrv/slapd-ldap1' | ||
global[:cert].should eq '/tmp/globalsign_root.pem' | ||
end | ||
end |