mirror of
https://github.com/inspec/inspec
synced 2024-11-10 15:14:23 +00:00
add file uid and gid accessors
This commit is contained in:
parent
d086102c79
commit
419b6a087c
1 changed files with 16 additions and 0 deletions
|
@ -4,6 +4,8 @@
|
||||||
# author: Christoph Hartmann
|
# author: Christoph Hartmann
|
||||||
# license: All rights reserved
|
# license: All rights reserved
|
||||||
|
|
||||||
|
require 'shellwords'
|
||||||
|
|
||||||
module Inspec::Resources
|
module Inspec::Resources
|
||||||
class FileResource < Inspec.resource(1) # rubocop:disable Metrics/ClassLength
|
class FileResource < Inspec.resource(1) # rubocop:disable Metrics/ClassLength
|
||||||
name 'file'
|
name 'file'
|
||||||
|
@ -89,6 +91,20 @@ module Inspec::Resources
|
||||||
end
|
end
|
||||||
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
|
def to_s
|
||||||
"File #{path}"
|
"File #{path}"
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue