Skip to content

Commit

Permalink
(SIMP-7819) Add default_entry and alias types as parameters (#49)
Browse files Browse the repository at this point in the history
SIMP-7819 #close
  • Loading branch information
silug authored Jun 10, 2020
1 parent 237ca31 commit d708fa0
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 10 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
.yardoc
dist/
pkg/
spec/fixtures/
spec/fixtures/hieradata/*
!spec/fixtures/hieradata/sudo__*.yaml
spec/fixtures/modules/
spec/fixtures/simp_rspec/
spec/rp_env/
!/spec/hieradata/default.yaml
!/spec/fixtures/site.pp
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
* Tue Jun 09 2020 Steven Pritchard <[email protected]> - 5.3.0-0
- Add parameters for sudo::default_entry and sudo::alias defined types

* Tue Feb 04 2020 Jeanne Greulich <[email protected]> - 5.2.1-0
- Update for EL8.
- CVE-2019-14287 mitigation. See
Expand Down
6 changes: 6 additions & 0 deletions data/common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@ lookup_options:
'sudo::user_specifications':
merge:
strategy: deep
'sudo::default_entries':
merge:
strategy: deep
'sudo::aliases':
merge:
strategy: deep
26 changes: 18 additions & 8 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
# @author https://github.com/simp/pupmod-simp-sudo/graphs/contributors
#
class sudo (
Optional[Hash] $user_specifications = undef,
String $package_ensure = simplib::lookup('simp_options::package_ensure', { 'default_value' => 'installed' }),
Hash $user_specifications = {},
Hash $default_entries = {},
Hash $aliases = {},
String $package_ensure = simplib::lookup('simp_options::package_ensure', { 'default_value' => 'installed' }),
) {

package { 'sudo':
Expand All @@ -41,13 +43,21 @@
require => Package['sudo']
}

if $user_specifications {
$user_specifications.each |$spec, $options| {
$args = $options ? { Hash => $options, default => {} }
sudo::user_specification {
$spec: * => $args;
}
$user_specifications.each |$spec, $options| {
sudo::user_specification { $spec:
* => $options,
}
}

$default_entries.each |$key, $value| {
sudo::default_entry { $key:
* => $value,
}
}

$aliases.each |$key, $value| {
sudo::alias { $key:
* => $value,
}
}
}
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "simp-sudo",
"version": "5.2.1",
"version": "5.3.0",
"author": "SIMP Team",
"summary": "Manage sudo",
"license": "Apache-2.0",
Expand Down
30 changes: 30 additions & 0 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,36 @@
end
end

context 'should create sudo::default_entry resources with an iterator' do
context 'with properly formatted and complete yaml' do
let(:hieradata) { 'sudo__default_entries' }
it { is_expected.to create_sudo__default_entry('00_main').with({
:content => ['requiretty','syslog=authpriv'],
:def_type => 'base',
})}
it { is_expected.to create_sudo__default_entry('host_override').with({
:content => ['passwd_timeout=0.017'],
:target => 'SERVERS',
:def_type => 'host',
})}
end
end

context 'should create sudo::alias resources with an iterator' do
context 'with properly formatted and complete yaml' do
let(:hieradata) { 'sudo__aliases' }
it { is_expected.to create_sudo__alias('user_alias').with({
:content => ['user1','user2'],
:alias_type => 'user',
:order => 99,
})}
it { is_expected.to create_sudo__alias('host_alias').with({
:content => ['host1','host2'],
:alias_type => 'host',
:order => 10, # default
})}
end
end
end
end
end
Expand Down
13 changes: 13 additions & 0 deletions spec/fixtures/hieradata/sudo__aliases.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
sudo::aliases:
user_alias:
content:
- user1
- user2
alias_type: user
order: 99
host_alias:
content:
- host1
- host2
alias_type: host
11 changes: 11 additions & 0 deletions spec/fixtures/hieradata/sudo__default_entries.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
sudo::default_entries:
'00_main':
content:
- requiretty
- syslog=authpriv
'host_override':
content:
- passwd_timeout=0.017
target: SERVERS
def_type: host

0 comments on commit d708fa0

Please sign in to comment.