summaryrefslogtreecommitdiff
path: root/lib/chef/provider/script.rb
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2014-12-08 13:44:59 -0800
committerLamont Granquist <lamont@scriptkiddie.org>2014-12-08 13:45:29 -0800
commit1b3705ca383b64092c9ef54d7e46201fab6271c7 (patch)
treee14588c68939b80e9cd8c5bf0b0eab4bfddbc96c /lib/chef/provider/script.rb
parent2bdc79409711e836a7698f7b44d171fa7973d4f1 (diff)
downloadchef-1b3705ca383b64092c9ef54d7e46201fab6271c7.tar.gz
Execute and Script Resource improvements
- Warning on incorrect usage of the command resource in any script resource - Warning on code in script resource being nil - Specs added to force deprecation of incorrect usage in Chef-13 - Specs added around the (supported) incorrect usage in Chef-12 - Cleanup+Modernization of providers and specs - Fixed some global state bugs around the Chef::Log.level in the spec tests
Diffstat (limited to 'lib/chef/provider/script.rb')
-rw-r--r--lib/chef/provider/script.rb38
1 files changed, 22 insertions, 16 deletions
diff --git a/lib/chef/provider/script.rb b/lib/chef/provider/script.rb
index 1615517553..ea286cb0e4 100644
--- a/lib/chef/provider/script.rb
+++ b/lib/chef/provider/script.rb
@@ -18,10 +18,13 @@
require 'tempfile'
require 'chef/provider/execute'
+require 'forwardable'
class Chef
class Provider
class Script < Chef::Provider::Execute
+ extend Forwardable
+
provides :bash
provides :csh
provides :perl
@@ -29,30 +32,40 @@ class Chef
provides :ruby
provides :script
+ def_delegators :@new_resource, :code, :interpreter, :flags
+
def initialize(new_resource, run_context)
super
- @code = @new_resource.code
+ end
+
+ def command
+ "\"#{interpreter}\" #{flags} \"#{script_file.path}\""
+ end
+
+ def load_current_resource
+ super
+ # @todo Chef-13: change this to an exception
+ if code.nil?
+ Chef::Log.warn "#{@new_resource}: No code attribute was given, resource does nothing, this behavior is deprecated and will be removed in Chef-13"
+ end
end
def action_run
- script_file.puts(@code)
+ script_file.puts(code)
script_file.close
set_owner_and_group
- @new_resource.command("\"#{interpreter}\" #{flags} \"#{script_file.path}\"")
super
- converge_by(nil) do
- # ensure script is unlinked at end of converge!
- unlink_script_file
- end
+
+ unlink_script_file
end
def set_owner_and_group
# FileUtils itself implements a no-op if +user+ or +group+ are nil
# You can prove this by running FileUtils.chown(nil,nil,'/tmp/file')
# as an unprivileged user.
- FileUtils.chown(@new_resource.user, @new_resource.group, script_file.path)
+ FileUtils.chown(new_resource.user, new_resource.group, script_file.path)
end
def script_file
@@ -60,16 +73,9 @@ class Chef
end
def unlink_script_file
- @script_file && @script_file.close!
+ script_file && script_file.close!
end
- def interpreter
- @new_resource.interpreter
- end
-
- def flags
- @new_resource.flags
- end
end
end
end