Skip to content

Commit

Permalink
Merge pull request #97 from voxpupuli/modulesync
Browse files Browse the repository at this point in the history
modulesync 5.1.0 / Drop EoL Puppet 5 support
  • Loading branch information
bastelfreak authored Jan 20, 2022
2 parents 1be25fa + 0d66d1e commit ae18d3b
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .msync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# Managed by modulesync - DO NOT EDIT
# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/

modulesync_config_version: '4.2.0'
modulesync_config_version: '5.1.0'
3 changes: 3 additions & 0 deletions .puppet-lint.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--fail-on-warnings
--no-parameter_documentation-check
--no-parameter_types-check
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
source ENV['GEM_SOURCE'] || "https://rubygems.org"

group :test do
gem 'voxpupuli-test', '~> 2.5', :require => false
gem 'voxpupuli-test', '~> 5.0', :require => false
gem 'coveralls', :require => false
gem 'simplecov-console', :require => false
gem 'puppet_metadata', '~> 1.0', :require => false
Expand All @@ -21,7 +21,7 @@ end

group :release do
gem 'github_changelog_generator', '>= 1.16.1', :require => false if RUBY_VERSION >= '2.5'
gem 'voxpupuli-release', '>= 1.0.2', :require => false
gem 'voxpupuli-release', '>= 1.2.0', :require => false
gem 'puppet-strings', '>= 2.2', :require => false
end

Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Managed by modulesync - DO NOT EDIT
# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/

# Attempt to load voxupuli-test (which pulls in puppetlabs_spec_helper),
# Attempt to load voxpupuli-test (which pulls in puppetlabs_spec_helper),
# otherwise attempt to load it directly.
begin
require 'voxpupuli/test/rake'
Expand Down
4 changes: 3 additions & 1 deletion lib/puppet/provider/posix_acl/genericacl.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
Puppet::Type.type(:posix_acl).provide(:genericacl, parent: Puppet::Provider) do
# frozen_string_literal: true

Puppet::Type.type(:posix_acl).provide(:genericacl, parent: Puppet::Provider) do # rubocop:disable Lint/EmptyBlock
end
11 changes: 8 additions & 3 deletions lib/puppet/provider/posix_acl/posixacl.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

Puppet::Type.type(:posix_acl).provide(:posixacl, parent: Puppet::Provider) do
desc 'Provide posix 1e acl functions using posix getfacl/setfacl commands'

Expand All @@ -10,7 +12,7 @@
end

confine feature: :posix
defaultfor osfamily: [:debian, :redhat, :suse, :gentoo]
defaultfor osfamily: %i[debian redhat suse gentoo]

def exists?
permission
Expand Down Expand Up @@ -55,6 +57,7 @@ def purge

def permission
return [] unless File.exist?(@resource.value(:path))

value = []
# String#lines would be nice, but we need to support Ruby 1.8.5
getfacl('--absolute-names', '--no-effective', @resource.value(:path)).split("\n").each do |line|
Expand Down Expand Up @@ -85,7 +88,8 @@ def check_set
@resource.value(:action) == :set
end

def permission=(_value) # TODO: Investigate why we're not using this parameter
# TODO: Investigate why we're not using this parameter
def permission=(_value)
Puppet.debug @resource.value(:action)
case @resource.value(:action)
when :unset
Expand All @@ -104,7 +108,8 @@ def permission=(_value) # TODO: Investigate why we're not using this parameter
# Unset perms always should match against lowercased x.
perm_to_unset = cur_perm - new_perm
perm_to_unset_check = lc_cur_perm - lc_new_perm
return false if perm_to_set_check.empty? && perm_to_unset_check.empty?
return false if perm_to_set_check.empty? && perm_to_unset_check.empty? # rubocop:disable Lint/ReturnInVoidContext

# Take supplied perms literally, unset any existing perms which
# are absent from ACLs given
if check_exact
Expand Down
36 changes: 18 additions & 18 deletions lib/puppet/type/posix_acl.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# frozen_string_literal: true

require 'set'
require 'pathname'
require 'English'

# rubocop:disable Naming/MethodParameterName
Puppet::Type.newtype(:posix_acl) do
desc <<-EOT
Ensures that a set of ACL permissions are applied to a given file
Expand Down Expand Up @@ -39,7 +41,7 @@
file { '/var/www/html':
mode => 754,
}
EOT
EOT

newparam(:action) do
desc 'What do we do with this list of ACLs? Options are set, unset, exact, and purge'
Expand All @@ -52,9 +54,7 @@
isnamevar
validate do |value|
path = Pathname.new(value)
unless path.absolute?
raise ArgumentError, "Path must be absolute: #{path}"
end
raise ArgumentError, "Path must be absolute: #{path}" unless path.absolute?
end
end

Expand All @@ -79,7 +79,7 @@ def self.descendant?(a, b)
end

# Snippet based on upstream Puppet (ASL 2.0)
[:posix_acl, :file].each do |autorequire_type|
%i[posix_acl file].each do |autorequire_type|
autorequire(autorequire_type) do
req = []
path = Pathname.new(self[:path])
Expand All @@ -103,7 +103,6 @@ def self.descendant?(a, b)
end
req
end
# rubocop:enable Style/MultilineBlockChain
end
# End of Snippet

Expand All @@ -114,7 +113,7 @@ def self.descendant?(a, b)
newproperty(:permission, array_matching: :all) do
desc 'ACL permission(s).'

def is_to_s(value) # rubocop:disable Style/PredicateName
def is_to_s(value) # rubocop:disable Naming/PredicateName
if value == :absent || value.include?(:absent)
super
else
Expand Down Expand Up @@ -163,7 +162,7 @@ def unset_insync(cur_perm)

# Make sure we are not misinterpreting recursive permission notation (e.g. rwX) when
# comparing current to new perms.
def set_insync(cur_perm) # rubocop:disable Style/AccessorMethodName
def set_insync(cur_perm) # rubocop:disable Naming/AccessorMethodName
lc_cur_perm = cur_perm.map(&:downcase).uniq.sort
should = @should.map(&:downcase).uniq.sort
(lc_cur_perm.sort == should) || (provider.check_set && (should - lc_cur_perm).empty?)
Expand All @@ -182,6 +181,7 @@ def insync?(is)
Puppet.debug "permission.insync? is: #{is.inspect} @should: #{@should.inspect}"
return purge_insync(is) if provider.check_purge
return unset_insync(is) if provider.check_unset

set_insync(is)
end

Expand All @@ -191,13 +191,15 @@ def insync?(is)
a = acl.split ':', -1 # -1 keeps trailing empty fields.
raise ArgumentError, "Too few fields. At least 3 required, got #{a.length}." if a.length < 3
raise ArgumentError, "Too many fields. At most 4 allowed, got #{a.length}." if a.length > 4

if a.length == 4
d = a.shift
raise ArgumentError, %(First field of 4 must be "d" or "default", got "#{d}".) unless %w[d default].include?(d)

r << 'default:'
end
t = a.shift # Copy the type.
r << case t
r += case t
when 'u', 'user'
'user:'
when 'g', 'group'
Expand Down Expand Up @@ -239,18 +241,17 @@ def self.pick_default_perms(acl)
end

def newchild(path)
options = @original_parameters.merge(name: path).reject { |_param, value| value.nil? }
unless File.directory?(options[:name])
options[:permission] = self.class.pick_default_perms(options[:permission]) if options.include?(:permission)
end
[:recursive, :recursemode, :path].each do |param|
options = @original_parameters.merge(name: path).reject { |_param, value| value.nil? } # rubocop:disable Style/CollectionCompact
options[:permission] = self.class.pick_default_perms(options[:permission]) if !File.directory?(options[:name]) && options.include?(:permission)
%i[recursive recursemode path].each do |param|
options.delete(param) if options.include?(param)
end
self.class.new(options)
end

def generate
return [] unless self[:recursive] == :true && self[:recursemode] == :deep

results = []
paths = Set.new
if File.directory?(self[:path])
Expand All @@ -275,8 +276,7 @@ def generate
end

validate do
unless self[:permission]
raise(Puppet::Error, 'permission is a required property.')
end
raise(Puppet::Error, 'permission is a required property.') unless self[:permission]
end
end
# rubocop:enable Naming/MethodParameterName
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"requirements": [
{
"name": "puppet",
"version_requirement": ">= 5.5.8 < 8.0.0"
"version_requirement": ">= 6.1.0 < 8.0.0"
}
],
"description": "Manages posix 1e ACLs on files, provides base classes so additional ACL standards can be supported.",
Expand Down
10 changes: 5 additions & 5 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# frozen_string_literal: true

# Managed by modulesync - DO NOT EDIT
# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/

# puppetlabs_spec_helper will set up coverage if the env variable is set.
# We want to do this if lib exists and it hasn't been explicitly set.
ENV['COVERAGE'] ||= 'yes' if Dir.exist?(File.expand_path('../../lib', __FILE__))
ENV['COVERAGE'] ||= 'yes' if Dir.exist?(File.expand_path('../lib', __dir__))

require 'voxpupuli/test/spec_helper'

if File.exist?(File.join(__dir__, 'default_module_facts.yml'))
facts = YAML.safe_load(File.read(File.join(__dir__, 'default_module_facts.yml')))
if facts
facts.each do |name, value|
add_custom_fact name.to_sym, value
end
facts&.each do |name, value|
add_custom_fact name.to_sym, value
end
end
4 changes: 4 additions & 0 deletions spec/unit/puppet/provider/posixacl_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'spec_helper'
require 'rspec/mocks'

Expand All @@ -9,11 +11,13 @@
provider_class.command :getfacl
end.not_to raise_error
end

it 'declares a setfacl command' do
expect do
provider_class.command :setfacl
end.not_to raise_error
end

it 'encodes spaces in group names' do
RSpec::Mocks.with_temporary_scope do
allow(Puppet::Type).to receive(:getfacl).and_return("group:test group:rwx\n")
Expand Down
Loading

0 comments on commit ae18d3b

Please sign in to comment.