Skip to content

Commit

Permalink
Merge pull request #66 from daks/purge-included-dir
Browse files Browse the repository at this point in the history
New feature to purge included dir
  • Loading branch information
myii authored Nov 24, 2020
2 parents 153ac6e + 7400528 commit a56d54e
Show file tree
Hide file tree
Showing 18 changed files with 36 additions and 30 deletions.
2 changes: 2 additions & 0 deletions pillar.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
sudoers:
# By default the main sudoers file is managed by this formula (False to skip)
manage_main_config: true
# By default the included directory is not purged from unwanted files
purge_includedir: false
users:
johndoe:
- 'ALL=(ALL) ALL'
Expand Down
1 change: 1 addition & 0 deletions sudoers/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
sudoers:
pkg: sudo
manage_main_config: true
purge_includedir: false
configpath: /etc
group: root
execprefix: /usr/sbin
Expand Down
7 changes: 7 additions & 0 deletions sudoers/included.sls
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
include:
- sudoers
{{ sudoers.includedir }}:
file.directory:
- user: root
- group: {{ sudoers.group }}
- mode: 440
- clean: {{ sudoers.purge_includedir }}
{% set included_files = sudoers.included_files %}
{% for included_file, spec in included_files.items() -%}
sudoers include {{ included_file }}:
Expand Down
1 change: 1 addition & 0 deletions test/integration/default/files/_mapdata/amazonlinux-1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ sudoers:
sysadmins:
- ALL=(ALL) ALL
pkg: sudo
purge_includedir: false
users:
johndoe:
- ALL=(ALL) ALL
Expand Down
1 change: 1 addition & 0 deletions test/integration/default/files/_mapdata/amazonlinux-2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ sudoers:
sysadmins:
- ALL=(ALL) ALL
pkg: sudo
purge_includedir: false
users:
johndoe:
- ALL=(ALL) ALL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ sudoers:
sysadmins:
- ALL=(ALL) ALL
pkg: sudo
purge_includedir: false
users:
johndoe:
- ALL=(ALL) ALL
Expand Down
1 change: 1 addition & 0 deletions test/integration/default/files/_mapdata/centos-6.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ sudoers:
sysadmins:
- ALL=(ALL) ALL
pkg: sudo
purge_includedir: false
users:
johndoe:
- ALL=(ALL) ALL
Expand Down
1 change: 1 addition & 0 deletions test/integration/default/files/_mapdata/centos-7.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ sudoers:
sysadmins:
- ALL=(ALL) ALL
pkg: sudo
purge_includedir: false
users:
johndoe:
- ALL=(ALL) ALL
Expand Down
1 change: 1 addition & 0 deletions test/integration/default/files/_mapdata/centos-8.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ sudoers:
sysadmins:
- ALL=(ALL) ALL
pkg: sudo
purge_includedir: false
users:
johndoe:
- ALL=(ALL) ALL
Expand Down
1 change: 1 addition & 0 deletions test/integration/default/files/_mapdata/debian-10.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ sudoers:
sysadmins:
- ALL=(ALL) ALL
pkg: sudo
purge_includedir: false
users:
johndoe:
- ALL=(ALL) ALL
Expand Down
1 change: 1 addition & 0 deletions test/integration/default/files/_mapdata/debian-9.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ sudoers:
sysadmins:
- ALL=(ALL) ALL
pkg: sudo
purge_includedir: false
users:
johndoe:
- ALL=(ALL) ALL
Expand Down
1 change: 1 addition & 0 deletions test/integration/default/files/_mapdata/fedora-31.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ sudoers:
sysadmins:
- ALL=(ALL) ALL
pkg: sudo
purge_includedir: false
users:
johndoe:
- ALL=(ALL) ALL
Expand Down
1 change: 1 addition & 0 deletions test/integration/default/files/_mapdata/fedora-32.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ sudoers:
sysadmins:
- ALL=(ALL) ALL
pkg: sudo
purge_includedir: false
users:
johndoe:
- ALL=(ALL) ALL
Expand Down
1 change: 1 addition & 0 deletions test/integration/default/files/_mapdata/opensuse-15.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ sudoers:
sysadmins:
- ALL=(ALL) ALL
pkg: sudo
purge_includedir: false
users:
johndoe:
- ALL=(ALL) ALL
Expand Down
1 change: 1 addition & 0 deletions test/integration/default/files/_mapdata/ubuntu-16.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ sudoers:
sysadmins:
- ALL=(ALL) ALL
pkg: sudo
purge_includedir: false
users:
johndoe:
- ALL=(ALL) ALL
Expand Down
1 change: 1 addition & 0 deletions test/integration/default/files/_mapdata/ubuntu-18.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ sudoers:
sysadmins:
- ALL=(ALL) ALL
pkg: sudo
purge_includedir: false
users:
johndoe:
- ALL=(ALL) ALL
Expand Down
1 change: 1 addition & 0 deletions test/integration/default/files/_mapdata/ubuntu-20.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ sudoers:
sysadmins:
- ALL=(ALL) ALL
pkg: sudo
purge_includedir: false
users:
johndoe:
- ALL=(ALL) ALL
Expand Down
42 changes: 12 additions & 30 deletions test/integration/share/libraries/system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,18 @@
# Author: Daniel Dehennin <[email protected]>
# Copyright (C) 2020 Daniel Dehennin <[email protected]>

HOSTNAME_CMDS = %w[hostname hostnamectl].freeze
HOSTNAME_CMDS_OPT = {
'hostname' => '-s',
'hostnamectl' => '--static'
}.freeze

class SystemResource < Inspec.resource(1)
name 'system'

attr_reader :platform
attr_reader :hostname

def initialize
super
@platform = build_platform
@hostname = found_hostname
end

private

def found_hostname
cmd = guess_hostname_cmd

unless cmd.exit_status.zero?
raise Inspec::Exceptions::ResourceSkipped,
"Error running '#{cmd}': #{cmd.stderr}"
end

cmd.stdout.chomp
end

def guess_hostname_cmd
HOSTNAME_CMDS.each do |cmd|
if inspec.command(cmd).exist?
return inspec.command("#{cmd} #{HOSTNAME_CMDS_OPT[cmd]}")
end
end

raise Inspec::Exceptions::ResourceSkipped,
"Error: #{@platform[:finger]}} has none of #{HOSTNAME_CMDS.join(', ')}"
end

def build_platform
{
family: build_platform_family,
Expand Down Expand Up @@ -79,11 +50,22 @@ def build_platform_release
inspec.platform[:release].gsub(/2018.*/, '1')
when 'arch'
'base-latest'
when 'gentoo'
"#{inspec.platform[:release].split('.')[0]}-#{derive_gentoo_init_system}"
else
inspec.platform[:release]
end
end

def derive_gentoo_init_system
case inspec.command('systemctl').exist?
when true
'sysd'
else
'sysv'
end
end

def build_platform_finger
"#{build_platform_name}-#{build_finger_release}"
end
Expand Down

0 comments on commit a56d54e

Please sign in to comment.