Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ AllCops:
Metrics/LineLength:
Description: People have wide screens, use them.
Max: 200
Exclude:
- spec/defines/init_spec.rb
GetText:
Enabled: false
GetText/DecorateString:
Expand Down
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ group :development do
gem "puppet-module-win-dev-r#{minor_version}", '~> 0.4', require: false, platforms: [:mswin, :mingw, :x64_mingw]
end

group :acceptance do
gem 'beaker-rspec'
gem 'beaker-vagrant'
end

puppet_version = ENV['PUPPET_GEM_VERSION']
facter_version = ENV['FACTER_GEM_VERSION']
hiera_version = ENV['HIERA_GEM_VERSION']
Expand Down
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,35 @@ recursive_file_permissions { '/my_dir':
}
```

### Ignoring Paths

Normally you can just specify a file within a managed directory as a separate
file resource to adjust its permissions separately, but due to the way
recursive_file_permissions works it's necessary to explicitly ignore paths:

```puppet
recursive_file_permissions { '/my_dir':
owner => 'me',
ignore_paths => [ '/my_dir/stuff/*' ]
}
```

Note that if you want to ignore a directory and its contents both will need
adding to the list:

```puppet
ignore_paths => [ '/my_dir/this/', '/my_dir/this/*' ]
```

## Development

PRs welcome.

### Testing

```
# To run spec tests
bundle exec rake spec
# To run beaker acceptance tests (requires vagrant)
bundle exec rake beaker
```
35 changes: 22 additions & 13 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@
#
# @example
# recursive_file_permissions { '/my_dir':
# file_mode => '0644',
# dir_mode => '0744',
# owner => 'me',
# group => 'us',
# file_mode => '0644',
# dir_mode => '0744',
# owner => 'me',
# group => 'us',
# ignore_paths => ['/my_dir/ignored/*']
# }
define recursive_file_permissions(
Recursive_file_permissions::Unixpath $target_dir = $title,
Optional[Recursive_file_permissions::Filemode] $file_mode = undef,
Optional[Recursive_file_permissions::Filemode] $dir_mode = undef,
Optional[String[1]] $owner = undef,
Optional[String[1]] $group = undef,
Recursive_file_permissions::Unixpath $target_dir = $title,
Optional[Recursive_file_permissions::Filemode] $file_mode = undef,
Optional[Recursive_file_permissions::Filemode] $dir_mode = undef,
Optional[String[1]] $owner = undef,
Optional[String[1]] $group = undef,
Optional[Array[Recursive_file_permissions::Unixpath]] $ignore_paths = undef,
) {

if $facts['os']['family'] == 'windows' {
Expand All @@ -29,7 +31,7 @@

# Define the find arguments to find and fix any of the permissions we want to
# recursively manage. Each element defines:
#
#
# - input. The param this relates to. If not undef, the check will be used.
# - find. String. Find args that will identify files in need of fixing.
# - fix. String. Find -exec command to fix identified files.
Expand Down Expand Up @@ -70,15 +72,23 @@
}
}.recursive_file_permissions::join(' -o ')

$ignore_path_args = case $ignore_paths {
undef: { '' }
default: {
$ignore_path_join = recursive_file_permissions::join($ignore_paths.map |$path| { shellquote('(', '!', '-path', $path, ')') }, ' -a ')
"-a ${ignore_path_join}"
}
}

# This will become the onlyif commmand to run.
$onlyif = "find ${shellsafe_dir} ${onlyif_find_args} | grep '.*'"
$onlyif = "find ${shellsafe_dir} \"(\" ${onlyif_find_args} \")\" ${ignore_path_args} | grep '.*'"

# Build an &&-joined command series to run that will find and fix any
# deviation from the desired state of any validator.
$command = $validators.reduce([]) |$arr,$validator| {
$validator[input] ? {
undef => $arr,
default => $arr << "find ${shellsafe_dir} '(' ${validator[find]} ')' ${validator[fix]}"
default => $arr << "find ${shellsafe_dir} \"(\" ${validator[find]} \")\" ${ignore_path_args} ${validator[fix]}"
}
}.recursive_file_permissions::join(' && ')

Expand All @@ -90,5 +100,4 @@
onlyif => $onlyif,
command => $command,
}

}
10 changes: 10 additions & 0 deletions spec/acceptance/nodesets/default.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
HOSTS:
testserver:
roles:
- master
platform: ubuntu-20.04-amd64
box: ubuntu/focal64
hypervisor: vagrant
CONFIG:
type: foss
Loading