Class: Inspec::Resources::FileResource
- Inherits:
-
Object
- Object
- Inspec::Resources::FileResource
- Includes:
- FilePermissionsSelector, LinuxMountParser
- Defined in:
- lib/resources/file.rb
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 (also: #setgid?)
- #sticky ⇒ Object (also: #sticky?)
- #suid ⇒ Object (also: #setuid?)
- #to_s ⇒ Object
- #writable?(by_usergroup, by_specific_user) ⇒ Boolean
Methods included from LinuxMountParser
Methods included from FilePermissionsSelector
Constructor Details
#initialize(path) ⇒ FileResource
Returns a new instance of FileResource.
38 39 40 41 42 |
# File 'lib/resources/file.rb', line 38 def initialize(path) # select permissions style @perms_provider = select_file_perms_style(inspec.os) @file = inspec.backend.file(path) end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
37 38 39 |
# File 'lib/resources/file.rb', line 37 def file @file end |
#mount_options ⇒ Object (readonly)
Returns the value of attribute mount_options.
37 38 39 |
# File 'lib/resources/file.rb', line 37 def @mount_options end |
Instance Method Details
#contain(*_) ⇒ Object
62 63 64 |
# File 'lib/resources/file.rb', line 62 def contain(*_) raise 'Contain is not supported. Please use standard RSpec matchers.' end |
#content ⇒ Object
56 57 58 59 60 |
# File 'lib/resources/file.rb', line 56 def content res = file.content return nil if res.nil? res.force_encoding('utf-8') end |
#executable?(by_usergroup, by_specific_user) ⇒ Boolean
80 81 82 83 84 85 |
# File 'lib/resources/file.rb', line 80 def executable?(by_usergroup, by_specific_user) return false unless exist? return skip_resource '`executable?` is not supported on your OS yet.' if @perms_provider.nil? ('execute', by_usergroup, by_specific_user) end |
#mounted?(expected_options = nil, identical = false) ⇒ Boolean
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/resources/file.rb', line 87 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
66 67 68 69 70 71 |
# File 'lib/resources/file.rb', line 66 def readable?(by_usergroup, by_specific_user) return false unless exist? return skip_resource '`readable?` is not supported on your OS yet.' if @perms_provider.nil? ('read', by_usergroup, by_specific_user) end |
#sgid ⇒ Object Also known as: setgid?
117 118 119 |
# File 'lib/resources/file.rb', line 117 def sgid (mode & 02000) > 0 end |
#sticky ⇒ Object Also known as: sticky?
123 124 125 |
# File 'lib/resources/file.rb', line 123 def sticky (mode & 01000) > 0 end |
#suid ⇒ Object Also known as: setuid?
111 112 113 |
# File 'lib/resources/file.rb', line 111 def suid (mode & 04000) > 0 end |
#to_s ⇒ Object
129 130 131 |
# File 'lib/resources/file.rb', line 129 def to_s "File #{source_path}" end |
#writable?(by_usergroup, by_specific_user) ⇒ Boolean
73 74 75 76 77 78 |
# File 'lib/resources/file.rb', line 73 def writable?(by_usergroup, by_specific_user) return false unless exist? return skip_resource '`writable?` is not supported on your OS yet.' if @perms_provider.nil? ('write', by_usergroup, by_specific_user) end |