2015-07-15 13:15:18 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
# copyright: 2015, Vulcano Security GmbH
|
2015-10-06 16:55:44 +00:00
|
|
|
# author: Dominik Richter
|
|
|
|
# author: Christoph Hartmann
|
2015-07-15 13:15:18 +00:00
|
|
|
# license: All rights reserved
|
|
|
|
|
2015-08-30 00:14:17 +00:00
|
|
|
module Vulcano::Resources
|
|
|
|
class File < Vulcano.resource(1)
|
|
|
|
name 'file'
|
2015-08-29 07:44:16 +00:00
|
|
|
|
2015-10-06 12:11:48 +00:00
|
|
|
attr_reader :path
|
2015-08-30 00:14:17 +00:00
|
|
|
def initialize(path)
|
|
|
|
@path = path
|
2015-10-05 16:44:52 +00:00
|
|
|
@file = vulcano.backend.file(@path)
|
2015-08-30 00:14:17 +00:00
|
|
|
end
|
2015-08-29 07:44:16 +00:00
|
|
|
|
2015-08-30 00:14:17 +00:00
|
|
|
%w{
|
2015-09-18 10:35:32 +00:00
|
|
|
type exist? file? block_device? character_device? socket? directory?
|
2015-09-05 14:07:54 +00:00
|
|
|
symlink? pipe? mode mode? owner owned_by? group grouped_into? link_target
|
2015-09-22 17:31:47 +00:00
|
|
|
link_path linked_to? content mtime size selinux_label mounted? immutable?
|
2015-09-05 14:07:54 +00:00
|
|
|
product_version file_version version? md5sum sha256sum
|
2015-09-03 14:17:52 +00:00
|
|
|
}.each do |m|
|
|
|
|
define_method m.to_sym do |*args|
|
|
|
|
@file.method(m.to_sym).call(*args)
|
2015-08-30 00:14:17 +00:00
|
|
|
end
|
2015-08-29 07:44:16 +00:00
|
|
|
end
|
|
|
|
|
2015-09-09 16:52:27 +00:00
|
|
|
def contain(*_)
|
2015-10-24 09:12:15 +00:00
|
|
|
fail '`contain` will not be implemented. Use standard RSpec matcher.'
|
2015-08-30 00:14:17 +00:00
|
|
|
end
|
2015-08-29 07:44:16 +00:00
|
|
|
|
2015-09-01 22:50:52 +00:00
|
|
|
def readable?(by_owner, by_user)
|
2015-10-24 09:12:15 +00:00
|
|
|
m = unix_mode_mask(by_owner, 'r') ||
|
|
|
|
fail("#{by_owner} is not a valid unix owner.")
|
|
|
|
(@file.mask & m) != 0
|
2015-08-30 00:14:17 +00:00
|
|
|
end
|
2015-08-29 07:44:16 +00:00
|
|
|
|
2015-09-01 22:50:52 +00:00
|
|
|
def writable?(by_owner, by_user)
|
2015-10-24 09:12:15 +00:00
|
|
|
m = unix_mode_mask(by_owner, 'w') ||
|
|
|
|
fail("#{by_owner} is not a valid unix owner.")
|
|
|
|
(@file.mask & m) != 0
|
2015-06-21 09:23:30 +00:00
|
|
|
end
|
2015-08-29 07:44:16 +00:00
|
|
|
|
2015-09-01 22:50:52 +00:00
|
|
|
def executable?(by_owner, by_user)
|
2015-10-24 09:12:15 +00:00
|
|
|
m = unix_mode_mask(by_owner, 'x') ||
|
|
|
|
fail("#{by_owner} is not a valid unix owner.")
|
|
|
|
(@file.mask & m) != 0
|
2015-08-29 07:44:16 +00:00
|
|
|
end
|
|
|
|
|
2015-08-30 00:14:17 +00:00
|
|
|
def to_s
|
2015-10-12 11:01:58 +00:00
|
|
|
"File #{@path}"
|
2015-08-30 00:14:17 +00:00
|
|
|
end
|
2015-08-29 07:44:16 +00:00
|
|
|
end
|
|
|
|
end
|