Class: Inspec::Resources::FileResource
- Inherits:
-
Object
- Object
- Inspec::Resources::FileResource
- Includes:
- MountParser
- Defined in:
- lib/resources/file.rb
Overview
rubocop:disable Metrics/ClassLength
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#mount_options ⇒ Object
readonly
Returns the value of attribute mount_options.
Instance Method Summary collapse
- #contain(*_) ⇒ Object
- #content ⇒ Object
- #executable?(by_usergroup, by_specific_user) ⇒ Boolean
-
#initialize(path) ⇒ FileResource
constructor
A new instance of FileResource.
- #mounted?(expected_options = nil, identical = false) ⇒ Boolean
- #readable?(by_usergroup, by_specific_user) ⇒ Boolean
- #sgid ⇒ Object
- #sticky ⇒ Object
- #suid ⇒ Object
- #to_s ⇒ Object
- #writable?(by_usergroup, by_specific_user) ⇒ Boolean
Methods included from MountParser
Constructor Details
#initialize(path) ⇒ FileResource
Returns a new instance of FileResource.
26 27 28 |
# File 'lib/resources/file.rb', line 26 def initialize(path) @file = inspec.backend.file(path) end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
25 26 27 |
# File 'lib/resources/file.rb', line 25 def file @file end |
#mount_options ⇒ Object (readonly)
Returns the value of attribute mount_options.
25 26 27 |
# File 'lib/resources/file.rb', line 25 def @mount_options end |
Instance Method Details
#contain(*_) ⇒ Object
48 49 50 |
# File 'lib/resources/file.rb', line 48 def contain(*_) fail 'Contain is not supported. Please use standard RSpec matchers.' end |
#content ⇒ Object
42 43 44 45 46 |
# File 'lib/resources/file.rb', line 42 def content res = file.content return nil if res.nil? res.force_encoding('utf-8') end |
#executable?(by_usergroup, by_specific_user) ⇒ Boolean
64 65 66 67 68 |
# File 'lib/resources/file.rb', line 64 def executable?(by_usergroup, by_specific_user) return false unless exist? ('x', by_usergroup, by_specific_user) end |
#mounted?(expected_options = nil, identical = false) ⇒ Boolean
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/resources/file.rb', line 70 def mounted?( = nil, identical = false) mounted = file.mounted # return if no additional parameters have been provided return file.mounted? if .nil? # deprecation warning, this functionality will be removed in future version warn "[DEPRECATION] `be_mounted.with and be_mounted.only_with` are deprecated. Please use `mount('#{source_path}')` instead." # we cannot read mount data on non-Linux systems return nil if !inspec.os.linux? # parse content if we are on linux @mount_options ||= (mounted.stdout, true) if identical # check if the options should be identical @mount_options == else # otherwise compare the selected values @mount_options.contains() end end |
#readable?(by_usergroup, by_specific_user) ⇒ Boolean
52 53 54 55 56 |
# File 'lib/resources/file.rb', line 52 def readable?(by_usergroup, by_specific_user) return false unless exist? ('r', by_usergroup, by_specific_user) end |
#sgid ⇒ Object
98 99 100 |
# File 'lib/resources/file.rb', line 98 def sgid (mode & 02000) > 0 end |
#sticky ⇒ Object
102 103 104 |
# File 'lib/resources/file.rb', line 102 def sticky (mode & 01000) > 0 end |
#suid ⇒ Object
94 95 96 |
# File 'lib/resources/file.rb', line 94 def suid (mode & 04000) > 0 end |
#to_s ⇒ Object
106 107 108 |
# File 'lib/resources/file.rb', line 106 def to_s "File #{source_path}" end |
#writable?(by_usergroup, by_specific_user) ⇒ Boolean
58 59 60 61 62 |
# File 'lib/resources/file.rb', line 58 def writable?(by_usergroup, by_specific_user) return false unless exist? ('w', by_usergroup, by_specific_user) end |