forked from sprinkle-tool/sprinkle
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request sprinkle-tool#86 from fetch/permission-verifiers
Permission verifiers
- Loading branch information
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |