mirror of
https://github.com/inspec/inspec
synced 2024-11-10 15:14:23 +00:00
Merge pull request #603 from chef/dr/file-uid-gid
add file uid and gid accessors
This commit is contained in:
commit
2b2a9793a6
1 changed files with 16 additions and 0 deletions
|
@ -4,6 +4,8 @@
|
|||
# author: Christoph Hartmann
|
||||
# license: All rights reserved
|
||||
|
||||
require 'shellwords'
|
||||
|
||||
module Inspec::Resources
|
||||
class FileResource < Inspec.resource(1) # rubocop:disable Metrics/ClassLength
|
||||
name 'file'
|
||||
|
@ -89,6 +91,20 @@ module Inspec::Resources
|
|||
end
|
||||
end
|
||||
|
||||
# TODO: This is temporary and must be moved to train
|
||||
def uid
|
||||
res = inspec.command('stat '+Shellwords.escape(@path)+' -c %u')
|
||||
return nil if res.exit_status != 0 || res.stdout.empty?
|
||||
res.stdout.to_i
|
||||
end
|
||||
|
||||
# TODO: This is temporary and must be moved to train
|
||||
def gid
|
||||
res = inspec.command('stat '+Shellwords.escape(@path)+' -c %u')
|
||||
return nil if res.exit_status != 0 || res.stdout.empty?
|
||||
res.stdout.to_i
|
||||
end
|
||||
|
||||
def to_s
|
||||
"File #{path}"
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue