summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Batye <gbatye@fb.com>2017-02-17 09:22:38 -0800
committerGregory Batye <gbatye@fb.com>2017-02-17 09:23:09 -0800
commit934d4e09c9462e3339c6132ea7970369b7bb0cdc (patch)
treec74f038bc3522cd362ec0d28c12ae09dbedbdf21
parentc0f2f0e22d6bd8c14e39dc8950a751fccaa30910 (diff)
parenta048bda66fa719607b85af72bceb79136fe2fe57 (diff)
downloadchef-934d4e09c9462e3339c6132ea7970369b7bb0cdc.tar.gz
Merge remote-tracking branch 'chef/master' into fix_osx_profile
Signed-off-by: Gregory Batye <gbatye@fb.com>
-rw-r--r--CHANGELOG.md5
-rw-r--r--Gemfile.lock10
-rw-r--r--VERSION2
-rw-r--r--chef-config/lib/chef-config/version.rb2
-rw-r--r--lib/chef/provider/batch.rb2
-rw-r--r--lib/chef/provider/breakpoint.rb2
-rw-r--r--lib/chef/provider/cookbook_file.rb6
-rw-r--r--lib/chef/provider/cron.rb76
-rw-r--r--lib/chef/provider/deploy.rb162
-rw-r--r--lib/chef/provider/directory.rb64
-rw-r--r--lib/chef/provider/dsc_resource.rb10
-rw-r--r--lib/chef/provider/env.rb56
-rw-r--r--lib/chef/provider/erl_call.rb26
-rw-r--r--lib/chef/provider/execute.rb2
-rw-r--r--lib/chef/provider/file.rb92
-rw-r--r--lib/chef/provider/git.rb110
-rw-r--r--lib/chef/provider/http_request.rb72
-rw-r--r--lib/chef/provider/launchd.rb2
-rw-r--r--lib/chef/provider/link.rb100
-rw-r--r--lib/chef/provider/log.rb4
-rw-r--r--lib/chef/provider/mdadm.rb50
-rw-r--r--lib/chef/provider/ohai.rb2
-rw-r--r--lib/chef/provider/osx_profile.rb38
-rw-r--r--lib/chef/provider/powershell_script.rb12
-rw-r--r--lib/chef/provider/reboot.rb20
-rw-r--r--lib/chef/provider/registry_key.rb78
-rw-r--r--lib/chef/provider/remote_directory.rb6
-rw-r--r--lib/chef/provider/remote_file.rb6
-rw-r--r--lib/chef/provider/ruby_block.rb6
-rw-r--r--lib/chef/provider/script.rb4
-rw-r--r--lib/chef/provider/service.rb96
-rw-r--r--lib/chef/provider/subversion.rb78
-rw-r--r--lib/chef/provider/template.rb6
-rw-r--r--lib/chef/provider/user.rb84
-rw-r--r--lib/chef/provider/whyrun_safe_ruby_block.rb8
-rw-r--r--lib/chef/version.rb2
36 files changed, 650 insertions, 651 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4fdbf7627d..ed3ba8d973 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,7 +1,7 @@
This changelog reflects the current state of chef's master branch on github and may not reflect the current released version of chef, which is [![Gem Version](https://badge.fury.io/rb/chef.svg)](https://badge.fury.io/rb/chef).
-## [v12.19.30](https://github.com/chef/chef/tree/v12.19.30) (2017-02-14)
-[Full Changelog](https://github.com/chef/chef/compare/v12.18.31...v12.19.30)
+## [v12.19.33](https://github.com/chef/chef/tree/v12.19.33) (2017-02-16)
+[Full Changelog](https://github.com/chef/chef/compare/v12.18.31...v12.19.33)
**Closed issues:**
@@ -31,7 +31,6 @@ This changelog reflects the current state of chef's master branch on github and
- Core: Ensure paths are correctly escaped when syntax checking [\#5704](https://github.com/chef/chef/pull/5704) ([ceneo](https://github.com/ceneo))
- Added module\_version attribute for dsc\_resource for SxS support [\#5701](https://github.com/chef/chef/pull/5701) ([Aliasgar16](https://github.com/Aliasgar16))
- Bump net-ssh to v4, add dependencies for ed25519 support [\#5687](https://github.com/chef/chef/pull/5687) ([onlyhavecans](https://github.com/onlyhavecans))
-- Initial habitat plan for chef-client [\#5677](https://github.com/chef/chef/pull/5677) ([adamhjk](https://github.com/adamhjk))
## [v12.18.31](https://github.com/chef/chef/tree/v12.18.31) (2017-01-11)
[Full Changelog](https://github.com/chef/chef/compare/v12.17.44...v12.18.31)
diff --git a/Gemfile.lock b/Gemfile.lock
index 00b17a1f57..bdb9ce29e1 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -46,10 +46,10 @@ GIT
PATH
remote: .
specs:
- chef (12.19.30)
+ chef (12.19.33)
addressable
bundler (>= 1.10)
- chef-config (= 12.19.30)
+ chef-config (= 12.19.33)
chef-zero (>= 4.8)
diff-lcs (~> 1.2, >= 1.2.4)
erubis (~> 2.7)
@@ -75,10 +75,10 @@ PATH
specinfra (~> 2.10)
syslog-logger (~> 1.6)
uuidtools (~> 2.1.5)
- chef (12.19.30-universal-mingw32)
+ chef (12.19.33-universal-mingw32)
addressable
bundler (>= 1.10)
- chef-config (= 12.19.30)
+ chef-config (= 12.19.33)
chef-zero (>= 4.8)
diff-lcs (~> 1.2, >= 1.2.4)
erubis (~> 2.7)
@@ -119,7 +119,7 @@ PATH
PATH
remote: chef-config
specs:
- chef-config (12.19.30)
+ chef-config (12.19.33)
addressable
fuzzyurl
mixlib-config (~> 2.0)
diff --git a/VERSION b/VERSION
index 40d1f067de..343d768725 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-12.19.30 \ No newline at end of file
+12.19.33 \ No newline at end of file
diff --git a/chef-config/lib/chef-config/version.rb b/chef-config/lib/chef-config/version.rb
index ca6c51b3fb..0610cc3100 100644
--- a/chef-config/lib/chef-config/version.rb
+++ b/chef-config/lib/chef-config/version.rb
@@ -21,7 +21,7 @@
module ChefConfig
CHEFCONFIG_ROOT = File.expand_path("../..", __FILE__)
- VERSION = "12.19.30"
+ VERSION = "12.19.33"
end
#
diff --git a/lib/chef/provider/batch.rb b/lib/chef/provider/batch.rb
index 0d857aaa79..83218e4f76 100644
--- a/lib/chef/provider/batch.rb
+++ b/lib/chef/provider/batch.rb
@@ -37,7 +37,7 @@ class Chef
end
def flags
- @new_resource.flags.nil? ? "/c" : new_resource.flags + " /c"
+ new_resource.flags.nil? ? "/c" : new_resource.flags + " /c"
end
end
diff --git a/lib/chef/provider/breakpoint.rb b/lib/chef/provider/breakpoint.rb
index a71c9e317d..0902634a64 100644
--- a/lib/chef/provider/breakpoint.rb
+++ b/lib/chef/provider/breakpoint.rb
@@ -28,7 +28,7 @@ class Chef
def action_break
if defined?(Shell) && Shell.running?
run_context.resource_collection.iterator.pause
- @new_resource.updated_by_last_action(true)
+ new_resource.updated_by_last_action(true)
run_context.resource_collection.iterator
end
end
diff --git a/lib/chef/provider/cookbook_file.rb b/lib/chef/provider/cookbook_file.rb
index 3ca0bbd47a..dc900d871b 100644
--- a/lib/chef/provider/cookbook_file.rb
+++ b/lib/chef/provider/cookbook_file.rb
@@ -36,15 +36,15 @@ class Chef
end
def load_current_resource
- @current_resource = Chef::Resource::CookbookFile.new(@new_resource.name)
+ @current_resource = Chef::Resource::CookbookFile.new(new_resource.name)
super
end
private
def managing_content?
- return true if @new_resource.checksum
- return true if !@new_resource.source.nil? && @action != :create_if_missing
+ return true if new_resource.checksum
+ return true if !new_resource.source.nil? && @action != :create_if_missing
false
end
diff --git a/lib/chef/provider/cron.rb b/lib/chef/provider/cron.rb
index 35e5bb874c..f22367b461 100644
--- a/lib/chef/provider/cron.rb
+++ b/lib/chef/provider/cron.rb
@@ -48,15 +48,15 @@ class Chef
def load_current_resource
crontab_lines = []
- @current_resource = Chef::Resource::Cron.new(@new_resource.name)
- @current_resource.user(@new_resource.user)
+ @current_resource = Chef::Resource::Cron.new(new_resource.name)
+ current_resource.user(new_resource.user)
@cron_exists = false
if crontab = read_crontab
cron_found = false
crontab.each_line do |line|
case line.chomp
- when "# Chef Name: #{@new_resource.name}"
- Chef::Log.debug("Found cron '#{@new_resource.name}'")
+ when "# Chef Name: #{new_resource.name}"
+ Chef::Log.debug("Found cron '#{new_resource.name}'")
cron_found = true
@cron_exists = true
next
@@ -65,18 +65,18 @@ class Chef
next
when SPECIAL_PATTERN
if cron_found
- @current_resource.time($2.to_sym)
- @current_resource.command($3)
+ current_resource.time($2.to_sym)
+ current_resource.command($3)
cron_found = false
end
when CRON_PATTERN
if cron_found
- @current_resource.minute($1)
- @current_resource.hour($2)
- @current_resource.day($3)
- @current_resource.month($4)
- @current_resource.weekday($5)
- @current_resource.command($6)
+ current_resource.minute($1)
+ current_resource.hour($2)
+ current_resource.day($3)
+ current_resource.month($4)
+ current_resource.weekday($5)
+ current_resource.command($6)
cron_found = false
end
next
@@ -85,18 +85,18 @@ class Chef
next
end
end
- Chef::Log.debug("Cron '#{@new_resource.name}' not found") unless @cron_exists
+ Chef::Log.debug("Cron '#{new_resource.name}' not found") unless @cron_exists
else
- Chef::Log.debug("Cron empty for '#{@new_resource.user}'")
+ Chef::Log.debug("Cron empty for '#{new_resource.user}'")
@cron_empty = true
end
- @current_resource
+ current_resource
end
def cron_different?
CRON_ATTRIBUTES.any? do |cron_var|
- @new_resource.send(cron_var) != @current_resource.send(cron_var)
+ new_resource.send(cron_var) != current_resource.send(cron_var)
end
end
@@ -109,12 +109,12 @@ class Chef
if @cron_exists
unless cron_different?
- Chef::Log.debug("Skipping existing cron entry '#{@new_resource.name}'")
+ Chef::Log.debug("Skipping existing cron entry '#{new_resource.name}'")
return
end
read_crontab.each_line do |line|
case line.chomp
- when "# Chef Name: #{@new_resource.name}"
+ when "# Chef Name: #{new_resource.name}"
cron_found = true
next
when ENV_PATTERN
@@ -144,18 +144,18 @@ class Chef
# Handle edge case where the Chef comment is the last line in the current crontab
crontab << newcron if cron_found
- converge_by("update crontab entry for #{@new_resource}") do
+ converge_by("update crontab entry for #{new_resource}") do
write_crontab crontab
- Chef::Log.info("#{@new_resource} updated crontab entry")
+ Chef::Log.info("#{new_resource} updated crontab entry")
end
else
crontab = read_crontab unless @cron_empty
crontab << newcron
- converge_by("add crontab entry for #{@new_resource}") do
+ converge_by("add crontab entry for #{new_resource}") do
write_crontab crontab
- Chef::Log.info("#{@new_resource} added crontab entry")
+ Chef::Log.info("#{new_resource} added crontab entry")
end
end
end
@@ -166,7 +166,7 @@ class Chef
cron_found = false
read_crontab.each_line do |line|
case line.chomp
- when "# Chef Name: #{@new_resource.name}"
+ when "# Chef Name: #{new_resource.name}"
cron_found = true
next
when ENV_PATTERN
@@ -187,10 +187,10 @@ class Chef
end
crontab << line
end
- description = cron_found ? "remove #{@new_resource.name} from crontab" : "save unmodified crontab"
+ description = cron_found ? "remove #{new_resource.name} from crontab" : "save unmodified crontab"
converge_by(description) do
write_crontab crontab
- Chef::Log.info("#{@new_resource} deleted crontab entry")
+ Chef::Log.info("#{new_resource} deleted crontab entry")
end
end
end
@@ -199,26 +199,26 @@ class Chef
def set_environment_var(attr_name, attr_value)
if %w{MAILTO PATH SHELL HOME}.include?(attr_name)
- @current_resource.send(attr_name.downcase.to_sym, attr_value.gsub(/^"|"$/, ""))
+ current_resource.send(attr_name.downcase.to_sym, attr_value.gsub(/^"|"$/, ""))
else
- @current_resource.environment(@current_resource.environment.merge(attr_name => attr_value))
+ current_resource.environment(current_resource.environment.merge(attr_name => attr_value))
end
end
def read_crontab
crontab = nil
- status = popen4("crontab -l -u #{@new_resource.user}") do |pid, stdin, stdout, stderr|
+ status = popen4("crontab -l -u #{new_resource.user}") do |pid, stdin, stdout, stderr|
crontab = stdout.read
end
if status.exitstatus > 1
- raise Chef::Exceptions::Cron, "Error determining state of #{@new_resource.name}, exit: #{status.exitstatus}"
+ raise Chef::Exceptions::Cron, "Error determining state of #{new_resource.name}, exit: #{status.exitstatus}"
end
crontab
end
def write_crontab(crontab)
write_exception = false
- status = popen4("crontab -u #{@new_resource.user} -", :waitlast => true) do |pid, stdin, stdout, stderr|
+ status = popen4("crontab -u #{new_resource.user} -", :waitlast => true) do |pid, stdin, stdout, stderr|
begin
stdin.write crontab
rescue Errno::EPIPE => e
@@ -228,7 +228,7 @@ class Chef
end
end
if status.exitstatus > 0 || write_exception
- raise Chef::Exceptions::Cron, "Error updating state of #{@new_resource.name}, exit: #{status.exitstatus}"
+ raise Chef::Exceptions::Cron, "Error updating state of #{new_resource.name}, exit: #{status.exitstatus}"
end
end
@@ -236,23 +236,23 @@ class Chef
newcron = ""
newcron << "# Chef Name: #{new_resource.name}\n"
[ :mailto, :path, :shell, :home ].each do |v|
- newcron << "#{v.to_s.upcase}=\"#{@new_resource.send(v)}\"\n" if @new_resource.send(v)
+ newcron << "#{v.to_s.upcase}=\"#{new_resource.send(v)}\"\n" if new_resource.send(v)
end
- @new_resource.environment.each do |name, value|
+ new_resource.environment.each do |name, value|
newcron << "#{name}=#{value}\n"
end
- if @new_resource.time
- newcron << "@#{@new_resource.time} #{@new_resource.command}\n"
+ if new_resource.time
+ newcron << "@#{new_resource.time} #{new_resource.command}\n"
else
- newcron << "#{@new_resource.minute} #{@new_resource.hour} #{@new_resource.day} #{@new_resource.month} #{@new_resource.weekday} #{@new_resource.command}\n"
+ newcron << "#{new_resource.minute} #{new_resource.hour} #{new_resource.day} #{new_resource.month} #{new_resource.weekday} #{new_resource.command}\n"
end
newcron
end
def weekday_in_crontab
- weekday_in_crontab = WEEKDAY_SYMBOLS.index(@new_resource.weekday)
+ weekday_in_crontab = WEEKDAY_SYMBOLS.index(new_resource.weekday)
if weekday_in_crontab.nil?
- @new_resource.weekday
+ new_resource.weekday
else
weekday_in_crontab.to_s
end
diff --git a/lib/chef/provider/deploy.rb b/lib/chef/provider/deploy.rb
index 4c758033ac..2cd6ad62c6 100644
--- a/lib/chef/provider/deploy.rb
+++ b/lib/chef/provider/deploy.rb
@@ -42,7 +42,7 @@ class Chef
# @configuration is not used by Deploy, it is only for backwards compat with
# chef-deploy or capistrano hooks that might use it to get environment information
- @configuration = @new_resource.to_hash
+ @configuration = new_resource.to_hash
@configuration[:environment] = @configuration[:environment] && @configuration[:environment]["RAILS_ENV"]
end
@@ -52,8 +52,8 @@ class Chef
def load_current_resource
@scm_provider.load_current_resource
- @release_path = @new_resource.deploy_to + "/releases/#{release_slug}"
- @shared_path = @new_resource.shared_path
+ @release_path = new_resource.deploy_to + "/releases/#{release_slug}"
+ @shared_path = new_resource.shared_path
end
def sudo(command, &block)
@@ -62,10 +62,10 @@ class Chef
def run(command, &block)
exec = execute(command, &block)
- exec.user(@new_resource.user) if @new_resource.user
- exec.group(@new_resource.group) if @new_resource.group
+ exec.user(new_resource.user) if new_resource.user
+ exec.group(new_resource.group) if new_resource.group
exec.cwd(release_path) unless exec.cwd
- exec.environment(@new_resource.environment) unless exec.environment
+ exec.environment(new_resource.environment) unless exec.environment
converge_by("execute #{command}") do
exec
end
@@ -78,8 +78,8 @@ class Chef
#There is no reason to assume 2 deployments in a single chef run, hence fails in whyrun.
end
- [ @new_resource.before_migrate, @new_resource.before_symlink,
- @new_resource.before_restart, @new_resource.after_restart ].each do |script|
+ [ new_resource.before_migrate, new_resource.before_symlink,
+ new_resource.before_restart, new_resource.after_restart ].each do |script|
requirements.assert(:deploy, :force_deploy) do |a|
callback_file = "#{release_path}/#{script}"
a.assertion do
@@ -99,7 +99,7 @@ class Chef
save_release_state
if deployed?(release_path )
if current_release?(release_path )
- Chef::Log.debug("#{@new_resource} is the latest version")
+ Chef::Log.debug("#{new_resource} is the latest version")
else
rollback_to release_path
end
@@ -116,7 +116,7 @@ class Chef
converge_by("delete deployed app at #{release_path} prior to force-deploy") do
Chef::Log.info("Already deployed app at #{release_path}, forcing.")
FileUtils.rm_rf(release_path)
- Chef::Log.info("#{@new_resource} forcing deploy of already deployed app at #{release_path}")
+ Chef::Log.info("#{new_resource} forcing deploy of already deployed app at #{release_path}")
end
end
@@ -142,7 +142,7 @@ class Chef
releases_to_nuke.each do |i|
converge_by("roll back by removing release #{i}") do
- Chef::Log.info "#{@new_resource} removing release: #{i}"
+ Chef::Log.info "#{new_resource} removing release: #{i}"
FileUtils.rm_rf i
end
release_deleted(i)
@@ -156,21 +156,21 @@ class Chef
copy_cached_repo
install_gems
enforce_ownership
- callback(:before_migrate, @new_resource.before_migrate)
+ callback(:before_migrate, new_resource.before_migrate)
migrate
- callback(:before_symlink, @new_resource.before_symlink)
+ callback(:before_symlink, new_resource.before_symlink)
symlink
- callback(:before_restart, @new_resource.before_restart)
+ callback(:before_restart, new_resource.before_restart)
restart
- callback(:after_restart, @new_resource.after_restart)
+ callback(:after_restart, new_resource.after_restart)
cleanup!
- Chef::Log.info "#{@new_resource} deployed to #{@new_resource.deploy_to}"
+ Chef::Log.info "#{new_resource} deployed to #{new_resource.deploy_to}"
end
def rollback
- Chef::Log.info "#{@new_resource} rolling back to previous release #{release_path}"
+ Chef::Log.info "#{new_resource} rolling back to previous release #{release_path}"
symlink
- Chef::Log.info "#{@new_resource} restarting with previous release"
+ Chef::Log.info "#{new_resource} restarting with previous release"
restart
end
@@ -178,7 +178,7 @@ class Chef
@collection = Chef::ResourceCollection.new
case callback_code
when Proc
- Chef::Log.info "#{@new_resource} running callback #{what}"
+ Chef::Log.info "#{new_resource} running callback #{what}"
recipe_eval(&callback_code)
when String
run_callback_from_file("#{release_path}/#{callback_code}")
@@ -190,17 +190,17 @@ class Chef
def migrate
run_symlinks_before_migrate
- if @new_resource.migrate
+ if new_resource.migrate
enforce_ownership
- environment = @new_resource.environment
+ environment = new_resource.environment
env_info = environment && environment.map do |key_and_val|
"#{key_and_val.first}='#{key_and_val.last}'"
end.join(" ")
- converge_by("execute migration command #{@new_resource.migration_command}") do
- Chef::Log.info "#{@new_resource} migrating #{@new_resource.user} with environment #{env_info}"
- shell_out!(@new_resource.migration_command, run_options(:cwd => release_path, :log_level => :info))
+ converge_by("execute migration command #{new_resource.migration_command}") do
+ Chef::Log.info "#{new_resource} migrating #{new_resource.user} with environment #{env_info}"
+ shell_out!(new_resource.migration_command, run_options(:cwd => release_path, :log_level => :info))
end
end
end
@@ -209,18 +209,18 @@ class Chef
purge_tempfiles_from_current_release
link_tempfiles_to_current_release
link_current_release_to_production
- Chef::Log.info "#{@new_resource} updated symlinks"
+ Chef::Log.info "#{new_resource} updated symlinks"
end
def restart
- if restart_cmd = @new_resource.restart_command
+ if restart_cmd = new_resource.restart_command
if restart_cmd.kind_of?(Proc)
- Chef::Log.info("#{@new_resource} restarting app with embedded recipe")
+ Chef::Log.info("#{new_resource} restarting app with embedded recipe")
recipe_eval(&restart_cmd)
else
- converge_by("restart app using command #{@new_resource.restart_command}") do
- Chef::Log.info("#{@new_resource} restarting app")
- shell_out!(@new_resource.restart_command, run_options(:cwd => @new_resource.current_path))
+ converge_by("restart app using command #{new_resource.restart_command}") do
+ Chef::Log.info("#{new_resource} restarting app")
+ shell_out!(new_resource.restart_command, run_options(:cwd => new_resource.current_path))
end
end
end
@@ -231,10 +231,10 @@ class Chef
release_created(release_path)
end
- chop = -1 - @new_resource.keep_releases
+ chop = -1 - new_resource.keep_releases
all_releases[0..chop].each do |old_release|
converge_by("remove old release #{old_release}") do
- Chef::Log.info "#{@new_resource} removing old release #{old_release}"
+ Chef::Log.info "#{new_resource} removing old release #{old_release}"
FileUtils.rm_rf(old_release)
end
release_deleted(old_release)
@@ -242,11 +242,11 @@ class Chef
end
def all_releases
- Dir.glob(Chef::Util::PathHelper.escape_glob_dir(@new_resource.deploy_to) + "/releases/*").sort
+ Dir.glob(Chef::Util::PathHelper.escape_glob_dir(new_resource.deploy_to) + "/releases/*").sort
end
def update_cached_repo
- if @new_resource.svn_force_export
+ if new_resource.svn_force_export
# TODO assertion, non-recoverable - @scm_provider must be svn if force_export?
svn_force_export
else
@@ -259,78 +259,78 @@ class Chef
end
def svn_force_export
- Chef::Log.info "#{@new_resource} exporting source repository"
+ Chef::Log.info "#{new_resource} exporting source repository"
@scm_provider.run_action(:force_export)
end
def copy_cached_repo
- target_dir_path = @new_resource.deploy_to + "/releases"
+ target_dir_path = new_resource.deploy_to + "/releases"
converge_by("deploy from repo to #{target_dir_path} ") do
FileUtils.rm_rf(release_path) if ::File.exist?(release_path)
FileUtils.mkdir_p(target_dir_path)
- FileUtils.cp_r(::File.join(@new_resource.destination, "."), release_path, :preserve => true)
- Chef::Log.info "#{@new_resource} copied the cached checkout to #{release_path}"
+ FileUtils.cp_r(::File.join(new_resource.destination, "."), release_path, :preserve => true)
+ Chef::Log.info "#{new_resource} copied the cached checkout to #{release_path}"
end
end
def enforce_ownership
- converge_by("force ownership of #{@new_resource.deploy_to} to #{@new_resource.group}:#{@new_resource.user}") do
- FileUtils.chown_R(@new_resource.user, @new_resource.group, @new_resource.deploy_to, :force => true)
- Chef::Log.info("#{@new_resource} set user to #{@new_resource.user}") if @new_resource.user
- Chef::Log.info("#{@new_resource} set group to #{@new_resource.group}") if @new_resource.group
+ converge_by("force ownership of #{new_resource.deploy_to} to #{new_resource.group}:#{new_resource.user}") do
+ FileUtils.chown_R(new_resource.user, new_resource.group, new_resource.deploy_to, :force => true)
+ Chef::Log.info("#{new_resource} set user to #{new_resource.user}") if new_resource.user
+ Chef::Log.info("#{new_resource} set group to #{new_resource.group}") if new_resource.group
end
end
def verify_directories_exist
- create_dir_unless_exists(@new_resource.deploy_to)
- create_dir_unless_exists(@new_resource.shared_path)
+ create_dir_unless_exists(new_resource.deploy_to)
+ create_dir_unless_exists(new_resource.shared_path)
end
def link_current_release_to_production
- converge_by(["remove existing link at #{@new_resource.current_path}",
- "link release #{release_path} into production at #{@new_resource.current_path}"]) do
- FileUtils.rm_f(@new_resource.current_path)
+ converge_by(["remove existing link at #{new_resource.current_path}",
+ "link release #{release_path} into production at #{new_resource.current_path}"]) do
+ FileUtils.rm_f(new_resource.current_path)
begin
- FileUtils.ln_sf(release_path, @new_resource.current_path)
+ FileUtils.ln_sf(release_path, new_resource.current_path)
rescue => e
raise Chef::Exceptions::FileNotFound.new("Cannot symlink current release to production: #{e.message}")
end
- Chef::Log.info "#{@new_resource} linked release #{release_path} into production at #{@new_resource.current_path}"
+ Chef::Log.info "#{new_resource} linked release #{release_path} into production at #{new_resource.current_path}"
end
enforce_ownership
end
def run_symlinks_before_migrate
- links_info = @new_resource.symlink_before_migrate.map { |src, dst| "#{src} => #{dst}" }.join(", ")
+ links_info = new_resource.symlink_before_migrate.map { |src, dst| "#{src} => #{dst}" }.join(", ")
converge_by("make pre-migration symlinks: #{links_info}") do
- @new_resource.symlink_before_migrate.each do |src, dest|
+ new_resource.symlink_before_migrate.each do |src, dest|
begin
- FileUtils.ln_sf(@new_resource.shared_path + "/#{src}", release_path + "/#{dest}")
+ FileUtils.ln_sf(new_resource.shared_path + "/#{src}", release_path + "/#{dest}")
rescue => e
- raise Chef::Exceptions::FileNotFound.new("Cannot symlink #{@new_resource.shared_path}/#{src} to #{release_path}/#{dest} before migrate: #{e.message}")
+ raise Chef::Exceptions::FileNotFound.new("Cannot symlink #{new_resource.shared_path}/#{src} to #{release_path}/#{dest} before migrate: #{e.message}")
end
end
- Chef::Log.info "#{@new_resource} made pre-migration symlinks"
+ Chef::Log.info "#{new_resource} made pre-migration symlinks"
end
end
def link_tempfiles_to_current_release
- dirs_info = @new_resource.create_dirs_before_symlink.join(",")
- @new_resource.create_dirs_before_symlink.each do |dir|
+ dirs_info = new_resource.create_dirs_before_symlink.join(",")
+ new_resource.create_dirs_before_symlink.each do |dir|
create_dir_unless_exists(release_path + "/#{dir}")
end
- Chef::Log.info("#{@new_resource} created directories before symlinking: #{dirs_info}")
+ Chef::Log.info("#{new_resource} created directories before symlinking: #{dirs_info}")
- links_info = @new_resource.symlinks.map { |src, dst| "#{src} => #{dst}" }.join(", ")
+ links_info = new_resource.symlinks.map { |src, dst| "#{src} => #{dst}" }.join(", ")
converge_by("link shared paths into current release: #{links_info}") do
- @new_resource.symlinks.each do |src, dest|
+ new_resource.symlinks.each do |src, dest|
begin
- FileUtils.ln_sf(::File.join(@new_resource.shared_path, src), ::File.join(release_path, dest))
+ FileUtils.ln_sf(::File.join(new_resource.shared_path, src), ::File.join(release_path, dest))
rescue => e
- raise Chef::Exceptions::FileNotFound.new("Cannot symlink shared data #{::File.join(@new_resource.shared_path, src)} to #{::File.join(release_path, dest)}: #{e.message}")
+ raise Chef::Exceptions::FileNotFound.new("Cannot symlink shared data #{::File.join(new_resource.shared_path, src)} to #{::File.join(release_path, dest)}: #{e.message}")
end
end
- Chef::Log.info("#{@new_resource} linked shared paths into current release: #{links_info}")
+ Chef::Log.info("#{new_resource} linked shared paths into current release: #{links_info}")
end
run_symlinks_before_migrate
enforce_ownership
@@ -340,10 +340,10 @@ class Chef
end
def purge_tempfiles_from_current_release
- log_info = @new_resource.purge_before_symlink.join(", ")
+ log_info = new_resource.purge_before_symlink.join(", ")
converge_by("purge directories in checkout #{log_info}") do
- @new_resource.purge_before_symlink.each { |dir| FileUtils.rm_rf(release_path + "/#{dir}") }
- Chef::Log.info("#{@new_resource} purged directories in checkout #{log_info}")
+ new_resource.purge_before_symlink.each { |dir| FileUtils.rm_rf(release_path + "/#{dir}") }
+ Chef::Log.info("#{new_resource} purged directories in checkout #{log_info}")
end
end
@@ -391,10 +391,10 @@ class Chef
end
def run_options(run_opts = {})
- run_opts[:user] = @new_resource.user if @new_resource.user
- run_opts[:group] = @new_resource.group if @new_resource.group
- run_opts[:environment] = @new_resource.environment if @new_resource.environment
- run_opts[:log_tag] = @new_resource.to_s
+ run_opts[:user] = new_resource.user if new_resource.user
+ run_opts[:group] = new_resource.group if new_resource.group
+ run_opts[:environment] = new_resource.environment if new_resource.environment
+ run_opts[:log_tag] = new_resource.to_s
run_opts[:log_level] ||= :debug
if run_opts[:log_level] == :info
if STDOUT.tty? && !Chef::Config[:daemon] && Chef::Log.info?
@@ -405,7 +405,7 @@ class Chef
end
def run_callback_from_file(callback_file)
- Chef::Log.info "#{@new_resource} queueing checkdeploy hook #{callback_file}"
+ Chef::Log.info "#{new_resource} queueing checkdeploy hook #{callback_file}"
recipe_eval do
Dir.chdir(release_path) do
from_file(callback_file) if ::File.exist?(callback_file)
@@ -415,20 +415,20 @@ class Chef
def create_dir_unless_exists(dir)
if ::File.directory?(dir)
- Chef::Log.debug "#{@new_resource} not creating #{dir} because it already exists"
+ Chef::Log.debug "#{new_resource} not creating #{dir} because it already exists"
return false
end
converge_by("create new directory #{dir}") do
begin
FileUtils.mkdir_p(dir)
- Chef::Log.debug "#{@new_resource} created directory #{dir}"
- if @new_resource.user
- FileUtils.chown(@new_resource.user, nil, dir)
- Chef::Log.debug("#{@new_resource} set user to #{@new_resource.user} for #{dir}")
+ Chef::Log.debug "#{new_resource} created directory #{dir}"
+ if new_resource.user
+ FileUtils.chown(new_resource.user, nil, dir)
+ Chef::Log.debug("#{new_resource} set user to #{new_resource.user} for #{dir}")
end
- if @new_resource.group
- FileUtils.chown(nil, @new_resource.group, dir)
- Chef::Log.debug("#{@new_resource} set group to #{@new_resource.group} for #{dir}")
+ if new_resource.group
+ FileUtils.chown(nil, new_resource.group, dir)
+ Chef::Log.debug("#{new_resource} set group to #{new_resource.group} for #{dir}")
end
rescue => e
raise Chef::Exceptions::FileNotFound.new("Cannot create directory #{dir}: #{e.message}")
@@ -439,7 +439,7 @@ class Chef
def with_rollback_on_error
yield
rescue ::Exception => e
- if @new_resource.rollback_on_error
+ if new_resource.rollback_on_error
Chef::Log.warn "Error on deploying #{release_path}: #{e.message}"
failed_release = release_path
@@ -458,8 +458,8 @@ class Chef
end
def save_release_state
- if ::File.exists?(@new_resource.current_path)
- release = ::File.readlink(@new_resource.current_path)
+ if ::File.exists?(new_resource.current_path)
+ release = ::File.readlink(new_resource.current_path)
@previous_release_path = release if ::File.exists?(release)
end
end
diff --git a/lib/chef/provider/directory.rb b/lib/chef/provider/directory.rb
index 1cacc3fcb9..38ee1f241f 100644
--- a/lib/chef/provider/directory.rb
+++ b/lib/chef/provider/directory.rb
@@ -34,12 +34,12 @@ class Chef
end
def load_current_resource
- @current_resource = Chef::Resource::Directory.new(@new_resource.name)
- @current_resource.path(@new_resource.path)
- if ::File.exists?(@current_resource.path) && @action != :create_if_missing
- load_resource_attributes_from_file(@current_resource)
+ @current_resource = Chef::Resource::Directory.new(new_resource.name)
+ current_resource.path(new_resource.path)
+ if ::File.exists?(current_resource.path) && @action != :create_if_missing
+ load_resource_attributes_from_file(current_resource)
end
- @current_resource
+ current_resource
end
def define_resource_requirements
@@ -49,9 +49,9 @@ class Chef
requirements.assert(:create) do |a|
# Make sure the parent dir exists, or else fail.
# for why run, print a message explaining the potential error.
- parent_directory = ::File.dirname(@new_resource.path)
+ parent_directory = ::File.dirname(new_resource.path)
a.assertion do
- if @new_resource.recursive
+ if new_resource.recursive
does_parent_exist = lambda do |base_dir|
base_dir = ::File.dirname(base_dir)
if ::File.exist?(base_dir)
@@ -60,20 +60,20 @@ class Chef
does_parent_exist.call(base_dir)
end
end
- does_parent_exist.call(@new_resource.path)
+ does_parent_exist.call(new_resource.path)
else
::File.directory?(parent_directory)
end
end
- a.failure_message(Chef::Exceptions::EnclosingDirectoryDoesNotExist, "Parent directory #{parent_directory} does not exist, cannot create #{@new_resource.path}")
+ a.failure_message(Chef::Exceptions::EnclosingDirectoryDoesNotExist, "Parent directory #{parent_directory} does not exist, cannot create #{new_resource.path}")
a.whyrun("Assuming directory #{parent_directory} would have been created")
end
requirements.assert(:create) do |a|
- parent_directory = ::File.dirname(@new_resource.path)
+ parent_directory = ::File.dirname(new_resource.path)
a.assertion do
- if @new_resource.recursive
- # find the lowest-level directory in @new_resource.path that already exists
+ if new_resource.recursive
+ # find the lowest-level directory in new_resource.path that already exists
# make sure we have write permissions to that directory
is_parent_writable = lambda do |base_dir|
base_dir = ::File.dirname(base_dir)
@@ -89,7 +89,7 @@ class Chef
is_parent_writable.call(base_dir)
end
end
- is_parent_writable.call(@new_resource.path)
+ is_parent_writable.call(new_resource.path)
else
# in why run mode & parent directory does not exist no permissions check is required
# If not in why run, permissions must be valid and we rely on prior assertion that dir exists
@@ -97,7 +97,7 @@ class Chef
if Chef::FileAccessControl.writable?(parent_directory)
true
elsif Chef::Util::PathHelper.is_sip_path?(parent_directory, node)
- Chef::Util::PathHelper.writable_sip_path?(@new_resource.path)
+ Chef::Util::PathHelper.writable_sip_path?(new_resource.path)
else
false
end
@@ -107,18 +107,18 @@ class Chef
end
end
a.failure_message(Chef::Exceptions::InsufficientPermissions,
- "Cannot create #{@new_resource} at #{@new_resource.path} due to insufficient permissions")
+ "Cannot create #{new_resource} at #{new_resource.path} due to insufficient permissions")
end
requirements.assert(:delete) do |a|
a.assertion do
- if ::File.exists?(@new_resource.path)
- ::File.directory?(@new_resource.path) && Chef::FileAccessControl.writable?(@new_resource.path)
+ if ::File.exists?(new_resource.path)
+ ::File.directory?(new_resource.path) && Chef::FileAccessControl.writable?(new_resource.path)
else
true
end
end
- a.failure_message(RuntimeError, "Cannot delete #{@new_resource} at #{@new_resource.path}!")
+ a.failure_message(RuntimeError, "Cannot delete #{new_resource} at #{new_resource.path}!")
# No why-run handling here:
# * if we don't have permissions, this is unlikely to be changed earlier in the run
# * if the target is a file (not a dir), there's no reasonable path by which this would have been changed
@@ -126,32 +126,32 @@ class Chef
end
def action_create
- unless ::File.exists?(@new_resource.path)
- converge_by("create new directory #{@new_resource.path}") do
- if @new_resource.recursive == true
- ::FileUtils.mkdir_p(@new_resource.path)
+ unless ::File.exists?(new_resource.path)
+ converge_by("create new directory #{new_resource.path}") do
+ if new_resource.recursive == true
+ ::FileUtils.mkdir_p(new_resource.path)
else
- ::Dir.mkdir(@new_resource.path)
+ ::Dir.mkdir(new_resource.path)
end
- Chef::Log.info("#{@new_resource} created directory #{@new_resource.path}")
+ Chef::Log.info("#{new_resource} created directory #{new_resource.path}")
end
end
do_acl_changes
do_selinux(true)
- load_resource_attributes_from_file(@new_resource) unless Chef::Config[:why_run]
+ load_resource_attributes_from_file(new_resource) unless Chef::Config[:why_run]
end
def action_delete
- if ::File.exists?(@new_resource.path)
- converge_by("delete existing directory #{@new_resource.path}") do
- if @new_resource.recursive == true
+ if ::File.exists?(new_resource.path)
+ converge_by("delete existing directory #{new_resource.path}") do
+ if new_resource.recursive == true
# we don't use rm_rf here because it masks all errors, including
# IO errors or permission errors that would prvent the deletion
- FileUtils.rm_r(@new_resource.path)
- Chef::Log.info("#{@new_resource} deleted #{@new_resource.path} recursively")
+ FileUtils.rm_r(new_resource.path)
+ Chef::Log.info("#{new_resource} deleted #{new_resource.path} recursively")
else
- ::Dir.delete(@new_resource.path)
- Chef::Log.info("#{@new_resource} deleted #{@new_resource.path}")
+ ::Dir.delete(new_resource.path)
+ Chef::Log.info("#{new_resource} deleted #{new_resource.path}")
end
end
end
diff --git a/lib/chef/provider/dsc_resource.rb b/lib/chef/provider/dsc_resource.rb
index 026d2ef104..0ad075484f 100644
--- a/lib/chef/provider/dsc_resource.rb
+++ b/lib/chef/provider/dsc_resource.rb
@@ -165,8 +165,8 @@ class Chef
end
def invoke_resource(method, output_format = :object)
- properties = translate_type(@new_resource.properties)
- switches = "-Method #{method} -Name #{@new_resource.resource}"\
+ properties = translate_type(new_resource.properties)
+ switches = "-Method #{method} -Name #{new_resource.resource}"\
" -Property #{properties} -Module #{module_info_object} -Verbose"
cmdlet = Chef::Util::Powershell::Cmdlet.new(
node,
@@ -188,15 +188,15 @@ class Chef
def create_reboot_resource
@reboot_resource = Chef::Resource::Reboot.new(
- "Reboot for #{@new_resource.name}",
+ "Reboot for #{new_resource.name}",
run_context
).tap do |r|
- r.reason("Reboot for #{@new_resource.resource}.")
+ r.reason("Reboot for #{new_resource.resource}.")
end
end
def reboot_if_required
- reboot_action = @new_resource.reboot_action
+ reboot_action = new_resource.reboot_action
unless @reboot_resource.nil?
case reboot_action
when :nothing
diff --git a/lib/chef/provider/env.rb b/lib/chef/provider/env.rb
index 5b252dd344..5e05fe4798 100644
--- a/lib/chef/provider/env.rb
+++ b/lib/chef/provider/env.rb
@@ -34,17 +34,17 @@ class Chef
end
def load_current_resource
- @current_resource = Chef::Resource::Env.new(@new_resource.name)
- @current_resource.key_name(@new_resource.key_name)
+ @current_resource = Chef::Resource::Env.new(new_resource.name)
+ current_resource.key_name(new_resource.key_name)
- if env_key_exists(@new_resource.key_name)
- @current_resource.value(env_value(@new_resource.key_name))
+ if env_key_exists(new_resource.key_name)
+ current_resource.value(env_value(new_resource.key_name))
else
@key_exists = false
- Chef::Log.debug("#{@new_resource} key does not exist")
+ Chef::Log.debug("#{new_resource} key does not exist")
end
- @current_resource
+ current_resource
end
def env_value(key_name)
@@ -61,7 +61,7 @@ class Chef
# <true>:: If a change is required
# <false>:: If a change is not required
def requires_modify_or_create?
- if @new_resource.delim
+ if new_resource.delim
#e.g. check for existing value within PATH
new_values.inject(0) do |index, val|
next_index = current_values.find_index val
@@ -70,7 +70,7 @@ class Chef
end
false
else
- @new_resource.value != @current_resource.value
+ new_resource.value != current_resource.value
end
end
@@ -80,13 +80,13 @@ class Chef
if @key_exists
if requires_modify_or_create?
modify_env
- Chef::Log.info("#{@new_resource} altered")
- @new_resource.updated_by_last_action(true)
+ Chef::Log.info("#{new_resource} altered")
+ new_resource.updated_by_last_action(true)
end
else
create_env
- Chef::Log.info("#{@new_resource} created")
- @new_resource.updated_by_last_action(true)
+ Chef::Log.info("#{new_resource} created")
+ new_resource.updated_by_last_action(true)
end
end
@@ -97,24 +97,24 @@ class Chef
# <false>:: Caller should delete the key, either no :delim was specific or value was empty
# after we removed the element.
def delete_element
- return false unless @new_resource.delim #no delim: delete the key
+ return false unless new_resource.delim #no delim: delete the key
needs_delete = new_values.any? { |v| current_values.include?(v) }
if !needs_delete
- Chef::Log.debug("#{@new_resource} element '#{@new_resource.value}' does not exist")
+ Chef::Log.debug("#{new_resource} element '#{new_resource.value}' does not exist")
return true #do not delete the key
else
new_value =
current_values.select do |item|
not new_values.include?(item)
- end.join(@new_resource.delim)
+ end.join(new_resource.delim)
if new_value.empty?
return false #nothing left here, delete the key
else
- old_value = @new_resource.value(new_value)
+ old_value = new_resource.value(new_value)
create_env
- Chef::Log.debug("#{@new_resource} deleted #{old_value} element")
- @new_resource.updated_by_last_action(true)
+ Chef::Log.debug("#{new_resource} deleted #{old_value} element")
+ new_resource.updated_by_last_action(true)
return true #we removed the element and updated; do not delete the key
end
end
@@ -123,8 +123,8 @@ class Chef
def action_delete
if @key_exists && !delete_element
delete_env
- Chef::Log.info("#{@new_resource} deleted")
- @new_resource.updated_by_last_action(true)
+ Chef::Log.info("#{new_resource} deleted")
+ new_resource.updated_by_last_action(true)
end
end
@@ -132,16 +132,16 @@ class Chef
if @key_exists
if requires_modify_or_create?
modify_env
- Chef::Log.info("#{@new_resource} modified")
- @new_resource.updated_by_last_action(true)
+ Chef::Log.info("#{new_resource} modified")
+ new_resource.updated_by_last_action(true)
end
else
- raise Chef::Exceptions::Env, "Cannot modify #{@new_resource} - key does not exist!"
+ raise Chef::Exceptions::Env, "Cannot modify #{new_resource} - key does not exist!"
end
end
def create_env
- raise Chef::Exceptions::UnsupportedAction, "#{self} does not support :#{@new_resource.action}"
+ raise Chef::Exceptions::UnsupportedAction, "#{self} does not support :#{new_resource.action}"
end
def delete_env
@@ -149,20 +149,20 @@ class Chef
end
def modify_env
- if @new_resource.delim
- @new_resource.value((new_values + current_values).uniq.join(@new_resource.delim))
+ if new_resource.delim
+ new_resource.value((new_values + current_values).uniq.join(new_resource.delim))
end
create_env
end
# Returns the current values to split by delimiter
def current_values
- @current_values ||= @current_resource.value.split(@new_resource.delim)
+ @current_values ||= current_resource.value.split(new_resource.delim)
end
# Returns the new values to split by delimiter
def new_values
- @new_values ||= @new_resource.value.split(@new_resource.delim)
+ @new_values ||= new_resource.value.split(new_resource.delim)
end
end
end
diff --git a/lib/chef/provider/erl_call.rb b/lib/chef/provider/erl_call.rb
index 7167f3b8a5..50571d5256 100644
--- a/lib/chef/provider/erl_call.rb
+++ b/lib/chef/provider/erl_call.rb
@@ -40,20 +40,20 @@ class Chef
end
def action_run
- case @new_resource.name_type
+ case new_resource.name_type
when "sname"
- node = "-sname #{@new_resource.node_name}"
+ node = "-sname #{new_resource.node_name}"
when "name"
- node = "-name #{@new_resource.node_name}"
+ node = "-name #{new_resource.node_name}"
end
- if @new_resource.cookie
- cookie = "-c #{@new_resource.cookie}"
+ if new_resource.cookie
+ cookie = "-c #{new_resource.cookie}"
else
cookie = ""
end
- if @new_resource.distributed
+ if new_resource.distributed
distributed = "-s"
else
distributed = ""
@@ -65,15 +65,15 @@ class Chef
begin
pid, stdin, stdout, stderr = popen4(command, :waitlast => true)
- Chef::Log.debug("#{@new_resource} running")
- Chef::Log.debug("#{@new_resource} command: #{command}")
- Chef::Log.debug("#{@new_resource} code: #{@new_resource.code}")
+ Chef::Log.debug("#{new_resource} running")
+ Chef::Log.debug("#{new_resource} command: #{command}")
+ Chef::Log.debug("#{new_resource} code: #{new_resource.code}")
- @new_resource.code.each_line { |line| stdin.puts(line.chomp) }
+ new_resource.code.each_line { |line| stdin.puts(line.chomp) }
stdin.close
- Chef::Log.debug("#{@new_resource} output: ")
+ Chef::Log.debug("#{new_resource} output: ")
stdout_output = ""
stdout.each_line { |line| stdout_output << line }
@@ -93,9 +93,9 @@ class Chef
raise Chef::Exceptions::ErlCall, stdout_output
end
- @new_resource.updated_by_last_action(true)
+ new_resource.updated_by_last_action(true)
- Chef::Log.debug("#{@new_resource} #{stdout_output}")
+ Chef::Log.debug("#{new_resource} #{stdout_output}")
Chef::Log.info("#{@new_resouce} ran successfully")
ensure
Process.wait(pid) if pid
diff --git a/lib/chef/provider/execute.rb b/lib/chef/provider/execute.rb
index a605d9f7ec..28dce5d18c 100644
--- a/lib/chef/provider/execute.rb
+++ b/lib/chef/provider/execute.rb
@@ -27,7 +27,7 @@ class Chef
provides :execute
- def_delegators :@new_resource, :command, :returns, :environment, :user, :domain, :password, :group, :cwd, :umask, :creates
+ def_delegators :new_resource, :command, :returns, :environment, :user, :domain, :password, :group, :cwd, :umask, :creates
def load_current_resource
current_resource = Chef::Resource::Execute.new(new_resource.name)
diff --git a/lib/chef/provider/file.rb b/lib/chef/provider/file.rb
index d87004d543..ecde068751 100644
--- a/lib/chef/provider/file.rb
+++ b/lib/chef/provider/file.rb
@@ -1,7 +1,7 @@
#
# Author:: Adam Jacob (<adam@chef.io>)
# Author:: Lamont Granquist (<lamont@chef.io>)
-# Copyright:: Copyright 2008-2016, Chef Software, Inc.
+# Copyright:: Copyright 2008-2017, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -95,7 +95,7 @@ class Chef
# true if we are going to be creating a new file
@needs_creating = !::File.exist?(new_resource.path) || needs_unlinking?
- # Let children resources override constructing the @current_resource
+ # Let children resources override constructing the current_resource
@current_resource ||= Chef::Resource::File.new(new_resource.name)
current_resource.path(new_resource.path)
@@ -120,17 +120,17 @@ class Chef
# Make sure the parent directory exists, otherwise fail. For why-run assume it would have been created.
requirements.assert(:create, :create_if_missing, :touch) do |a|
- parent_directory = ::File.dirname(@new_resource.path)
+ parent_directory = ::File.dirname(new_resource.path)
a.assertion { ::File.directory?(parent_directory) }
a.failure_message(Chef::Exceptions::EnclosingDirectoryDoesNotExist, "Parent directory #{parent_directory} does not exist.")
a.whyrun("Assuming directory #{parent_directory} would have been created")
end
# Make sure the file is deletable if it exists, otherwise fail.
- if ::File.exist?(@new_resource.path)
+ if ::File.exist?(new_resource.path)
requirements.assert(:delete) do |a|
- a.assertion { ::File.writable?(@new_resource.path) }
- a.failure_message(Chef::Exceptions::InsufficientPermissions, "File #{@new_resource.path} exists but is not writable so it cannot be deleted")
+ a.assertion { ::File.writable?(new_resource.path) }
+ a.failure_message(Chef::Exceptions::InsufficientPermissions, "File #{new_resource.path} exists but is not writable so it cannot be deleted")
end
end
@@ -154,33 +154,33 @@ class Chef
do_contents_changes
do_acl_changes
do_selinux
- load_resource_attributes_from_file(@new_resource) unless Chef::Config[:why_run]
+ load_resource_attributes_from_file(new_resource) unless Chef::Config[:why_run]
end
def action_create_if_missing
- unless ::File.exist?(@new_resource.path)
+ unless ::File.exist?(new_resource.path)
action_create
else
- Chef::Log.debug("#{@new_resource} exists at #{@new_resource.path} taking no action.")
+ Chef::Log.debug("#{new_resource} exists at #{new_resource.path} taking no action.")
end
end
def action_delete
- if ::File.exists?(@new_resource.path)
- converge_by("delete file #{@new_resource.path}") do
- do_backup unless file_class.symlink?(@new_resource.path)
- ::File.delete(@new_resource.path)
- Chef::Log.info("#{@new_resource} deleted file at #{@new_resource.path}")
+ if ::File.exists?(new_resource.path)
+ converge_by("delete file #{new_resource.path}") do
+ do_backup unless file_class.symlink?(new_resource.path)
+ ::File.delete(new_resource.path)
+ Chef::Log.info("#{new_resource} deleted file at #{new_resource.path}")
end
end
end
def action_touch
action_create
- converge_by("update utime on file #{@new_resource.path}") do
+ converge_by("update utime on file #{new_resource.path}") do
time = Time.now
- ::File.utime(time, time, @new_resource.path)
- Chef::Log.info("#{@new_resource} updated atime and mtime to #{time}")
+ ::File.utime(time, time, new_resource.path)
+ Chef::Log.info("#{new_resource} updated atime and mtime to #{time}")
end
end
@@ -197,8 +197,8 @@ class Chef
# content (for things like doing checksums in load_current_resource). Expected to
# be overridden in subclasses.
def managing_content?
- return true if @new_resource.checksum
- return true if !@new_resource.content.nil? && @action != :create_if_missing
+ return true if new_resource.checksum
+ return true if !new_resource.content.nil? && @action != :create_if_missing
false
end
@@ -228,25 +228,25 @@ class Chef
# assertions, which then decide whether or not to raise or issue a
# warning for whyrun mode.
def inspect_existing_fs_entry
- path = @new_resource.path
+ path = new_resource.path
if !l_exist?(path)
[nil, nil, nil]
elsif real_file?(path)
[nil, nil, nil]
- elsif file_class.symlink?(path) && @new_resource.manage_symlink_source
+ elsif file_class.symlink?(path) && new_resource.manage_symlink_source
verify_symlink_sanity(path)
- elsif file_class.symlink?(@new_resource.path) && @new_resource.manage_symlink_source.nil?
- Chef::Log.warn("File #{path} managed by #{@new_resource} is really a symlink. Managing the source file instead.")
+ elsif file_class.symlink?(new_resource.path) && new_resource.manage_symlink_source.nil?
+ Chef::Log.warn("File #{path} managed by #{new_resource} is really a symlink. Managing the source file instead.")
Chef::Log.warn("Disable this warning by setting `manage_symlink_source true` on the resource")
Chef::Log.warn("In a future Chef release, 'manage_symlink_source' will not be enabled by default")
verify_symlink_sanity(path)
- elsif @new_resource.force_unlink
+ elsif new_resource.force_unlink
[nil, nil, nil]
else
[ Chef::Exceptions::FileTypeMismatch,
- "File #{path} exists, but is a #{file_type_string(@new_resource.path)}, set force_unlink to true to remove",
- "Assuming #{file_type_string(@new_resource.path)} at #{@new_resource.path} would have been removed by a previous resource",
+ "File #{path} exists, but is a #{file_type_string(new_resource.path)}, set force_unlink to true to remove",
+ "Assuming #{file_type_string(new_resource.path)} at #{new_resource.path} would have been removed by a previous resource",
]
end
end
@@ -282,8 +282,8 @@ class Chef
def content
@content ||= begin
- load_current_resource if @current_resource.nil?
- @content_class.new(@new_resource, @current_resource, @run_context)
+ load_current_resource if current_resource.nil?
+ @content_class.new(new_resource, current_resource, @run_context)
end
end
@@ -356,12 +356,12 @@ class Chef
end
def do_unlink
- if @new_resource.force_unlink
+ if new_resource.force_unlink
if needs_unlinking?
# unlink things that aren't normal files
- description = "unlink #{file_type_string(@new_resource.path)} at #{@new_resource.path}"
+ description = "unlink #{file_type_string(new_resource.path)} at #{new_resource.path}"
converge_by(description) do
- unlink(@new_resource.path)
+ unlink(new_resource.path)
end
end
end
@@ -369,15 +369,15 @@ class Chef
def do_create_file
if needs_creating?
- converge_by("create new file #{@new_resource.path}") do
- deployment_strategy.create(@new_resource.path)
- Chef::Log.info("#{@new_resource} created file #{@new_resource.path}")
+ converge_by("create new file #{new_resource.path}") do
+ deployment_strategy.create(new_resource.path)
+ Chef::Log.info("#{new_resource} created file #{new_resource.path}")
end
end
end
def do_backup(file = nil)
- Chef::Util::Backup.new(@new_resource, file).backup!
+ Chef::Util::Backup.new(new_resource, file).backup!
end
def diff
@@ -403,17 +403,17 @@ class Chef
end
# the file? on the next line suppresses the case in why-run when we have a not-file here that would have otherwise been removed
- if ::File.file?(@new_resource.path) && contents_changed?
- description = [ "update content in file #{@new_resource.path} from \
-#{short_cksum(@current_resource.checksum)} to #{short_cksum(tempfile_checksum)}" ]
+ if ::File.file?(new_resource.path) && contents_changed?
+ description = [ "update content in file #{new_resource.path} from \
+#{short_cksum(current_resource.checksum)} to #{short_cksum(tempfile_checksum)}" ]
# Hide the diff output if the resource is marked as a sensitive resource
- if @new_resource.sensitive
- @new_resource.diff("suppressed sensitive resource")
+ if new_resource.sensitive
+ new_resource.diff("suppressed sensitive resource")
description << "suppressed sensitive resource"
else
- diff.diff(@current_resource.path, tempfile.path)
- @new_resource.diff( diff.for_reporting ) unless needs_creating?
+ diff.diff(current_resource.path, tempfile.path)
+ new_resource.diff( diff.for_reporting ) unless needs_creating?
description << diff.for_output
end
@@ -435,7 +435,7 @@ class Chef
if resource_updated? && Chef::Config[:enable_selinux_file_permission_fixup]
if selinux_enabled?
converge_by("restore selinux security context") do
- restore_security_context(::File.realpath(@new_resource.path), recursive)
+ restore_security_context(::File.realpath(new_resource.path), recursive)
end
else
Chef::Log.debug "selinux utilities can not be found. Skipping selinux permission fixup."
@@ -452,8 +452,8 @@ class Chef
end
def contents_changed?
- Chef::Log.debug "calculating checksum of #{tempfile.path} to compare with #{@current_resource.checksum}"
- tempfile_checksum != @current_resource.checksum
+ Chef::Log.debug "calculating checksum of #{tempfile.path} to compare with #{current_resource.checksum}"
+ tempfile_checksum != current_resource.checksum
end
def tempfile
@@ -468,7 +468,7 @@ class Chef
# reporting won't work for Windows.
return
end
- acl_scanner = ScanAccessControl.new(@new_resource, resource)
+ acl_scanner = ScanAccessControl.new(new_resource, resource)
acl_scanner.set_all!
end
diff --git a/lib/chef/provider/git.rb b/lib/chef/provider/git.rb
index a5c5e0d267..2907c20211 100644
--- a/lib/chef/provider/git.rb
+++ b/lib/chef/provider/git.rb
@@ -28,7 +28,7 @@ class Chef
extend Forwardable
provides :git
- def_delegator :@new_resource, :destination, :cwd
+ def_delegator :new_resource, :destination, :cwd
def whyrun_supported?
true
@@ -36,9 +36,9 @@ class Chef
def load_current_resource
@resolved_reference = nil
- @current_resource = Chef::Resource::Git.new(@new_resource.name)
+ @current_resource = Chef::Resource::Git.new(new_resource.name)
if current_revision = find_current_revision
- @current_resource.revision current_revision
+ current_resource.revision current_revision
end
end
@@ -49,16 +49,16 @@ class Chef
a.assertion { ::File.directory?(dirname) }
a.whyrun("Directory #{dirname} does not exist, this run will fail unless it has been previously created. Assuming it would have been created.")
a.failure_message(Chef::Exceptions::MissingParentDirectory,
- "Cannot clone #{@new_resource} to #{cwd}, the enclosing directory #{dirname} does not exist")
+ "Cannot clone #{new_resource} to #{cwd}, the enclosing directory #{dirname} does not exist")
end
requirements.assert(:all_actions) do |a|
- a.assertion { !(@new_resource.revision =~ /^origin\//) }
+ a.assertion { !(new_resource.revision =~ /^origin\//) }
a.failure_message Chef::Exceptions::InvalidRemoteGitReference,
"Deploying remote branches is not supported. " +
"Specify the remote branch as a local branch for " +
"the git repository you're deploying from " +
- "(ie: '#{@new_resource.revision.gsub('origin/', '')}' rather than '#{@new_resource.revision}')."
+ "(ie: '#{new_resource.revision.gsub('origin/', '')}' rather than '#{new_resource.revision}')."
end
requirements.assert(:all_actions) do |a|
@@ -67,22 +67,22 @@ class Chef
# if we can't resolve it up front.
a.assertion { !target_revision.nil? }
a.failure_message Chef::Exceptions::UnresolvableGitReference,
- "Unable to parse SHA reference for '#{@new_resource.revision}' in repository '#{@new_resource.repository}'. " +
+ "Unable to parse SHA reference for '#{new_resource.revision}' in repository '#{new_resource.repository}'. " +
"Verify your (case-sensitive) repository URL and revision.\n" +
- "`git ls-remote '#{@new_resource.repository}' '#{rev_search_pattern}'` output: #{@resolved_reference}"
+ "`git ls-remote '#{new_resource.repository}' '#{rev_search_pattern}'` output: #{@resolved_reference}"
end
end
def action_checkout
if target_dir_non_existent_or_empty?
clone
- if @new_resource.enable_checkout
+ if new_resource.enable_checkout
checkout
end
enable_submodules
add_remotes
else
- Chef::Log.debug "#{@new_resource} checkout destination #{cwd} already exists or is a non-empty directory"
+ Chef::Log.debug "#{new_resource} checkout destination #{cwd} already exists or is a non-empty directory"
end
end
@@ -95,11 +95,11 @@ class Chef
def action_sync
if existing_git_clone?
- Chef::Log.debug "#{@new_resource} current revision: #{@current_resource.revision} target revision: #{target_revision}"
+ Chef::Log.debug "#{new_resource} current revision: #{current_resource.revision} target revision: #{target_revision}"
unless current_revision_matches_target_revision?
fetch_updates
enable_submodules
- Chef::Log.info "#{@new_resource} updated to revision #{target_revision}"
+ Chef::Log.info "#{new_resource} updated to revision #{target_revision}"
end
add_remotes
else
@@ -120,7 +120,7 @@ class Chef
end
def find_current_revision
- Chef::Log.debug("#{@new_resource} finding current git revision")
+ Chef::Log.debug("#{new_resource} finding current git revision")
if ::File.exist?(::File.join(cwd, ".git"))
# 128 is returned when we're not in a git repo. this is fine
result = git("rev-parse", "HEAD", cwd: cwd, returns: [0, 128]).stdout.strip
@@ -129,10 +129,10 @@ class Chef
end
def add_remotes
- if @new_resource.additional_remotes.length > 0
- @new_resource.additional_remotes.each_pair do |remote_name, remote_url|
+ if new_resource.additional_remotes.length > 0
+ new_resource.additional_remotes.each_pair do |remote_name, remote_url|
converge_by("add remote #{remote_name} from #{remote_url}") do
- Chef::Log.info "#{@new_resource} adding git remote #{remote_name} = #{remote_url}"
+ Chef::Log.info "#{new_resource} adding git remote #{remote_name} = #{remote_url}"
setup_remote_tracking_branches(remote_name, remote_url)
end
end
@@ -140,17 +140,17 @@ class Chef
end
def clone
- converge_by("clone from #{@new_resource.repository} into #{cwd}") do
- remote = @new_resource.remote
+ converge_by("clone from #{new_resource.repository} into #{cwd}") do
+ remote = new_resource.remote
clone_cmd = ["clone"]
clone_cmd << "-o #{remote}" unless remote == "origin"
- clone_cmd << "--depth #{@new_resource.depth}" if @new_resource.depth
- clone_cmd << "--no-single-branch" if @new_resource.depth && git_minor_version >= Gem::Version.new("1.7.10")
- clone_cmd << "\"#{@new_resource.repository}\""
+ clone_cmd << "--depth #{new_resource.depth}" if new_resource.depth
+ clone_cmd << "--no-single-branch" if new_resource.depth && git_minor_version >= Gem::Version.new("1.7.10")
+ clone_cmd << "\"#{new_resource.repository}\""
clone_cmd << "\"#{cwd}\""
- Chef::Log.info "#{@new_resource} cloning repo #{@new_resource.repository} to #{cwd}"
+ Chef::Log.info "#{new_resource} cloning repo #{new_resource.repository} to #{cwd}"
git clone_cmd
end
end
@@ -158,20 +158,20 @@ class Chef
def checkout
sha_ref = target_revision
- converge_by("checkout ref #{sha_ref} branch #{@new_resource.revision}") do
+ converge_by("checkout ref #{sha_ref} branch #{new_resource.revision}") do
# checkout into a local branch rather than a detached HEAD
- git("branch", "-f", @new_resource.checkout_branch, sha_ref, cwd: cwd)
- git("checkout", @new_resource.checkout_branch, cwd: cwd)
- Chef::Log.info "#{@new_resource} checked out branch: #{@new_resource.revision} onto: #{@new_resource.checkout_branch} reference: #{sha_ref}"
+ git("branch", "-f", new_resource.checkout_branch, sha_ref, cwd: cwd)
+ git("checkout", new_resource.checkout_branch, cwd: cwd)
+ Chef::Log.info "#{new_resource} checked out branch: #{new_resource.revision} onto: #{new_resource.checkout_branch} reference: #{sha_ref}"
end
end
def enable_submodules
- if @new_resource.enable_submodules
- converge_by("enable git submodules for #{@new_resource}") do
- Chef::Log.info "#{@new_resource} synchronizing git submodules"
+ if new_resource.enable_submodules
+ converge_by("enable git submodules for #{new_resource}") do
+ Chef::Log.info "#{new_resource} synchronizing git submodules"
git("submodule", "sync", cwd: cwd)
- Chef::Log.info "#{@new_resource} enabling git submodules"
+ Chef::Log.info "#{new_resource} enabling git submodules"
# the --recursive flag means we require git 1.6.5+ now, see CHEF-1827
git("submodule", "update", "--init", "--recursive", cwd: cwd)
end
@@ -179,19 +179,19 @@ class Chef
end
def fetch_updates
- setup_remote_tracking_branches(@new_resource.remote, @new_resource.repository)
- converge_by("fetch updates for #{@new_resource.remote}") do
+ setup_remote_tracking_branches(new_resource.remote, new_resource.repository)
+ converge_by("fetch updates for #{new_resource.remote}") do
# since we're in a local branch already, just reset to specified revision rather than merge
Chef::Log.debug "Fetching updates from #{new_resource.remote} and resetting to revision #{target_revision}"
- git("fetch", @new_resource.remote, cwd: cwd)
- git("fetch", @new_resource.remote, "--tags", cwd: cwd)
+ git("fetch", new_resource.remote, cwd: cwd)
+ git("fetch", new_resource.remote, "--tags", cwd: cwd)
git("reset", "--hard", target_revision, cwd: cwd)
end
end
def setup_remote_tracking_branches(remote_name, remote_url)
converge_by("set up remote tracking branches for #{remote_url} at #{remote_name}") do
- Chef::Log.debug "#{@new_resource} configuring remote tracking branches for repository #{remote_url} " + "at remote #{remote_name}"
+ Chef::Log.debug "#{new_resource} configuring remote tracking branches for repository #{remote_url} " + "at remote #{remote_name}"
check_remote_command = ["config", "--get", "remote.#{remote_name}.url"]
remote_status = git(check_remote_command, cwd: cwd, returns: [0, 1, 2])
case remote_status.exitstatus
@@ -219,13 +219,13 @@ class Chef
end
def current_revision_matches_target_revision?
- (!@current_resource.revision.nil?) && (target_revision.strip.to_i(16) == @current_resource.revision.strip.to_i(16))
+ (!current_resource.revision.nil?) && (target_revision.strip.to_i(16) == current_resource.revision.strip.to_i(16))
end
def target_revision
@target_revision ||= begin
- if sha_hash?(@new_resource.revision)
- @target_revision = @new_resource.revision
+ if sha_hash?(new_resource.revision)
+ @target_revision = new_resource.revision
else
@target_revision = remote_resolve_reference
end
@@ -235,7 +235,7 @@ class Chef
alias :revision_slug :target_revision
def remote_resolve_reference
- Chef::Log.debug("#{@new_resource} resolving remote reference")
+ Chef::Log.debug("#{new_resource} resolving remote reference")
# The sha pointed to by an annotated tag is identified by the
# '^{}' suffix appended to the tag. In order to resolve
# annotated tags, we have to search for "revision*" and
@@ -250,11 +250,11 @@ class Chef
# confusing. We avoid the issue by disallowing the use of
# annotated tags named 'HEAD'.
if rev_search_pattern != "HEAD"
- found = find_revision(refs, @new_resource.revision, "^{}")
+ found = find_revision(refs, new_resource.revision, "^{}")
else
found = refs_search(refs, "HEAD")
end
- found = find_revision(refs, @new_resource.revision) if found.empty?
+ found = find_revision(refs, new_resource.revision) if found.empty?
found.size == 1 ? found.first[0] : nil
end
@@ -274,15 +274,15 @@ class Chef
end
def rev_search_pattern
- if ["", "HEAD"].include? @new_resource.revision
+ if ["", "HEAD"].include? new_resource.revision
"HEAD"
else
- @new_resource.revision + "*"
+ new_resource.revision + "*"
end
end
def git_ls_remote(rev_pattern)
- git("ls-remote", "\"#{@new_resource.repository}\"", "\"#{rev_pattern}\"").stdout
+ git("ls-remote", "\"#{new_resource.repository}\"", "\"#{rev_pattern}\"").stdout
end
def refs_search(refs, pattern)
@@ -293,28 +293,28 @@ class Chef
def run_options(run_opts = {})
env = {}
- if @new_resource.user
- run_opts[:user] = @new_resource.user
+ if new_resource.user
+ run_opts[:user] = new_resource.user
# Certain versions of `git` misbehave if git configuration is
# inaccessible in $HOME. We need to ensure $HOME matches the
# user who is executing `git` not the user running Chef.
env["HOME"] = begin
require "etc"
- case @new_resource.user
+ case new_resource.user
when Integer
- Etc.getpwuid(@new_resource.user).dir
+ Etc.getpwuid(new_resource.user).dir
else
- Etc.getpwnam(@new_resource.user.to_s).dir
+ Etc.getpwnam(new_resource.user.to_s).dir
end
rescue ArgumentError # user not found
- raise Chef::Exceptions::User, "Could not determine HOME for specified user '#{@new_resource.user}' for resource '#{@new_resource.name}'"
+ raise Chef::Exceptions::User, "Could not determine HOME for specified user '#{new_resource.user}' for resource '#{new_resource.name}'"
end
end
- run_opts[:group] = @new_resource.group if @new_resource.group
- env["GIT_SSH"] = @new_resource.ssh_wrapper if @new_resource.ssh_wrapper
- run_opts[:log_tag] = @new_resource.to_s
- run_opts[:timeout] = @new_resource.timeout if @new_resource.timeout
- env.merge!(@new_resource.environment) if @new_resource.environment
+ run_opts[:group] = new_resource.group if new_resource.group
+ env["GIT_SSH"] = new_resource.ssh_wrapper if new_resource.ssh_wrapper
+ run_opts[:log_tag] = new_resource.to_s
+ run_opts[:timeout] = new_resource.timeout if new_resource.timeout
+ env.merge!(new_resource.environment) if new_resource.environment
run_opts[:environment] = env unless env.empty?
run_opts
end
diff --git a/lib/chef/provider/http_request.rb b/lib/chef/provider/http_request.rb
index e1ee01d9b4..eaca17a972 100644
--- a/lib/chef/provider/http_request.rb
+++ b/lib/chef/provider/http_request.rb
@@ -32,78 +32,78 @@ class Chef
end
def load_current_resource
- @http = Chef::HTTP::Simple.new(@new_resource.url)
+ @http = Chef::HTTP::Simple.new(new_resource.url)
end
- # Send a HEAD request to @new_resource.url
+ # Send a HEAD request to new_resource.url
def action_head
- message = check_message(@new_resource.message)
+ message = check_message(new_resource.message)
# CHEF-4762: we expect a nil return value from Chef::HTTP for a "200 Success" response
# and false for a "304 Not Modified" response
modified = @http.head(
- "#{@new_resource.url}",
- @new_resource.headers
+ "#{new_resource.url}",
+ new_resource.headers
)
- Chef::Log.info("#{@new_resource} HEAD to #{@new_resource.url} successful")
- Chef::Log.debug("#{@new_resource} HEAD request response: #{modified}")
+ Chef::Log.info("#{new_resource} HEAD to #{new_resource.url} successful")
+ Chef::Log.debug("#{new_resource} HEAD request response: #{modified}")
# :head is usually used to trigger notifications, which converge_by now does
if modified != false
- converge_by("#{@new_resource} HEAD to #{@new_resource.url} returned modified, trigger notifications") {}
+ converge_by("#{new_resource} HEAD to #{new_resource.url} returned modified, trigger notifications") {}
end
end
- # Send a GET request to @new_resource.url
+ # Send a GET request to new_resource.url
def action_get
- converge_by("#{@new_resource} GET to #{@new_resource.url}") do
+ converge_by("#{new_resource} GET to #{new_resource.url}") do
- message = check_message(@new_resource.message)
+ message = check_message(new_resource.message)
body = @http.get(
- "#{@new_resource.url}",
- @new_resource.headers
+ "#{new_resource.url}",
+ new_resource.headers
)
- Chef::Log.info("#{@new_resource} GET to #{@new_resource.url} successful")
- Chef::Log.debug("#{@new_resource} GET request response: #{body}")
+ Chef::Log.info("#{new_resource} GET to #{new_resource.url} successful")
+ Chef::Log.debug("#{new_resource} GET request response: #{body}")
end
end
- # Send a PUT request to @new_resource.url, with the message as the payload
+ # Send a PUT request to new_resource.url, with the message as the payload
def action_put
- converge_by("#{@new_resource} PUT to #{@new_resource.url}") do
- message = check_message(@new_resource.message)
+ converge_by("#{new_resource} PUT to #{new_resource.url}") do
+ message = check_message(new_resource.message)
body = @http.put(
- "#{@new_resource.url}",
+ "#{new_resource.url}",
message,
- @new_resource.headers
+ new_resource.headers
)
- Chef::Log.info("#{@new_resource} PUT to #{@new_resource.url} successful")
- Chef::Log.debug("#{@new_resource} PUT request response: #{body}")
+ Chef::Log.info("#{new_resource} PUT to #{new_resource.url} successful")
+ Chef::Log.debug("#{new_resource} PUT request response: #{body}")
end
end
- # Send a POST request to @new_resource.url, with the message as the payload
+ # Send a POST request to new_resource.url, with the message as the payload
def action_post
- converge_by("#{@new_resource} POST to #{@new_resource.url}") do
- message = check_message(@new_resource.message)
+ converge_by("#{new_resource} POST to #{new_resource.url}") do
+ message = check_message(new_resource.message)
body = @http.post(
- "#{@new_resource.url}",
+ "#{new_resource.url}",
message,
- @new_resource.headers
+ new_resource.headers
)
- Chef::Log.info("#{@new_resource} POST to #{@new_resource.url} message: #{message.inspect} successful")
- Chef::Log.debug("#{@new_resource} POST request response: #{body}")
+ Chef::Log.info("#{new_resource} POST to #{new_resource.url} message: #{message.inspect} successful")
+ Chef::Log.debug("#{new_resource} POST request response: #{body}")
end
end
- # Send a DELETE request to @new_resource.url
+ # Send a DELETE request to new_resource.url
def action_delete
- converge_by("#{@new_resource} DELETE to #{@new_resource.url}") do
+ converge_by("#{new_resource} DELETE to #{new_resource.url}") do
body = @http.delete(
- "#{@new_resource.url}",
- @new_resource.headers
+ "#{new_resource.url}",
+ new_resource.headers
)
- @new_resource.updated_by_last_action(true)
- Chef::Log.info("#{@new_resource} DELETE to #{@new_resource.url} successful")
- Chef::Log.debug("#{@new_resource} DELETE request response: #{body}")
+ new_resource.updated_by_last_action(true)
+ Chef::Log.info("#{new_resource} DELETE to #{new_resource.url} successful")
+ Chef::Log.debug("#{new_resource} DELETE request response: #{body}")
end
end
diff --git a/lib/chef/provider/launchd.rb b/lib/chef/provider/launchd.rb
index f3e0a00758..a58954c707 100644
--- a/lib/chef/provider/launchd.rb
+++ b/lib/chef/provider/launchd.rb
@@ -30,7 +30,7 @@ class Chef
extend Forwardable
provides :launchd, os: "darwin"
- def_delegators :@new_resource, *[
+ def_delegators :new_resource, *[
:backup,
:cookbook,
:group,
diff --git a/lib/chef/provider/link.rb b/lib/chef/provider/link.rb
index 5add453072..aed60b7c47 100644
--- a/lib/chef/provider/link.rb
+++ b/lib/chef/provider/link.rb
@@ -47,41 +47,41 @@ class Chef
end
def load_current_resource
- @current_resource = Chef::Resource::Link.new(@new_resource.name)
- @current_resource.target_file(@new_resource.target_file)
- if file_class.symlink?(@current_resource.target_file)
- @current_resource.link_type(:symbolic)
- @current_resource.to(
- canonicalize(file_class.readlink(@current_resource.target_file))
+ @current_resource = Chef::Resource::Link.new(new_resource.name)
+ current_resource.target_file(new_resource.target_file)
+ if file_class.symlink?(current_resource.target_file)
+ current_resource.link_type(:symbolic)
+ current_resource.to(
+ canonicalize(file_class.readlink(current_resource.target_file))
)
else
- @current_resource.link_type(:hard)
- if ::File.exists?(@current_resource.target_file)
- if ::File.exists?(@new_resource.to) &&
- file_class.stat(@current_resource.target_file).ino ==
- file_class.stat(@new_resource.to).ino
- @current_resource.to(canonicalize(@new_resource.to))
+ current_resource.link_type(:hard)
+ if ::File.exists?(current_resource.target_file)
+ if ::File.exists?(new_resource.to) &&
+ file_class.stat(current_resource.target_file).ino ==
+ file_class.stat(new_resource.to).ino
+ current_resource.to(canonicalize(new_resource.to))
else
- @current_resource.to("")
+ current_resource.to("")
end
end
end
- ScanAccessControl.new(@new_resource, @current_resource).set_all!
- @current_resource
+ ScanAccessControl.new(new_resource, current_resource).set_all!
+ current_resource
end
def define_resource_requirements
requirements.assert(:delete) do |a|
a.assertion do
- if @current_resource.to
- @current_resource.link_type == @new_resource.link_type &&
- (@current_resource.link_type == :symbolic || @current_resource.to != "")
+ if current_resource.to
+ current_resource.link_type == new_resource.link_type &&
+ (current_resource.link_type == :symbolic || current_resource.to != "")
else
true
end
end
- a.failure_message Chef::Exceptions::Link, "Cannot delete #{@new_resource} at #{@new_resource.target_file}! Not a #{@new_resource.link_type} link."
- a.whyrun("Would assume the link at #{@new_resource.target_file} was previously created")
+ a.failure_message Chef::Exceptions::Link, "Cannot delete #{new_resource} at #{new_resource.target_file}! Not a #{new_resource.link_type} link."
+ a.whyrun("Would assume the link at #{new_resource.target_file} was previously created")
end
end
@@ -95,48 +95,48 @@ class Chef
# to - the location to link to
# target_file - the name of the link
- if @current_resource.to != canonicalize(@new_resource.to) ||
- @current_resource.link_type != @new_resource.link_type
+ if current_resource.to != canonicalize(new_resource.to) ||
+ current_resource.link_type != new_resource.link_type
# Handle the case where the symlink already exists and is pointing at a valid to_file
- if @current_resource.to
+ if current_resource.to
# On Windows, to fix a symlink already pointing at a directory we must first
# ::Dir.unlink the symlink (not the directory), while if we have a symlink
# pointing at file we must use ::File.unlink on the symlink.
# However if the new symlink will point to a file and the current symlink is pointing at a
# directory we want to throw an exception and calling ::File.unlink on the directory symlink
# will throw the correct ones.
- if Chef::Platform.windows? && ::File.directory?(@new_resource.to) &&
- ::File.directory?(@current_resource.target_file)
- converge_by("unlink existing windows symlink to dir at #{@new_resource.target_file}") do
- ::Dir.unlink(@new_resource.target_file)
+ if Chef::Platform.windows? && ::File.directory?(new_resource.to) &&
+ ::File.directory?(current_resource.target_file)
+ converge_by("unlink existing windows symlink to dir at #{new_resource.target_file}") do
+ ::Dir.unlink(new_resource.target_file)
end
else
- converge_by("unlink existing symlink to file at #{@new_resource.target_file}") do
- ::File.unlink(@new_resource.target_file)
+ converge_by("unlink existing symlink to file at #{new_resource.target_file}") do
+ ::File.unlink(new_resource.target_file)
end
end
end
- if @new_resource.link_type == :symbolic
- converge_by("create symlink at #{@new_resource.target_file} to #{@new_resource.to}") do
- file_class.symlink(canonicalize(@new_resource.to), @new_resource.target_file)
- Chef::Log.debug("#{@new_resource} created #{@new_resource.link_type} link from #{@new_resource.target_file} -> #{@new_resource.to}")
- Chef::Log.info("#{@new_resource} created")
+ if new_resource.link_type == :symbolic
+ converge_by("create symlink at #{new_resource.target_file} to #{new_resource.to}") do
+ file_class.symlink(canonicalize(new_resource.to), new_resource.target_file)
+ Chef::Log.debug("#{new_resource} created #{new_resource.link_type} link from #{new_resource.target_file} -> #{new_resource.to}")
+ Chef::Log.info("#{new_resource} created")
# file_class.symlink will create the link with default access controls.
# This means that the access controls of the file could be different
# than those captured during the initial evaluation of current_resource.
# We need to re-evaluate the current_resource to ensure that the desired
# access controls are applied.
- ScanAccessControl.new(@new_resource, @current_resource).set_all!
+ ScanAccessControl.new(new_resource, current_resource).set_all!
end
- elsif @new_resource.link_type == :hard
- converge_by("create hard link at #{@new_resource.target_file} to #{@new_resource.to}") do
- file_class.link(@new_resource.to, @new_resource.target_file)
- Chef::Log.debug("#{@new_resource} created #{@new_resource.link_type} link from #{@new_resource.target_file} -> #{@new_resource.to}")
- Chef::Log.info("#{@new_resource} created")
+ elsif new_resource.link_type == :hard
+ converge_by("create hard link at #{new_resource.target_file} to #{new_resource.to}") do
+ file_class.link(new_resource.to, new_resource.target_file)
+ Chef::Log.debug("#{new_resource} created #{new_resource.link_type} link from #{new_resource.target_file} -> #{new_resource.to}")
+ Chef::Log.info("#{new_resource} created")
end
end
end
- if @new_resource.link_type == :symbolic
+ if new_resource.link_type == :symbolic
if access_controls.requires_changes?
converge_by(access_controls.describe_changes) do
access_controls.set_all
@@ -146,16 +146,16 @@ class Chef
end
def action_delete
- if @current_resource.to # Exists
- if Chef::Platform.windows? && ::File.directory?(@current_resource.target_file)
- converge_by("delete link to dir at #{@new_resource.target_file}") do
- ::Dir.delete(@new_resource.target_file)
- Chef::Log.info("#{@new_resource} deleted")
+ if current_resource.to # Exists
+ if Chef::Platform.windows? && ::File.directory?(current_resource.target_file)
+ converge_by("delete link to dir at #{new_resource.target_file}") do
+ ::Dir.delete(new_resource.target_file)
+ Chef::Log.info("#{new_resource} deleted")
end
else
- converge_by("delete link to file at #{@new_resource.target_file}") do
- ::File.delete(@new_resource.target_file)
- Chef::Log.info("#{@new_resource} deleted")
+ converge_by("delete link to file at #{new_resource.target_file}") do
+ ::File.delete(new_resource.target_file)
+ Chef::Log.info("#{new_resource} deleted")
end
end
end
@@ -165,7 +165,7 @@ class Chef
# access control (e.g., use lchmod instead of chmod) if the resource is a
# symlink.
def manage_symlink_access?
- @new_resource.link_type == :symbolic
+ new_resource.link_type == :symbolic
end
end
end
diff --git a/lib/chef/provider/log.rb b/lib/chef/provider/log.rb
index 567781cb41..a0219db753 100644
--- a/lib/chef/provider/log.rb
+++ b/lib/chef/provider/log.rb
@@ -44,8 +44,8 @@ class Chef
# === Return
# true:: Always return true
def action_write
- Chef::Log.send(@new_resource.level, @new_resource.message)
- @new_resource.updated_by_last_action(true) if Chef::Config[:count_log_resource_updates]
+ Chef::Log.send(new_resource.level, new_resource.message)
+ new_resource.updated_by_last_action(true) if Chef::Config[:count_log_resource_updates]
end
end
diff --git a/lib/chef/provider/mdadm.rb b/lib/chef/provider/mdadm.rb
index f8225ff63a..88da7b5eff 100644
--- a/lib/chef/provider/mdadm.rb
+++ b/lib/chef/provider/mdadm.rb
@@ -34,57 +34,57 @@ class Chef
end
def load_current_resource
- @current_resource = Chef::Resource::Mdadm.new(@new_resource.name)
- @current_resource.raid_device(@new_resource.raid_device)
- Chef::Log.debug("#{@new_resource} checking for software raid device #{@current_resource.raid_device}")
+ @current_resource = Chef::Resource::Mdadm.new(new_resource.name)
+ current_resource.raid_device(new_resource.raid_device)
+ Chef::Log.debug("#{new_resource} checking for software raid device #{current_resource.raid_device}")
device_not_found = 4
- mdadm = shell_out!("mdadm --detail --test #{@new_resource.raid_device}", :returns => [0, device_not_found])
+ mdadm = shell_out!("mdadm --detail --test #{new_resource.raid_device}", :returns => [0, device_not_found])
exists = (mdadm.status == 0)
- @current_resource.exists(exists)
+ current_resource.exists(exists)
end
def action_create
- unless @current_resource.exists
+ unless current_resource.exists
converge_by("create RAID device #{new_resource.raid_device}") do
- command = "yes | mdadm --create #{@new_resource.raid_device} --level #{@new_resource.level}"
- command << " --chunk=#{@new_resource.chunk}" unless @new_resource.level == 1
- command << " --metadata=#{@new_resource.metadata}"
- command << " --bitmap=#{@new_resource.bitmap}" if @new_resource.bitmap
- command << " --layout=#{@new_resource.layout}" if @new_resource.layout
- command << " --raid-devices #{@new_resource.devices.length} #{@new_resource.devices.join(" ")}"
- Chef::Log.debug("#{@new_resource} mdadm command: #{command}")
+ command = "yes | mdadm --create #{new_resource.raid_device} --level #{new_resource.level}"
+ command << " --chunk=#{new_resource.chunk}" unless new_resource.level == 1
+ command << " --metadata=#{new_resource.metadata}"
+ command << " --bitmap=#{new_resource.bitmap}" if new_resource.bitmap
+ command << " --layout=#{new_resource.layout}" if new_resource.layout
+ command << " --raid-devices #{new_resource.devices.length} #{new_resource.devices.join(" ")}"
+ Chef::Log.debug("#{new_resource} mdadm command: #{command}")
shell_out!(command)
- Chef::Log.info("#{@new_resource} created raid device (#{@new_resource.raid_device})")
+ Chef::Log.info("#{new_resource} created raid device (#{new_resource.raid_device})")
end
else
- Chef::Log.debug("#{@new_resource} raid device already exists, skipping create (#{@new_resource.raid_device})")
+ Chef::Log.debug("#{new_resource} raid device already exists, skipping create (#{new_resource.raid_device})")
end
end
def action_assemble
- unless @current_resource.exists
+ unless current_resource.exists
converge_by("assemble RAID device #{new_resource.raid_device}") do
- command = "yes | mdadm --assemble #{@new_resource.raid_device} #{@new_resource.devices.join(" ")}"
- Chef::Log.debug("#{@new_resource} mdadm command: #{command}")
+ command = "yes | mdadm --assemble #{new_resource.raid_device} #{new_resource.devices.join(" ")}"
+ Chef::Log.debug("#{new_resource} mdadm command: #{command}")
shell_out!(command)
- Chef::Log.info("#{@new_resource} assembled raid device (#{@new_resource.raid_device})")
+ Chef::Log.info("#{new_resource} assembled raid device (#{new_resource.raid_device})")
end
else
- Chef::Log.debug("#{@new_resource} raid device already exists, skipping assemble (#{@new_resource.raid_device})")
+ Chef::Log.debug("#{new_resource} raid device already exists, skipping assemble (#{new_resource.raid_device})")
end
end
def action_stop
- if @current_resource.exists
+ if current_resource.exists
converge_by("stop RAID device #{new_resource.raid_device}") do
- command = "yes | mdadm --stop #{@new_resource.raid_device}"
- Chef::Log.debug("#{@new_resource} mdadm command: #{command}")
+ command = "yes | mdadm --stop #{new_resource.raid_device}"
+ Chef::Log.debug("#{new_resource} mdadm command: #{command}")
shell_out!(command)
- Chef::Log.info("#{@new_resource} stopped raid device (#{@new_resource.raid_device})")
+ Chef::Log.info("#{new_resource} stopped raid device (#{new_resource.raid_device})")
end
else
- Chef::Log.debug("#{@new_resource} raid device doesn't exist (#{@new_resource.raid_device}) - not stopping")
+ Chef::Log.debug("#{new_resource} raid device doesn't exist (#{new_resource.raid_device}) - not stopping")
end
end
diff --git a/lib/chef/provider/ohai.rb b/lib/chef/provider/ohai.rb
index 8f1939af6d..c36655077b 100644
--- a/lib/chef/provider/ohai.rb
+++ b/lib/chef/provider/ohai.rb
@@ -37,7 +37,7 @@ class Chef
converge_by("re-run ohai and merge results into node attributes") do
ohai = ::Ohai::System.new
- # If @new_resource.plugin is nil, ohai will reload all the plugins
+ # If new_resource.plugin is nil, ohai will reload all the plugins
# Otherwise it will only reload the specified plugin
# Note that any changes to plugins, or new plugins placed on
# the path are picked up by ohai.
diff --git a/lib/chef/provider/osx_profile.rb b/lib/chef/provider/osx_profile.rb
index 6939c386a1..9a3b0f9b4a 100644
--- a/lib/chef/provider/osx_profile.rb
+++ b/lib/chef/provider/osx_profile.rb
@@ -34,16 +34,16 @@ class Chef
end
def load_current_resource
- @current_resource = Chef::Resource::OsxProfile.new(@new_resource.name)
- @current_resource.profile_name(@new_resource.profile_name)
+ @current_resource = Chef::Resource::OsxProfile.new(new_resource.name)
+ current_resource.profile_name(new_resource.profile_name)
all_profiles = get_installed_profiles
- @new_resource.profile(
- @new_resource.profile ||
- @new_resource.profile_name
+ new_resource.profile(
+ new_resource.profile ||
+ new_resource.profile_name
)
- @new_profile_hash = get_profile_hash(@new_resource.profile)
+ @new_profile_hash = get_profile_hash(new_resource.profile)
if @new_profile_hash
@new_profile_hash["PayloadUUID"] =
config_uuid(@new_profile_hash)
@@ -52,8 +52,8 @@ class Chef
if @new_profile_hash
@new_profile_identifier = @new_profile_hash["PayloadIdentifier"]
else
- @new_profile_identifier = @new_resource.identifier ||
- @new_resource.profile_name
+ @new_profile_identifier = new_resource.identifier ||
+ new_resource.profile_name
end
current_profile = nil
@@ -62,7 +62,7 @@ class Chef
item["ProfileIdentifier"] == @new_profile_identifier
end
end
- @current_resource.profile(current_profile)
+ current_resource.profile(current_profile)
end
def define_resource_requirements
@@ -75,7 +75,7 @@ class Chef
end
a.failure_message RuntimeError, "when removing using the identifier attribute, it must match the profile identifier"
else
- new_profile_name = @new_resource.profile_name
+ new_profile_name = new_resource.profile_name
a.assertion do
!new_profile_name.end_with?(".mobileconfig") &&
/^\w+(?:(\.| )\w+)+$/.match(new_profile_name)
@@ -136,13 +136,13 @@ class Chef
def cookbook_file_available?(cookbook_file)
run_context.has_cookbook_file_in_cookbook?(
- @new_resource.cookbook_name, cookbook_file
+ new_resource.cookbook_name, cookbook_file
)
end
def get_cache_dir
cache_dir = Chef::FileCache.create_cache_path(
- "profiles/#{@new_resource.cookbook_name}"
+ "profiles/#{new_resource.cookbook_name}"
)
end
@@ -150,7 +150,7 @@ class Chef
Chef::FileCache.create_cache_path(
::File.join(
"profiles",
- @new_resource.cookbook_name,
+ new_resource.cookbook_name,
::File.dirname(cookbook_file)
)
)
@@ -161,7 +161,7 @@ class Chef
),
run_context
)
- remote_file.cookbook_name = @new_resource.cookbook_name
+ remote_file.cookbook_name = new_resource.cookbook_name
remote_file.source(cookbook_file)
remote_file.backup(false)
remote_file.run_action(:create)
@@ -185,8 +185,8 @@ class Chef
end
def write_profile_to_disk
- @new_resource.path(Chef::FileCache.create_cache_path("profiles"))
- tempfile = Chef::FileContentManagement::Tempfile.new(@new_resource).tempfile
+ new_resource.path(Chef::FileCache.create_cache_path("profiles"))
+ tempfile = Chef::FileContentManagement::Tempfile.new(new_resource).tempfile
tempfile.write(@new_profile_hash.to_plist)
tempfile.close
tempfile.path
@@ -240,13 +240,13 @@ class Chef
def profile_installed?
# Profile Identifier and UUID must match a currently installed profile
- if @current_resource.profile.nil? || @current_resource.profile.empty?
+ if current_resource.profile.nil? || current_resource.profile.empty?
false
else
- if @new_resource.action.include?(:remove)
+ if new_resource.action.include?(:remove)
true
else
- @current_resource.profile["ProfileUUID"] ==
+ current_resource.profile["ProfileUUID"] ==
@new_profile_hash["PayloadUUID"]
end
end
diff --git a/lib/chef/provider/powershell_script.rb b/lib/chef/provider/powershell_script.rb
index db12f61a0b..87705ef59a 100644
--- a/lib/chef/provider/powershell_script.rb
+++ b/lib/chef/provider/powershell_script.rb
@@ -60,8 +60,8 @@ class Chef
def flags
interpreter_flags = [*default_interpreter_flags].join(" ")
- if ! (@new_resource.flags.nil?)
- interpreter_flags = [@new_resource.flags, interpreter_flags].join(" ")
+ if ! (new_resource.flags.nil?)
+ interpreter_flags = [new_resource.flags, interpreter_flags].join(" ")
end
interpreter_flags
@@ -73,7 +73,7 @@ class Chef
# special handling to cover common use cases.
def add_exit_status_wrapper
self.code = wrapper_script
- Chef::Log.debug("powershell_script provider called with script code:\n\n#{@new_resource.code}\n")
+ Chef::Log.debug("powershell_script provider called with script code:\n\n#{new_resource.code}\n")
Chef::Log.debug("powershell_script provider will execute transformed code:\n\n#{code}\n")
end
@@ -87,7 +87,7 @@ class Chef
# actually running the script.
user_code_wrapped_in_powershell_script_block = <<-EOH
{
- #{@new_resource.code}
+ #{new_resource.code}
}
EOH
user_script_file.puts user_code_wrapped_in_powershell_script_block
@@ -167,7 +167,7 @@ $global:LASTEXITCODE = 0
trap [Exception] {write-error ($_.Exception.Message);exit 1}
# Variable state that should not be accessible to the user code
-new-variable -name interpolatedexitcode -visibility private -value $#{@new_resource.convert_boolean_return}
+new-variable -name interpolatedexitcode -visibility private -value $#{new_resource.convert_boolean_return}
new-variable -name chefscriptresult -visibility private
# Initialize a variable we use to capture $? inside a block
@@ -176,7 +176,7 @@ $global:lastcmdlet = $null
# Execute the user's code in a script block --
$chefscriptresult =
{
- #{@new_resource.code}
+ #{new_resource.code}
# This assignment doesn't affect the block's return value
$global:lastcmdlet = $?
diff --git a/lib/chef/provider/reboot.rb b/lib/chef/provider/reboot.rb
index 34eee9236d..ff85f7a99a 100644
--- a/lib/chef/provider/reboot.rb
+++ b/lib/chef/provider/reboot.rb
@@ -29,31 +29,31 @@ class Chef
end
def load_current_resource
- @current_resource ||= Chef::Resource::Reboot.new(@new_resource.name)
- @current_resource.reason(@new_resource.reason)
- @current_resource.delay_mins(@new_resource.delay_mins)
- @current_resource
+ @current_resource ||= Chef::Resource::Reboot.new(new_resource.name)
+ current_resource.reason(new_resource.reason)
+ current_resource.delay_mins(new_resource.delay_mins)
+ current_resource
end
def request_reboot
node.run_context.request_reboot(
- :delay_mins => @new_resource.delay_mins,
- :reason => @new_resource.reason,
+ :delay_mins => new_resource.delay_mins,
+ :reason => new_resource.reason,
:timestamp => Time.now,
- :requested_by => @new_resource.name
+ :requested_by => new_resource.name
)
end
def action_request_reboot
converge_by("request a system reboot to occur if the run succeeds") do
- Chef::Log.warn "Reboot requested:'#{@new_resource.name}'"
+ Chef::Log.warn "Reboot requested:'#{new_resource.name}'"
request_reboot
end
end
def action_reboot_now
converge_by("rebooting the system immediately") do
- Chef::Log.warn "Rebooting system immediately, requested by '#{@new_resource.name}'"
+ Chef::Log.warn "Rebooting system immediately, requested by '#{new_resource.name}'"
request_reboot
throw :end_client_run_early
end
@@ -61,7 +61,7 @@ class Chef
def action_cancel
converge_by("cancel any existing end-of-run reboot request") do
- Chef::Log.warn "Reboot canceled: '#{@new_resource.name}'"
+ Chef::Log.warn "Reboot canceled: '#{new_resource.name}'"
node.run_context.cancel_reboot
end
end
diff --git a/lib/chef/provider/registry_key.rb b/lib/chef/provider/registry_key.rb
index 58b0a19586..2443a3d184 100644
--- a/lib/chef/provider/registry_key.rb
+++ b/lib/chef/provider/registry_key.rb
@@ -2,7 +2,7 @@
# Author:: Prajakta Purohit (<prajakta@chef.io>)
# Author:: Lamont Granquist (<lamont@chef.io>)
#
-# Copyright:: Copyright 2011-2016, Chef Software Inc.
+# Copyright:: Copyright 2011-2017, Chef Software Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -47,19 +47,19 @@ class Chef
def load_current_resource
running_on_windows!
- @current_resource ||= Chef::Resource::RegistryKey.new(@new_resource.key, run_context)
- @current_resource.key(@new_resource.key)
- @current_resource.architecture(@new_resource.architecture)
- @current_resource.recursive(@new_resource.recursive)
- if registry.key_exists?(@new_resource.key)
- @current_resource.values(registry.get_values(@new_resource.key))
- end
- values_to_hash(@current_resource.unscrubbed_values)
- @current_resource
+ @current_resource ||= Chef::Resource::RegistryKey.new(new_resource.key, run_context)
+ current_resource.key(new_resource.key)
+ current_resource.architecture(new_resource.architecture)
+ current_resource.recursive(new_resource.recursive)
+ if registry.key_exists?(new_resource.key)
+ current_resource.values(registry.get_values(new_resource.key))
+ end
+ values_to_hash(current_resource.unscrubbed_values)
+ current_resource
end
def registry
- @registry ||= Chef::Win32::Registry.new(@run_context, @new_resource.architecture)
+ @registry ||= Chef::Win32::Registry.new(@run_context, new_resource.architecture)
end
def values_to_hash(values)
@@ -79,51 +79,51 @@ class Chef
def define_resource_requirements
requirements.assert(:create, :create_if_missing, :delete, :delete_key) do |a|
- a.assertion { registry.hive_exists?(@new_resource.key) }
- a.failure_message(Chef::Exceptions::Win32RegHiveMissing, "Hive #{@new_resource.key.split("\\").shift} does not exist")
+ a.assertion { registry.hive_exists?(new_resource.key) }
+ a.failure_message(Chef::Exceptions::Win32RegHiveMissing, "Hive #{new_resource.key.split("\\").shift} does not exist")
end
requirements.assert(:create) do |a|
- a.assertion { registry.key_exists?(@new_resource.key) }
- a.whyrun("Key #{@new_resource.key} does not exist. Unless it would have been created before, attempt to modify its values would fail.")
+ a.assertion { registry.key_exists?(new_resource.key) }
+ a.whyrun("Key #{new_resource.key} does not exist. Unless it would have been created before, attempt to modify its values would fail.")
end
requirements.assert(:create, :create_if_missing) do |a|
# If keys missing in the path and recursive == false
- a.assertion { !registry.keys_missing?(@current_resource.key) || @new_resource.recursive }
+ a.assertion { !registry.keys_missing?(current_resource.key) || new_resource.recursive }
a.failure_message(Chef::Exceptions::Win32RegNoRecursive, "Intermediate keys missing but recursive is set to false")
- a.whyrun("Intermediate keys in #{@new_resource.key} do not exist. Unless they would have been created earlier, attempt to modify them would fail.")
+ a.whyrun("Intermediate keys in #{new_resource.key} do not exist. Unless they would have been created earlier, attempt to modify them would fail.")
end
requirements.assert(:delete_key) do |a|
# If key to be deleted has subkeys but recurssive == false
- a.assertion { !registry.key_exists?(@new_resource.key) || !registry.has_subkeys?(@new_resource.key) || @new_resource.recursive }
- a.failure_message(Chef::Exceptions::Win32RegNoRecursive, "#{@new_resource.key} has subkeys but recursive is set to false.")
- a.whyrun("#{@current_resource.key} has subkeys, but recursive is set to false. attempt to delete would fails unless subkeys were deleted prior to this action.")
+ a.assertion { !registry.key_exists?(new_resource.key) || !registry.has_subkeys?(new_resource.key) || new_resource.recursive }
+ a.failure_message(Chef::Exceptions::Win32RegNoRecursive, "#{new_resource.key} has subkeys but recursive is set to false.")
+ a.whyrun("#{current_resource.key} has subkeys, but recursive is set to false. attempt to delete would fails unless subkeys were deleted prior to this action.")
end
requirements.assert(:create, :create_if_missing) do |a|
# If type key missing in the RegistryKey values hash
- a.assertion { !key_missing?(@new_resource.values, :type) }
+ a.assertion { !key_missing?(new_resource.values, :type) }
a.failure_message(Chef::Exceptions::RegKeyValuesTypeMissing, "Missing type key in RegistryKey values hash")
a.whyrun("Type key does not exist. Attempt would fail unless the complete values hash containing all the keys does not exist for registry_key resource's create action.")
end
requirements.assert(:create, :create_if_missing) do |a|
# If data key missing in the RegistryKey values hash
- a.assertion { !key_missing?(@new_resource.values, :data) }
+ a.assertion { !key_missing?(new_resource.values, :data) }
a.failure_message(Chef::Exceptions::RegKeyValuesDataMissing, "Missing data key in RegistryKey values hash")
a.whyrun("Data key does not exist. Attempt would fail unless the complete values hash containing all the keys does not exist for registry_key resource's create action.")
end
end
def action_create
- unless registry.key_exists?(@current_resource.key)
- converge_by("create key #{@new_resource.key}") do
- registry.create_key(@new_resource.key, @new_resource.recursive)
+ unless registry.key_exists?(current_resource.key)
+ converge_by("create key #{new_resource.key}") do
+ registry.create_key(new_resource.key, new_resource.recursive)
end
end
- @new_resource.unscrubbed_values.each do |value|
+ new_resource.unscrubbed_values.each do |value|
if @name_hash.has_key?(value[:name].downcase)
current_value = @name_hash[value[:name].downcase]
if [:dword, :dword_big_endian, :qword].include? value[:type]
@@ -131,38 +131,38 @@ class Chef
end
unless current_value[:type] == value[:type] && current_value[:data] == value[:data]
converge_by("set value #{value}") do
- registry.set_value(@new_resource.key, value)
+ registry.set_value(new_resource.key, value)
end
end
else
converge_by("set value #{value}") do
- registry.set_value(@new_resource.key, value)
+ registry.set_value(new_resource.key, value)
end
end
end
end
def action_create_if_missing
- unless registry.key_exists?(@new_resource.key)
- converge_by("create key #{@new_resource.key}") do
- registry.create_key(@new_resource.key, @new_resource.recursive)
+ unless registry.key_exists?(new_resource.key)
+ converge_by("create key #{new_resource.key}") do
+ registry.create_key(new_resource.key, new_resource.recursive)
end
end
- @new_resource.unscrubbed_values.each do |value|
+ new_resource.unscrubbed_values.each do |value|
unless @name_hash.has_key?(value[:name].downcase)
converge_by("create value #{value}") do
- registry.set_value(@new_resource.key, value)
+ registry.set_value(new_resource.key, value)
end
end
end
end
def action_delete
- if registry.key_exists?(@new_resource.key)
- @new_resource.unscrubbed_values.each do |value|
+ if registry.key_exists?(new_resource.key)
+ new_resource.unscrubbed_values.each do |value|
if @name_hash.has_key?(value[:name].downcase)
converge_by("delete value #{value}") do
- registry.delete_value(@new_resource.key, value)
+ registry.delete_value(new_resource.key, value)
end
end
end
@@ -170,9 +170,9 @@ class Chef
end
def action_delete_key
- if registry.key_exists?(@new_resource.key)
- converge_by("delete key #{@new_resource.key}") do
- registry.delete_key(@new_resource.key, @new_resource.recursive)
+ if registry.key_exists?(new_resource.key)
+ converge_by("delete key #{new_resource.key}") do
+ registry.delete_key(new_resource.key, new_resource.recursive)
end
end
end
diff --git a/lib/chef/provider/remote_directory.rb b/lib/chef/provider/remote_directory.rb
index 15b71c43bd..d2f90d233b 100644
--- a/lib/chef/provider/remote_directory.rb
+++ b/lib/chef/provider/remote_directory.rb
@@ -36,9 +36,9 @@ class Chef
provides :remote_directory
- def_delegators :@new_resource, :purge, :path, :source, :cookbook, :cookbook_name
- def_delegators :@new_resource, :files_rights, :files_mode, :files_group, :files_owner, :files_backup
- def_delegators :@new_resource, :rights, :mode, :group, :owner
+ def_delegators :new_resource, :purge, :path, :source, :cookbook, :cookbook_name
+ def_delegators :new_resource, :files_rights, :files_mode, :files_group, :files_owner, :files_backup
+ def_delegators :new_resource, :rights, :mode, :group, :owner
# The overwrite property on the resource. Delegates to new_resource but can be mutated.
#
diff --git a/lib/chef/provider/remote_file.rb b/lib/chef/provider/remote_file.rb
index 9207e62ac6..05e213e842 100644
--- a/lib/chef/provider/remote_file.rb
+++ b/lib/chef/provider/remote_file.rb
@@ -36,15 +36,15 @@ class Chef
end
def load_current_resource
- @current_resource = Chef::Resource::RemoteFile.new(@new_resource.name)
+ @current_resource = Chef::Resource::RemoteFile.new(new_resource.name)
super
end
private
def managing_content?
- return true if @new_resource.checksum
- return true if !@new_resource.source.nil? && @action != :create_if_missing
+ return true if new_resource.checksum
+ return true if !new_resource.source.nil? && @action != :create_if_missing
false
end
diff --git a/lib/chef/provider/ruby_block.rb b/lib/chef/provider/ruby_block.rb
index 18ee9cecc5..c44b776661 100644
--- a/lib/chef/provider/ruby_block.rb
+++ b/lib/chef/provider/ruby_block.rb
@@ -31,9 +31,9 @@ class Chef
end
def action_run
- converge_by("execute the ruby block #{@new_resource.name}") do
- @new_resource.block.call
- Chef::Log.info("#{@new_resource} called")
+ converge_by("execute the ruby block #{new_resource.name}") do
+ new_resource.block.call
+ Chef::Log.info("#{new_resource} called")
end
end
diff --git a/lib/chef/provider/script.rb b/lib/chef/provider/script.rb
index fca9cea467..4046b7c0dd 100644
--- a/lib/chef/provider/script.rb
+++ b/lib/chef/provider/script.rb
@@ -34,7 +34,7 @@ class Chef
provides :ruby
provides :script
- def_delegators :@new_resource, :interpreter, :flags
+ def_delegators :new_resource, :interpreter, :flags
attr_accessor :code
@@ -51,7 +51,7 @@ class Chef
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"
+ 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
diff --git a/lib/chef/provider/service.rb b/lib/chef/provider/service.rb
index e048b2e43b..2f08697ed7 100644
--- a/lib/chef/provider/service.rb
+++ b/lib/chef/provider/service.rb
@@ -51,21 +51,21 @@ class Chef
# XXX?: the #nil? check below will likely fail if this is a cloned resource or if
# we just run multiple actions.
def load_new_resource_state
- if @new_resource.enabled.nil?
- @new_resource.enabled(@current_resource.enabled)
+ if new_resource.enabled.nil?
+ new_resource.enabled(current_resource.enabled)
end
- if @new_resource.running.nil?
- @new_resource.running(@current_resource.running)
+ if new_resource.running.nil?
+ new_resource.running(current_resource.running)
end
- if @new_resource.masked.nil?
- @new_resource.masked(@current_resource.masked)
+ if new_resource.masked.nil?
+ new_resource.masked(current_resource.masked)
end
end
# subclasses should override this if they do implement user services
def user_services_requirements
requirements.assert(:all_actions) do |a|
- a.assertion { @new_resource.user.nil? }
+ a.assertion { new_resource.user.nil? }
a.failure_message Chef::Exceptions::UnsupportedAction, "#{self} does not support user services"
end
end
@@ -76,7 +76,7 @@ class Chef
def define_resource_requirements
requirements.assert(:reload) do |a|
- a.assertion { supports[:reload] || @new_resource.reload_command }
+ a.assertion { supports[:reload] || new_resource.reload_command }
a.failure_message Chef::Exceptions::UnsupportedAction, "#{self} does not support :reload"
# if a service is not declared to support reload, that won't
# typically change during the course of a run - so no whyrun
@@ -85,97 +85,97 @@ class Chef
end
def action_enable
- if @current_resource.enabled
- Chef::Log.debug("#{@new_resource} already enabled - nothing to do")
+ if current_resource.enabled
+ Chef::Log.debug("#{new_resource} already enabled - nothing to do")
else
- converge_by("enable service #{@new_resource}") do
+ converge_by("enable service #{new_resource}") do
enable_service
- Chef::Log.info("#{@new_resource} enabled")
+ Chef::Log.info("#{new_resource} enabled")
end
end
load_new_resource_state
- @new_resource.enabled(true)
+ new_resource.enabled(true)
end
def action_disable
- if @current_resource.enabled
- converge_by("disable service #{@new_resource}") do
+ if current_resource.enabled
+ converge_by("disable service #{new_resource}") do
disable_service
- Chef::Log.info("#{@new_resource} disabled")
+ Chef::Log.info("#{new_resource} disabled")
end
else
- Chef::Log.debug("#{@new_resource} already disabled - nothing to do")
+ Chef::Log.debug("#{new_resource} already disabled - nothing to do")
end
load_new_resource_state
- @new_resource.enabled(false)
+ new_resource.enabled(false)
end
def action_mask
- if @current_resource.masked
- Chef::Log.debug("#{@new_resource} already masked - nothing to do")
+ if current_resource.masked
+ Chef::Log.debug("#{new_resource} already masked - nothing to do")
else
- converge_by("mask service #{@new_resource}") do
+ converge_by("mask service #{new_resource}") do
mask_service
- Chef::Log.info("#{@new_resource} masked")
+ Chef::Log.info("#{new_resource} masked")
end
end
load_new_resource_state
- @new_resource.masked(true)
+ new_resource.masked(true)
end
def action_unmask
- if @current_resource.masked
- converge_by("unmask service #{@new_resource}") do
+ if current_resource.masked
+ converge_by("unmask service #{new_resource}") do
unmask_service
- Chef::Log.info("#{@new_resource} unmasked")
+ Chef::Log.info("#{new_resource} unmasked")
end
else
- Chef::Log.debug("#{@new_resource} already unmasked - nothing to do")
+ Chef::Log.debug("#{new_resource} already unmasked - nothing to do")
end
load_new_resource_state
- @new_resource.masked(false)
+ new_resource.masked(false)
end
def action_start
- unless @current_resource.running
- converge_by("start service #{@new_resource}") do
+ unless current_resource.running
+ converge_by("start service #{new_resource}") do
start_service
- Chef::Log.info("#{@new_resource} started")
+ Chef::Log.info("#{new_resource} started")
end
else
- Chef::Log.debug("#{@new_resource} already running - nothing to do")
+ Chef::Log.debug("#{new_resource} already running - nothing to do")
end
load_new_resource_state
- @new_resource.running(true)
+ new_resource.running(true)
end
def action_stop
- if @current_resource.running
- converge_by("stop service #{@new_resource}") do
+ if current_resource.running
+ converge_by("stop service #{new_resource}") do
stop_service
- Chef::Log.info("#{@new_resource} stopped")
+ Chef::Log.info("#{new_resource} stopped")
end
else
- Chef::Log.debug("#{@new_resource} already stopped - nothing to do")
+ Chef::Log.debug("#{new_resource} already stopped - nothing to do")
end
load_new_resource_state
- @new_resource.running(false)
+ new_resource.running(false)
end
def action_restart
- converge_by("restart service #{@new_resource}") do
+ converge_by("restart service #{new_resource}") do
restart_service
- Chef::Log.info("#{@new_resource} restarted")
+ Chef::Log.info("#{new_resource} restarted")
end
load_new_resource_state
- @new_resource.running(true)
+ new_resource.running(true)
end
def action_reload
- if @current_resource.running
- converge_by("reload service #{@new_resource}") do
+ if current_resource.running
+ converge_by("reload service #{new_resource}") do
reload_service
- Chef::Log.info("#{@new_resource} reloaded")
+ Chef::Log.info("#{new_resource} reloaded")
end
end
load_new_resource_state
@@ -216,8 +216,8 @@ class Chef
protected
def default_init_command
- if @new_resource.init_command
- @new_resource.init_command
+ if new_resource.init_command
+ new_resource.init_command
elsif instance_variable_defined?(:@init_command)
@init_command
end
@@ -225,8 +225,8 @@ class Chef
def custom_command_for_action?(action)
method_name = "#{action}_command".to_sym
- @new_resource.respond_to?(method_name) &&
- !!@new_resource.send(method_name)
+ new_resource.respond_to?(method_name) &&
+ !!new_resource.send(method_name)
end
module ServicePriorityInit
diff --git a/lib/chef/provider/subversion.rb b/lib/chef/provider/subversion.rb
index ea32283bc9..ee8ea7c495 100644
--- a/lib/chef/provider/subversion.rb
+++ b/lib/chef/provider/subversion.rb
@@ -40,11 +40,11 @@ class Chef
end
def load_current_resource
- @current_resource = Chef::Resource::Subversion.new(@new_resource.name)
+ @current_resource = Chef::Resource::Subversion.new(new_resource.name)
- unless [:export, :force_export].include?(Array(@new_resource.action).first)
+ unless [:export, :force_export].include?(Array(new_resource.action).first)
if current_revision = find_current_revision
- @current_resource.revision current_revision
+ current_resource.revision current_revision
end
end
end
@@ -53,21 +53,21 @@ class Chef
requirements.assert(:all_actions) do |a|
# Make sure the parent dir exists, or else fail.
# for why run, print a message explaining the potential error.
- parent_directory = ::File.dirname(@new_resource.destination)
+ parent_directory = ::File.dirname(new_resource.destination)
a.assertion { ::File.directory?(parent_directory) }
a.failure_message(Chef::Exceptions::MissingParentDirectory,
- "Cannot clone #{@new_resource} to #{@new_resource.destination}, the enclosing directory #{parent_directory} does not exist")
+ "Cannot clone #{new_resource} to #{new_resource.destination}, the enclosing directory #{parent_directory} does not exist")
a.whyrun("Directory #{parent_directory} does not exist, assuming it would have been created")
end
end
def action_checkout
if target_dir_non_existent_or_empty?
- converge_by("perform checkout of #{@new_resource.repository} into #{@new_resource.destination}") do
+ converge_by("perform checkout of #{new_resource.repository} into #{new_resource.destination}") do
shell_out!(checkout_command, run_options)
end
else
- Chef::Log.debug "#{@new_resource} checkout destination #{@new_resource.destination} already exists or is a non-empty directory - nothing to do"
+ Chef::Log.debug "#{new_resource} checkout destination #{new_resource.destination} already exists or is a non-empty directory - nothing to do"
end
end
@@ -75,25 +75,25 @@ class Chef
if target_dir_non_existent_or_empty?
action_force_export
else
- Chef::Log.debug "#{@new_resource} export destination #{@new_resource.destination} already exists or is a non-empty directory - nothing to do"
+ Chef::Log.debug "#{new_resource} export destination #{new_resource.destination} already exists or is a non-empty directory - nothing to do"
end
end
def action_force_export
- converge_by("export #{@new_resource.repository} into #{@new_resource.destination}") do
+ converge_by("export #{new_resource.repository} into #{new_resource.destination}") do
shell_out!(export_command, run_options)
end
end
def action_sync
assert_target_directory_valid!
- if ::File.exist?(::File.join(@new_resource.destination, ".svn"))
+ if ::File.exist?(::File.join(new_resource.destination, ".svn"))
current_rev = find_current_revision
- Chef::Log.debug "#{@new_resource} current revision: #{current_rev} target revision: #{revision_int}"
+ Chef::Log.debug "#{new_resource} current revision: #{current_rev} target revision: #{revision_int}"
unless current_revision_matches_target_revision?
- converge_by("sync #{@new_resource.destination} from #{@new_resource.repository}") do
+ converge_by("sync #{new_resource.destination} from #{new_resource.repository}") do
shell_out!(sync_command, run_options)
- Chef::Log.info "#{@new_resource} updated to revision: #{revision_int}"
+ Chef::Log.info "#{new_resource} updated to revision: #{revision_int}"
end
end
else
@@ -102,24 +102,24 @@ class Chef
end
def sync_command
- c = scm :update, @new_resource.svn_arguments, verbose, authentication, proxy, "-r#{revision_int}", @new_resource.destination
- Chef::Log.debug "#{@new_resource} updated working copy #{@new_resource.destination} to revision #{@new_resource.revision}"
+ c = scm :update, new_resource.svn_arguments, verbose, authentication, proxy, "-r#{revision_int}", new_resource.destination
+ Chef::Log.debug "#{new_resource} updated working copy #{new_resource.destination} to revision #{new_resource.revision}"
c
end
def checkout_command
- c = scm :checkout, @new_resource.svn_arguments, verbose, authentication, proxy,
- "-r#{revision_int}", @new_resource.repository, @new_resource.destination
- Chef::Log.info "#{@new_resource} checked out #{@new_resource.repository} at revision #{@new_resource.revision} to #{@new_resource.destination}"
+ c = scm :checkout, new_resource.svn_arguments, verbose, authentication, proxy,
+ "-r#{revision_int}", new_resource.repository, new_resource.destination
+ Chef::Log.info "#{new_resource} checked out #{new_resource.repository} at revision #{new_resource.revision} to #{new_resource.destination}"
c
end
def export_command
args = ["--force"]
- args << @new_resource.svn_arguments << verbose << authentication << proxy <<
- "-r#{revision_int}" << @new_resource.repository << @new_resource.destination
+ args << new_resource.svn_arguments << verbose << authentication << proxy <<
+ "-r#{revision_int}" << new_resource.repository << new_resource.destination
c = scm :export, *args
- Chef::Log.info "#{@new_resource} exported #{@new_resource.repository} at revision #{@new_resource.revision} to #{@new_resource.destination}"
+ Chef::Log.info "#{new_resource} exported #{new_resource.repository} at revision #{new_resource.revision} to #{new_resource.destination}"
c
end
@@ -128,10 +128,10 @@ class Chef
# If the specified revision is an integer, trust it.
def revision_int
@revision_int ||= begin
- if @new_resource.revision =~ /^\d+$/
- @new_resource.revision
+ if new_resource.revision =~ /^\d+$/
+ new_resource.revision
else
- command = scm(:info, @new_resource.repository, @new_resource.svn_info_args, authentication, "-r#{@new_resource.revision}")
+ command = scm(:info, new_resource.repository, new_resource.svn_info_args, authentication, "-r#{new_resource.revision}")
svn_info = shell_out!(command, run_options(:cwd => cwd, :returns => [0, 1])).stdout
extract_revision_info(svn_info)
@@ -142,7 +142,7 @@ class Chef
alias :revision_slug :revision_int
def find_current_revision
- return nil unless ::File.exist?(::File.join(@new_resource.destination, ".svn"))
+ return nil unless ::File.exist?(::File.join(new_resource.destination, ".svn"))
command = scm(:info)
svn_info = shell_out!(command, run_options(:cwd => cwd, :returns => [0, 1])).stdout
@@ -150,20 +150,20 @@ class Chef
end
def current_revision_matches_target_revision?
- (!@current_resource.revision.nil?) && (revision_int.strip.to_i == @current_resource.revision.strip.to_i)
+ (!current_resource.revision.nil?) && (revision_int.strip.to_i == current_resource.revision.strip.to_i)
end
def run_options(run_opts = {})
- run_opts[:user] = @new_resource.user if @new_resource.user
- run_opts[:group] = @new_resource.group if @new_resource.group
- run_opts[:timeout] = @new_resource.timeout if @new_resource.timeout
+ run_opts[:user] = new_resource.user if new_resource.user
+ run_opts[:group] = new_resource.group if new_resource.group
+ run_opts[:timeout] = new_resource.timeout if new_resource.timeout
run_opts
end
private
def cwd
- @new_resource.destination
+ new_resource.destination
end
def verbose
@@ -181,7 +181,7 @@ class Chef
rev = (repo_attrs["Last Changed Rev"] || repo_attrs["Revision"])
rev.strip! if rev
raise "Could not parse `svn info` data: #{svn_info}" if repo_attrs.empty?
- Chef::Log.debug "#{@new_resource} resolved revision #{@new_resource.revision} to #{rev}"
+ Chef::Log.debug "#{new_resource} resolved revision #{new_resource.revision} to #{rev}"
rev
end
@@ -190,14 +190,14 @@ class Chef
# switch, since Capistrano will check for that prompt in the output
# and will respond appropriately.
def authentication
- return "" unless @new_resource.svn_username
- result = "--username #{@new_resource.svn_username} "
- result << "--password #{@new_resource.svn_password} "
+ return "" unless new_resource.svn_username
+ result = "--username #{new_resource.svn_username} "
+ result << "--password #{new_resource.svn_password} "
result
end
def proxy
- repo_uri = URI.parse(@new_resource.repository)
+ repo_uri = URI.parse(new_resource.repository)
proxy_uri = Chef::Config.proxy_uri(repo_uri.scheme, repo_uri.host, repo_uri.port)
return "" if proxy_uri.nil?
@@ -213,18 +213,18 @@ class Chef
end
def target_dir_non_existent_or_empty?
- !::File.exist?(@new_resource.destination) || Dir.entries(@new_resource.destination).sort == [".", ".."]
+ !::File.exist?(new_resource.destination) || Dir.entries(new_resource.destination).sort == [".", ".."]
end
def svn_binary
- @new_resource.svn_binary ||
+ new_resource.svn_binary ||
(Chef::Platform.windows? ? "svn.exe" : "svn")
end
def assert_target_directory_valid!
- target_parent_directory = ::File.dirname(@new_resource.destination)
+ target_parent_directory = ::File.dirname(new_resource.destination)
unless ::File.directory?(target_parent_directory)
- msg = "Cannot clone #{@new_resource} to #{@new_resource.destination}, the enclosing directory #{target_parent_directory} does not exist"
+ msg = "Cannot clone #{new_resource} to #{new_resource.destination}, the enclosing directory #{target_parent_directory} does not exist"
raise Chef::Exceptions::MissingParentDirectory, msg
end
end
diff --git a/lib/chef/provider/template.rb b/lib/chef/provider/template.rb
index 3c46a6eb7d..7cb0ba008d 100644
--- a/lib/chef/provider/template.rb
+++ b/lib/chef/provider/template.rb
@@ -37,7 +37,7 @@ class Chef
end
def load_current_resource
- @current_resource = Chef::Resource::Template.new(@new_resource.name)
+ @current_resource = Chef::Resource::Template.new(new_resource.name)
super
end
@@ -55,8 +55,8 @@ class Chef
private
def managing_content?
- return true if @new_resource.checksum
- return true if !@new_resource.source.nil? && @action != :create_if_missing
+ return true if new_resource.checksum
+ return true if !new_resource.source.nil? && @action != :create_if_missing
false
end
diff --git a/lib/chef/provider/user.rb b/lib/chef/provider/user.rb
index de94871a87..c44adbf818 100644
--- a/lib/chef/provider/user.rb
+++ b/lib/chef/provider/user.rb
@@ -36,8 +36,8 @@ class Chef
end
def convert_group_name
- if @new_resource.gid.is_a? String
- @new_resource.gid(Etc.getgrnam(@new_resource.gid).gid)
+ if new_resource.gid.is_a? String
+ new_resource.gid(Etc.getgrnam(new_resource.gid).gid)
end
rescue ArgumentError
@group_name_resolved = false
@@ -48,51 +48,51 @@ class Chef
end
def load_current_resource
- @current_resource = Chef::Resource::User.new(@new_resource.name)
- @current_resource.username(@new_resource.username)
+ @current_resource = Chef::Resource::User.new(new_resource.name)
+ current_resource.username(new_resource.username)
begin
- user_info = Etc.getpwnam(@new_resource.username)
+ user_info = Etc.getpwnam(new_resource.username)
rescue ArgumentError
@user_exists = false
- Chef::Log.debug("#{@new_resource} user does not exist")
+ Chef::Log.debug("#{new_resource} user does not exist")
user_info = nil
end
if user_info
- @current_resource.uid(user_info.uid)
- @current_resource.gid(user_info.gid)
- @current_resource.home(user_info.dir)
- @current_resource.shell(user_info.shell)
- @current_resource.password(user_info.passwd)
-
- if @new_resource.comment
- user_info.gecos.force_encoding(@new_resource.comment.encoding)
+ current_resource.uid(user_info.uid)
+ current_resource.gid(user_info.gid)
+ current_resource.home(user_info.dir)
+ current_resource.shell(user_info.shell)
+ current_resource.password(user_info.passwd)
+
+ if new_resource.comment
+ user_info.gecos.force_encoding(new_resource.comment.encoding)
end
- @current_resource.comment(user_info.gecos)
+ current_resource.comment(user_info.gecos)
- if @new_resource.password && @current_resource.password == "x"
+ if new_resource.password && current_resource.password == "x"
begin
require "shadow"
rescue LoadError
@shadow_lib_ok = false
else
- shadow_info = Shadow::Passwd.getspnam(@new_resource.username)
- @current_resource.password(shadow_info.sp_pwdp)
+ shadow_info = Shadow::Passwd.getspnam(new_resource.username)
+ current_resource.password(shadow_info.sp_pwdp)
end
end
- convert_group_name if @new_resource.gid
+ convert_group_name if new_resource.gid
end
- @current_resource
+ current_resource
end
def define_resource_requirements
requirements.assert(:create, :modify, :manage, :lock, :unlock) do |a|
a.assertion { @group_name_resolved }
- a.failure_message Chef::Exceptions::User, "Couldn't lookup integer GID for group name #{@new_resource.gid}"
- a.whyrun "group name #{@new_resource.gid} does not exist. This will cause group assignment to fail. Assuming this group will have been created previously."
+ a.failure_message Chef::Exceptions::User, "Couldn't lookup integer GID for group name #{new_resource.gid}"
+ a.whyrun "group name #{new_resource.gid} does not exist. This will cause group assignment to fail. Assuming this group will have been created previously."
end
requirements.assert(:all_actions) do |a|
a.assertion { @shadow_lib_ok }
@@ -102,8 +102,8 @@ class Chef
end
requirements.assert(:modify, :lock, :unlock) do |a|
a.assertion { @user_exists }
- a.failure_message(Chef::Exceptions::User, "Cannot modify user #{@new_resource.username} - does not exist!")
- a.whyrun("Assuming user #{@new_resource.username} would have been created")
+ a.failure_message(Chef::Exceptions::User, "Cannot modify user #{new_resource.username} - does not exist!")
+ a.whyrun("Assuming user #{new_resource.username} would have been created")
end
end
@@ -113,10 +113,10 @@ class Chef
# <true>:: If a change is required
# <false>:: If the users are identical
def compare_user
- return true if !@new_resource.home.nil? && Pathname.new(@new_resource.home).cleanpath != Pathname.new(@current_resource.home).cleanpath
+ return true if !new_resource.home.nil? && Pathname.new(new_resource.home).cleanpath != Pathname.new(current_resource.home).cleanpath
[ :comment, :shell, :password, :uid, :gid ].each do |user_attrib|
- return true if !@new_resource.send(user_attrib).nil? && @new_resource.send(user_attrib).to_s != @current_resource.send(user_attrib).to_s
+ return true if !new_resource.send(user_attrib).nil? && new_resource.send(user_attrib).to_s != current_resource.send(user_attrib).to_s
end
false
@@ -124,61 +124,61 @@ class Chef
def action_create
if !@user_exists
- converge_by("create user #{@new_resource.username}") do
+ converge_by("create user #{new_resource.username}") do
create_user
- Chef::Log.info("#{@new_resource} created")
+ Chef::Log.info("#{new_resource} created")
end
elsif compare_user
- converge_by("alter user #{@new_resource.username}") do
+ converge_by("alter user #{new_resource.username}") do
manage_user
- Chef::Log.info("#{@new_resource} altered")
+ Chef::Log.info("#{new_resource} altered")
end
end
end
def action_remove
return unless @user_exists
- converge_by("remove user #{@new_resource.username}") do
+ converge_by("remove user #{new_resource.username}") do
remove_user
- Chef::Log.info("#{@new_resource} removed")
+ Chef::Log.info("#{new_resource} removed")
end
end
def action_manage
return unless @user_exists && compare_user
- converge_by("manage user #{@new_resource.username}") do
+ converge_by("manage user #{new_resource.username}") do
manage_user
- Chef::Log.info("#{@new_resource} managed")
+ Chef::Log.info("#{new_resource} managed")
end
end
def action_modify
return unless compare_user
- converge_by("modify user #{@new_resource.username}") do
+ converge_by("modify user #{new_resource.username}") do
manage_user
- Chef::Log.info("#{@new_resource} modified")
+ Chef::Log.info("#{new_resource} modified")
end
end
def action_lock
if check_lock == false
- converge_by("lock the user #{@new_resource.username}") do
+ converge_by("lock the user #{new_resource.username}") do
lock_user
- Chef::Log.info("#{@new_resource} locked")
+ Chef::Log.info("#{new_resource} locked")
end
else
- Chef::Log.debug("#{@new_resource} already locked - nothing to do")
+ Chef::Log.debug("#{new_resource} already locked - nothing to do")
end
end
def action_unlock
if check_lock == true
- converge_by("unlock user #{@new_resource.username}") do
+ converge_by("unlock user #{new_resource.username}") do
unlock_user
- Chef::Log.info("#{@new_resource} unlocked")
+ Chef::Log.info("#{new_resource} unlocked")
end
else
- Chef::Log.debug("#{@new_resource} already unlocked - nothing to do")
+ Chef::Log.debug("#{new_resource} already unlocked - nothing to do")
end
end
diff --git a/lib/chef/provider/whyrun_safe_ruby_block.rb b/lib/chef/provider/whyrun_safe_ruby_block.rb
index 3ea48017b7..6e43dd4766 100644
--- a/lib/chef/provider/whyrun_safe_ruby_block.rb
+++ b/lib/chef/provider/whyrun_safe_ruby_block.rb
@@ -22,10 +22,10 @@ class Chef
provides :whyrun_safe_ruby_block
def action_run
- @new_resource.block.call
- @new_resource.updated_by_last_action(true)
- @run_context.events.resource_update_applied(@new_resource, :create, "execute the whyrun_safe_ruby_block #{@new_resource.name}")
- Chef::Log.info("#{@new_resource} called")
+ new_resource.block.call
+ new_resource.updated_by_last_action(true)
+ @run_context.events.resource_update_applied(new_resource, :create, "execute the whyrun_safe_ruby_block #{new_resource.name}")
+ Chef::Log.info("#{new_resource} called")
end
end
end
diff --git a/lib/chef/version.rb b/lib/chef/version.rb
index a7f9b8061a..9ca321b634 100644
--- a/lib/chef/version.rb
+++ b/lib/chef/version.rb
@@ -21,7 +21,7 @@
class Chef
CHEF_ROOT = File.expand_path("../..", __FILE__)
- VERSION = "12.19.30"
+ VERSION = "12.19.33"
end
#