Skip to content

Commit

Permalink
Merge pull request sprinkle-tool#86 from fetch/permission-verifiers
Browse files Browse the repository at this point in the history
Permission verifiers
  • Loading branch information
crafterm committed Apr 6, 2013
2 parents 2c17967 + 16a586d commit 749dc87
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions lib/sprinkle/verifiers/permission.rb
@@ -0,0 +1,40 @@
module Sprinkle
module Verifiers
# = Permission and ownership Verifier
#
# Contains a verifier to check the permissions and ownership of a file or directory.
#
# == Example Usage
#
# verify { has_permission '/etc/apache2/apache2.conf', 0644 }
#
# verify { belongs_to_user '/etc/apache2/apache2.conf', 'noop' }
#
# verify { belongs_to_user '/etc/apache2/apache2.conf', 1000 }
#
module Permission
Sprinkle::Verify.register(Sprinkle::Verifiers::Permission)

def has_permission(path, permission)
@commands << "find #{path} -maxdepth 0 -perm #{permission} | egrep '.*'"
end

def belongs_to_user(path, user)
if user.is_a?(Integer)
@commands << "find #{path} -maxdepth 0 -uid #{user} | egrep '.*'"
else
@commands << "find #{path} -maxdepth 0 -user #{user} | egrep '.*'"
end
end

def belongs_to_group(path, group)
if group.is_a?(Integer)
@commands << "find #{path} -maxdepth 0 -gid #{group} | egrep '.*'"
else
@commands << "find #{path} -maxdepth 0 -group #{group} | egrep '.*'"
end
end

end
end
end

0 comments on commit 749dc87

Please sign in to comment.