summaryrefslogtreecommitdiff
path: root/lib/chef/resource/file.rb
diff options
context:
space:
mode:
authorSteven Danna <steve@opscode.com>2014-12-09 13:27:21 +0000
committerBryan McLellan <btm@opscode.com>2015-02-17 08:46:37 -0500
commit9b6f1129364ab39dd272ccffd14bbc82f4c32ace (patch)
treeedf4a8534cef7b646ffc30783c0f3ae08ed6f092 /lib/chef/resource/file.rb
parentcd7bac6dc131c958c8f6ccac6e50f2dca655dfd9 (diff)
downloadchef-9b6f1129364ab39dd272ccffd14bbc82f4c32ace.tar.gz
Implement RFC 027 File Verification
This implements usable-suppliable file content verification per RFC 027. Users can supplie a block, string, or symbol to the `verify` resource attribute. Blocks will be called, string will be executed as shell commands (respecing the same options as not_if and only_if), and symbols can be used to access built-in registered validations.
Diffstat (limited to 'lib/chef/resource/file.rb')
-rw-r--r--lib/chef/resource/file.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/chef/resource/file.rb b/lib/chef/resource/file.rb
index 16491f9bc8..7662731f44 100644
--- a/lib/chef/resource/file.rb
+++ b/lib/chef/resource/file.rb
@@ -20,6 +20,7 @@
require 'chef/resource'
require 'chef/platform/query_helpers'
require 'chef/mixin/securable'
+require 'chef/resource/file/verification'
class Chef
class Resource
@@ -50,6 +51,7 @@ class Chef
@force_unlink = false
@manage_symlink_source = nil
@diff = nil
+ @user_verifications = []
end
def content(arg=nil)
@@ -115,6 +117,18 @@ class Chef
:kind_of => [ TrueClass, FalseClass ]
)
end
+
+ def verify(command=nil, opts={}, &block)
+ if ! (command.nil? || [String, Symbol].include?(command.class))
+ raise ArgumentError, "verify requires either a string, symbol, or a block"
+ end
+
+ if command || block_given?
+ @user_verifications << Verification.new(self, command, opts, &block)
+ else
+ @user_verifications
+ end
+ end
end
end
end