]> review.fuel-infra Code Review - puppet-modules/puppetlabs-firewall.git/commitdiff
MODULES-753
authorJonathan Tripathy <jonathan.tripathy@puppetlabs.com>
Wed, 21 Jan 2015 23:48:22 +0000 (15:48 -0800)
committerJonathan Tripathy <jonathan.tripathy@puppetlabs.com>
Thu, 22 Jan 2015 19:17:28 +0000 (11:17 -0800)
Fixes user adding and removing using either UID or string username.
Tested with both negated and non-negated values and works on all
supported operating systems.

Remote whitespace

lib/puppet/type/firewall.rb

index b2bccb96dc68313a28553f81aec4fbb8f8d83796..0895b6c6209f212c9c03dfad5aaae7bc6ba6abd4 100644 (file)
@@ -737,20 +737,37 @@ Puppet::Type.newtype(:firewall) do
       # between string usernames and UIDs (integers). We also need to ignore
       # spaces as they are irrelevant with respect to rule sync.
 
+      # Remove whitespace
       is = is.gsub(/\s+/,'')
+      should = @should.first.to_s.gsub(/\s+/,'')
 
+      # Keep track of negation, but remove the '!'
+      is_negate = ''
+      should_negate = ''
       if is.start_with?('!')
-        lookup_id = is.gsub(/^!/,'')
-        negate = '!'
-      else
-        lookup_id = is
-        negate = ''
+        is = is.gsub(/^!/,'')
+        is_negate = '!'
+      end
+      if should.start_with?('!')
+        should = should.gsub(/^!/,'')
+        should_negate = '!'
       end
 
-      resolve = Etc.getpwuid(Integer(lookup_id)).name
-      resolve_with_negate = "#{negate}#{resolve}"
+      # If 'should' contains anything other than digits,
+      # we assume that we have to do a lookup to convert
+      # to UID
+      unless should[/[0-9]+/] == should
+        should = Etc.getpwnam(should).uid
+      end
+
+      # If 'is' contains anything other than digits,
+      # we assume that we have to do a lookup to convert
+      # to UID
+      unless is[/[0-9]+/] == is
+        is = Etc.getpwnam(is).uid
+      end
 
-      return is.to_s == @should.first.to_s.gsub(/\s+/,'') || resolve_with_negate == @should.first.to_s.gsub(/\s+/,'')
+      return "#{is_negate}#{is}" == "#{should_negate}#{should}"
     end
 
   end