summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore15
-rw-r--r--.rubocop.yml4
-rw-r--r--.travis.yml5
-rw-r--r--CHANGELOG.md1
-rw-r--r--Gemfile3
-rw-r--r--README.md2
-rw-r--r--Rakefile7
-rw-r--r--ci/jenkins_run_tests.bat14
-rwxr-xr-xci/jenkins_run_tests.sh13
-rwxr-xr-xci/verify-chef.bat56
-rwxr-xr-xci/verify-chef.sh89
-rw-r--r--lib/chef/api_client/registration.rb4
-rw-r--r--lib/chef/application.rb6
-rw-r--r--lib/chef/application/windows_service.rb4
-rw-r--r--lib/chef/audit/audit_reporter.rb4
-rw-r--r--lib/chef/chef_fs/file_system/chef_server_root_dir.rb2
-rw-r--r--lib/chef/client.rb9
-rw-r--r--lib/chef/cookbook/remote_file_vendor.rb2
-rw-r--r--lib/chef/cookbook/synchronizer.rb5
-rw-r--r--lib/chef/cookbook_loader.rb2
-rw-r--r--lib/chef/cookbook_uploader.rb5
-rw-r--r--lib/chef/cookbook_version.rb30
-rw-r--r--lib/chef/data_bag.rb19
-rw-r--r--lib/chef/data_bag_item.rb36
-rw-r--r--lib/chef/environment.rb23
-rw-r--r--lib/chef/formatters/minimal.rb2
-rw-r--r--lib/chef/guard_interpreter/resource_guard_interpreter.rb2
-rw-r--r--lib/chef/http.rb2
-rw-r--r--lib/chef/http/http_request.rb2
-rw-r--r--lib/chef/http/simple.rb18
-rw-r--r--lib/chef/http/simple_json.rb43
-rw-r--r--lib/chef/key.rb21
-rw-r--r--lib/chef/knife.rb14
-rw-r--r--lib/chef/knife/bootstrap/client_builder.rb12
-rw-r--r--lib/chef/knife/cookbook_bulk_delete.rb4
-rw-r--r--lib/chef/knife/cookbook_delete.rb4
-rw-r--r--lib/chef/knife/cookbook_download.rb5
-rw-r--r--lib/chef/knife/cookbook_list.rb2
-rw-r--r--lib/chef/knife/cookbook_show.rb10
-rw-r--r--lib/chef/knife/cookbook_site_download.rb6
-rw-r--r--lib/chef/knife/cookbook_site_list.rb2
-rw-r--r--lib/chef/knife/cookbook_site_search.rb2
-rw-r--r--lib/chef/knife/cookbook_site_share.rb2
-rw-r--r--lib/chef/knife/cookbook_site_show.rb6
-rw-r--r--lib/chef/knife/cookbook_site_unshare.rb2
-rw-r--r--lib/chef/knife/data_bag_create.rb4
-rw-r--r--lib/chef/knife/data_bag_delete.rb4
-rw-r--r--lib/chef/knife/data_bag_edit.rb2
-rw-r--r--lib/chef/knife/environment_compare.rb2
-rw-r--r--lib/chef/knife/index_rebuild.rb4
-rw-r--r--lib/chef/knife/raw.rb1
-rw-r--r--lib/chef/knife/recipe_list.rb2
-rw-r--r--lib/chef/knife/status.rb4
-rw-r--r--lib/chef/mixin/securable.rb2
-rw-r--r--lib/chef/node.rb36
-rw-r--r--lib/chef/org.rb20
-rw-r--r--lib/chef/platform/provider_mapping.rb2
-rw-r--r--lib/chef/policy_builder/dynamic.rb1
-rw-r--r--lib/chef/policy_builder/expand_node_object.rb11
-rw-r--r--lib/chef/policy_builder/policyfile.rb4
-rw-r--r--lib/chef/provider.rb6
-rw-r--r--lib/chef/provider/deploy.rb2
-rw-r--r--lib/chef/provider/dsc_resource.rb2
-rw-r--r--lib/chef/provider/dsc_script.rb2
-rw-r--r--lib/chef/provider/env.rb6
-rw-r--r--lib/chef/provider/group/aix.rb2
-rw-r--r--lib/chef/provider/group/groupadd.rb8
-rw-r--r--lib/chef/provider/group/usermod.rb8
-rw-r--r--lib/chef/provider/link.rb2
-rw-r--r--lib/chef/provider/mount.rb14
-rw-r--r--lib/chef/provider/osx_profile.rb2
-rw-r--r--lib/chef/provider/package.rb12
-rw-r--r--lib/chef/provider/package/chocolatey.rb246
-rw-r--r--lib/chef/provider/package/rubygems.rb4
-rw-r--r--lib/chef/provider/package/windows.rb2
-rw-r--r--lib/chef/provider/package/windows/exe.rb14
-rw-r--r--lib/chef/provider/remote_file/content.rb2
-rw-r--r--lib/chef/provider/service.rb14
-rw-r--r--lib/chef/provider/service/macosx.rb2
-rw-r--r--lib/chef/provider/service/simple.rb8
-rw-r--r--lib/chef/provider/service/windows.rb69
-rw-r--r--lib/chef/providers.rb3
-rw-r--r--lib/chef/resource.rb4
-rw-r--r--lib/chef/resource/chocolatey_package.rb39
-rw-r--r--lib/chef/resource/cron.rb2
-rw-r--r--lib/chef/resource/dsc_resource.rb240
-rw-r--r--lib/chef/resource/file/verification.rb2
-rw-r--r--lib/chef/resource/windows_script.rb2
-rw-r--r--lib/chef/resource_definition.rb2
-rw-r--r--lib/chef/resource_reporter.rb7
-rw-r--r--lib/chef/resources.rb3
-rw-r--r--lib/chef/role.rb28
-rw-r--r--lib/chef/run_list/run_list_expansion.rb8
-rw-r--r--lib/chef/search/query.rb22
-rw-r--r--lib/chef/server_api.rb26
-rw-r--r--lib/chef/shell/ext.rb6
-rw-r--r--lib/chef/shell/shell_rest.rb28
-rw-r--r--lib/chef/shell/shell_session.rb5
-rw-r--r--lib/chef/user_v1.rb6
-rw-r--r--lib/chef/util/dsc/configuration_generator.rb2
-rw-r--r--lib/chef/util/powershell/cmdlet.rb6
-rw-r--r--lib/chef/version/platform.rb2
-rw-r--r--lib/chef/version_class.rb2
-rw-r--r--lib/chef/version_constraint.rb2
-rw-r--r--lib/chef/win32/api.rb7
-rw-r--r--lib/chef/win32/api/security.rb38
-rw-r--r--lib/chef/win32/error.rb3
-rw-r--r--lib/chef/win32/security.rb63
-rw-r--r--omnibus/.gitignore11
-rw-r--r--omnibus/.kitchen.local.yml.vmware.example6
-rw-r--r--omnibus/.kitchen.yml111
-rw-r--r--omnibus/Berksfile12
-rw-r--r--omnibus/Berksfile.lock30
-rw-r--r--omnibus/Gemfile18
-rw-r--r--omnibus/Gemfile.lock203
-rw-r--r--omnibus/README.md144
-rw-r--r--omnibus/config/projects/angrychef.rb41
-rw-r--r--omnibus/config/projects/chef-fips.rb48
-rw-r--r--omnibus/config/projects/chef.rb86
-rw-r--r--omnibus/files/mapfiles/solaris19
-rw-r--r--omnibus/files/openssl-customization/windows/ssl_env_hack.rb34
-rw-r--r--omnibus/omnibus.rb54
-rwxr-xr-xomnibus/package-scripts/angrychef/postinst115
-rwxr-xr-xomnibus/package-scripts/angrychef/postrm42
-rwxr-xr-xomnibus/package-scripts/chef-fips/postinst115
-rwxr-xr-xomnibus/package-scripts/chef-fips/postrm42
-rwxr-xr-xomnibus/package-scripts/chef/postinst115
-rwxr-xr-xomnibus/package-scripts/chef/postrm42
-rw-r--r--omnibus/resources/chef/dmg/background.pngbin0 -> 44066 bytes
-rw-r--r--omnibus/resources/chef/dmg/icon.pngbin0 -> 280172 bytes
-rw-r--r--omnibus/resources/chef/msi/assets/LICENSE.rtf197
-rw-r--r--omnibus/resources/chef/msi/assets/banner_background.bmpbin0 -> 114432 bytes
-rw-r--r--omnibus/resources/chef/msi/assets/dialog_background.bmpbin0 -> 615320 bytes
-rw-r--r--omnibus/resources/chef/msi/assets/oc.icobin0 -> 41880 bytes
-rw-r--r--omnibus/resources/chef/msi/assets/oc_16x16.icobin0 -> 1286 bytes
-rw-r--r--omnibus/resources/chef/msi/assets/oc_32x32.icobin0 -> 4682 bytes
-rw-r--r--omnibus/resources/chef/msi/localization-en-us.wxl.erb30
-rw-r--r--omnibus/resources/chef/msi/parameters.wxi.erb9
-rw-r--r--omnibus/resources/chef/msi/source.wxs.erb171
-rw-r--r--omnibus/resources/chef/pkg/background.pngbin0 -> 55731 bytes
-rw-r--r--omnibus/resources/chef/pkg/license.html.erb202
-rw-r--r--omnibus/resources/chef/pkg/welcome.html.erb5
-rw-r--r--spec/functional/file_content_management/deploy_strategies_spec.rb2
-rwxr-xr-xspec/functional/resource/aixinit_service_spec.rb2
-rw-r--r--spec/functional/resource/dsc_script_spec.rb4
-rw-r--r--spec/functional/resource/mount_spec.rb28
-rw-r--r--spec/functional/resource/powershell_script_spec.rb2
-rw-r--r--spec/functional/resource/registry_spec.rb2
-rw-r--r--spec/functional/resource/windows_package_spec.rb15
-rw-r--r--spec/functional/resource/windows_service_spec.rb7
-rw-r--r--spec/functional/tiny_server_spec.rb4
-rw-r--r--spec/integration/knife/diff_spec.rb4
-rw-r--r--spec/support/shared/context/client.rb20
-rw-r--r--spec/support/shared/unit/file_system_support.rb2
-rw-r--r--spec/unit/api_client_spec.rb2
-rw-r--r--spec/unit/audit/audit_reporter_spec.rb9
-rw-r--r--spec/unit/client_spec.rb18
-rw-r--r--spec/unit/cookbook/file_vendor_spec.rb2
-rw-r--r--spec/unit/cookbook/metadata_spec.rb14
-rw-r--r--spec/unit/cookbook/synchronizer_spec.rb43
-rw-r--r--spec/unit/cookbook_loader_spec.rb2
-rw-r--r--spec/unit/cookbook_uploader_spec.rb6
-rw-r--r--spec/unit/data_bag_item_spec.rb28
-rw-r--r--spec/unit/data_bag_spec.rb20
-rw-r--r--spec/unit/encrypted_data_bag_item_spec.rb2
-rw-r--r--spec/unit/environment_spec.rb6
-rw-r--r--spec/unit/key_spec.rb28
-rw-r--r--spec/unit/knife/bootstrap/client_builder_spec.rb26
-rw-r--r--spec/unit/knife/configure_spec.rb2
-rw-r--r--spec/unit/knife/cookbook_bulk_delete_spec.rb16
-rw-r--r--spec/unit/knife/cookbook_delete_spec.rb6
-rw-r--r--spec/unit/knife/cookbook_download_spec.rb7
-rw-r--r--spec/unit/knife/cookbook_list_spec.rb8
-rw-r--r--spec/unit/knife/cookbook_show_spec.rb30
-rw-r--r--spec/unit/knife/cookbook_site_download_spec.rb10
-rw-r--r--spec/unit/knife/cookbook_site_share_spec.rb10
-rw-r--r--spec/unit/knife/cookbook_site_unshare_spec.rb12
-rw-r--r--spec/unit/knife/data_bag_create_spec.rb12
-rw-r--r--spec/unit/knife/data_bag_edit_spec.rb4
-rw-r--r--spec/unit/knife/data_bag_from_file_spec.rb2
-rw-r--r--spec/unit/knife/data_bag_show_spec.rb2
-rw-r--r--spec/unit/knife/environment_compare_spec.rb2
-rw-r--r--spec/unit/knife/index_rebuild_spec.rb6
-rw-r--r--spec/unit/knife_spec.rb6
-rw-r--r--spec/unit/mixin/command_spec.rb2
-rw-r--r--spec/unit/node_spec.rb56
-rw-r--r--spec/unit/org_spec.rb14
-rw-r--r--spec/unit/policy_builder/expand_node_object_spec.rb8
-rw-r--r--spec/unit/policy_builder/policyfile_spec.rb6
-rw-r--r--spec/unit/provider/group/groupadd_spec.rb4
-rw-r--r--spec/unit/provider/group/pw_spec.rb2
-rw-r--r--spec/unit/provider/group/usermod_spec.rb4
-rw-r--r--spec/unit/provider/http_request_spec.rb4
-rw-r--r--spec/unit/provider/ifconfig_spec.rb2
-rw-r--r--spec/unit/provider/mdadm_spec.rb2
-rw-r--r--spec/unit/provider/mount/mount_spec.rb2
-rw-r--r--spec/unit/provider/package/chocolatey_spec.rb450
-rw-r--r--spec/unit/provider/package/windows/exe_spec.rb74
-rw-r--r--spec/unit/provider/package/yum_spec.rb2
-rw-r--r--spec/unit/provider/package/zypper_spec.rb2
-rw-r--r--spec/unit/provider/service/gentoo_service_spec.rb2
-rw-r--r--spec/unit/provider/service/openbsd_service_spec.rb2
-rw-r--r--spec/unit/provider/service/windows_spec.rb45
-rw-r--r--spec/unit/resource/chocolatey_package_spec.rb67
-rw-r--r--spec/unit/resource/deploy_spec.rb4
-rw-r--r--spec/unit/resource/env_spec.rb2
-rw-r--r--spec/unit/resource/link_spec.rb2
-rw-r--r--spec/unit/resource_reporter_spec.rb46
-rw-r--r--spec/unit/resource_spec.rb24
-rw-r--r--spec/unit/role_spec.rb4
-rw-r--r--spec/unit/run_list_spec.rb23
-rw-r--r--spec/unit/search/query_spec.rb36
-rw-r--r--spec/unit/shell/shell_session_spec.rb4
-rw-r--r--spec/unit/user_v1_spec.rb4
-rw-r--r--tasks/external_tests.rb3
215 files changed, 3882 insertions, 960 deletions
diff --git a/.gitignore b/.gitignore
index cdb29d0679..064d998d6e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,18 +1,21 @@
.autotest
coverage
.DS_Store
-pkg
+pkg/*
tags
*/tags
*~
.chef
-# you should check in your Gemfile.lock in applications, and not in gems
+# You should check in your Gemfile.lock in applications, and not in gems
+# This also matches Berksfile.lock
external_tests/*.lock
-*.lock
-Gemfile.local
+/*.lock
+/Gemfile.local
-# Do not check in the .bundle directory, or any of the files inside it. Those files are specific to each particular machine, and are used to persist installation options between runs of the bundle install command.
+# Do not check in the .bundle directory, or any of the files inside it. Those
+# files are specific to each particular machine, and are used to persist
+# installation options between runs of the bundle install command.
.bundle
# ignore some common Bundler 'binstubs' directory names
@@ -36,7 +39,6 @@ doc/
# Test Kitchen
.kitchen/
-Berksfile.lock
# Vagrant
Vagrantfile
@@ -47,3 +49,4 @@ kitchen-tests/nodes/*
# Temporary files present during spec runs
spec/data/test-dir
+config/
diff --git a/.rubocop.yml b/.rubocop.yml
new file mode 100644
index 0000000000..c4272bd0f4
--- /dev/null
+++ b/.rubocop.yml
@@ -0,0 +1,4 @@
+AllCops:
+ Exclude:
+ - "spec/data/**/*"
+ - "vendor/**/*"
diff --git a/.travis.yml b/.travis.yml
index 78303d7591..cd91884f68 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -15,6 +15,8 @@ branches:
# do not run expensive spec tests on PRs, only on branches
script: "
+set -e;
+bundle exec rake style;
echo '--color\n-fp' > .rspec;
sudo sed -i -e 's/^Defaults\tsecure_path.*$//' /etc/sudoers;
sudo -E $(which bundle) exec rake spec;
@@ -50,6 +52,9 @@ matrix:
- rvm: 2.2
env: "GEMFILE_MOD=\"gem 'chef-sugar'\""
script: bundle exec rake chef_sugar_spec
+ - rvm: 2.2
+ env: "GEMFILE_MOD=\"gem 'knife-windows', github: 'chef/knife-windows'\""
+ script: bundle exec rake knife_windows_spec
# Requires vagrant
# - rvm: 2.2
# cache:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 330f93fae7..5c79dcb1c5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,7 @@
* [pr#4278](https://github.com/chef/chef/pull/4278) make file resource use properties
* [**Nate Walck**](https://github.com/natewalck)
[pr#4078](https://github.com/chef/chef/pull/4078) Add `osx_profile` HWRP for OS X
+* [pr#4369](https://github.com/chef/chef/pull/4396) Import omnibus-chef chef project definition and history
## 12.6.0
diff --git a/Gemfile b/Gemfile
index 822a6a8217..3a29aa52aa 100644
--- a/Gemfile
+++ b/Gemfile
@@ -27,6 +27,9 @@ group(:development, :test) do
gem "simplecov"
gem 'rack', "~> 1.5.1"
+ # for testing new chefstyle rules
+ # gem 'chefstyle', github: 'chef/chefstyle'
+ gem 'chefstyle', '= 0.1.0'
gem 'ruby-shadow', :platforms => :ruby unless RUBY_PLATFORM.downcase.match(/(aix|cygwin)/)
diff --git a/README.md b/README.md
index 8c2df43a34..1c1c83ca07 100644
--- a/README.md
+++ b/README.md
@@ -56,7 +56,7 @@ Then get the source and install it:
bundle install
# Build a gem
- rake gem
+ bundle exec rake gem
# Install the gem you just built
gem install pkg/chef-VERSION.gem
diff --git a/Rakefile b/Rakefile
index 25ad13f097..9fe1147928 100644
--- a/Rakefile
+++ b/Rakefile
@@ -45,6 +45,13 @@ task :register_eventlog do
end
end
+
+require "chefstyle"
+require "rubocop/rake_task"
+RuboCop::RakeTask.new(:style) do |task|
+ task.options += ["--display-cop-names", "--no-color"]
+end
+
begin
require 'yard'
DOC_FILES = [ "README.rdoc", "LICENSE", "spec/tiny_server.rb", "lib/**/*.rb" ]
diff --git a/ci/jenkins_run_tests.bat b/ci/jenkins_run_tests.bat
deleted file mode 100644
index ba9cedd5e2..0000000000
--- a/ci/jenkins_run_tests.bat
+++ /dev/null
@@ -1,14 +0,0 @@
-ruby -v
-
-call bundle check
-
-if %ERRORLEVEL% NEQ 0 (
- call rm Gemfile.lock
- call bundle install --without docgen --path vendor/bundle
-)
-
-bundle exec rspec -r rspec_junit_formatter -f RspecJunitFormatter -o test.xml -f documentation spec/functional spec/unit spec/stress spec/integration
-
-set RSPEC_ERRORLVL=%ERRORLEVEL%
-REM Return the error level from rspec
-exit /B %RSPEC_ERRORLVL%
diff --git a/ci/jenkins_run_tests.sh b/ci/jenkins_run_tests.sh
deleted file mode 100755
index 5bf7def062..0000000000
--- a/ci/jenkins_run_tests.sh
+++ /dev/null
@@ -1,13 +0,0 @@
-#!/bin/bash
-
-export PATH=$PATH:/usr/local/bin
-
-ruby -v;
-# remove the Gemfile.lock and try again if bundler fails.
-# This should take care of Gemfile changes that result in "bad" bundles without forcing us to rebundle every time
-bundle install --without docgen --path vendor/bundle || ( rm Gemfile.lock && bundle install --path vendor/bundle )
-bundle exec rspec -r rspec_junit_formatter -f RspecJunitFormatter -o test.xml -f documentation spec;
-RSPEC_RETURNCODE=$?
-
-# exit with the result of running rspec
-exit $RSPEC_RETURNCODE
diff --git a/ci/verify-chef.bat b/ci/verify-chef.bat
new file mode 100755
index 0000000000..1c159f0668
--- /dev/null
+++ b/ci/verify-chef.bat
@@ -0,0 +1,56 @@
+
+@ECHO OFF
+
+REM ; %PROJECT_NAME% is set by Jenkins, this allows us to use the same script to verify
+REM ; Chef and Angry Chef
+cd C:\opscode\%PROJECT_NAME%\bin
+
+REM ; We don't want to add the embedded bin dir to the main PATH as this
+REM ; could mask issues in our binstub shebangs.
+SET EMBEDDED_BIN_DIR=C:\opscode\%PROJECT_NAME%\embedded\bin
+
+ECHO.
+
+FOR %%b IN (
+ chef-client
+ knife
+ chef-solo
+ ohai
+) DO (
+
+
+ ECHO Checking for existence of binfile `%%b`...
+
+ IF EXIST %%b (
+ ECHO ...FOUND IT!
+ ) ELSE (
+ GOTO :error
+ )
+ ECHO.
+)
+
+call chef-client --version
+
+REM ; Exercise various packaged tools to validate binstub shebangs
+call %EMBEDDED_BIN_DIR%\ruby --version
+call %EMBEDDED_BIN_DIR%\gem --version
+call %EMBEDDED_BIN_DIR%\bundle --version
+call %EMBEDDED_BIN_DIR%\rspec --version
+
+SET PATH=C:\opscode\%PROJECT_NAME%\bin;C:\opscode\%PROJECT_NAME%\embedded\bin;%PATH%
+
+REM ; Test against the vendored chef gem
+cd C:\opscode\%PROJECT_NAME%\embedded\lib\ruby\gems\2*\gems\chef-*-mingw32
+
+IF NOT EXIST "Gemfile.lock" (
+ ECHO "Chef gem does not contain a Gemfile.lock! This is needed to run any tests."
+ GOTO :error
+)
+
+IF "%PIPELINE_NAME%" == "chef-13" (
+ REM ; Running unit and functional tests
+ call bundle exec rspec -r rspec_junit_formatter -f RspecJunitFormatter -o %WORKSPACE%\test.xml -f documentation spec/unit spec/functional
+) ELSE (
+ REM ; Running unit tests
+ call bundle exec rspec -r rspec_junit_formatter -f RspecJunitFormatter -o %WORKSPACE%\test.xml -f documentation spec/unit spec/functional
+)
diff --git a/ci/verify-chef.sh b/ci/verify-chef.sh
new file mode 100755
index 0000000000..4e60b1fd9f
--- /dev/null
+++ b/ci/verify-chef.sh
@@ -0,0 +1,89 @@
+#!/bin/sh
+
+# $PROJECT_NAME is set by Jenkins, this allows us to use the same script to verify
+# Chef and Angry Chef
+PATH=/opt/$PROJECT_NAME/bin:$PATH
+export PATH
+
+BIN_DIR=/opt/$PROJECT_NAME/bin
+export BIN_DIR
+
+# We don't want to add the embedded bin dir to the main PATH as this
+# could mask issues in our binstub shebangs.
+EMBEDDED_BIN_DIR=/opt/$PROJECT_NAME/embedded/bin
+export EMBEDDED_BIN_DIR
+
+# If we are on Mac our symlinks are located under /usr/local/bin
+# otherwise they are under /usr/bin
+if [ -f /usr/bin/sw_vers ]; then
+ USR_BIN_DIR="/usr/local/bin"
+else
+ USR_BIN_DIR="/usr/bin"
+fi
+export USR_BIN_DIR
+
+# sanity check that we're getting the correct symlinks from the pre-install script
+# solaris doesn't have readlink or test -e. ls -n is different on BSD. proceed with caution.
+if [ ! -L $USR_BIN_DIR/chef-client ] || [ `ls -l $USR_BIN_DIR/chef-client | awk '{print$NF}'` != "$BIN_DIR/chef-client" ]; then
+ echo "$USR_BIN_DIR/chef-client symlink to $BIN_DIR/chef-client was not correctly created by the pre-install script!"
+ exit 1
+fi
+
+if [ ! -L $USR_BIN_DIR/knife ] || [ `ls -l $USR_BIN_DIR/knife | awk '{print$NF}'` != "$BIN_DIR/knife" ]; then
+ echo "$USR_BIN_DIR/knife symlink to $BIN_DIR/knife was not correctly created by the pre-install script!"
+ exit 1
+fi
+
+if [ ! -L $USR_BIN_DIR/chef-solo ] || [ `ls -l $USR_BIN_DIR/chef-solo | awk '{print$NF}'` != "$BIN_DIR/chef-solo" ]; then
+ echo "$USR_BIN_DIR/chef-solo symlink to $BIN_DIR/chef-solo was not correctly created by the pre-install script!"
+ exit 1
+fi
+
+if [ ! -L $USR_BIN_DIR/ohai ] || [ `ls -l $USR_BIN_DIR/ohai | awk '{print$NF}'` != "$BIN_DIR/ohai" ]; then
+ echo "$USR_BIN_DIR/ohai symlink to $BIN_DIR/ohai was not correctly created by the pre-install script!"
+ exit 1
+fi
+
+# Ensure the calling environment (disapproval look Bundler) does not
+# infect our Ruby environment created by the `chef-client` cli.
+for ruby_env_var in _ORIGINAL_GEM_PATH \
+ BUNDLE_BIN_PATH \
+ BUNDLE_GEMFILE \
+ GEM_HOME \
+ GEM_PATH \
+ GEM_ROOT \
+ RUBYLIB \
+ RUBYOPT \
+ RUBY_ENGINE \
+ RUBY_ROOT \
+ RUBY_VERSION
+
+do
+ unset $ruby_env_var
+done
+
+chef-client --version
+
+# Exercise various packaged tools to validate binstub shebangs
+$EMBEDDED_BIN_DIR/ruby --version
+$EMBEDDED_BIN_DIR/gem --version
+$EMBEDDED_BIN_DIR/bundle --version
+$EMBEDDED_BIN_DIR/rspec --version
+
+# ffi-yajl must run in c-extension mode or we take perf hits, so we force it
+# before running rspec so that we don't wind up testing the ffi mode
+FORCE_FFI_YAJL=ext
+export FORCE_FFI_YAJL
+
+PATH=/opt/$PROJECT_NAME/bin:/opt/$PROJECT_NAME/embedded/bin:$PATH
+export PATH
+
+# Test against the vendored Chef gem
+cd /opt/$PROJECT_NAME/embedded/lib/ruby/gems/*/gems/chef-[0-9]*
+
+if [ ! -f "Gemfile.lock" ]; then
+ echo "Chef gem does not contain a Gemfile.lock! This is needed to run any tests."
+ exit 1
+fi
+
+sudo env PATH=$PATH TERM=xterm bundle exec rspec -r rspec_junit_formatter -f RspecJunitFormatter -o $WORKSPACE/test.xml -f documentation spec/functional spec/unit
diff --git a/lib/chef/api_client/registration.rb b/lib/chef/api_client/registration.rb
index bc941d5bfa..99667acc0a 100644
--- a/lib/chef/api_client/registration.rb
+++ b/lib/chef/api_client/registration.rb
@@ -17,7 +17,7 @@
#
require 'chef/config'
-require 'chef/rest'
+require 'chef/server_api'
require 'chef/exceptions'
class Chef
@@ -45,7 +45,7 @@ class Chef
#--
# If client creation fails with a 5xx, it is retried up to 5 times. These
# retries are on top of the retries with randomized exponential backoff
- # built in to Chef::REST. The retries here are a workaround for failures
+ # built in to Chef::ServerAPI. The retries here are a workaround for failures
# caused by resource contention in Hosted Chef when creating a very large
# number of clients simultaneously, (e.g., spinning up 100s of ec2 nodes
# at once). Future improvements to the affected component should make
diff --git a/lib/chef/application.rb b/lib/chef/application.rb
index 0ee201f103..3ab68260d7 100644
--- a/lib/chef/application.rb
+++ b/lib/chef/application.rb
@@ -186,12 +186,12 @@ class Chef
# Called prior to starting the application, by the run method
def setup_application
- raise Chef::Exceptions::Application, "#{self.to_s}: you must override setup_application"
+ raise Chef::Exceptions::Application, "#{self}: you must override setup_application"
end
# Actually run the application
def run_application
- raise Chef::Exceptions::Application, "#{self.to_s}: you must override run_application"
+ raise Chef::Exceptions::Application, "#{self}: you must override run_application"
end
# Initializes Chef::Client instance and runs it
@@ -307,7 +307,7 @@ class Chef
class << self
def debug_stacktrace(e)
message = "#{e.class}: #{e}\n#{e.backtrace.join("\n")}"
- chef_stacktrace_out = "Generated at #{Time.now.to_s}\n"
+ chef_stacktrace_out = "Generated at #{Time.now}\n"
chef_stacktrace_out += message
Chef::FileCache.store("chef-stacktrace.out", chef_stacktrace_out)
diff --git a/lib/chef/application/windows_service.rb b/lib/chef/application/windows_service.rb
index 2f938059ca..9becf4b33f 100644
--- a/lib/chef/application/windows_service.rb
+++ b/lib/chef/application/windows_service.rb
@@ -23,7 +23,7 @@ require 'chef/client'
require 'chef/config'
require 'chef/handler/error_report'
require 'chef/log'
-require 'chef/rest'
+require 'chef/http'
require 'mixlib/cli'
require 'socket'
require 'uri'
@@ -308,7 +308,7 @@ class Chef
begin
case config[:config_file]
when /^(http|https):\/\//
- Chef::REST.new("", nil, nil).fetch(config[:config_file]) { |f| apply_config(f.path) }
+ Chef::HTTP.new("").streaming_request(config[:config_file]) { |f| apply_config(f.path) }
else
::File::open(config[:config_file]) { |f| apply_config(f.path) }
end
diff --git a/lib/chef/audit/audit_reporter.rb b/lib/chef/audit/audit_reporter.rb
index d952d8a249..face24f1f5 100644
--- a/lib/chef/audit/audit_reporter.rb
+++ b/lib/chef/audit/audit_reporter.rb
@@ -127,10 +127,8 @@ class Chef
end
Chef::Log.debug "Audit Report:\n#{Chef::JSONCompat.to_json_pretty(run_data)}"
- # Since we're posting compressed data we can not directly call post_rest which expects JSON
begin
- audit_url = rest_client.create_url(audit_history_url)
- rest_client.post(audit_url, run_data, headers)
+ rest_client.post(audit_history_url, run_data, headers)
rescue StandardError => e
if e.respond_to? :response
# 404 error code is OK. This means the version of server we're running against doesn't support
diff --git a/lib/chef/chef_fs/file_system/chef_server_root_dir.rb b/lib/chef/chef_fs/file_system/chef_server_root_dir.rb
index 09181ac4b4..badb70ce50 100644
--- a/lib/chef/chef_fs/file_system/chef_server_root_dir.rb
+++ b/lib/chef/chef_fs/file_system/chef_server_root_dir.rb
@@ -104,7 +104,7 @@ class Chef
end
def chef_rest
- Chef::REST.new(chef_server_url, chef_username, chef_private_key)
+ Chef::ServerAPI.new(chef_server_url, :client_name => chef_username, :signing_key_filename => chef_private_key)
end
def api_path
diff --git a/lib/chef/client.rb b/lib/chef/client.rb
index 6ac5cecbdf..ead804879f 100644
--- a/lib/chef/client.rb
+++ b/lib/chef/client.rb
@@ -22,7 +22,7 @@ require 'chef/config'
require 'chef/mixin/params_validate'
require 'chef/mixin/path_sanity'
require 'chef/log'
-require 'chef/rest'
+require 'chef/server_api'
require 'chef/api_client'
require 'chef/api_client/registration'
require 'chef/audit/runner'
@@ -92,7 +92,7 @@ class Chef
#
# The rest object used to communicate with the Chef server.
#
- # @return [Chef::REST]
+ # @return [Chef::ServerAPI]
#
attr_reader :rest
@@ -575,7 +575,7 @@ class Chef
# If Chef::Config.client_key does not exist, we register the client with the
# Chef server and fire the registration_start and registration_completed events.
#
- # @return [Chef::REST] The server connection object.
+ # @return [Chef::ServerAPI] The server connection object.
#
# @see Chef::Config#chef_server_url
# @see Chef::Config#client_key
@@ -601,7 +601,8 @@ class Chef
events.registration_completed
end
# We now have the client key, and should use it from now on.
- @rest = Chef::REST.new(config[:chef_server_url], client_name, config[:client_key])
+ @rest = Chef::ServerAPI.new(config[:chef_server_url], client_name: client_name,
+ signing_key_filename: config[:client_key])
register_reporters
rescue Exception => e
# TODO this should probably only ever fire if we *started* registration.
diff --git a/lib/chef/cookbook/remote_file_vendor.rb b/lib/chef/cookbook/remote_file_vendor.rb
index 7868430227..b118c75f9e 100644
--- a/lib/chef/cookbook/remote_file_vendor.rb
+++ b/lib/chef/cookbook/remote_file_vendor.rb
@@ -63,7 +63,7 @@ class Chef
# (remote, per manifest), do the update. This will also execute if there
# is no current checksum.
if current_checksum != found_manifest_record['checksum']
- raw_file = @rest.get_rest(found_manifest_record[:url], true)
+ raw_file = @rest.get(found_manifest_record[:url], true)
Chef::Log.debug("Storing updated #{cache_filename} in the cache.")
Chef::FileCache.move_to(raw_file.path, cache_filename)
diff --git a/lib/chef/cookbook/synchronizer.rb b/lib/chef/cookbook/synchronizer.rb
index fc8e739d73..b499963653 100644
--- a/lib/chef/cookbook/synchronizer.rb
+++ b/lib/chef/cookbook/synchronizer.rb
@@ -1,5 +1,6 @@
require 'chef/client'
require 'chef/util/threaded_job_queue'
+require 'chef/server_api'
require 'singleton'
class Chef
@@ -274,7 +275,7 @@ class Chef
# downloaded to the path +destination+ which is relative to the Chef file
# cache root.
def download_file(url, destination)
- raw_file = server_api.get_rest(url, true)
+ raw_file = server_api.streaming_request(url)
Chef::Log.info("Storing updated #{destination} in the cache.")
cache.move_to(raw_file.path, destination)
@@ -286,7 +287,7 @@ class Chef
end
def server_api
- Chef::REST.new(Chef::Config[:chef_server_url])
+ Chef::ServerAPI.new(Chef::Config[:chef_server_url])
end
end
diff --git a/lib/chef/cookbook_loader.rb b/lib/chef/cookbook_loader.rb
index 79005b1569..e783405b9b 100644
--- a/lib/chef/cookbook_loader.rb
+++ b/lib/chef/cookbook_loader.rb
@@ -106,7 +106,7 @@ class Chef
if @cookbooks_by_name.has_key?(cookbook.to_sym) or load_cookbook(cookbook.to_sym)
@cookbooks_by_name[cookbook.to_sym]
else
- raise Exceptions::CookbookNotFoundInRepo, "Cannot find a cookbook named #{cookbook.to_s}; did you forget to add metadata to a cookbook? (https://docs.chef.io/config_rb_metadata.html)"
+ raise Exceptions::CookbookNotFoundInRepo, "Cannot find a cookbook named #{cookbook}; did you forget to add metadata to a cookbook? (https://docs.chef.io/config_rb_metadata.html)"
end
end
diff --git a/lib/chef/cookbook_uploader.rb b/lib/chef/cookbook_uploader.rb
index f24ce2cd56..64a8a4e168 100644
--- a/lib/chef/cookbook_uploader.rb
+++ b/lib/chef/cookbook_uploader.rb
@@ -9,6 +9,7 @@ require 'chef/cookbook/syntax_check'
require 'chef/cookbook/file_system_file_vendor'
require 'chef/util/threaded_job_queue'
require 'chef/sandbox'
+require 'chef/server_api'
class Chef
class CookbookUploader
@@ -31,7 +32,7 @@ class Chef
# uploading the cookbook. This allows frozen CookbookVersion
# documents on the server to be overwritten (otherwise a 409 is
# returned by the server)
- # * :rest A Chef::REST object that you have configured the way you like it.
+ # * :rest A Chef::ServerAPI object that you have configured the way you like it.
# If you don't provide this, one will be created using the values
# in Chef::Config.
# * :concurrency An integer that decided how many threads will be used to
@@ -39,7 +40,7 @@ class Chef
def initialize(cookbooks, opts={})
@opts = opts
@cookbooks = Array(cookbooks)
- @rest = opts[:rest] || Chef::REST.new(Chef::Config[:chef_server_url])
+ @rest = opts[:rest] || Chef::ServerAPI.new(Chef::Config[:chef_server_url])
@concurrency = opts[:concurrency] || 10
@policy_mode = opts[:policy_mode] || false
end
diff --git a/lib/chef/cookbook_version.rb b/lib/chef/cookbook_version.rb
index 0e9617f98c..4eb118d3bc 100644
--- a/lib/chef/cookbook_version.rb
+++ b/lib/chef/cookbook_version.rb
@@ -25,6 +25,7 @@ require 'chef/cookbook/metadata'
require 'chef/version_class'
require 'chef/digester'
require 'chef/cookbook_manifest'
+require 'chef/server_api'
class Chef
@@ -459,11 +460,13 @@ class Chef
end
private :preferences_for_path
- def self.json_create(o)
- cookbook_version = new(o["cookbook_name"])
+ def self.from_hash(o)
+ cookbook_version = new(o["cookbook_name"] || o["name"])
+
# We want the Chef::Cookbook::Metadata object to always be inflated
cookbook_version.metadata = Chef::Cookbook::Metadata.from_hash(o["metadata"])
cookbook_version.manifest = o
+ cookbook_version.identifier = o["identifier"] if o.key?("identifier")
# We don't need the following step when we decide to stop supporting deprecated operators in the metadata (e.g. <<, >>)
cookbook_version.manifest["metadata"] = Chef::JSONCompat.from_json(Chef::JSONCompat.to_json(cookbook_version.metadata))
@@ -472,13 +475,12 @@ class Chef
cookbook_version
end
+ def self.json_create(o)
+ from_hash(o)
+ end
+
def self.from_cb_artifact_data(o)
- cookbook_version = new(o["name"])
- # We want the Chef::Cookbook::Metadata object to always be inflated
- cookbook_version.metadata = Chef::Cookbook::Metadata.from_hash(o["metadata"])
- cookbook_version.manifest = o
- cookbook_version.identifier = o["identifier"]
- cookbook_version
+ from_hash(o)
end
# @deprecated This method was used by the Ruby Chef Server and is no longer
@@ -543,22 +545,22 @@ class Chef
end
def self.chef_server_rest
- Chef::REST.new(Chef::Config[:chef_server_url])
+ Chef::ServerAPI.new(Chef::Config[:chef_server_url])
end
def destroy
- chef_server_rest.delete_rest("cookbooks/#{name}/#{version}")
+ chef_server_rest.delete("cookbooks/#{name}/#{version}")
self
end
def self.load(name, version="_latest")
version = "_latest" if version == "latest"
- chef_server_rest.get_rest("cookbooks/#{name}/#{version}")
+ from_hash(chef_server_rest.get("cookbooks/#{name}/#{version}"))
end
# The API returns only a single version of each cookbook in the result from the cookbooks method
def self.list
- chef_server_rest.get_rest('cookbooks')
+ chef_server_rest.get('cookbooks')
end
# Alias latest_cookbooks as list
@@ -567,7 +569,7 @@ class Chef
end
def self.list_all_versions
- chef_server_rest.get_rest('cookbooks?num_versions=all')
+ chef_server_rest.get('cookbooks?num_versions=all')
end
##
@@ -577,7 +579,7 @@ class Chef
# [String]:: Array of cookbook versions, which are strings like 'x.y.z'
# nil:: if the cookbook doesn't exist. an error will also be logged.
def self.available_versions(cookbook_name)
- chef_server_rest.get_rest("cookbooks/#{cookbook_name}")[cookbook_name]["versions"].map do |cb|
+ chef_server_rest.get("cookbooks/#{cookbook_name}")[cookbook_name]["versions"].map do |cb|
cb["version"]
end
rescue Net::HTTPServerException => e
diff --git a/lib/chef/data_bag.rb b/lib/chef/data_bag.rb
index 401ba6f63f..9d0dc53da5 100644
--- a/lib/chef/data_bag.rb
+++ b/lib/chef/data_bag.rb
@@ -24,6 +24,7 @@ require 'chef/mixin/from_file'
require 'chef/data_bag_item'
require 'chef/mash'
require 'chef/json_compat'
+require 'chef/server_api'
class Chef
class DataBag
@@ -70,15 +71,19 @@ class Chef
end
def chef_server_rest
- @chef_server_rest ||= Chef::REST.new(Chef::Config[:chef_server_url])
+ @chef_server_rest ||= Chef::ServerAPI.new(Chef::Config[:chef_server_url])
end
def self.chef_server_rest
- Chef::REST.new(Chef::Config[:chef_server_url])
+ Chef::ServerAPI.new(Chef::Config[:chef_server_url])
end
# Create a Chef::Role from JSON
def self.json_create(o)
+ from_hash(o)
+ end
+
+ def self.from_hash(o)
bag = new
bag.name(o["name"])
bag
@@ -104,7 +109,7 @@ class Chef
response
end
else
- Chef::REST.new(Chef::Config[:chef_server_url]).get_rest("data")
+ Chef::ServerAPI.new(Chef::Config[:chef_server_url]).get("data")
end
end
end
@@ -120,7 +125,7 @@ class Chef
end
Dir.glob(File.join(Chef::Util::PathHelper.escape_glob(path, name.to_s), "*.json")).inject({}) do |bag, f|
- item = Chef::JSONCompat.from_json(IO.read(f))
+ item = Chef::JSONCompat.parse(IO.read(f))
# Check if we have multiple items with similar names (ids) and raise if their content differs
if data_bag.has_key?(item["id"]) && data_bag[item["id"]] != item
@@ -132,12 +137,12 @@ class Chef
end
return data_bag
else
- Chef::REST.new(Chef::Config[:chef_server_url]).get_rest("data/#{name}")
+ Chef::ServerAPI.new(Chef::Config[:chef_server_url]).get("data/#{name}")
end
end
def destroy
- chef_server_rest.delete_rest("data/#{@name}")
+ chef_server_rest.delete("data/#{@name}")
end
# Save the Data Bag via RESTful API
@@ -156,7 +161,7 @@ class Chef
#create a data bag via RESTful API
def create
- chef_server_rest.post_rest("data", self)
+ chef_server_rest.post("data", self)
self
end
diff --git a/lib/chef/data_bag_item.rb b/lib/chef/data_bag_item.rb
index 31c9b69330..7ef9fffe07 100644
--- a/lib/chef/data_bag_item.rb
+++ b/lib/chef/data_bag_item.rb
@@ -25,6 +25,7 @@ require 'chef/mixin/params_validate'
require 'chef/mixin/from_file'
require 'chef/data_bag'
require 'chef/mash'
+require 'chef/server_api'
require 'chef/json_compat'
class Chef
@@ -58,11 +59,11 @@ class Chef
end
def chef_server_rest
- @chef_server_rest ||= Chef::REST.new(Chef::Config[:chef_server_url])
+ @chef_server_rest ||= Chef::ServerAPI.new(Chef::Config[:chef_server_url])
end
def self.chef_server_rest
- Chef::REST.new(Chef::Config[:chef_server_url])
+ Chef::ServerAPI.new(Chef::Config[:chef_server_url])
end
def raw_data
@@ -125,22 +126,23 @@ class Chef
end
def self.from_hash(h)
+ h.delete("chef_type")
+ h.delete("json_class")
+ h.delete("name")
+
item = new
- item.raw_data = h
+ item.data_bag(h.delete("data_bag")) if h.key?("data_bag")
+ if h.key?("raw_data")
+ item.raw_data = Mash.new(h["raw_data"])
+ else
+ item.raw_data = h
+ end
item
end
# Create a Chef::DataBagItem from JSON
def self.json_create(o)
- bag_item = new
- bag_item.data_bag(o["data_bag"])
- o.delete("data_bag")
- o.delete("chef_type")
- o.delete("json_class")
- o.delete("name")
-
- bag_item.raw_data = Mash.new(o["raw_data"])
- bag_item
+ from_hash(o)
end
# Load a Data Bag Item by name via either the RESTful API or local data_bag_path if run in solo mode
@@ -149,7 +151,7 @@ class Chef
bag = Chef::DataBag.load(data_bag)
item = bag[name]
else
- item = Chef::REST.new(Chef::Config[:chef_server_url]).get_rest("data/#{data_bag}/#{name}")
+ item = Chef::ServerAPI.new(Chef::Config[:chef_server_url]).get("data/#{data_bag}/#{name}")
end
if item.kind_of?(DataBagItem)
@@ -162,7 +164,7 @@ class Chef
end
def destroy(data_bag=data_bag(), databag_item=name)
- chef_server_rest.delete_rest("data/#{data_bag}/#{databag_item}")
+ chef_server_rest.delete("data/#{data_bag}/#{databag_item}")
end
# Save this Data Bag Item via RESTful API
@@ -172,18 +174,18 @@ class Chef
if Chef::Config[:why_run]
Chef::Log.warn("In why-run mode, so NOT performing data bag item save.")
else
- r.put_rest("data/#{data_bag}/#{item_id}", self)
+ r.put("data/#{data_bag}/#{item_id}", self)
end
rescue Net::HTTPServerException => e
raise e unless e.response.code == "404"
- r.post_rest("data/#{data_bag}", self)
+ r.post("data/#{data_bag}", self)
end
self
end
# Create this Data Bag Item via RESTful API
def create
- chef_server_rest.post_rest("data/#{data_bag}", self)
+ chef_server_rest.post("data/#{data_bag}", self)
self
end
diff --git a/lib/chef/environment.rb b/lib/chef/environment.rb
index 7d4b410639..5612978a08 100644
--- a/lib/chef/environment.rb
+++ b/lib/chef/environment.rb
@@ -24,6 +24,7 @@ require 'chef/mash'
require 'chef/mixin/params_validate'
require 'chef/mixin/from_file'
require 'chef/version_constraint'
+require 'chef/server_api'
class Chef
class Environment
@@ -47,11 +48,11 @@ class Chef
end
def chef_server_rest
- @chef_server_rest ||= Chef::REST.new(Chef::Config[:chef_server_url])
+ @chef_server_rest ||= Chef::ServerAPI.new(Chef::Config[:chef_server_url])
end
def self.chef_server_rest
- Chef::REST.new(Chef::Config[:chef_server_url])
+ Chef::ServerAPI.new(Chef::Config[:chef_server_url])
end
def name(arg=nil)
@@ -216,6 +217,10 @@ class Chef
end
def self.json_create(o)
+ from_hash(o)
+ end
+
+ def self.from_hash(o)
environment = new
environment.name(o["name"])
environment.description(o["description"])
@@ -233,7 +238,7 @@ class Chef
end
response
else
- chef_server_rest.get_rest("environments")
+ chef_server_rest.get("environments")
end
end
@@ -241,7 +246,7 @@ class Chef
if Chef::Config[:solo]
load_from_file(name)
else
- chef_server_rest.get_rest("environments/#{name}")
+ chef_server_rest.get("environments/#{name}")
end
end
@@ -267,26 +272,26 @@ class Chef
end
def destroy
- chef_server_rest.delete_rest("environments/#{@name}")
+ chef_server_rest.delete("environments/#{@name}")
end
def save
begin
- chef_server_rest.put_rest("environments/#{@name}", self)
+ chef_server_rest.put("environments/#{@name}", self)
rescue Net::HTTPServerException => e
raise e unless e.response.code == "404"
- chef_server_rest.post_rest("environments", self)
+ chef_server_rest.post("environments", self)
end
self
end
def create
- chef_server_rest.post_rest("environments", self)
+ chef_server_rest.post("environments", self)
self
end
def self.load_filtered_recipe_list(environment)
- chef_server_rest.get_rest("environments/#{environment}/recipes")
+ chef_server_rest.get("environments/#{environment}/recipes")
end
def to_s
diff --git a/lib/chef/formatters/minimal.rb b/lib/chef/formatters/minimal.rb
index 3862951f76..62db517e3e 100644
--- a/lib/chef/formatters/minimal.rb
+++ b/lib/chef/formatters/minimal.rb
@@ -157,7 +157,7 @@ class Chef
puts "\n"
puts "resources updated this run:"
updated_resources.each do |resource|
- puts "* #{resource.to_s}"
+ puts "* #{resource}"
updates_by_resource[resource.name].flatten.each do |update|
puts " - #{update}"
end
diff --git a/lib/chef/guard_interpreter/resource_guard_interpreter.rb b/lib/chef/guard_interpreter/resource_guard_interpreter.rb
index 8cff3bc032..a333028a22 100644
--- a/lib/chef/guard_interpreter/resource_guard_interpreter.rb
+++ b/lib/chef/guard_interpreter/resource_guard_interpreter.rb
@@ -88,7 +88,7 @@ class Chef
resource_class = Chef::Resource.resource_for_node(parent_resource.guard_interpreter, parent_resource.node)
if resource_class.nil?
- raise ArgumentError, "Specified guard_interpreter resource #{parent_resource.guard_interpreter.to_s} unknown for this platform"
+ raise ArgumentError, "Specified guard_interpreter resource #{parent_resource.guard_interpreter} unknown for this platform"
end
if ! resource_class.ancestors.include?(Chef::Resource::Execute)
diff --git a/lib/chef/http.rb b/lib/chef/http.rb
index 9f1eeed55f..a26e82f795 100644
--- a/lib/chef/http.rb
+++ b/lib/chef/http.rb
@@ -396,7 +396,7 @@ class Chef
if Chef::Platform.windows?
tf.binmode # required for binary files on Windows platforms
end
- Chef::Log.debug("Streaming download from #{url.to_s} to tempfile #{tf.path}")
+ Chef::Log.debug("Streaming download from #{url} to tempfile #{tf.path}")
# Stolen from http://www.ruby-forum.com/topic/166423
# Kudos to _why!
diff --git a/lib/chef/http/http_request.rb b/lib/chef/http/http_request.rb
index 1baf5724ae..24cd99375d 100644
--- a/lib/chef/http/http_request.rb
+++ b/lib/chef/http/http_request.rb
@@ -127,7 +127,7 @@ class Chef
# http://redmine.ruby-lang.org/issues/show/2758
if e.to_s =~ /#{Regexp.escape(%q|undefined method `closed?' for nil:NilClass|)}/
Chef::Log.debug("Rescued error in http connect, re-raising as Errno::ECONNREFUSED to hide bug in net/http")
- Chef::Log.debug("#{e.class.name}: #{e.to_s}")
+ Chef::Log.debug("#{e.class.name}: #{e}")
Chef::Log.debug(e.backtrace.join("\n"))
raise Errno::ECONNREFUSED, "Connection refused attempting to contact #{url.scheme}://#{host}:#{port}"
else
diff --git a/lib/chef/http/simple.rb b/lib/chef/http/simple.rb
index 8519554f2b..f59fcaa08b 100644
--- a/lib/chef/http/simple.rb
+++ b/lib/chef/http/simple.rb
@@ -1,3 +1,21 @@
+#
+# Author:: Daniel DeLeo (<dan@chef.io>)
+# Copyright:: Copyright (c) 2015 Chef Software, Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
require 'chef/http'
require 'chef/http/authenticator'
require 'chef/http/decompressor'
diff --git a/lib/chef/http/simple_json.rb b/lib/chef/http/simple_json.rb
new file mode 100644
index 0000000000..5dfdfbb680
--- /dev/null
+++ b/lib/chef/http/simple_json.rb
@@ -0,0 +1,43 @@
+#
+# Author:: Thom May (<thom@chef.io>)
+# Copyright:: Copyright (c) 2015 Chef Software, Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+require 'chef/http'
+require 'chef/http/authenticator'
+require 'chef/http/decompressor'
+require 'chef/http/cookie_manager'
+require 'chef/http/validate_content_length'
+
+class Chef
+ class HTTP
+
+ class SimpleJSON < HTTP
+
+ use JSONInput
+ use JSONOutput
+ use CookieManager
+ use Decompressor
+ use RemoteRequestID
+
+ # ValidateContentLength should come after Decompressor
+ # because the order of middlewares is reversed when handling
+ # responses.
+ use ValidateContentLength
+
+ end
+ end
+end
diff --git a/lib/chef/key.rb b/lib/chef/key.rb
index be4be7f230..47bfe1fcee 100644
--- a/lib/chef/key.rb
+++ b/lib/chef/key.rb
@@ -19,6 +19,7 @@
require 'chef/json_compat'
require 'chef/mixin/params_validate'
require 'chef/exceptions'
+require 'chef/server_api'
class Chef
# Class for interacting with a chef key object. Can be used to create new keys,
@@ -31,7 +32,7 @@ class Chef
# @attr [String] public_key the RSA string of this key
# @attr [String] private_key the RSA string of the private key if returned via a POST or PUT
# @attr [String] expiration_date the ISO formatted string YYYY-MM-DDTHH:MM:SSZ, i.e. 2020-12-24T21:00:00Z
- # @attr [String] rest Chef::REST object, initialized and cached via chef_rest method
+ # @attr [String] rest Chef::ServerAPI object, initialized and cached via chef_rest method
# @attr [string] api_base either "users" or "clients", initialized and cached via api_base method
#
# @attr_reader [String] actor_field_name must be either 'client' or 'user'
@@ -60,9 +61,9 @@ class Chef
def chef_rest
@rest ||= if @actor_field_name == "user"
- Chef::REST.new(Chef::Config[:chef_server_root])
+ Chef::ServerAPI.new(Chef::Config[:chef_server_root])
else
- Chef::REST.new(Chef::Config[:chef_server_url])
+ Chef::ServerAPI.new(Chef::Config[:chef_server_url])
end
end
@@ -151,7 +152,7 @@ class Chef
payload['public_key'] = @public_key unless @public_key.nil?
payload['create_key'] = @create_key if @create_key
payload['expiration_date'] = @expiration_date unless @expiration_date.nil?
- result = chef_rest.post_rest("#{api_base}/#{@actor}/keys", payload)
+ result = chef_rest.post("#{api_base}/#{@actor}/keys", payload)
# append the private key to the current key if the server returned one,
# since the POST endpoint just returns uri and private_key if needed.
new_key = self.to_hash
@@ -174,7 +175,7 @@ class Chef
# to @name.
put_name = @name if put_name.nil?
- new_key = chef_rest.put_rest("#{api_base}/#{@actor}/keys/#{put_name}", to_hash)
+ new_key = chef_rest.put("#{api_base}/#{@actor}/keys/#{put_name}", to_hash)
# if the server returned a public_key, remove the create_key field, as we now have a key
if new_key["public_key"]
self.delete_create_key
@@ -197,7 +198,7 @@ class Chef
raise Chef::Exceptions::MissingKeyAttribute, "the name field must be populated when delete is called"
end
- chef_rest.delete_rest("#{api_base}/#{@actor}/keys/#{@name}")
+ chef_rest.delete("#{api_base}/#{@actor}/keys/#{@name}")
end
# Class methods
@@ -226,22 +227,22 @@ class Chef
end
def self.list_by_user(actor, inflate=false)
- keys = Chef::REST.new(Chef::Config[:chef_server_root]).get_rest("users/#{actor}/keys")
+ keys = Chef::ServerAPI.new(Chef::Config[:chef_server_root]).get("users/#{actor}/keys")
self.list(keys, actor, :load_by_user, inflate)
end
def self.list_by_client(actor, inflate=false)
- keys = Chef::REST.new(Chef::Config[:chef_server_url]).get_rest("clients/#{actor}/keys")
+ keys = Chef::ServerAPI.new(Chef::Config[:chef_server_url]).get("clients/#{actor}/keys")
self.list(keys, actor, :load_by_client, inflate)
end
def self.load_by_user(actor, key_name)
- response = Chef::REST.new(Chef::Config[:chef_server_root]).get_rest("users/#{actor}/keys/#{key_name}")
+ response = Chef::ServerAPI.new(Chef::Config[:chef_server_root]).get("users/#{actor}/keys/#{key_name}")
Chef::Key.from_hash(response.merge({"user" => actor}))
end
def self.load_by_client(actor, key_name)
- response = Chef::REST.new(Chef::Config[:chef_server_url]).get_rest("clients/#{actor}/keys/#{key_name}")
+ response = Chef::ServerAPI.new(Chef::Config[:chef_server_url]).get("clients/#{actor}/keys/#{key_name}")
Chef::Key.from_hash(response.merge({"client" => actor}))
end
diff --git a/lib/chef/knife.rb b/lib/chef/knife.rb
index 2820f58e85..34e437c82f 100644
--- a/lib/chef/knife.rb
+++ b/lib/chef/knife.rb
@@ -26,14 +26,16 @@ require 'chef/mixin/path_sanity'
require 'chef/knife/core/subcommand_loader'
require 'chef/knife/core/ui'
require 'chef/local_mode'
-require 'chef/rest'
+require 'chef/server_api'
require 'chef/http/authenticator'
+require 'chef/http/http_request'
+require 'chef/http'
require 'pp'
class Chef
class Knife
- Chef::REST::RESTRequest.user_agent = "Chef Knife#{Chef::REST::RESTRequest::UA_COMMON}"
+ Chef::HTTP::HTTPRequest.user_agent = "Chef Knife#{Chef::HTTP::HTTPRequest::UA_COMMON}"
include Mixlib::CLI
include Chef::Mixin::PathSanity
@@ -551,15 +553,15 @@ class Chef
def rest
@rest ||= begin
- require 'chef/rest'
- Chef::REST.new(Chef::Config[:chef_server_url])
+ require 'chef/server_api'
+ Chef::ServerAPI.new(Chef::Config[:chef_server_url])
end
end
def noauth_rest
@rest ||= begin
- require 'chef/rest'
- Chef::REST.new(Chef::Config[:chef_server_url], false, false)
+ require 'chef/http/simple_json'
+ Chef::HTTP::SimpleJSON.new(Chef::Config[:chef_server_url])
end
end
diff --git a/lib/chef/knife/bootstrap/client_builder.rb b/lib/chef/knife/bootstrap/client_builder.rb
index 6414ac5c72..f5a2ff2bb1 100644
--- a/lib/chef/knife/bootstrap/client_builder.rb
+++ b/lib/chef/knife/bootstrap/client_builder.rb
@@ -17,7 +17,7 @@
#
require 'chef/node'
-require 'chef/rest'
+require 'chef/server_api'
require 'chef/api_client/registration'
require 'chef/api_client'
require 'chef/knife/bootstrap'
@@ -185,22 +185,22 @@ class Chef
# @param relative_path [String] URI path relative to the chef organization
# @return [Boolean] if the relative path exists or returns a 404
def resource_exists?(relative_path)
- rest.get_rest(relative_path)
+ rest.get(relative_path)
true
rescue Net::HTTPServerException => e
raise unless e.response.code == "404"
false
end
- # @return [Chef::REST] REST client using the client credentials
+ # @return [Chef::ServerAPI] REST client using the client credentials
def client_rest
- @client_rest ||= Chef::REST.new(chef_server_url, node_name, client_path)
+ @client_rest ||= Chef::ServerAPI.new(chef_server_url, :client_name => node_name, :signing_key_filename => client_path)
end
- # @return [Chef::REST] REST client using the cli user's knife credentials
+ # @return [Chef::ServerAPI] REST client using the cli user's knife credentials
# this uses the users's credentials
def rest
- @rest ||= Chef::REST.new(chef_server_url)
+ @rest ||= Chef::ServerAPI.new(chef_server_url)
end
end
end
diff --git a/lib/chef/knife/cookbook_bulk_delete.rb b/lib/chef/knife/cookbook_bulk_delete.rb
index 65fa888486..ec0d06937f 100644
--- a/lib/chef/knife/cookbook_bulk_delete.rb
+++ b/lib/chef/knife/cookbook_bulk_delete.rb
@@ -60,9 +60,9 @@ class Chef
cookbooks_names.each do |cookbook_name|
- versions = rest.get_rest("cookbooks/#{cookbook_name}")[cookbook_name]["versions"].map {|v| v["version"]}.flatten
+ versions = rest.get("cookbooks/#{cookbook_name}")[cookbook_name]["versions"].map {|v| v["version"]}.flatten
versions.each do |version|
- object = rest.delete_rest("cookbooks/#{cookbook_name}/#{version}#{config[:purge] ? "?purge=true" : ""}")
+ object = rest.delete("cookbooks/#{cookbook_name}/#{version}#{config[:purge] ? "?purge=true" : ""}")
ui.info("Deleted cookbook #{cookbook_name.ljust(25)} [#{version}]")
end
end
diff --git a/lib/chef/knife/cookbook_delete.rb b/lib/chef/knife/cookbook_delete.rb
index f436d270bd..5fe0e9664d 100644
--- a/lib/chef/knife/cookbook_delete.rb
+++ b/lib/chef/knife/cookbook_delete.rb
@@ -85,7 +85,7 @@ class Chef
end
def available_versions
- @available_versions ||= rest.get_rest("cookbooks/#{@cookbook_name}").map do |name, url_and_version|
+ @available_versions ||= rest.get("cookbooks/#{@cookbook_name}").map do |name, url_and_version|
url_and_version["versions"].map {|url_by_version| url_by_version["version"]}
end.flatten
rescue Net::HTTPServerException => e
@@ -143,7 +143,7 @@ class Chef
def delete_request(path)
path += "?purge=true" if config[:purge]
- rest.delete_rest(path)
+ rest.delete(path)
end
end
diff --git a/lib/chef/knife/cookbook_download.rb b/lib/chef/knife/cookbook_download.rb
index cb8eeb8edf..6ba5fc7d6c 100644
--- a/lib/chef/knife/cookbook_download.rb
+++ b/lib/chef/knife/cookbook_download.rb
@@ -69,7 +69,7 @@ class Chef
ui.info("Downloading #{@cookbook_name} cookbook version #{@version}")
- cookbook = rest.get_rest("cookbooks/#{@cookbook_name}/#{@version}")
+ cookbook = Chef::CookbookVersion.load(@cookbook_name, @version)
manifest = cookbook.manifest
basedir = File.join(config[:download_directory], "#{@cookbook_name}-#{cookbook.version}")
@@ -90,8 +90,7 @@ class Chef
dest = File.join(basedir, segment_file['path'].gsub('/', File::SEPARATOR))
Chef::Log.debug("Downloading #{segment_file['path']} to #{dest}")
FileUtils.mkdir_p(File.dirname(dest))
- rest.sign_on_redirect = false
- tempfile = rest.get_rest(segment_file['url'], true)
+ tempfile = rest.streaming_request(segment_file['url'])
FileUtils.mv(tempfile.path, dest)
end
end
diff --git a/lib/chef/knife/cookbook_list.rb b/lib/chef/knife/cookbook_list.rb
index 75f18a154b..dd78e854da 100644
--- a/lib/chef/knife/cookbook_list.rb
+++ b/lib/chef/knife/cookbook_list.rb
@@ -39,7 +39,7 @@ class Chef
env = config[:environment]
num_versions = config[:all_versions] ? "num_versions=all" : "num_versions=1"
api_endpoint = env ? "/environments/#{env}/cookbooks?#{num_versions}" : "/cookbooks?#{num_versions}"
- cookbook_versions = rest.get_rest(api_endpoint)
+ cookbook_versions = rest.get(api_endpoint)
ui.output(format_cookbook_list_for_display(cookbook_versions))
end
end
diff --git a/lib/chef/knife/cookbook_show.rb b/lib/chef/knife/cookbook_show.rb
index 7c9cbebdb1..07f7684c27 100644
--- a/lib/chef/knife/cookbook_show.rb
+++ b/lib/chef/knife/cookbook_show.rb
@@ -67,9 +67,9 @@ class Chef
cookbook_name, segment, filename = @name_args[0], @name_args[2], @name_args[3]
cookbook_version = @name_args[1] == 'latest' ? '_latest' : @name_args[1]
- cookbook = rest.get_rest("cookbooks/#{cookbook_name}/#{cookbook_version}")
+ cookbook = rest.get("cookbooks/#{cookbook_name}/#{cookbook_version}")
manifest_entry = cookbook.preferred_manifest_record(node, segment, filename)
- temp_file = rest.get_rest(manifest_entry[:url], true)
+ temp_file = rest.get(manifest_entry[:url], true)
# the temp file is cleaned up elsewhere
temp_file.open if temp_file.closed?
@@ -77,16 +77,16 @@ class Chef
when 3 # We are showing a specific part of the cookbook
cookbook_version = @name_args[1] == 'latest' ? '_latest' : @name_args[1]
- result = rest.get_rest("cookbooks/#{@name_args[0]}/#{cookbook_version}")
+ result = rest.get("cookbooks/#{@name_args[0]}/#{cookbook_version}")
output(result.manifest[@name_args[2]])
when 2 # We are showing the whole cookbook data
cookbook_version = @name_args[1] == 'latest' ? '_latest' : @name_args[1]
- output(rest.get_rest("cookbooks/#{@name_args[0]}/#{cookbook_version}"))
+ output(rest.get("cookbooks/#{@name_args[0]}/#{cookbook_version}"))
when 1 # We are showing the cookbook versions (all of them)
cookbook_name = @name_args[0]
env = config[:environment]
api_endpoint = env ? "environments/#{env}/cookbooks/#{cookbook_name}" : "cookbooks/#{cookbook_name}"
- output(format_cookbook_list_for_display(rest.get_rest(api_endpoint)))
+ output(format_cookbook_list_for_display(rest.get(api_endpoint)))
when 0
show_usage
ui.fatal("You must specify a cookbook name")
diff --git a/lib/chef/knife/cookbook_site_download.rb b/lib/chef/knife/cookbook_site_download.rb
index 3e586e6542..72608f3a30 100644
--- a/lib/chef/knife/cookbook_site_download.rb
+++ b/lib/chef/knife/cookbook_site_download.rb
@@ -63,7 +63,7 @@ class Chef
def current_cookbook_data
@current_cookbook_data ||= begin
- noauth_rest.get_rest "#{cookbooks_api_url}/#{@name_args[0]}"
+ noauth_rest.get "#{cookbooks_api_url}/#{@name_args[0]}"
end
end
@@ -79,14 +79,14 @@ class Chef
specific_cookbook_version_url
end
- noauth_rest.get_rest uri
+ noauth_rest.get uri
end
end
def download_cookbook
ui.info "Downloading #{@name_args[0]} from Supermarket at version #{version} to #{download_location}"
noauth_rest.sign_on_redirect = false
- tf = noauth_rest.get_rest desired_cookbook_data["file"], true
+ tf = noauth_rest.get desired_cookbook_data["file"], true
::FileUtils.cp tf.path, download_location
ui.info "Cookbook saved: #{download_location}"
diff --git a/lib/chef/knife/cookbook_site_list.rb b/lib/chef/knife/cookbook_site_list.rb
index 846123c867..b5354ed6e6 100644
--- a/lib/chef/knife/cookbook_site_list.rb
+++ b/lib/chef/knife/cookbook_site_list.rb
@@ -42,7 +42,7 @@ class Chef
def get_cookbook_list(items=10, start=0, cookbook_collection={})
cookbooks_url = "https://supermarket.chef.io/api/v1/cookbooks?items=#{items}&start=#{start}"
- cr = noauth_rest.get_rest(cookbooks_url)
+ cr = noauth_rest.get(cookbooks_url)
cr["items"].each do |cookbook|
cookbook_collection[cookbook["cookbook_name"]] = cookbook
end
diff --git a/lib/chef/knife/cookbook_site_search.rb b/lib/chef/knife/cookbook_site_search.rb
index 0baaf90f1c..decbf6c2c3 100644
--- a/lib/chef/knife/cookbook_site_search.rb
+++ b/lib/chef/knife/cookbook_site_search.rb
@@ -30,7 +30,7 @@ class Chef
def search_cookbook(query, items=10, start=0, cookbook_collection={})
cookbooks_url = "https://supermarket.chef.io/api/v1/search?q=#{query}&items=#{items}&start=#{start}"
- cr = noauth_rest.get_rest(cookbooks_url)
+ cr = noauth_rest.get(cookbooks_url)
cr["items"].each do |cookbook|
cookbook_collection[cookbook["cookbook_name"]] = cookbook
end
diff --git a/lib/chef/knife/cookbook_site_share.rb b/lib/chef/knife/cookbook_site_share.rb
index beb98b71b8..043ca84a58 100644
--- a/lib/chef/knife/cookbook_site_share.rb
+++ b/lib/chef/knife/cookbook_site_share.rb
@@ -108,7 +108,7 @@ class Chef
def get_category(cookbook_name)
begin
- data = noauth_rest.get_rest("https://supermarket.chef.io/api/v1/cookbooks/#{@name_args[0]}")
+ data = noauth_rest.get("https://supermarket.chef.io/api/v1/cookbooks/#{@name_args[0]}")
if !data["category"] && data["error_code"]
ui.fatal("Received an error from Supermarket: #{data["error_code"]}. On the first time you upload it, you are required to specify the category you want to share this cookbook to.")
exit(1)
diff --git a/lib/chef/knife/cookbook_site_show.rb b/lib/chef/knife/cookbook_site_show.rb
index 6b65b62570..521a60eb36 100644
--- a/lib/chef/knife/cookbook_site_show.rb
+++ b/lib/chef/knife/cookbook_site_show.rb
@@ -31,15 +31,15 @@ class Chef
def get_cookbook_data
case @name_args.length
when 1
- noauth_rest.get_rest("https://supermarket.chef.io/api/v1/cookbooks/#{@name_args[0]}")
+ noauth_rest.get("https://supermarket.chef.io/api/v1/cookbooks/#{@name_args[0]}")
when 2
- noauth_rest.get_rest("https://supermarket.chef.io/api/v1/cookbooks/#{@name_args[0]}/versions/#{name_args[1].gsub('.', '_')}")
+ noauth_rest.get("https://supermarket.chef.io/api/v1/cookbooks/#{@name_args[0]}/versions/#{name_args[1].gsub('.', '_')}")
end
end
def get_cookbook_list(items=10, start=0, cookbook_collection={})
cookbooks_url = "https://supermarket.chef.io/api/v1/cookbooks?items=#{items}&start=#{start}"
- cr = noauth_rest.get_rest(cookbooks_url)
+ cr = noauth_rest.get(cookbooks_url)
cr["items"].each do |cookbook|
cookbook_collection[cookbook["cookbook_name"]] = cookbook
end
diff --git a/lib/chef/knife/cookbook_site_unshare.rb b/lib/chef/knife/cookbook_site_unshare.rb
index 77bb18322c..0c196c328a 100644
--- a/lib/chef/knife/cookbook_site_unshare.rb
+++ b/lib/chef/knife/cookbook_site_unshare.rb
@@ -41,7 +41,7 @@ class Chef
confirm "Do you really want to unshare all versions of the cookbook #{@cookbook_name}"
begin
- rest.delete_rest "https://supermarket.chef.io/api/v1/cookbooks/#{@name_args[0]}"
+ rest.delete "https://supermarket.chef.io/api/v1/cookbooks/#{@name_args[0]}"
rescue Net::HTTPServerException => e
raise e unless e.message =~ /Forbidden/
ui.error "Forbidden: You must be the maintainer of #{@cookbook_name} to unshare it."
diff --git a/lib/chef/knife/data_bag_create.rb b/lib/chef/knife/data_bag_create.rb
index f8a7619a8a..1becad88b9 100644
--- a/lib/chef/knife/data_bag_create.rb
+++ b/lib/chef/knife/data_bag_create.rb
@@ -51,7 +51,7 @@ class Chef
# create the data bag
begin
- rest.post_rest("data", { "name" => @data_bag_name })
+ rest.post("data", { "name" => @data_bag_name })
ui.info("Created data_bag[#{@data_bag_name}]")
rescue Net::HTTPServerException => e
raise unless e.to_s =~ /^409/
@@ -68,7 +68,7 @@ class Chef
output
end)
item.data_bag(@data_bag_name)
- rest.post_rest("data/#{@data_bag_name}", item)
+ rest.post("data/#{@data_bag_name}", item)
end
end
end
diff --git a/lib/chef/knife/data_bag_delete.rb b/lib/chef/knife/data_bag_delete.rb
index 575e9d604d..a3215d4c54 100644
--- a/lib/chef/knife/data_bag_delete.rb
+++ b/lib/chef/knife/data_bag_delete.rb
@@ -32,11 +32,11 @@ class Chef
def run
if @name_args.length == 2
delete_object(Chef::DataBagItem, @name_args[1], "data_bag_item") do
- rest.delete_rest("data/#{@name_args[0]}/#{@name_args[1]}")
+ rest.delete("data/#{@name_args[0]}/#{@name_args[1]}")
end
elsif @name_args.length == 1
delete_object(Chef::DataBag, @name_args[0], "data_bag") do
- rest.delete_rest("data/#{@name_args[0]}")
+ rest.delete("data/#{@name_args[0]}")
end
else
show_usage
diff --git a/lib/chef/knife/data_bag_edit.rb b/lib/chef/knife/data_bag_edit.rb
index 6ef4b33f59..88c5669508 100644
--- a/lib/chef/knife/data_bag_edit.rb
+++ b/lib/chef/knife/data_bag_edit.rb
@@ -65,7 +65,7 @@ class Chef
item_to_save = edited_item
end
- rest.put_rest("data/#{@name_args[0]}/#{@name_args[1]}", item_to_save)
+ rest.put("data/#{@name_args[0]}/#{@name_args[1]}", item_to_save)
stdout.puts("Saved data_bag_item[#{@name_args[1]}]")
ui.output(edited_item) if config[:print_after]
end
diff --git a/lib/chef/knife/environment_compare.rb b/lib/chef/knife/environment_compare.rb
index 792ec444ea..54f011f323 100644
--- a/lib/chef/knife/environment_compare.rb
+++ b/lib/chef/knife/environment_compare.rb
@@ -57,7 +57,7 @@ class Chef
end
# Get all cookbooks so we can compare them all
- cookbooks = rest.get_rest("/cookbooks?num_versions=1") if config[:all]
+ cookbooks = rest.get("/cookbooks?num_versions=1") if config[:all]
# display matrix view of in the requested format.
if config[:format] == 'summary'
diff --git a/lib/chef/knife/index_rebuild.rb b/lib/chef/knife/index_rebuild.rb
index 4b9fcdd159..95b0dcaffb 100644
--- a/lib/chef/knife/index_rebuild.rb
+++ b/lib/chef/knife/index_rebuild.rb
@@ -38,7 +38,7 @@ class Chef
else
deprecated_server_message
nag
- output rest.post_rest("/search/reindex", {})
+ output rest.post("/search/reindex", {})
end
end
@@ -50,7 +50,7 @@ class Chef
# for a node we know won't exist; the 404 response that comes
# back will give us what we want
dummy_node = "knife_index_rebuild_test_#{rand(1000000)}"
- rest.get_rest("/nodes/#{dummy_node}")
+ rest.get("/nodes/#{dummy_node}")
rescue Net::HTTPServerException => exception
r = exception.response
parse_api_info(r)
diff --git a/lib/chef/knife/raw.rb b/lib/chef/knife/raw.rb
index 601cfcef9b..de8742deb9 100644
--- a/lib/chef/knife/raw.rb
+++ b/lib/chef/knife/raw.rb
@@ -1,4 +1,5 @@
require 'chef/knife'
+require 'chef/http'
class Chef
class Knife
diff --git a/lib/chef/knife/recipe_list.rb b/lib/chef/knife/recipe_list.rb
index ed7d2a9509..46ad619f1d 100644
--- a/lib/chef/knife/recipe_list.rb
+++ b/lib/chef/knife/recipe_list.rb
@@ -22,7 +22,7 @@ class Chef::Knife::RecipeList < Chef::Knife
banner "knife recipe list [PATTERN]"
def run
- recipes = rest.get_rest('cookbooks/_recipes')
+ recipes = rest.get('cookbooks/_recipes')
if pattern = @name_args.first
recipes = recipes.grep(Regexp.new(pattern))
end
diff --git a/lib/chef/knife/status.rb b/lib/chef/knife/status.rb
index 1a61b035cb..e649c01ef4 100644
--- a/lib/chef/knife/status.rb
+++ b/lib/chef/knife/status.rb
@@ -76,7 +76,7 @@ class Chef
time = Time.now.to_i
# AND NOT is not valid lucene syntax, so don't use append_to_query
@query << " " unless @query.empty?
- @query << "NOT ohai_time:[#{(time - 60*60).to_s} TO #{time.to_s}]"
+ @query << "NOT ohai_time:[#{(time - 60*60)} TO #{time}]"
end
if config[:hide_by_mins]
@@ -84,7 +84,7 @@ class Chef
time = Time.now.to_i
# AND NOT is not valid lucene syntax, so don't use append_to_query
@query << " " unless @query.empty?
- @query << "NOT ohai_time:[#{(time - hidemins*60).to_s} TO #{time.to_s}]"
+ @query << "NOT ohai_time:[#{(time - hidemins*60)} TO #{time}]"
end
@query = @query.empty? ? "*:*" : @query
diff --git a/lib/chef/mixin/securable.rb b/lib/chef/mixin/securable.rb
index aaedf0b9ba..396243693e 100644
--- a/lib/chef/mixin/securable.rb
+++ b/lib/chef/mixin/securable.rb
@@ -112,7 +112,7 @@ class Chef
# equivalent to something like:
# def rights(permissions=nil, principals=nil, args_hash=nil)
define_method(name) do |permissions=nil, principals=nil, args_hash=nil|
- rights = self.instance_variable_get("@#{name.to_s}".to_sym)
+ rights = self.instance_variable_get("@#{name}".to_sym)
unless permissions.nil?
input = {
:permissions => permissions,
diff --git a/lib/chef/node.rb b/lib/chef/node.rb
index 0c13e5474a..f6c7d68f74 100644
--- a/lib/chef/node.rb
+++ b/lib/chef/node.rb
@@ -27,7 +27,7 @@ require 'chef/mixin/deep_merge'
require 'chef/dsl/include_attribute'
require 'chef/dsl/platform_introspection'
require 'chef/environment'
-require 'chef/rest'
+require 'chef/server_api'
require 'chef/run_list'
require 'chef/node/attribute'
require 'chef/mash'
@@ -99,10 +99,10 @@ class Chef
# for saving node data we use validate_utf8: false which will not
# raise an exception on bad utf8 data, but will replace the bad
# characters and render valid JSON.
- @chef_server_rest ||= Chef::REST.new(
+ @chef_server_rest ||= Chef::ServerAPI.new(
Chef::Config[:chef_server_url],
- Chef::Config[:node_name],
- Chef::Config[:client_key],
+ client_name: Chef::Config[:node_name],
+ signing_key_filename: Chef::Config[:client_key],
validate_utf8: false,
)
end
@@ -390,7 +390,7 @@ class Chef
if attrs.key?("recipes") || attrs.key?("run_list")
raise Chef::Exceptions::AmbiguousRunlistSpecification, "please set the node's run list using the 'run_list' attribute only."
end
- Chef::Log.info("Setting the run_list to #{new_run_list.to_s} from CLI options")
+ Chef::Log.info("Setting the run_list to #{new_run_list} from CLI options")
run_list(new_run_list)
end
attrs
@@ -532,6 +532,11 @@ class Chef
# Create a Chef::Node from JSON
def self.json_create(o)
+ from_hash(o)
+ end
+
+ def self.from_hash(o)
+ return o if o.kind_of? Chef::Node
node = new
node.name(o["name"])
node.chef_environment(o["chef_environment"])
@@ -561,7 +566,7 @@ class Chef
Chef::Search::Query.new.search(:node, "chef_environment:#{environment}") {|n| response[n.name] = n unless n.nil?}
response
else
- Chef::REST.new(Chef::Config[:chef_server_url]).get_rest("environments/#{environment}/nodes")
+ Chef::ServerAPI.new(Chef::Config[:chef_server_url]).get("environments/#{environment}/nodes")
end
end
@@ -569,11 +574,12 @@ class Chef
if inflate
response = Hash.new
Chef::Search::Query.new.search(:node) do |n|
+ n = Chef::Node.from_hash(n)
response[n.name] = n unless n.nil?
end
response
else
- Chef::REST.new(Chef::Config[:chef_server_url]).get_rest("nodes")
+ Chef::ServerAPI.new(Chef::Config[:chef_server_url]).get("nodes")
end
end
@@ -594,12 +600,12 @@ class Chef
# Load a node by name
def self.load(name)
- Chef::REST.new(Chef::Config[:chef_server_url]).get_rest("nodes/#{name}")
+ from_hash(Chef::ServerAPI.new(Chef::Config[:chef_server_url]).get("nodes/#{name}"))
end
# Remove this node via the REST API
def destroy
- chef_server_rest.delete_rest("nodes/#{name}")
+ chef_server_rest.delete("nodes/#{name}")
end
# Save this node via the REST API
@@ -610,11 +616,11 @@ class Chef
if Chef::Config[:why_run]
Chef::Log.warn("In why-run mode, so NOT performing node save.")
else
- chef_server_rest.put_rest("nodes/#{name}", data_for_save)
+ chef_server_rest.put("nodes/#{name}", data_for_save)
end
rescue Net::HTTPServerException => e
if e.response.code == "404"
- chef_server_rest.post_rest("nodes", data_for_save)
+ chef_server_rest.post("nodes", data_for_save)
# Chef Server before 12.3 rejects node JSON with 'policy_name' or
# 'policy_group' keys, but 'policy_name' will be detected first.
# Backcompat can be removed in 13.0
@@ -629,14 +635,14 @@ class Chef
# Create the node via the REST API
def create
- chef_server_rest.post_rest("nodes", data_for_save)
+ chef_server_rest.post("nodes", data_for_save)
self
rescue Net::HTTPServerException => e
# Chef Server before 12.3 rejects node JSON with 'policy_name' or
# 'policy_group' keys, but 'policy_name' will be detected first.
# Backcompat can be removed in 13.0
if e.response.code == "400" && e.response.body.include?("Invalid key policy_name")
- chef_server_rest.post_rest("nodes", data_for_save_without_policyfile_attrs)
+ chef_server_rest.post("nodes", data_for_save_without_policyfile_attrs)
else
raise
end
@@ -663,10 +669,10 @@ class Chef
def save_without_policyfile_attrs
trimmed_data = data_for_save_without_policyfile_attrs
- chef_server_rest.put_rest("nodes/#{name}", trimmed_data)
+ chef_server_rest.put("nodes/#{name}", trimmed_data)
rescue Net::HTTPServerException => e
raise e unless e.response.code == "404"
- chef_server_rest.post_rest("nodes", trimmed_data)
+ chef_server_rest.post("nodes", trimmed_data)
end
def data_for_save_without_policyfile_attrs
diff --git a/lib/chef/org.rb b/lib/chef/org.rb
index 41d74b6186..81eca6a991 100644
--- a/lib/chef/org.rb
+++ b/lib/chef/org.rb
@@ -18,7 +18,7 @@
require 'chef/json_compat'
require 'chef/mixin/params_validate'
-require 'chef/rest'
+require 'chef/server_api'
class Chef
class Org
@@ -35,7 +35,7 @@ class Chef
end
def chef_rest
- @chef_rest ||= Chef::REST.new(Chef::Config[:chef_server_root])
+ @chef_rest ||= Chef::ServerAPI.new(Chef::Config[:chef_server_root])
end
def name(arg=nil)
@@ -74,18 +74,18 @@ class Chef
def create
payload = {:name => self.name, :full_name => self.full_name}
- new_org = chef_rest.post_rest("organizations", payload)
+ new_org = chef_rest.post("organizations", payload)
Chef::Org.from_hash(self.to_hash.merge(new_org))
end
def update
payload = {:name => self.name, :full_name => self.full_name}
- new_org = chef_rest.put_rest("organizations/#{name}", payload)
+ new_org = chef_rest.put("organizations/#{name}", payload)
Chef::Org.from_hash(self.to_hash.merge(new_org))
end
def destroy
- chef_rest.delete_rest("organizations/#{@name}")
+ chef_rest.delete("organizations/#{@name}")
end
def save
@@ -102,13 +102,13 @@ class Chef
def associate_user(username)
request_body = {:user => username}
- response = chef_rest.post_rest "organizations/#{@name}/association_requests", request_body
+ response = chef_rest.post "organizations/#{@name}/association_requests", request_body
association_id = response["uri"].split("/").last
- chef_rest.put_rest "users/#{username}/association_requests/#{association_id}", { :response => 'accept' }
+ chef_rest.put "users/#{username}/association_requests/#{association_id}", { :response => 'accept' }
end
def dissociate_user(username)
- chef_rest.delete_rest "organizations/#{name}/users/#{username}"
+ chef_rest.delete "organizations/#{name}/users/#{username}"
end
# Class methods
@@ -129,12 +129,12 @@ class Chef
end
def self.load(org_name)
- response = Chef::REST.new(Chef::Config[:chef_server_root]).get_rest("organizations/#{org_name}")
+ response = Chef::ServerAPI.new(Chef::Config[:chef_server_root]).get("organizations/#{org_name}")
Chef::Org.from_hash(response)
end
def self.list(inflate=false)
- orgs = Chef::REST.new(Chef::Config[:chef_server_root]).get_rest('organizations')
+ orgs = Chef::ServerAPI.new(Chef::Config[:chef_server_root]).get('organizations')
if inflate
orgs.inject({}) do |org_map, (name, _url)|
org_map[name] = Chef::Org.load(name)
diff --git a/lib/chef/platform/provider_mapping.rb b/lib/chef/platform/provider_mapping.rb
index 9b511f0237..1de6d61029 100644
--- a/lib/chef/platform/provider_mapping.rb
+++ b/lib/chef/platform/provider_mapping.rb
@@ -53,7 +53,7 @@ class Chef
begin
version_constraint = Chef::VersionConstraint::Platform.new(platform_version)
if version_constraint.include?(version)
- Chef::Log.debug("Platform #{name.to_s} version #{version} found")
+ Chef::Log.debug("Platform #{name} version #{version} found")
provider_map.merge!(provider)
end
rescue Chef::Exceptions::InvalidPlatformVersion
diff --git a/lib/chef/policy_builder/dynamic.rb b/lib/chef/policy_builder/dynamic.rb
index c9842ba532..d4b3df748e 100644
--- a/lib/chef/policy_builder/dynamic.rb
+++ b/lib/chef/policy_builder/dynamic.rb
@@ -19,7 +19,6 @@
require 'forwardable'
require 'chef/log'
-require 'chef/rest'
require 'chef/run_context'
require 'chef/config'
require 'chef/node'
diff --git a/lib/chef/policy_builder/expand_node_object.rb b/lib/chef/policy_builder/expand_node_object.rb
index 848dd00684..870351b6fb 100644
--- a/lib/chef/policy_builder/expand_node_object.rb
+++ b/lib/chef/policy_builder/expand_node_object.rb
@@ -20,7 +20,7 @@
#
require 'chef/log'
-require 'chef/rest'
+require 'chef/server_api'
require 'chef/run_context'
require 'chef/config'
require 'chef/node'
@@ -198,7 +198,12 @@ class Chef
begin
events.cookbook_resolution_start(@expanded_run_list_with_versions)
cookbook_hash = api_service.post("environments/#{node.chef_environment}/cookbook_versions",
- {:run_list => @expanded_run_list_with_versions})
+ {:run_list => @expanded_run_list_with_versions})
+
+ cookbook_hash = cookbook_hash.inject({}) do |memo, (key, value)|
+ memo[key] = Chef::CookbookVersion.from_hash(value)
+ memo
+ end
rescue Exception => e
# TODO: wrap/munge exception to provide helpful error output
events.cookbook_resolution_failed(@expanded_run_list_with_versions, e)
@@ -257,7 +262,7 @@ class Chef
end
def api_service
- @api_service ||= Chef::REST.new(config[:chef_server_url])
+ @api_service ||= Chef::ServerAPI.new(config[:chef_server_url])
end
def config
diff --git a/lib/chef/policy_builder/policyfile.rb b/lib/chef/policy_builder/policyfile.rb
index 3633110d6c..249bebbd98 100644
--- a/lib/chef/policy_builder/policyfile.rb
+++ b/lib/chef/policy_builder/policyfile.rb
@@ -20,10 +20,10 @@
#
require 'chef/log'
-require 'chef/rest'
require 'chef/run_context'
require 'chef/config'
require 'chef/node'
+require 'chef/server_api'
class Chef
module PolicyBuilder
@@ -455,7 +455,7 @@ class Chef
# @api private
def http_api
- @api_service ||= Chef::REST.new(config[:chef_server_url])
+ @api_service ||= Chef::ServerAPI.new(config[:chef_server_url])
end
# @api private
diff --git a/lib/chef/provider.rb b/lib/chef/provider.rb
index 68bc8d78bd..c53f4a6991 100644
--- a/lib/chef/provider.rb
+++ b/lib/chef/provider.rb
@@ -94,7 +94,7 @@ class Chef
end
def load_current_resource
- raise Chef::Exceptions::Override, "You must override load_current_resource in #{self.to_s}"
+ raise Chef::Exceptions::Override, "You must override load_current_resource in #{self}"
end
def define_resource_requirements
@@ -104,7 +104,7 @@ class Chef
end
def action_nothing
- Chef::Log.debug("Doing nothing for #{@new_resource.to_s}")
+ Chef::Log.debug("Doing nothing for #{@new_resource}")
true
end
@@ -209,7 +209,7 @@ class Chef
else
specified_properties.map { |p| "#{p}=#{new_resource.send(p).inspect}" }.join(", ")
end
- Chef::Log.debug("Skipping update of #{new_resource.to_s}: has not changed any of the specified properties #{properties_str}.")
+ Chef::Log.debug("Skipping update of #{new_resource}: has not changed any of the specified properties #{properties_str}.")
return false
end
diff --git a/lib/chef/provider/deploy.rb b/lib/chef/provider/deploy.rb
index c59200e717..fe6b288eda 100644
--- a/lib/chef/provider/deploy.rb
+++ b/lib/chef/provider/deploy.rb
@@ -365,7 +365,7 @@ class Chef
end
def release_slug
- raise Chef::Exceptions::Override, "You must override release_slug in #{self.to_s}"
+ raise Chef::Exceptions::Override, "You must override release_slug in #{self}"
end
def install_gems
diff --git a/lib/chef/provider/dsc_resource.rb b/lib/chef/provider/dsc_resource.rb
index fd25a14ea5..432fe3987f 100644
--- a/lib/chef/provider/dsc_resource.rb
+++ b/lib/chef/provider/dsc_resource.rb
@@ -144,7 +144,7 @@ class Chef
def invoke_resource(method, output_format=:object)
properties = translate_type(@new_resource.properties)
- switches = "-Method #{method.to_s} -Name #{@new_resource.resource}"\
+ switches = "-Method #{method} -Name #{@new_resource.resource}"\
" -Property #{properties} -Verbose"
if module_name != :none
switches += " -Module #{module_name}"
diff --git a/lib/chef/provider/dsc_script.rb b/lib/chef/provider/dsc_script.rb
index b2432132b7..8205910d5a 100644
--- a/lib/chef/provider/dsc_script.rb
+++ b/lib/chef/provider/dsc_script.rb
@@ -99,7 +99,7 @@ class Chef
configuration_document = generate_configuration_document(config_directory, configuration_flags)
@operations[operation].call(config_manager, configuration_document, shellout_flags)
rescue Exception => e
- Chef::Log.error("DSC operation failed: #{e.message.to_s}")
+ Chef::Log.error("DSC operation failed: #{e.message}")
raise e
ensure
::FileUtils.rm_rf(config_directory)
diff --git a/lib/chef/provider/env.rb b/lib/chef/provider/env.rb
index cf75ff7d85..8bd7b3e6ca 100644
--- a/lib/chef/provider/env.rb
+++ b/lib/chef/provider/env.rb
@@ -48,7 +48,7 @@ class Chef
end
def env_value(key_name)
- raise Chef::Exceptions::Env, "#{self.to_s} provider does not implement env_value!"
+ raise Chef::Exceptions::Env, "#{self} provider does not implement env_value!"
end
def env_key_exists(key_name)
@@ -141,11 +141,11 @@ class Chef
end
def create_env
- raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :#{@new_resource.action}"
+ raise Chef::Exceptions::UnsupportedAction, "#{self} does not support :#{@new_resource.action}"
end
def delete_env
- raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :delete"
+ raise Chef::Exceptions::UnsupportedAction, "#{self} does not support :delete"
end
def modify_env
diff --git a/lib/chef/provider/group/aix.rb b/lib/chef/provider/group/aix.rb
index 92bb8cb225..d0de538e58 100644
--- a/lib/chef/provider/group/aix.rb
+++ b/lib/chef/provider/group/aix.rb
@@ -72,7 +72,7 @@ class Chef
{ :gid => "id" }.sort { |a,b| a[0] <=> b[0] }.each do |field, option|
if @current_resource.send(field) != @new_resource.send(field)
if @new_resource.send(field)
- Chef::Log.debug("#{@new_resource} setting #{field.to_s} to #{@new_resource.send(field)}")
+ Chef::Log.debug("#{@new_resource} setting #{field} to #{@new_resource.send(field)}")
opts << " '#{option}=#{@new_resource.send(field)}'"
end
end
diff --git a/lib/chef/provider/group/groupadd.rb b/lib/chef/provider/group/groupadd.rb
index cb480aab54..b2ca8fd4fe 100644
--- a/lib/chef/provider/group/groupadd.rb
+++ b/lib/chef/provider/group/groupadd.rb
@@ -96,15 +96,15 @@ class Chef
end
def add_member(member)
- raise Chef::Exceptions::Group, "you must override add_member in #{self.to_s}"
+ raise Chef::Exceptions::Group, "you must override add_member in #{self}"
end
def remove_member(member)
- raise Chef::Exceptions::Group, "you must override remove_member in #{self.to_s}"
+ raise Chef::Exceptions::Group, "you must override remove_member in #{self}"
end
def set_members(members)
- raise Chef::Exceptions::Group, "you must override set_members in #{self.to_s}"
+ raise Chef::Exceptions::Group, "you must override set_members in #{self}"
end
# Little bit of magic as per Adam's useradd provider to pull the assign the command line flags
@@ -117,7 +117,7 @@ class Chef
if @current_resource.send(field) != @new_resource.send(field)
if @new_resource.send(field)
opts << " #{option} '#{@new_resource.send(field)}'"
- Chef::Log.debug("#{@new_resource} set #{field.to_s} to #{@new_resource.send(field)}")
+ Chef::Log.debug("#{@new_resource} set #{field} to #{@new_resource.send(field)}")
end
end
end
diff --git a/lib/chef/provider/group/usermod.rb b/lib/chef/provider/group/usermod.rb
index d78d42d6e1..e3d960280d 100644
--- a/lib/chef/provider/group/usermod.rb
+++ b/lib/chef/provider/group/usermod.rb
@@ -41,13 +41,13 @@ class Chef
requirements.assert(:modify, :manage) do |a|
a.assertion { @new_resource.members.empty? || @new_resource.append }
- a.failure_message Chef::Exceptions::Group, "setting group members directly is not supported by #{self.to_s}, must set append true in group"
+ a.failure_message Chef::Exceptions::Group, "setting group members directly is not supported by #{self}, must set append true in group"
# No whyrun alternative - this action is simply not supported.
end
requirements.assert(:all_actions) do |a|
a.assertion { @new_resource.excluded_members.empty? }
- a.failure_message Chef::Exceptions::Group, "excluded_members is not supported by #{self.to_s}"
+ a.failure_message Chef::Exceptions::Group, "excluded_members is not supported by #{self}"
# No whyrun alternative - this action is simply not supported.
end
end
@@ -62,7 +62,7 @@ class Chef
add_member(member)
end
else
- raise Chef::Exceptions::UnsupportedAction, "Setting members directly is not supported by #{self.to_s}"
+ raise Chef::Exceptions::UnsupportedAction, "Setting members directly is not supported by #{self}"
end
end
@@ -73,7 +73,7 @@ class Chef
def remove_member(member)
# This provider only supports adding members with
# append. This function should never be called.
- raise Chef::Exceptions::UnsupportedAction, "Removing members members is not supported by #{self.to_s}"
+ raise Chef::Exceptions::UnsupportedAction, "Removing members members is not supported by #{self}"
end
def append_flags
diff --git a/lib/chef/provider/link.rb b/lib/chef/provider/link.rb
index c811c13cdf..a5f9b0bb29 100644
--- a/lib/chef/provider/link.rb
+++ b/lib/chef/provider/link.rb
@@ -80,7 +80,7 @@ class Chef
true
end
end
- a.failure_message Chef::Exceptions::Link, "Cannot delete #{@new_resource} at #{@new_resource.target_file}! Not a #{@new_resource.link_type.to_s} link."
+ 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
diff --git a/lib/chef/provider/mount.rb b/lib/chef/provider/mount.rb
index 6bdfd5b867..dc0382c689 100644
--- a/lib/chef/provider/mount.rb
+++ b/lib/chef/provider/mount.rb
@@ -118,12 +118,12 @@ class Chef
# should actually check if the filesystem is mounted (not just return current_resource) and return true/false
def mounted?
- raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not implement #mounted?"
+ raise Chef::Exceptions::UnsupportedAction, "#{self} does not implement #mounted?"
end
# should check new_resource against current_resource to see if mount options need updating, returns true/false
def mount_options_unchanged?
- raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not implement #mount_options_unchanged?"
+ raise Chef::Exceptions::UnsupportedAction, "#{self} does not implement #mount_options_unchanged?"
end
#
@@ -134,28 +134,28 @@ class Chef
# should implement mounting of the filesystem, raises if action does not succeed
def mount_fs
- raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :mount"
+ raise Chef::Exceptions::UnsupportedAction, "#{self} does not support :mount"
end
# should implement unmounting of the filesystem, raises if action does not succeed
def umount_fs
- raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :umount"
+ raise Chef::Exceptions::UnsupportedAction, "#{self} does not support :umount"
end
# should implement remounting of the filesystem (via a -o remount or some other atomic-ish action that isn't
# simply a umount/mount style remount), raises if action does not succeed
def remount_fs
- raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :remount"
+ raise Chef::Exceptions::UnsupportedAction, "#{self} does not support :remount"
end
# should implement enabling of the filesystem (e.g. in /etc/fstab), raises if action does not succeed
def enable_fs
- raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :enable"
+ raise Chef::Exceptions::UnsupportedAction, "#{self} does not support :enable"
end
# should implement disabling of the filesystem (e.g. in /etc/fstab), raises if action does not succeed
def disable_fs
- raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :disable"
+ raise Chef::Exceptions::UnsupportedAction, "#{self} does not support :disable"
end
private
diff --git a/lib/chef/provider/osx_profile.rb b/lib/chef/provider/osx_profile.rb
index ee355fd38e..085397efea 100644
--- a/lib/chef/provider/osx_profile.rb
+++ b/lib/chef/provider/osx_profile.rb
@@ -121,7 +121,7 @@ class Chef
# file must exist in cookbook
if new_profile.end_with?('.mobileconfig')
unless cookbook_file_available?(new_profile)
- error_string = "#{self.to_s}: '#{new_profile}' not found in cookbook"
+ error_string = "#{self}: '#{new_profile}' not found in cookbook"
raise Chef::Exceptions::FileNotFound, error_string
end
cookbook_profile = cache_cookbook_profile(new_profile)
diff --git a/lib/chef/provider/package.rb b/lib/chef/provider/package.rb
index 8e98a103bf..2238dc8654 100644
--- a/lib/chef/provider/package.rb
+++ b/lib/chef/provider/package.rb
@@ -228,27 +228,27 @@ class Chef
end
def install_package(name, version)
- raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :install"
+ raise Chef::Exceptions::UnsupportedAction, "#{self} does not support :install"
end
def upgrade_package(name, version)
- raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :upgrade"
+ raise Chef::Exceptions::UnsupportedAction, "#{self} does not support :upgrade"
end
def remove_package(name, version)
- raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :remove"
+ raise Chef::Exceptions::UnsupportedAction, "#{self} does not support :remove"
end
def purge_package(name, version)
- raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :purge"
+ raise Chef::Exceptions::UnsupportedAction, "#{self} does not support :purge"
end
def preseed_package(file)
- raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support pre-seeding package install/upgrade instructions"
+ raise Chef::Exceptions::UnsupportedAction, "#{self} does not support pre-seeding package install/upgrade instructions"
end
def reconfig_package(name, version)
- raise( Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :reconfig" )
+ raise( Chef::Exceptions::UnsupportedAction, "#{self} does not support :reconfig" )
end
# used by subclasses. deprecated. use #a_to_s instead.
diff --git a/lib/chef/provider/package/chocolatey.rb b/lib/chef/provider/package/chocolatey.rb
new file mode 100644
index 0000000000..7a9173e077
--- /dev/null
+++ b/lib/chef/provider/package/chocolatey.rb
@@ -0,0 +1,246 @@
+#
+# Copyright:: Copyright (c) 2015 Chef Software, Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+require 'chef/provider/package'
+require 'chef/resource/chocolatey_package'
+require 'chef/mixin/powershell_out'
+
+class Chef
+ class Provider
+ class Package
+ class Chocolatey < Chef::Provider::Package
+ include Chef::Mixin::PowershellOut
+
+ provides :chocolatey_package, os: "windows"
+
+ # Declare that our arguments should be arrays
+ use_multipackage_api
+
+ # Responsible for building the current_resource.
+ #
+ # @return [Chef::Resource::ChocolateyPackage] the current_resource
+ def load_current_resource
+ @current_resource = Chef::Resource::ChocolateyPackage.new(new_resource.name)
+ current_resource.package_name(new_resource.package_name)
+ current_resource.version(build_current_versions)
+ current_resource
+ end
+
+ def define_resource_requirements
+ super
+
+ # Chocolatey source attribute points to an alternate feed
+ # and not a package specific alternate source like other providers
+ # so we want to assert candidates exist for the alternate source
+ requirements.assert(:upgrade, :install) do |a|
+ a.assertion { candidates_exist_for_all_uninstalled? }
+ a.failure_message(Chef::Exceptions::Package, "No candidate version available for #{packages_missing_candidates.join(", ")}")
+ a.whyrun("Assuming a repository that offers #{packages_missing_candidates.join(", ")} would have been configured")
+ end
+ end
+
+ # Lazy initializer for candidate_version. A nil value means that there is no candidate
+ # version and the package is not installable (generally an error).
+ #
+ # @return [Array] list of candidate_versions indexed same as new_resource.package_name/version
+ def candidate_version
+ @candidate_version ||= build_candidate_versions
+ end
+
+ # Install multiple packages via choco.exe
+ #
+ # @param names [Array<String>] array of package names to install
+ # @param versions [Array<String>] array of versions to install
+ def install_package(names, versions)
+ name_versions_to_install = desired_name_versions.select { |n, v| names.include?(n) }
+
+ name_nil_versions = name_versions_to_install.select { |n,v| v.nil? }
+ name_has_versions = name_versions_to_install.reject { |n,v| v.nil? }
+
+ # choco does not support installing multiple packages with version pins
+ name_has_versions.each do |name, version|
+ choco_command("install -y -version", version, cmd_args, name)
+ end
+
+ # but we can do all the ones without version pins at once
+ unless name_nil_versions.empty?
+ cmd_names = name_nil_versions.keys
+ choco_command("install -y", cmd_args, *cmd_names)
+ end
+ end
+
+ # Upgrade multiple packages via choco.exe
+ #
+ # @param names [Array<String>] array of package names to install
+ # @param versions [Array<String>] array of versions to install
+ def upgrade_package(names, versions)
+ name_versions_to_install = desired_name_versions.select { |n, v| names.include?(n) }
+
+ name_nil_versions = name_versions_to_install.select { |n,v| v.nil? }
+ name_has_versions = name_versions_to_install.reject { |n,v| v.nil? }
+
+ # choco does not support installing multiple packages with version pins
+ name_has_versions.each do |name, version|
+ choco_command("upgrade -y -version", version, cmd_args, name)
+ end
+
+ # but we can do all the ones without version pins at once
+ unless name_nil_versions.empty?
+ cmd_names = name_nil_versions.keys
+ choco_command("upgrade -y", cmd_args, *cmd_names)
+ end
+ end
+
+ # Remove multiple packages via choco.exe
+ #
+ # @param names [Array<String>] array of package names to install
+ # @param versions [Array<String>] array of versions to install
+ def remove_package(names, versions)
+ choco_command("uninstall -y", cmd_args, *names)
+ end
+
+ # Support :uninstall as an action in order for users to easily convert
+ # from the `chocolatey` provider in the cookbook. It is, however,
+ # already deprecated.
+ def action_uninstall
+ Chef::Log.deprecation "The use of action :uninstall on the chocolatey_package provider is deprecated, please use :remove"
+ action_remove
+ end
+
+ # Choco does not have dpkg's distinction between purge and remove
+ alias_method :purge_package, :remove_package
+
+ # Override the superclass check. The semantics for our new_resource.source is not files to
+ # install from, but like the rubygem provider's sources which are more like repos.
+ def check_resource_semantics!
+ end
+
+ private
+
+ # Magic to find where chocolatey is installed in the system, and to
+ # return the full path of choco.exe
+ #
+ # @return [String] full path of choco.exe
+ def choco_exe
+ @choco_exe ||=
+ ::File.join(
+ powershell_out!(
+ "[System.Environment]::GetEnvironmentVariable('ChocolateyInstall', 'MACHINE')"
+ ).stdout.chomp,
+ 'bin',
+ 'choco.exe'
+ )
+ end
+
+ # Helper to dispatch a choco command through shell_out using the timeout
+ # set on the new resource, with nice command formatting.
+ #
+ # @param args [String] variable number of string arguments
+ # @return [Mixlib::ShellOut] object returned from shell_out!
+ def choco_command(*args)
+ shell_out_with_timeout!(args_to_string(choco_exe, *args))
+ end
+
+ # Use the available_packages Hash helper to create an array suitable for
+ # using in candidate_version
+ #
+ # @return [Array] list of candidate_version, same index as new_resource.package_name/version
+ def build_candidate_versions
+ new_resource.package_name.map do |package_name|
+ available_packages[package_name.downcase]
+ end
+ end
+
+ # Use the installed_packages Hash helper to create an array suitable for
+ # using in current_resource.version
+ #
+ # @return [Array] list of candidate_version, same index as new_resource.package_name/version
+ def build_current_versions
+ new_resource.package_name.map do |package_name|
+ installed_packages[package_name.downcase]
+ end
+ end
+
+ # Helper to construct Hash of names-to-versions, requested on the new_resource.
+ # If new_resource.version is nil, then all values will be nil.
+ #
+ # @return [Hash] Mapping of requested names to versions
+ def desired_name_versions
+ desired_versions = new_resource.version || new_resource.package_name.map { nil }
+ Hash[*new_resource.package_name.zip(desired_versions).flatten]
+ end
+
+ # Helper to construct optional args out of new_resource
+ #
+ # @return [String] options from new_resource or empty string
+ def cmd_args
+ cmd_args = [ new_resource.options ]
+ cmd_args.push( "-source #{new_resource.source}" ) if new_resource.source
+ args_to_string(*cmd_args)
+ end
+
+ # Helper to nicely convert variable string args into a single command line. It
+ # will compact nulls or empty strings and join arguments with single spaces, without
+ # introducing any double-spaces for missing args.
+ #
+ # @param args [String] variable number of string arguments
+ # @return [String] nicely concatenated string or empty string
+ def args_to_string(*args)
+ args.reject {|i| i.nil? || i == "" }.join(" ")
+ end
+
+ # Available packages in chocolatey as a Hash of names mapped to versions
+ # If pinning a package to a specific version, filter out all non matching versions
+ # (names are downcased for case-insensitive matching)
+ #
+ # @return [Hash] name-to-version mapping of available packages
+ def available_packages
+ @available_packages ||=
+ begin
+ cmd = [ "list -ar #{package_name_array.join ' '}" ]
+ cmd.push( "-source #{new_resource.source}" ) if new_resource.source
+ parse_list_output(*cmd).reject do |name,version|
+ desired_name_versions[name] && desired_name_versions[name] != version
+ end
+ end
+ end
+
+ # Installed packages in chocolatey as a Hash of names mapped to versions
+ # (names are downcased for case-insensitive matching)
+ #
+ # @return [Hash] name-to-version mapping of installed packages
+ def installed_packages
+ @installed_packages ||= parse_list_output("list -l -r")
+ end
+
+ # Helper to convert choco.exe list output to a Hash
+ # (names are downcased for case-insenstive matching)
+ #
+ # @param cmd [String] command to run
+ # @return [String] list output converted to ruby Hash
+ def parse_list_output(*args)
+ hash = {}
+ choco_command(*args).stdout.each_line do |line|
+ name, version = line.split('|')
+ hash[name.downcase] = version.chomp
+ end
+ hash
+ end
+ end
+ end
+ end
+end
diff --git a/lib/chef/provider/package/rubygems.rb b/lib/chef/provider/package/rubygems.rb
index 729f755b2a..0ea739e8d1 100644
--- a/lib/chef/provider/package/rubygems.rb
+++ b/lib/chef/provider/package/rubygems.rb
@@ -137,7 +137,7 @@ class Chef
spec.version
else
# This is probably going to end badly...
- logger.warn { "#{@new_resource} gem package #{source} does not satisfy the requirements #{gem_dependency.to_s}" }
+ logger.warn { "#{@new_resource} gem package #{source} does not satisfy the requirements #{gem_dependency}" }
nil
end
end
@@ -445,7 +445,7 @@ class Chef
logger.debug { "#{@new_resource} newest installed version of gem #{gemspec.name} is #{gemspec.version}" }
gemspec
else
- logger.debug { "#{@new_resource} no installed version found for #{gem_dependency.to_s}"}
+ logger.debug { "#{@new_resource} no installed version found for #{gem_dependency}"}
nil
end
end
diff --git a/lib/chef/provider/package/windows.rb b/lib/chef/provider/package/windows.rb
index fc90079846..43972c933c 100644
--- a/lib/chef/provider/package/windows.rb
+++ b/lib/chef/provider/package/windows.rb
@@ -109,7 +109,7 @@ class Chef
io.seek(io.tell() - overlap)
end
end
- end
+ end
# if file is named 'setup.exe' assume installshield
if basename == 'setup.exe'
diff --git a/lib/chef/provider/package/windows/exe.rb b/lib/chef/provider/package/windows/exe.rb
index 3758b8b1e2..8f6cd1efa5 100644
--- a/lib/chef/provider/package/windows/exe.rb
+++ b/lib/chef/provider/package/windows/exe.rb
@@ -48,7 +48,7 @@ class Chef
end
def package_version
- new_resource.version || install_file_version
+ new_resource.version
end
def install_package
@@ -97,18 +97,6 @@ class Chef
end
end
- def install_file_version
- @install_file_version ||= begin
- if !new_resource.source.nil? && ::File.exist?(new_resource.source)
- version_info = Chef::ReservedNames::Win32::File.version_info(new_resource.source)
- file_version = version_info.FileVersion || version_info.ProductVersion
- file_version == '' ? nil : file_version
- else
- nil
- end
- end
- end
-
# http://unattended.sourceforge.net/installers.php
def unattended_flags
case installer_type
diff --git a/lib/chef/provider/remote_file/content.rb b/lib/chef/provider/remote_file/content.rb
index 4f450ce333..01193907a1 100644
--- a/lib/chef/provider/remote_file/content.rb
+++ b/lib/chef/provider/remote_file/content.rb
@@ -55,7 +55,7 @@ class Chef
end
raw_file = grab_file_from_uri(uri)
rescue SocketError, Errno::ECONNREFUSED, Errno::ENOENT, Errno::EACCES, Timeout::Error, Net::HTTPServerException, Net::HTTPFatalError, Net::FTPError => e
- Chef::Log.warn("#{@new_resource} cannot be downloaded from #{source}: #{e.to_s}")
+ Chef::Log.warn("#{@new_resource} cannot be downloaded from #{source}: #{e}")
if source = sources.shift
Chef::Log.info("#{@new_resource} trying to download from another mirror")
retry
diff --git a/lib/chef/provider/service.rb b/lib/chef/provider/service.rb
index d72d135b09..311bb1082e 100644
--- a/lib/chef/provider/service.rb
+++ b/lib/chef/provider/service.rb
@@ -64,7 +64,7 @@ class Chef
def define_resource_requirements
requirements.assert(:reload) do |a|
a.assertion { supports[:reload] || @new_resource.reload_command }
- a.failure_message Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :reload"
+ 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
# alternative here.
@@ -143,27 +143,27 @@ class Chef
end
def enable_service
- raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :enable"
+ raise Chef::Exceptions::UnsupportedAction, "#{self} does not support :enable"
end
def disable_service
- raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :disable"
+ raise Chef::Exceptions::UnsupportedAction, "#{self} does not support :disable"
end
def start_service
- raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :start"
+ raise Chef::Exceptions::UnsupportedAction, "#{self} does not support :start"
end
def stop_service
- raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :stop"
+ raise Chef::Exceptions::UnsupportedAction, "#{self} does not support :stop"
end
def restart_service
- raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :restart"
+ raise Chef::Exceptions::UnsupportedAction, "#{self} does not support :restart"
end
def reload_service
- raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :reload"
+ raise Chef::Exceptions::UnsupportedAction, "#{self} does not support :reload"
end
protected
diff --git a/lib/chef/provider/service/macosx.rb b/lib/chef/provider/service/macosx.rb
index 0a8fca4262..9c733da493 100644
--- a/lib/chef/provider/service/macosx.rb
+++ b/lib/chef/provider/service/macosx.rb
@@ -74,7 +74,7 @@ class Chef
def define_resource_requirements
requirements.assert(:reload) do |a|
- a.failure_message Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :reload"
+ a.failure_message Chef::Exceptions::UnsupportedAction, "#{self} does not support :reload"
end
requirements.assert(:all_actions) do |a|
diff --git a/lib/chef/provider/service/simple.rb b/lib/chef/provider/service/simple.rb
index d295513b42..bb3d819b3d 100644
--- a/lib/chef/provider/service/simple.rb
+++ b/lib/chef/provider/service/simple.rb
@@ -58,21 +58,21 @@ class Chef
shared_resource_requirements
requirements.assert(:start) do |a|
a.assertion { @new_resource.start_command }
- a.failure_message Chef::Exceptions::Service, "#{self.to_s} requires that start_command be set"
+ a.failure_message Chef::Exceptions::Service, "#{self} requires that start_command be set"
end
requirements.assert(:stop) do |a|
a.assertion { @new_resource.stop_command }
- a.failure_message Chef::Exceptions::Service, "#{self.to_s} requires that stop_command be set"
+ a.failure_message Chef::Exceptions::Service, "#{self} requires that stop_command be set"
end
requirements.assert(:restart) do |a|
a.assertion { @new_resource.restart_command || ( @new_resource.start_command && @new_resource.stop_command ) }
- a.failure_message Chef::Exceptions::Service, "#{self.to_s} requires a restart_command or both start_command and stop_command be set in order to perform a restart"
+ a.failure_message Chef::Exceptions::Service, "#{self} requires a restart_command or both start_command and stop_command be set in order to perform a restart"
end
requirements.assert(:reload) do |a|
a.assertion { @new_resource.reload_command }
- a.failure_message Chef::Exceptions::UnsupportedAction, "#{self.to_s} requires a reload_command be set in order to perform a reload"
+ a.failure_message Chef::Exceptions::UnsupportedAction, "#{self} requires a reload_command be set in order to perform a reload"
end
requirements.assert(:all_actions) do |a|
diff --git a/lib/chef/provider/service/windows.rb b/lib/chef/provider/service/windows.rb
index 355ffafc2a..f5c370246c 100644
--- a/lib/chef/provider/service/windows.rb
+++ b/lib/chef/provider/service/windows.rb
@@ -47,6 +47,8 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service
TIMEOUT = 60
+ SERVICE_RIGHT = 'SeServiceLogonRight'
+
def whyrun_supported?
false
end
@@ -78,10 +80,10 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service
Win32::Service.configure(new_config)
Chef::Log.info "#{@new_resource} configured with #{new_config.inspect}"
- # it would be nice to check if the user already has the logon privilege, but that turns out to be
- # nontrivial.
if new_config.has_key?(:service_start_name)
- grant_service_logon(new_config[:service_start_name])
+ unless Chef::ReservedNames::Win32::Security.get_account_right(canonicalize_username(new_config[:service_start_name])).include?(SERVICE_RIGHT)
+ grant_service_logon(new_config[:service_start_name])
+ end
end
state = current_state
@@ -236,62 +238,15 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service
end
private
- def make_policy_text(username)
- text = <<-EOS
-[Unicode]
-Unicode=yes
-[Privilege Rights]
-SeServiceLogonRight = \\\\#{canonicalize_username(username)},*S-1-5-80-0
-[Version]
-signature="$CHICAGO$"
-Revision=1
-EOS
- end
-
- def grant_logfile_name(username)
- Chef::Util::PathHelper.canonical_path("#{Dir.tmpdir}/logon_grant-#{clean_username_for_path(username)}-#{$$}.log", prefix=false)
- end
-
- def grant_policyfile_name(username)
- Chef::Util::PathHelper.canonical_path("#{Dir.tmpdir}/service_logon_policy-#{clean_username_for_path(username)}-#{$$}.inf", prefix=false)
- end
-
- def grant_dbfile_name(username)
- "#{ENV['TEMP']}\\secedit.sdb"
- end
-
def grant_service_logon(username)
- logfile = grant_logfile_name(username)
- policy_file = ::File.new(grant_policyfile_name(username), 'w')
- policy_text = make_policy_text(username)
- dbfile = grant_dbfile_name(username) # this is just an audit file.
-
begin
- Chef::Log.debug "Policy file text:\n#{policy_text}"
- policy_file.puts(policy_text)
- policy_file.close # need to flush the buffer.
-
- # it would be nice to do this with APIs instead, but the LSA_* APIs are
- # particularly onerous and life is short.
- cmd = %Q{secedit.exe /configure /db "#{dbfile}" /cfg "#{policy_file.path}" /areas USER_RIGHTS SECURITYPOLICY SERVICES /log "#{logfile}"}
- Chef::Log.debug "Granting logon-as-service privilege with: #{cmd}"
- runner = shell_out(cmd)
-
- if runner.exitstatus != 0
- Chef::Log.fatal "Logon-as-service grant failed with output: #{runner.stdout}"
- raise Chef::Exceptions::Service, <<-EOS
-Logon-as-service grant failed with policy file #{policy_file.path}.
-You can look at #{logfile} for details, or do `secedit /analyze #{dbfile}`.
-The failed command was `#{cmd}`.
-EOS
- end
-
- Chef::Log.info "Grant logon-as-service to user '#{username}' successful."
-
- ::File.delete(dbfile) rescue nil
- ::File.delete(policy_file)
- ::File.delete(logfile) rescue nil # logfile is not always present at end.
+ Chef::ReservedNames::Win32::Security.add_account_right(canonicalize_username(username), SERVICE_RIGHT)
+ rescue Chef::Exceptions::Win32APIError => err
+ Chef::Log.fatal "Logon-as-service grant failed with output: #{err}"
+ raise Chef::Exceptions::Service, "Logon-as-service grant failed for #{username}: #{err}"
end
+
+ Chef::Log.info "Grant logon-as-service to user '#{username}' successful."
true
end
@@ -300,8 +255,6 @@ EOS
username.gsub(/[\/\\. ]+/, '_')
end
- # the security policy file only seems to accept \\username, so fix .\username or .\\username.
- # TODO: this probably has to be fixed to handle various valid Windows names correctly.
def canonicalize_username(username)
username.sub(/^\.?\\+/, '')
end
diff --git a/lib/chef/providers.rb b/lib/chef/providers.rb
index f5e7a0f989..b4eeabd48d 100644
--- a/lib/chef/providers.rb
+++ b/lib/chef/providers.rb
@@ -1,6 +1,6 @@
#
# Author:: Daniel DeLeo (<dan@opscode.com>)
-# Copyright:: Copyright (c) 2010 Opscode, Inc.
+# Copyright:: Copyright (c) 2010-2015 Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -57,6 +57,7 @@ require 'chef/provider/whyrun_safe_ruby_block'
require 'chef/provider/env/windows'
require 'chef/provider/package/apt'
+require 'chef/provider/package/chocolatey'
require 'chef/provider/package/dpkg'
require 'chef/provider/package/easy_install'
require 'chef/provider/package/freebsd/port'
diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb
index 4aec8cf1f6..6b56a0107a 100644
--- a/lib/chef/resource.rb
+++ b/lib/chef/resource.rb
@@ -658,7 +658,7 @@ class Chef
def inspect
ivars = instance_variables.map { |ivar| ivar.to_sym } - FORBIDDEN_IVARS
- ivars.inject("<#{to_s}") do |str, ivar|
+ ivars.inject("<#{self}") do |str, ivar|
str << " #{ivar}: #{instance_variable_get(ivar).inspect}"
end << ">"
end
@@ -1332,7 +1332,7 @@ class Chef
if enclosing_provider && enclosing_provider.respond_to?(method_symbol)
enclosing_provider.send(method_symbol, *args, &block)
else
- raise NoMethodError, "undefined method `#{method_symbol.to_s}' for #{self.class.to_s}"
+ raise NoMethodError, "undefined method `#{method_symbol}' for #{self.class}"
end
end
diff --git a/lib/chef/resource/chocolatey_package.rb b/lib/chef/resource/chocolatey_package.rb
new file mode 100644
index 0000000000..57a6bd2357
--- /dev/null
+++ b/lib/chef/resource/chocolatey_package.rb
@@ -0,0 +1,39 @@
+#
+# Author:: Adam Jacob (<adam@opscode.com>)
+# Copyright:: Copyright (c) 2008-2015 Chef Software, Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+require 'chef/resource/package'
+
+class Chef
+ class Resource
+ class ChocolateyPackage < Chef::Resource::Package
+
+ provides :chocolatey_package, os: "windows"
+
+ allowed_actions :install, :upgrade, :remove, :uninstall, :purge, :reconfig
+
+ def initialize(name, run_context=nil)
+ super
+ @resource_name = :chocolatey_package
+ end
+
+ property :package_name, [String, Array], coerce: proc { |x| [x].flatten }
+
+ property :version, [String, Array], coerce: proc { |x| [x].flatten }
+ end
+ end
+end
diff --git a/lib/chef/resource/cron.rb b/lib/chef/resource/cron.rb
index 93cf41bc37..70c2dd89a3 100644
--- a/lib/chef/resource/cron.rb
+++ b/lib/chef/resource/cron.rb
@@ -123,7 +123,7 @@ class Chef
end
begin
error_message = "You provided '#{arg}' as a weekday, acceptable values are "
- error_message << Provider::Cron::WEEKDAY_SYMBOLS.map {|sym| ":#{sym.to_s}"}.join(', ')
+ error_message << Provider::Cron::WEEKDAY_SYMBOLS.map {|sym| ":#{sym}"}.join(', ')
error_message << " and a string in crontab format"
if (arg.is_a?(Symbol) && !Provider::Cron::WEEKDAY_SYMBOLS.include?(arg)) ||
(!arg.is_a?(Symbol) && integerize(arg) > 7) ||
diff --git a/lib/chef/resource/dsc_resource.rb b/lib/chef/resource/dsc_resource.rb
index 0664dc7d7f..6ffa0ca248 100644
--- a/lib/chef/resource/dsc_resource.rb
+++ b/lib/chef/resource/dsc_resource.rb
@@ -1,120 +1,120 @@
-#
-# Author:: Adam Edwards (<adamed@getchef.com>)
-#
-# Copyright:: 2014, Opscode, Inc.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-require 'chef/dsl/powershell'
-
-class Chef
- class Resource
- class DscResource < Chef::Resource
- provides :dsc_resource, os: "windows"
-
- # This class will check if the object responds to
- # to_text. If it does, it will call that as opposed
- # to inspect. This is useful for properties that hold
- # objects such as PsCredential, where we do not want
- # to dump the actual ivars
- class ToTextHash < Hash
- def to_text
- descriptions = self.map do |(property, obj)|
- obj_text = if obj.respond_to?(:to_text)
- obj.to_text
- else
- obj.inspect
- end
- "#{property}=>#{obj_text}"
- end
- "{#{descriptions.join(', ')}}"
- end
- end
-
- include Chef::DSL::Powershell
-
- default_action :run
-
- def initialize(name, run_context)
- super
- @properties = ToTextHash.new
- @resource = nil
- @reboot_action = :nothing
- end
-
- def resource(value=nil)
- if value
- @resource = value
- else
- @resource
- end
- end
-
- def module_name(value=nil)
- if value
- @module_name = value
- else
- @module_name
- end
- end
-
- def property(property_name, value=nil)
- if not property_name.is_a?(Symbol)
- raise TypeError, "A property name of type Symbol must be specified, '#{property_name.to_s}' of type #{property_name.class.to_s} was given"
- end
-
- if value.nil?
- value_of(@properties[property_name])
- else
- @properties[property_name] = value
- end
- end
-
- def properties
- @properties.reduce({}) do |memo, (k, v)|
- memo[k] = value_of(v)
- memo
- end
- end
-
- # This property takes the action message for the reboot resource
- # If the set method of the DSC resource indicate that a reboot
- # is necessary, reboot_action provides the mechanism for a reboot to
- # be requested.
- def reboot_action(value=nil)
- if value
- @reboot_action = value
- else
- @reboot_action
- end
- end
-
- def timeout(arg=nil)
- set_or_return(
- :timeout,
- arg,
- :kind_of => [ Integer ]
- )
- end
- private
-
- def value_of(value)
- if value.is_a?(DelayedEvaluator)
- value.call
- else
- value
- end
- end
- end
- end
-end
+#
+# Author:: Adam Edwards (<adamed@getchef.com>)
+#
+# Copyright:: 2014, Opscode, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+require 'chef/dsl/powershell'
+
+class Chef
+ class Resource
+ class DscResource < Chef::Resource
+ provides :dsc_resource, os: "windows"
+
+ # This class will check if the object responds to
+ # to_text. If it does, it will call that as opposed
+ # to inspect. This is useful for properties that hold
+ # objects such as PsCredential, where we do not want
+ # to dump the actual ivars
+ class ToTextHash < Hash
+ def to_text
+ descriptions = self.map do |(property, obj)|
+ obj_text = if obj.respond_to?(:to_text)
+ obj.to_text
+ else
+ obj.inspect
+ end
+ "#{property}=>#{obj_text}"
+ end
+ "{#{descriptions.join(', ')}}"
+ end
+ end
+
+ include Chef::DSL::Powershell
+
+ default_action :run
+
+ def initialize(name, run_context)
+ super
+ @properties = ToTextHash.new
+ @resource = nil
+ @reboot_action = :nothing
+ end
+
+ def resource(value=nil)
+ if value
+ @resource = value
+ else
+ @resource
+ end
+ end
+
+ def module_name(value=nil)
+ if value
+ @module_name = value
+ else
+ @module_name
+ end
+ end
+
+ def property(property_name, value=nil)
+ if not property_name.is_a?(Symbol)
+ raise TypeError, "A property name of type Symbol must be specified, '#{property_name}' of type #{property_name.class} was given"
+ end
+
+ if value.nil?
+ value_of(@properties[property_name])
+ else
+ @properties[property_name] = value
+ end
+ end
+
+ def properties
+ @properties.reduce({}) do |memo, (k, v)|
+ memo[k] = value_of(v)
+ memo
+ end
+ end
+
+ # This property takes the action message for the reboot resource
+ # If the set method of the DSC resource indicate that a reboot
+ # is necessary, reboot_action provides the mechanism for a reboot to
+ # be requested.
+ def reboot_action(value=nil)
+ if value
+ @reboot_action = value
+ else
+ @reboot_action
+ end
+ end
+
+ def timeout(arg=nil)
+ set_or_return(
+ :timeout,
+ arg,
+ :kind_of => [ Integer ]
+ )
+ end
+ private
+
+ def value_of(value)
+ if value.is_a?(DelayedEvaluator)
+ value.call
+ else
+ value
+ end
+ end
+ end
+ end
+end
diff --git a/lib/chef/resource/file/verification.rb b/lib/chef/resource/file/verification.rb
index ba0bb08201..e7530ce628 100644
--- a/lib/chef/resource/file/verification.rb
+++ b/lib/chef/resource/file/verification.rb
@@ -28,7 +28,7 @@ class Chef
# See RFC 027 for a full specification
#
# File verifications allow user-supplied commands a means of
- # preventing file reosurce content deploys. Their intended use
+ # preventing file resource content deploys. Their intended use
# is to verify the contents of a temporary file before it is
# deployed onto the system.
#
diff --git a/lib/chef/resource/windows_script.rb b/lib/chef/resource/windows_script.rb
index 2bbd01d5aa..2dff4cde31 100644
--- a/lib/chef/resource/windows_script.rb
+++ b/lib/chef/resource/windows_script.rb
@@ -57,7 +57,7 @@ class Chef
"cannot execute script with requested architecture 'i386' on Windows Nano Server"
elsif ! node_supports_windows_architecture?(node, desired_architecture)
raise Chef::Exceptions::Win32ArchitectureIncorrect,
- "cannot execute script with requested architecture '#{desired_architecture.to_s}' on a system with architecture '#{node_windows_architecture(node)}'"
+ "cannot execute script with requested architecture '#{desired_architecture}' on a system with architecture '#{node_windows_architecture(node)}'"
end
end
end
diff --git a/lib/chef/resource_definition.rb b/lib/chef/resource_definition.rb
index cffabb6786..43350dda2b 100644
--- a/lib/chef/resource_definition.rb
+++ b/lib/chef/resource_definition.rb
@@ -62,7 +62,7 @@ class Chef
end
def to_s
- "#{name.to_s}"
+ "#{name}"
end
end
end
diff --git a/lib/chef/resource_reporter.rb b/lib/chef/resource_reporter.rb
index 1175b0afb3..e2c71f7bd5 100644
--- a/lib/chef/resource_reporter.rb
+++ b/lib/chef/resource_reporter.rb
@@ -121,7 +121,7 @@ class Chef
if reporting_enabled?
begin
resource_history_url = "reports/nodes/#{node_name}/runs"
- server_response = @rest_client.post_rest(resource_history_url, {:action => :start, :run_id => run_id,
+ server_response = @rest_client.post(resource_history_url, {:action => :start, :run_id => run_id,
:start_time => start_time.to_s}, headers)
rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
handle_error_starting_run(e, resource_history_url)
@@ -230,10 +230,9 @@ class Chef
Chef::Log.debug run_data.inspect
compressed_data = encode_gzip(Chef::JSONCompat.to_json(run_data))
Chef::Log.debug("Sending compressed run data...")
- # Since we're posting compressed data we can not directly call post_rest which expects JSON
- reporting_url = @rest_client.create_url(resource_history_url)
+ # Since we're posting compressed data we can not directly call post which expects JSON
begin
- @rest_client.raw_http_request(:POST, reporting_url, headers({'Content-Encoding' => 'gzip'}), compressed_data)
+ @rest_client.raw_request(:POST, resource_history_url, headers({'Content-Encoding' => 'gzip'}), compressed_data)
rescue StandardError => e
if e.respond_to? :response
Chef::FileCache.store("failed-reporting-data.json", Chef::JSONCompat.to_json_pretty(run_data), 0640)
diff --git a/lib/chef/resources.rb b/lib/chef/resources.rb
index f699d95ace..cc5b9be8c6 100644
--- a/lib/chef/resources.rb
+++ b/lib/chef/resources.rb
@@ -1,6 +1,6 @@
#
# Author:: Daniel DeLeo (<dan@opscode.com>)
-# Copyright:: Copyright (c) 2010 Opscode, Inc.
+# Copyright:: Copyright (c) 2010-2015 Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,6 +22,7 @@ require 'chef/resource/batch'
require 'chef/resource/breakpoint'
require 'chef/resource/cookbook_file'
require 'chef/resource/chef_gem'
+require 'chef/resource/chocolatey_package'
require 'chef/resource/cron'
require 'chef/resource/csh'
require 'chef/resource/deploy'
diff --git a/lib/chef/role.rb b/lib/chef/role.rb
index c085d1d714..6984a8a245 100644
--- a/lib/chef/role.rb
+++ b/lib/chef/role.rb
@@ -24,6 +24,7 @@ require 'chef/mixin/from_file'
require 'chef/run_list'
require 'chef/mash'
require 'chef/json_compat'
+require 'chef/server_api'
require 'chef/search/query'
class Chef
@@ -45,11 +46,11 @@ class Chef
end
def chef_server_rest
- @chef_server_rest ||= Chef::REST.new(Chef::Config[:chef_server_url])
+ @chef_server_rest ||= Chef::ServerAPI.new(Chef::Config[:chef_server_url])
end
def self.chef_server_rest
- Chef::REST.new(Chef::Config[:chef_server_url])
+ Chef::ServerAPI.new(Chef::Config[:chef_server_url])
end
def name(arg=nil)
@@ -170,6 +171,10 @@ class Chef
# Create a Chef::Role from JSON
def self.json_create(o)
+ from_hash(o)
+ end
+
+ def self.from_hash(o)
role = new
role.name(o["name"])
role.description(o["description"])
@@ -199,42 +204,42 @@ class Chef
end
response
else
- chef_server_rest.get_rest("roles")
+ chef_server_rest.get("roles")
end
end
# Load a role by name from the API
def self.load(name)
- chef_server_rest.get_rest("roles/#{name}")
+ from_hash(chef_server_rest.get("roles/#{name}"))
end
def environment(env_name)
- chef_server_rest.get_rest("roles/#{@name}/environments/#{env_name}")
+ chef_server_rest.get("roles/#{@name}/environments/#{env_name}")
end
def environments
- chef_server_rest.get_rest("roles/#{@name}/environments")
+ chef_server_rest.get("roles/#{@name}/environments")
end
# Remove this role via the REST API
def destroy
- chef_server_rest.delete_rest("roles/#{@name}")
+ chef_server_rest.delete("roles/#{@name}")
end
# Save this role via the REST API
def save
begin
- chef_server_rest.put_rest("roles/#{@name}", self)
+ chef_server_rest.put("roles/#{@name}", self)
rescue Net::HTTPServerException => e
raise e unless e.response.code == "404"
- chef_server_rest.post_rest("roles", self)
+ chef_server_rest.post("roles", self)
end
self
end
# Create the role via the REST API
def create
- chef_server_rest.post_rest("roles", self)
+ chef_server_rest.post("roles", self)
self
end
@@ -258,7 +263,8 @@ class Chef
if js_path && File.exists?(js_path)
# from_json returns object.class => json_class in the JSON.
- return Chef::JSONCompat.from_json(IO.read(js_path))
+ hsh = Chef::JSONCompat.parse(IO.read(js_path))
+ return from_hash(hsh)
elsif rb_path && File.exists?(rb_path)
role = Chef::Role.new
role.name(name)
diff --git a/lib/chef/run_list/run_list_expansion.rb b/lib/chef/run_list/run_list_expansion.rb
index 64e4326fb8..2f2d170446 100644
--- a/lib/chef/run_list/run_list_expansion.rb
+++ b/lib/chef/run_list/run_list_expansion.rb
@@ -21,7 +21,7 @@ require 'chef/mash'
require 'chef/mixin/deep_merge'
require 'chef/role'
-require 'chef/rest'
+require 'chef/server_api'
require 'chef/json_compat'
class Chef
@@ -45,7 +45,7 @@ class Chef
attr_reader :missing_roles_with_including_role
# The data source passed to the constructor. Not used in this class.
- # In subclasses, this is a couchdb or Chef::REST object pre-configured
+ # In subclasses, this is a Chef::ServerAPI object pre-configured
# to fetch roles from their correct location.
attr_reader :source
@@ -214,11 +214,11 @@ class Chef
class RunListExpansionFromAPI < RunListExpansion
def rest
- @rest ||= (source || Chef::REST.new(Chef::Config[:chef_server_url]))
+ @rest ||= (source || Chef::ServerAPI.new(Chef::Config[:chef_server_url]))
end
def fetch_role(name, included_by)
- rest.get_rest("roles/#{name}")
+ Chef::Role.from_hash(rest.get("roles/#{name}"))
rescue Net::HTTPServerException => e
if e.message == '404 "Not Found"'
role_not_found(name, included_by)
diff --git a/lib/chef/search/query.rb b/lib/chef/search/query.rb
index 658af8779c..c5c6bc6ce0 100644
--- a/lib/chef/search/query.rb
+++ b/lib/chef/search/query.rb
@@ -18,7 +18,7 @@
require 'chef/config'
require 'chef/exceptions'
-require 'chef/rest'
+require 'chef/server_api'
require 'uri'
@@ -35,7 +35,7 @@ class Chef
end
def rest
- @rest ||= Chef::REST.new(@url || @config[:chef_server_url])
+ @rest ||= Chef::ServerAPI.new(@url || @config[:chef_server_url])
end
# Backwards compatability for cookbooks.
@@ -150,12 +150,26 @@ WARNDEP
query_string = create_query_string(type, query, rows, start, sort)
if filter_result
- response = rest.post_rest(query_string, filter_result)
+ response = rest.post(query_string, filter_result)
# response returns rows in the format of
# { "url" => url_to_node, "data" => filter_result_hash }
response['rows'].map! { |row| row['data'] }
else
- response = rest.get_rest(query_string)
+ response = rest.get(query_string)
+ response['rows'].map! do |row|
+ case type.to_s
+ when 'node'
+ Chef::Node.from_hash(row)
+ when 'role'
+ Chef::Role.from_hash(row)
+ when 'environment'
+ Chef::Environment.from_hash(row)
+ when 'client'
+ Chef::ApiClient.from_hash(row)
+ else
+ Chef::DataBagItem.from_hash(row)
+ end
+ end
end
response
diff --git a/lib/chef/server_api.rb b/lib/chef/server_api.rb
index 764296f8c8..6c864d53fb 100644
--- a/lib/chef/server_api.rb
+++ b/lib/chef/server_api.rb
@@ -23,6 +23,7 @@ require 'chef/http/decompressor'
require 'chef/http/json_input'
require 'chef/http/json_output'
require 'chef/http/remote_request_id'
+require 'chef/http/validate_content_length'
class Chef
class ServerAPI < Chef::HTTP
@@ -31,6 +32,7 @@ class Chef
options[:client_name] ||= Chef::Config[:node_name]
options[:signing_key_filename] ||= Chef::Config[:client_key]
options[:signing_key_filename] = nil if chef_zero_uri?(url)
+ options[:inflate_json_class] = false
super(url, options)
end
@@ -40,6 +42,30 @@ class Chef
use Chef::HTTP::Decompressor
use Chef::HTTP::Authenticator
use Chef::HTTP::RemoteRequestID
+
+ # ValidateContentLength should come after Decompressor
+ # because the order of middlewares is reversed when handling
+ # responses.
+ use Chef::HTTP::ValidateContentLength
+
+ # Makes an HTTP request to +path+ with the given +method+, +headers+, and
+ # +data+ (if applicable). Does not apply any middleware, besides that
+ # needed for Authentication.
+ def raw_request(method, path, headers={}, data=false)
+ url = create_url(path)
+ method, url, headers, data = Chef::HTTP::Authenticator.new(options).handle_request(method, url, headers, data)
+ method, url, headers, data = Chef::HTTP::RemoteRequestID.new(options).handle_request(method, url, headers, data)
+ response, rest_request, return_value = send_http_request(method, url, headers, data)
+ response.error! unless success_response?(response)
+ return_value
+ rescue Exception => exception
+ log_failed_request(response, return_value) unless response.nil?
+
+ if exception.respond_to?(:chef_rest_request=)
+ exception.chef_rest_request = rest_request
+ end
+ raise
+ end
end
end
diff --git a/lib/chef/shell/ext.rb b/lib/chef/shell/ext.rb
index d516524765..ae013de76b 100644
--- a/lib/chef/shell/ext.rb
+++ b/lib/chef/shell/ext.rb
@@ -23,7 +23,7 @@ require 'chef/dsl/platform_introspection'
require 'chef/version'
require 'chef/shell/shell_session'
require 'chef/shell/model_wrapper'
-require 'chef/shell/shell_rest'
+require 'chef/server_api'
require 'chef/json_compat'
module Shell
@@ -331,7 +331,7 @@ E
edited_data = Tempfile.open([filename, ".js"]) do |tempfile|
tempfile.sync = true
tempfile.puts Chef::JSONCompat.to_json(object)
- system("#{Shell.editor.to_s} #{tempfile.path}")
+ system("#{Shell.editor} #{tempfile.path}")
tempfile.rewind
tempfile.read
end
@@ -536,7 +536,7 @@ E
desc "A REST Client configured to authenticate with the API"
def api
- @rest = Shell::ShellREST.new(Chef::Config[:chef_server_url])
+ @rest = Chef::ServerAPI.new(Chef::Config[:chef_server_url])
end
end
diff --git a/lib/chef/shell/shell_rest.rb b/lib/chef/shell/shell_rest.rb
deleted file mode 100644
index a485a0a1a8..0000000000
--- a/lib/chef/shell/shell_rest.rb
+++ /dev/null
@@ -1,28 +0,0 @@
-#--
-# Author:: Daniel DeLeo (<dan@opscode.com>)
-# Copyright:: Copyright (c) 2010 Opscode, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-module Shell
- class ShellREST < Chef::REST
-
- alias :get :get_rest
- alias :put :put_rest
- alias :post :post_rest
- alias :delete :delete_rest
-
- end
-end
diff --git a/lib/chef/shell/shell_session.rb b/lib/chef/shell/shell_session.rb
index 73e6c34ebb..7b3939da69 100644
--- a/lib/chef/shell/shell_session.rb
+++ b/lib/chef/shell/shell_session.rb
@@ -201,7 +201,7 @@ module Shell
def rebuild_context
@run_status = Chef::RunStatus.new(@node, @events)
- Chef::Cookbook::FileVendor.fetch_from_remote(Chef::REST.new(Chef::Config[:chef_server_url]))
+ Chef::Cookbook::FileVendor.fetch_from_remote(Chef::ServerAPI.new(Chef::Config[:chef_server_url]))
cookbook_hash = @client.sync_cookbooks
cookbook_collection = Chef::CookbookCollection.new(cookbook_hash)
@run_context = Chef::RunContext.new(node, cookbook_collection, @events)
@@ -253,7 +253,8 @@ module Shell
end
def register
- @rest = Chef::REST.new(Chef::Config[:chef_server_url], Chef::Config[:node_name], Chef::Config[:client_key])
+ @rest = Chef::ServerAPI.new(Chef::Config[:chef_server_url], :client_name => Chef::Config[:node_name],
+ :signing_key_filename => Chef::Config[:client_key])
end
end
diff --git a/lib/chef/user_v1.rb b/lib/chef/user_v1.rb
index 31cb0576a2..077fca50b9 100644
--- a/lib/chef/user_v1.rb
+++ b/lib/chef/user_v1.rb
@@ -140,7 +140,7 @@ class Chef
def destroy
# will default to the current API version (Chef::Authenticator::DEFAULT_SERVER_API_VERSION)
- Chef::REST.new(Chef::Config[:chef_server_url]).delete("users/#{@username}")
+ Chef::ServerAPI.new(Chef::Config[:chef_server_url]).delete("users/#{@username}")
end
def create
@@ -287,7 +287,7 @@ class Chef
end
def self.list(inflate=false)
- response = Chef::REST.new(Chef::Config[:chef_server_url]).get('users')
+ response = Chef::ServerAPI.new(Chef::Config[:chef_server_url]).get('users')
users = if response.is_a?(Array)
# EC 11 / CS 12 V0, V1
# GET /organizations/<org>/users
@@ -312,7 +312,7 @@ class Chef
def self.load(username)
# will default to the current API version (Chef::Authenticator::DEFAULT_SERVER_API_VERSION)
- response = Chef::REST.new(Chef::Config[:chef_server_url]).get("users/#{username}")
+ response = Chef::ServerAPI.new(Chef::Config[:chef_server_url]).get("users/#{username}")
Chef::UserV1.from_hash(response)
end
diff --git a/lib/chef/util/dsc/configuration_generator.rb b/lib/chef/util/dsc/configuration_generator.rb
index 0d7296eae9..2041278e4a 100644
--- a/lib/chef/util/dsc/configuration_generator.rb
+++ b/lib/chef/util/dsc/configuration_generator.rb
@@ -72,7 +72,7 @@ class Chef::Util::DSC
if configuration_flags
configuration_flags.map do | switch, value |
if merged_configuration_flags.key?(switch.to_s.downcase.to_sym)
- raise ArgumentError, "The `flags` attribute for the dsc_script resource contained a command line switch :#{switch.to_s} that is disallowed."
+ raise ArgumentError, "The `flags` attribute for the dsc_script resource contained a command line switch :#{switch} that is disallowed."
end
merged_configuration_flags[switch.to_s.downcase.to_sym] = value
end
diff --git a/lib/chef/util/powershell/cmdlet.rb b/lib/chef/util/powershell/cmdlet.rb
index 47d63a2b85..7eab098c83 100644
--- a/lib/chef/util/powershell/cmdlet.rb
+++ b/lib/chef/util/powershell/cmdlet.rb
@@ -38,7 +38,7 @@ class Powershell
when :object
@json_format = true
else
- raise ArgumentError, "Invalid output format #{output_format.to_s} specified"
+ raise ArgumentError, "Invalid output format #{output_format} specified"
end
@cmdlet = cmdlet
@@ -114,7 +114,7 @@ class Powershell
def command_switches_string(switches)
command_switches = switches.map do | switch_name, switch_value |
if switch_name.class != Symbol
- raise ArgumentError, "Invalid type `#{switch_name} `for PowerShell switch '#{switch_name.to_s}'. The switch must be specified as a Symbol'"
+ raise ArgumentError, "Invalid type `#{switch_name} `for PowerShell switch '#{switch_name}'. The switch must be specified as a Symbol'"
end
validate_switch_name!(switch_name)
@@ -133,7 +133,7 @@ class Powershell
when String
switch_argument = escape_string_parameter_value(switch_value)
else
- raise ArgumentError, "Invalid argument type `#{switch_value.class}` specified for PowerShell switch `:#{switch_name.to_s}`. Arguments to PowerShell must be of type `String`, `Numeric`, `Float`, `FalseClass`, or `TrueClass`"
+ raise ArgumentError, "Invalid argument type `#{switch_value.class}` specified for PowerShell switch `:#{switch_name}`. Arguments to PowerShell must be of type `String`, `Numeric`, `Float`, `FalseClass`, or `TrueClass`"
end
switch_present ? ["-#{switch_name.to_s.downcase}", switch_argument].join(' ').strip : ''
diff --git a/lib/chef/version/platform.rb b/lib/chef/version/platform.rb
index 81e7614646..d9028b5d15 100644
--- a/lib/chef/version/platform.rb
+++ b/lib/chef/version/platform.rb
@@ -34,7 +34,7 @@ class Chef
when /^(\d+).(\d+)-[a-z]+\d?(-p(\d+))?$/i # Match FreeBSD
[ $1.to_i, $2.to_i, ($4 ? $4.to_i : 0)]
else
- msg = "'#{str.to_s}' does not match 'x.y.z', 'x.y' or 'x'"
+ msg = "'#{str}' does not match 'x.y.z', 'x.y' or 'x'"
raise Chef::Exceptions::InvalidPlatformVersion.new( msg )
end
end
diff --git a/lib/chef/version_class.rb b/lib/chef/version_class.rb
index 01af6f1f55..913c50442d 100644
--- a/lib/chef/version_class.rb
+++ b/lib/chef/version_class.rb
@@ -61,7 +61,7 @@ class Chef
when /^(\d+)\.(\d+)$/
[ $1.to_i, $2.to_i, 0 ]
else
- msg = "'#{str.to_s}' does not match 'x.y.z' or 'x.y'"
+ msg = "'#{str}' does not match 'x.y.z' or 'x.y'"
raise Chef::Exceptions::InvalidCookbookVersion.new( msg )
end
end
diff --git a/lib/chef/version_constraint.rb b/lib/chef/version_constraint.rb
index a78e32e94f..ba2169c8cb 100644
--- a/lib/chef/version_constraint.rb
+++ b/lib/chef/version_constraint.rb
@@ -50,7 +50,7 @@ class Chef
end
def inspect
- "(#{to_s})"
+ "(#{self})"
end
def to_s
diff --git a/lib/chef/win32/api.rb b/lib/chef/win32/api.rb
index 4786222bd4..de3381c5ba 100644
--- a/lib/chef/win32/api.rb
+++ b/lib/chef/win32/api.rb
@@ -147,6 +147,8 @@ class Chef
host.typedef :long, :LRESULT # Signed result of message processing. WinDef.h: host.typedef LONG_PTR LRESULT;
host.typedef :pointer, :LPWIN32_FIND_DATA # Pointer to WIN32_FIND_DATA struct
host.typedef :pointer, :LPBY_HANDLE_FILE_INFORMATION # Point to a BY_HANDLE_FILE_INFORMATION struct
+ host.typedef :pointer, :LSA_HANDLE # A handle to a Policy object
+ host.typedef :ulong, :NTSTATUS # An NTSTATUS code returned by an LSA function call.
host.typedef :pointer, :PBOOL # Pointer to a BOOL.
host.typedef :pointer, :PBOOLEAN # Pointer to a BOOL.
host.typedef :pointer, :PBYTE # Pointer to a BYTE.
@@ -174,12 +176,16 @@ class Chef
host.typedef :pointer, :PLONG_PTR # Pointer to a LONG_PTR.
host.typedef :pointer, :PLONG32 # Pointer to a LONG32.
host.typedef :pointer, :PLONG64 # Pointer to a LONG64.
+ host.typedef :pointer, :PLSA_HANDLE # Pointer to an LSA_HANDLE
+ host.typedef :pointer, :PLSA_OBJECT_ATTRIBUTES # Pointer to an LSA_OBJECT_ATTRIBUTES
+ host.typedef :pointer, :PLSA_UNICODE_STRING # Pointer to LSA_UNICODE_STRING
host.typedef :pointer, :PLUID # Pointer to a LUID.
host.typedef :pointer, :POINTER_32 # 32-bit pointer. On a 32-bit system, this is a native pointer. On a 64-bit system, this is a truncated 64-bit pointer.
host.typedef :pointer, :POINTER_64 # 64-bit pointer. On a 64-bit system, this is a native pointer. On a 32-bit system, this is a sign-extended 32-bit pointer.
host.typedef :pointer, :POINTER_SIGNED # A signed pointer.
host.typedef :pointer, :POINTER_UNSIGNED # An unsigned pointer.
host.typedef :pointer, :PSHORT # Pointer to a SHORT.
+ host.typedef :pointer, :PSID # Pointer to an account SID
host.typedef :pointer, :PSIZE_T # Pointer to a SIZE_T.
host.typedef :pointer, :PSSIZE_T # Pointer to a SSIZE_T.
host.typedef :pointer, :PSTR # Pointer to a null-terminated string of 8-bit Windows (ANSI) characters. For more information, see Character Sets Used By Fonts.
@@ -188,7 +194,6 @@ class Chef
host.typedef :pointer, :PCRYPTPROTECT_PROMPTSTRUCT # Pointer to a CRYPTOPROTECT_PROMPTSTRUCT.
host.typedef :pointer, :PDATA_BLOB # Pointer to a DATA_BLOB.
host.typedef :pointer, :PTSTR # A PWSTR if UNICODE is defined, a PSTR otherwise.
- host.typedef :pointer, :PSID
host.typedef :pointer, :PUCHAR # Pointer to a UCHAR.
host.typedef :pointer, :PUHALF_PTR # Pointer to a UHALF_PTR.
host.typedef :pointer, :PUINT # Pointer to a UINT.
diff --git a/lib/chef/win32/api/security.rb b/lib/chef/win32/api/security.rb
index 4c352a3554..4353c488f8 100644
--- a/lib/chef/win32/api/security.rb
+++ b/lib/chef/win32/api/security.rb
@@ -207,6 +207,21 @@ class Chef
LOGON32_PROVIDER_WINNT40 = 2;
LOGON32_PROVIDER_WINNT50 = 3;
+ # LSA access policy
+ POLICY_VIEW_LOCAL_INFORMATION = 0x00000001
+ POLICY_VIEW_AUDIT_INFORMATION = 0x00000002
+ POLICY_GET_PRIVATE_INFORMATION = 0x00000004
+ POLICY_TRUST_ADMIN = 0x00000008
+ POLICY_CREATE_ACCOUNT = 0x00000010
+ POLICY_CREATE_SECRET = 0x00000020
+ POLICY_CREATE_PRIVILEGE = 0x00000040
+ POLICY_SET_DEFAULT_QUOTA_LIMITS = 0x00000080
+ POLICY_SET_AUDIT_REQUIREMENTS = 0x00000100
+ POLICY_AUDIT_LOG_ADMIN = 0x00000200
+ POLICY_SERVER_ADMIN = 0x00000400
+ POLICY_LOOKUP_NAMES = 0x00000800
+ POLICY_NOTIFICATION = 0x00001000
+
###############################################
# Win32 API Bindings
###############################################
@@ -381,6 +396,23 @@ class Chef
end
end
+ # https://msdn.microsoft.com/en-us/library/windows/desktop/ms721829(v=vs.85).aspx
+ class LSA_OBJECT_ATTRIBUTES < FFI::Struct
+ layout :Length, :ULONG,
+ :RootDirectory, :HANDLE,
+ :ObjectName, :pointer,
+ :Attributes, :ULONG,
+ :SecurityDescriptor, :PVOID,
+ :SecurityQualityOfService, :PVOID
+ end
+
+ # https://msdn.microsoft.com/en-us/library/windows/desktop/ms721841(v=vs.85).aspx
+ class LSA_UNICODE_STRING < FFI::Struct
+ layout :Length, :USHORT,
+ :MaximumLength, :USHORT,
+ :Buffer, :PWSTR
+ end
+
ffi_lib "advapi32"
safe_attach_function :AccessCheck, [:pointer, :HANDLE, :DWORD, :pointer, :pointer, :pointer, :pointer, :pointer], :BOOL
@@ -415,6 +447,12 @@ class Chef
safe_attach_function :LookupPrivilegeNameW, [ :LPCWSTR, :PLUID, :LPWSTR, :LPDWORD ], :BOOL
safe_attach_function :LookupPrivilegeDisplayNameW, [ :LPCWSTR, :LPCWSTR, :LPWSTR, :LPDWORD, :LPDWORD ], :BOOL
safe_attach_function :LookupPrivilegeValueW, [ :LPCWSTR, :LPCWSTR, :PLUID ], :BOOL
+ safe_attach_function :LsaAddAccountRights, [ :pointer, :pointer, :pointer, :ULONG ], :NTSTATUS
+ safe_attach_function :LsaClose, [ :LSA_HANDLE ], :NTSTATUS
+ safe_attach_function :LsaEnumerateAccountRights, [ :LSA_HANDLE, :PSID, :PLSA_UNICODE_STRING, :PULONG ], :NTSTATUS
+ safe_attach_function :LsaFreeMemory, [ :PVOID ], :NTSTATUS
+ safe_attach_function :LsaNtStatusToWinError, [ :NTSTATUS ], :ULONG
+ safe_attach_function :LsaOpenPolicy, [ :PLSA_UNICODE_STRING, :PLSA_OBJECT_ATTRIBUTES, :DWORD, :PLSA_HANDLE ], :NTSTATUS
safe_attach_function :MakeAbsoluteSD, [ :pointer, :pointer, :LPDWORD, :pointer, :LPDWORD, :pointer, :LPDWORD, :pointer, :LPDWORD, :pointer, :LPDWORD], :BOOL
safe_attach_function :MapGenericMask, [ :PDWORD, :PGENERICMAPPING ], :void
safe_attach_function :OpenProcessToken, [ :HANDLE, :DWORD, :PHANDLE ], :BOOL
diff --git a/lib/chef/win32/error.rb b/lib/chef/win32/error.rb
index 2175608eeb..c638773d2a 100644
--- a/lib/chef/win32/error.rb
+++ b/lib/chef/win32/error.rb
@@ -57,8 +57,7 @@ class Chef
# nil::: always returns nil when it does not raise
# === Raises
# Chef::Exceptions::Win32APIError:::
- def self.raise!(message = nil)
- code = get_last_error
+ def self.raise!(message = nil, code = get_last_error)
msg = format_message(code).strip
formatted_message = ""
formatted_message << message if message
diff --git a/lib/chef/win32/security.rb b/lib/chef/win32/security.rb
index bc80517d80..38694c9fec 100644
--- a/lib/chef/win32/security.rb
+++ b/lib/chef/win32/security.rb
@@ -104,6 +104,22 @@ class Chef
end
end
+ def self.add_account_right(name, privilege)
+ privilege_pointer = FFI::MemoryPointer.new LSA_UNICODE_STRING, 1
+ privilege_lsa_string = LSA_UNICODE_STRING.new(privilege_pointer)
+ privilege_lsa_string[:Buffer] = FFI::MemoryPointer.from_string(privilege.to_wstring)
+ privilege_lsa_string[:Length] = privilege.length * 2
+ privilege_lsa_string[:MaximumLength] = (privilege.length + 1) * 2
+
+ with_lsa_policy(name) do |policy_handle, sid|
+ result = LsaAddAccountRights(policy_handle.read_pointer, sid, privilege_pointer, 1)
+ win32_error = LsaNtStatusToWinError(result)
+ if win32_error != 0
+ Chef::ReservedNames::Win32::Error.raise!(nil, win32_error)
+ end
+ end
+ end
+
def self.adjust_token_privileges(token, privileges)
token = token.handle if token.respond_to?(:handle)
old_privileges_size = FFI::Buffer.new(:long).write_long(privileges.size_with_privileges)
@@ -165,6 +181,29 @@ class Chef
end
end
+ def self.get_account_right(name)
+ privileges = []
+ privilege_pointer = FFI::MemoryPointer.new(:pointer)
+ privilege_length = FFI::MemoryPointer.new(:ulong)
+
+ with_lsa_policy(name) do |policy_handle, sid|
+ result = LsaEnumerateAccountRights(policy_handle.read_pointer, sid, privilege_pointer, privilege_length)
+ win32_error = LsaNtStatusToWinError(result)
+ return [] if win32_error == 2 # FILE_NOT_FOUND - No rights assigned
+ if win32_error != 0
+ Chef::ReservedNames::Win32::Error.raise!(nil, win32_error)
+ end
+
+ privilege_length.read_ulong.times do |i|
+ privilege = LSA_UNICODE_STRING.new(privilege_pointer.read_pointer + i * LSA_UNICODE_STRING.size)
+ privileges << privilege[:Buffer].read_wstring
+ end
+ LsaFreeMemory(privilege_pointer)
+ end
+
+ privileges
+ end
+
def self.get_ace(acl, index)
acl = acl.pointer if acl.respond_to?(:pointer)
ace = FFI::Buffer.new :pointer
@@ -548,6 +587,30 @@ class Chef
end
end
+ def self.with_lsa_policy(username)
+ sid = lookup_account_name(username)[1]
+
+ access = 0
+ access |= POLICY_CREATE_ACCOUNT
+ access |= POLICY_LOOKUP_NAMES
+
+ policy_handle = FFI::MemoryPointer.new(:pointer)
+ result = LsaOpenPolicy(nil, LSA_OBJECT_ATTRIBUTES.new, access, policy_handle)
+ win32_error = LsaNtStatusToWinError(result)
+ if win32_error != 0
+ Chef::ReservedNames::Win32::Error.raise!(nil, win32_error)
+ end
+
+ begin
+ yield policy_handle, sid.pointer
+ ensure
+ win32_error = LsaNtStatusToWinError(LsaClose(policy_handle.read_pointer))
+ if win32_error != 0
+ Chef::ReservedNames::Win32::Error.raise!(nil, win32_error)
+ end
+ end
+ end
+
def self.with_privileges(*privilege_names)
# Set privileges
token = open_current_process_token(TOKEN_READ | TOKEN_ADJUST_PRIVILEGES)
diff --git a/omnibus/.gitignore b/omnibus/.gitignore
new file mode 100644
index 0000000000..d97af2ef9c
--- /dev/null
+++ b/omnibus/.gitignore
@@ -0,0 +1,11 @@
+vendor/bundle
+pkg/*
+.kitchen.local.yml
+bin/*
+files/chef-server-cookbooks/cache/
+files/msi/ChefClient-Config.wxi
+cookbooks
+vendor/cookbooks
+build_timestamp
+ldd.out
+jenkins/chef-solo
diff --git a/omnibus/.kitchen.local.yml.vmware.example b/omnibus/.kitchen.local.yml.vmware.example
new file mode 100644
index 0000000000..69f001ef97
--- /dev/null
+++ b/omnibus/.kitchen.local.yml.vmware.example
@@ -0,0 +1,6 @@
+driver:
+ name: vagrant
+ provider: vmware_fusion
+ customize:
+ numvcpus: 4
+ memsize: 4096
diff --git a/omnibus/.kitchen.yml b/omnibus/.kitchen.yml
new file mode 100644
index 0000000000..844ae9d895
--- /dev/null
+++ b/omnibus/.kitchen.yml
@@ -0,0 +1,111 @@
+#
+# NOTE: this runs the omnibus cookbook, but does not actually run Omnibus. Use
+# 'kichen converge' to setup the virtual machine and then `kitchen login` to
+# SSH into the machine and run Omnibus.
+#
+
+driver:
+ name: vagrant
+ forward_agent: yes
+ customize:
+ cpus: 4
+ memory: 4096
+ synced_folders:
+ - ['..', '/home/vagrant/chef']
+ - ['../../omnibus', '/home/vagrant/omnibus']
+ - ['../../omnibus-software', '/home/vagrant/omnibus-software']
+
+provisioner:
+ name: chef_zero
+ # Always install the latest version of Chef.
+ # This is not the version of chef that we're building - this is the version
+ # of chef that omnibus needs to build chef/chef.
+ require_chef_omnibus: true
+
+platforms:
+ - name: centos-5.10
+ run_list: yum-epel::default
+ - name: centos-6.5
+ run_list: yum-epel::default
+ - name: centos-7.0
+ run_list: yum-epel::default
+ - name: debian-7.2.0
+ run_list: apt::default
+ - name: debian-7.4
+ run_list: apt::default
+ - name: debian-6.0.8
+ run_list: apt::default
+ - name: freebsd-9.2
+ run_list:
+ - freebsd::portsnap
+ - freebsd::pkgng
+ - name: freebsd-10.0
+ run_list: freebsd::portsnap
+ - name: ubuntu-10.04
+ run_list: apt::default
+ - name: ubuntu-12.04
+ run_list: apt::default
+ - name: ubuntu-12.10
+ run_list: apt::default
+ - name: ubuntu-13.04
+ run_list: apt::default
+ - name: ubuntu-13.10
+ run_list: apt::default
+ - name: ubuntu-14.04
+ run_list: apt::default
+ # The following (private) boxes are shared via Atlas and are only
+ # available to users working for Chef. Sorry, it's about software licensing.
+ #
+ # Chef-internal users, you will need to:
+ # 1. Create an Atlas account: https://atlas.hashicorp.com/
+ # 2. Ping the Release Services room with your Atlas account name
+ # to be added to the relevant team in Atlas,
+ # 3. Do `vagrant login` with your Atlas creds so that you can download
+ # the private boxes.
+ #
+ # The Mac OS X boxes are VMware only also. You can enable VMware Fusion
+ # as the default provider by copying `.kitchen.local.yml.vmware.example`
+ # over to `.kitchen.local.yml`.
+ #
+ - name: macosx-10.8
+ driver:
+ box: chef/macosx-10.8 # private
+ - name: macosx-10.9
+ driver:
+ box: chef/macosx-10.9 # private
+ - name: macosx-10.10
+ driver:
+ box: chef/macosx-10.10 # private
+ - name: windows-7-professional
+ driver:
+ box: chef/windows-7-professional # private
+ - name: windows-8.1-professional
+ driver:
+ box: chef/windows-8.1-professional # private
+ - name: windows-2008r2-standard
+ driver:
+ box: chef/windows-server-2008r2-standard # private
+
+attribute_defaults: &attribute_defaults
+ build_user: vagrant
+ build_user_group: vagrant
+ build_user_password: vagrant
+
+suites:
+ - name: angrychef
+ attributes:
+ omnibus:
+ <<: *attribute_defaults
+ install_dir: /opt/angrychef
+ run_list:
+ - omnibus::default
+ - name: chef
+ provisioner:
+ chef_omnibus_install_options: -P angrychef
+ chef_omnibus_root: /opt/angrychef
+ attributes:
+ omnibus:
+ <<: *attribute_defaults
+ install_dir: /opt/chef
+ run_list:
+ - omnibus::default
diff --git a/omnibus/Berksfile b/omnibus/Berksfile
new file mode 100644
index 0000000000..acf0fa7389
--- /dev/null
+++ b/omnibus/Berksfile
@@ -0,0 +1,12 @@
+source 'https://api.berkshelf.com'
+
+cookbook 'omnibus'
+
+# Uncomment to use the latest version of the Omnibus cookbook from GitHub
+# cookbook 'omnibus', github: 'opscode-cookbooks/omnibus'
+
+group :integration do
+ cookbook 'apt', '~> 2.3'
+ cookbook 'freebsd', '~> 0.1'
+ cookbook 'yum-epel', '~> 0.3'
+end
diff --git a/omnibus/Berksfile.lock b/omnibus/Berksfile.lock
new file mode 100644
index 0000000000..975ab05c90
--- /dev/null
+++ b/omnibus/Berksfile.lock
@@ -0,0 +1,30 @@
+DEPENDENCIES
+ apt (~> 2.3)
+ freebsd (~> 0.1)
+ omnibus
+ yum-epel (~> 0.3)
+
+GRAPH
+ 7-zip (1.0.2)
+ windows (>= 1.2.2)
+ apt (2.7.0)
+ build-essential (2.2.3)
+ chef-sugar (3.1.0)
+ chef_handler (1.1.9)
+ freebsd (0.3.0)
+ homebrew (1.12.0)
+ build-essential (>= 2.1.2)
+ omnibus (2.6.7)
+ 7-zip (~> 1.0)
+ build-essential (~> 2.0)
+ chef-sugar (~> 3.0)
+ homebrew (~> 1.9)
+ windows (~> 1.30)
+ wix (~> 1.1)
+ windows (1.37.0)
+ chef_handler (>= 0.0.0)
+ wix (1.1.0)
+ windows (>= 1.2.2)
+ yum (3.6.0)
+ yum-epel (0.6.0)
+ yum (~> 3.0)
diff --git a/omnibus/Gemfile b/omnibus/Gemfile
new file mode 100644
index 0000000000..ad415d576a
--- /dev/null
+++ b/omnibus/Gemfile
@@ -0,0 +1,18 @@
+source 'https://rubygems.org'
+
+gem 'omnibus', github: 'chef/omnibus'
+gem 'omnibus-software', github: 'chef/omnibus-software'
+
+# This development group is installed by default when you run `bundle install`,
+# but if you are using Omnibus in a CI-based infrastructure, you do not need
+# the Test Kitchen-based build lab. You can skip these unnecessary dependencies
+# by running `bundle install --without development` to speed up build times.
+group :development do
+ # Use Berkshelf for resolving cookbook dependencies
+ gem 'berkshelf', '~> 3.0'
+
+ # Use Test Kitchen with Vagrant for converging the build environment
+ gem 'test-kitchen', '~> 1.4.0'
+ gem 'kitchen-vagrant', '~> 0.19.0'
+ gem 'winrm-transport', '~> 1.0'
+end
diff --git a/omnibus/Gemfile.lock b/omnibus/Gemfile.lock
new file mode 100644
index 0000000000..b452074e01
--- /dev/null
+++ b/omnibus/Gemfile.lock
@@ -0,0 +1,203 @@
+GIT
+ remote: git://github.com/chef/omnibus-software.git
+ revision: 7cbfe423d0720041c9007a0ddb15abc3b6480416
+ specs:
+ omnibus-software (4.0.0)
+
+GIT
+ remote: git://github.com/chef/omnibus.git
+ revision: b6422a3f9678a6f5cc145c9b0a488409ac0af73c
+ specs:
+ omnibus (5.0.0)
+ aws-sdk (~> 2)
+ chef-sugar (~> 3.0)
+ cleanroom (~> 1.0)
+ mixlib-shellout (~> 2.0)
+ mixlib-versioning
+ ohai (~> 8.0)
+ ruby-progressbar (~> 1.7)
+ thor (~> 0.18)
+
+GEM
+ remote: https://rubygems.org/
+ specs:
+ addressable (2.3.8)
+ aws-sdk (2.2.9)
+ aws-sdk-resources (= 2.2.9)
+ aws-sdk-core (2.2.9)
+ jmespath (~> 1.0)
+ aws-sdk-resources (2.2.9)
+ aws-sdk-core (= 2.2.9)
+ berkshelf (3.2.4)
+ addressable (~> 2.3.4)
+ berkshelf-api-client (~> 1.2)
+ buff-config (~> 1.0)
+ buff-extensions (~> 1.0)
+ buff-shell_out (~> 0.1)
+ celluloid (~> 0.16.0)
+ celluloid-io (~> 0.16.1)
+ cleanroom (~> 1.0)
+ faraday (~> 0.9.0)
+ minitar (~> 0.5.4)
+ octokit (~> 3.0)
+ retryable (~> 2.0)
+ ridley (~> 4.0)
+ solve (~> 1.1)
+ thor (~> 0.19)
+ berkshelf-api-client (1.2.1)
+ faraday (~> 0.9.0)
+ buff-config (1.0.1)
+ buff-extensions (~> 1.0)
+ varia_model (~> 0.4)
+ buff-extensions (1.0.0)
+ buff-ignore (1.1.1)
+ buff-ruby_engine (0.1.0)
+ buff-shell_out (0.2.0)
+ buff-ruby_engine (~> 0.1.0)
+ builder (3.2.2)
+ celluloid (0.16.0)
+ timers (~> 4.0.0)
+ celluloid-io (0.16.2)
+ celluloid (>= 0.16.0)
+ nio4r (>= 1.1.0)
+ chef-config (12.6.0)
+ mixlib-config (~> 2.0)
+ mixlib-shellout (~> 2.0)
+ chef-sugar (3.2.0)
+ cleanroom (1.0.0)
+ dep-selector-libgecode (1.0.2)
+ dep_selector (1.0.3)
+ dep-selector-libgecode (~> 1.0)
+ ffi (~> 1.9)
+ erubis (2.7.0)
+ faraday (0.9.1)
+ multipart-post (>= 1.2, < 3)
+ ffi (1.9.10)
+ ffi (1.9.10-x86-mingw32)
+ ffi-yajl (2.2.3)
+ libyajl2 (~> 1.2)
+ gssapi (1.2.0)
+ ffi (>= 1.0.1)
+ gyoku (1.3.1)
+ builder (>= 2.1.2)
+ hashie (2.1.2)
+ hitimes (1.2.2)
+ hitimes (1.2.2-x86-mingw32)
+ httpclient (2.6.0.1)
+ ipaddress (0.8.2)
+ jmespath (1.1.3)
+ json (1.8.3)
+ kitchen-vagrant (0.19.0)
+ test-kitchen (~> 1.4)
+ libyajl2 (1.2.0)
+ little-plugger (1.1.3)
+ logging (1.8.2)
+ little-plugger (>= 1.1.3)
+ multi_json (>= 1.8.4)
+ minitar (0.5.4)
+ mixlib-authentication (1.3.0)
+ mixlib-log
+ mixlib-cli (1.5.0)
+ mixlib-config (2.2.1)
+ mixlib-log (1.6.0)
+ mixlib-shellout (2.2.5)
+ mixlib-shellout (2.2.5-universal-mingw32)
+ win32-process (~> 0.8.2)
+ wmi-lite (~> 1.0)
+ mixlib-versioning (1.1.0)
+ multi_json (1.11.2)
+ multipart-post (2.0.0)
+ net-http-persistent (2.9.4)
+ net-scp (1.2.1)
+ net-ssh (>= 2.6.5)
+ net-ssh (2.9.2)
+ nio4r (1.1.1)
+ nori (2.6.0)
+ octokit (3.8.0)
+ sawyer (~> 0.6.0, >= 0.5.3)
+ ohai (8.8.1)
+ chef-config (>= 12.5.0.alpha.1, < 13)
+ ffi (~> 1.9)
+ ffi-yajl (~> 2.2)
+ ipaddress
+ mixlib-cli
+ mixlib-config (~> 2.0)
+ mixlib-log
+ mixlib-shellout (~> 2.0)
+ rake (~> 10.1)
+ systemu (~> 2.6.4)
+ wmi-lite (~> 1.0)
+ rake (10.4.2)
+ retryable (2.0.1)
+ ridley (4.2.0)
+ addressable
+ buff-config (~> 1.0)
+ buff-extensions (~> 1.0)
+ buff-ignore (~> 1.1)
+ buff-shell_out (~> 0.1)
+ celluloid (~> 0.16.0)
+ celluloid-io (~> 0.16.1)
+ erubis
+ faraday (~> 0.9.0)
+ hashie (>= 2.0.2, < 3.0.0)
+ json (>= 1.7.7)
+ mixlib-authentication (>= 1.3.0)
+ net-http-persistent (>= 2.8)
+ retryable (~> 2.0)
+ semverse (~> 1.1)
+ varia_model (~> 0.4)
+ ruby-progressbar (1.7.5)
+ rubyntlm (0.4.0)
+ rubyzip (1.1.7)
+ safe_yaml (1.0.4)
+ sawyer (0.6.0)
+ addressable (~> 2.3.5)
+ faraday (~> 0.8, < 0.10)
+ semverse (1.2.1)
+ solve (1.2.1)
+ dep_selector (~> 1.0)
+ semverse (~> 1.1)
+ systemu (2.6.5)
+ test-kitchen (1.4.2)
+ mixlib-shellout (>= 1.2, < 3.0)
+ net-scp (~> 1.1)
+ net-ssh (~> 2.7, < 2.10)
+ safe_yaml (~> 1.0)
+ thor (~> 0.18)
+ thor (0.19.1)
+ timers (4.0.1)
+ hitimes
+ uuidtools (2.1.5)
+ varia_model (0.4.0)
+ buff-extensions (~> 1.0)
+ hashie (>= 2.0.2, < 3.0.0)
+ win32-process (0.8.3)
+ ffi (>= 1.0.0)
+ winrm (1.3.3)
+ builder (>= 2.1.2)
+ gssapi (~> 1.2)
+ gyoku (~> 1.0)
+ httpclient (~> 2.2, >= 2.2.0.2)
+ logging (~> 1.6, >= 1.6.1)
+ nori (~> 2.0)
+ rubyntlm (~> 0.4.0)
+ uuidtools (~> 2.1.2)
+ winrm-transport (1.0.1)
+ rubyzip (~> 1.1, >= 1.1.7)
+ winrm (~> 1.3)
+ wmi-lite (1.0.0)
+
+PLATFORMS
+ ruby
+ x86-mingw32
+
+DEPENDENCIES
+ berkshelf (~> 3.0)
+ kitchen-vagrant (~> 0.19.0)
+ omnibus!
+ omnibus-software!
+ test-kitchen (~> 1.4.0)
+ winrm-transport (~> 1.0)
+
+BUNDLED WITH
+ 1.11.2
diff --git a/omnibus/README.md b/omnibus/README.md
new file mode 100644
index 0000000000..1e73ad80e4
--- /dev/null
+++ b/omnibus/README.md
@@ -0,0 +1,144 @@
+Client Tools Omnibus project
+============================
+This project creates full-stack platform-specific packages for the following projects:
+
+* AngryChef
+* Chef
+* Chef with FIPS enabled
+
+Installation
+------------
+You must have a sane Ruby 1.9+ environment with Bundler installed. Ensure all
+the required gems are installed:
+
+```shell
+$ bundle install --without development
+```
+
+Usage
+-----
+### Build
+
+You create a platform-specific package using the `build project` command:
+
+```shell
+$ bundle exec omnibus build <PROJECT>
+```
+
+The platform/architecture type of the package created will match the platform
+where the `build project` command is invoked. For example, running this command
+on a MacBook Pro will generate a Mac OS X package. After the build completes
+packages will be available in the `pkg/` folder.
+
+### Clean
+
+You can clean up all temporary files generated during the build process with
+the `clean` command:
+
+```shell
+$ bundle exec omnibus clean <PROJECT>
+```
+
+Adding the `--purge` purge option removes __ALL__ files generated during the
+build including the project install directory (`/opt/chef`) and
+the package cache directory (`/var/cache/omnibus/pkg`):
+
+```shell
+$ bundle exec omnibus clean <PROJECT> --purge
+```
+
+### Publish
+
+Omnibus has a built-in mechanism for releasing to a variety of "backends", such
+as Amazon S3 and Artifactory. You must set the proper credentials in your `omnibus.rb`
+config file or specify them via the command line.
+
+```shell
+$ bundle exec omnibus publish path/to/*.deb --backend s3
+```
+
+### Help
+
+Full help for the Omnibus command line interface can be accessed with the
+`help` command:
+
+```shell
+$ bundle exec omnibus help
+```
+
+Kitchen-based Build Environment
+-------------------------------
+Every Omnibus project ships will a project-specific
+[Berksfile](http://berkshelf.com/) that will allow you to build your omnibus projects on all of the projects listed
+in the `.kitchen.yml`. You can add/remove additional platforms as needed by
+changing the list found in the `.kitchen.yml` `platforms` YAML stanza.
+
+This build environment is designed to get you up-and-running quickly. However,
+there is nothing that restricts you to building on other platforms. Simply use
+the [omnibus cookbook](https://github.com/opscode-cookbooks/omnibus) to setup
+your desired platform and execute the build steps listed above.
+
+The default build environment requires Test Kitchen and VirtualBox for local
+development. Test Kitchen also exposes the ability to provision instances using
+various cloud providers like AWS, DigitalOcean, or OpenStack. For more
+information, please see the [Test Kitchen documentation](http://kitchen.ci).
+
+Once you have tweaked your `.kitchen.yml` (or `.kitchen.local.yml`) to your
+liking, you can bring up an individual build environment using the `kitchen`
+command.
+
+```shell
+$ bundle exec kitchen converge <PROJECT>-ubuntu-1204
+```
+
+Then login to the instance and build the project as described in the Usage
+section:
+
+```shell
+$ bundle exec kitchen login <PROJECT>-ubuntu-1204
+[vagrant@ubuntu...] $ cd chef/omnibus
+[vagrant@ubuntu...] $ bundle install --without development # Don't install dev tools!
+[vagrant@ubuntu...] $ ...
+[vagrant@ubuntu...] $ bundle exec omnibus build <PROJECT> -l internal
+```
+
+You can also login to Windows instances but will have to manually call the
+`load-omnibus-toolchain.bat` script which initializes the build environment.
+Please note the mounted code directory is also at `C:\home\vagrant\chef\omnibus`
+as opposed to `C:\Users\vagrant\chef\omnibus`.
+
+```shell
+$ bundle exec kitchen login <PROJECT>-windows-81-professional
+Last login: Sat Sep 13 10:19:04 2014 from 172.16.27.1
+Microsoft Windows [Version 6.3.9600]
+(c) 2013 Microsoft Corporation. All rights reserved.
+
+C:\Users\vagrant>load-omnibus-toolchain.bat
+
+C:\Users\vagrant>cd C:\home\vagrant\chef\omnibus
+
+C:\home\vagrant\chef\omnibus>bundle install --without development
+
+C:\home\vagrant\chef\omnibus>bundle exec omnibus build <PROJECT> -l internal
+```
+
+For a complete list of all commands and platforms, run `kitchen list` or
+`kitchen help`.
+
+License
+-------
+```text
+Copyright 2012-2014 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.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+```
diff --git a/omnibus/config/projects/angrychef.rb b/omnibus/config/projects/angrychef.rb
new file mode 100644
index 0000000000..c585c73040
--- /dev/null
+++ b/omnibus/config/projects/angrychef.rb
@@ -0,0 +1,41 @@
+#
+# Copyright 2012-2015 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.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+#
+# This is a clone of the Chef project that we can install on the Chef build and
+# test machines. As such this project definition is just a thin wrapper around
+# `config/project/chef.rb`.
+#
+chef_project_contents = IO.read(File.expand_path('../chef.rb', __FILE__))
+self.instance_eval chef_project_contents
+
+name "angrychef"
+friendly_name "Angry Chef Client"
+
+if windows?
+ # NOTE: Ruby DevKit fundamentally CANNOT be installed into "Program Files"
+ # Native gems will use gcc which will barf on files with spaces,
+ # which is only fixable if everyone in the world fixes their Makefiles
+ install_dir "#{default_root}/opscode/#{name}"
+ package_name "angrychef"
+else
+ install_dir "#{default_root}/#{name}"
+end
+
+resources_path "#{resources_path}/../chef"
+
+msi_upgrade_code = "D7FDDC1A-7668-404E-AD2F-61F875632A9C"
+project_location_dir = "angrychef"
diff --git a/omnibus/config/projects/chef-fips.rb b/omnibus/config/projects/chef-fips.rb
new file mode 100644
index 0000000000..32bbbc9c48
--- /dev/null
+++ b/omnibus/config/projects/chef-fips.rb
@@ -0,0 +1,48 @@
+#
+# Copyright 2012-2015 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.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+#
+# This is the chef client build with FIPS mode enabled.
+# It's a stub for now and produces identical results
+#
+chef_project_contents = IO.read(File.expand_path('../chef.rb', __FILE__))
+self.instance_eval chef_project_contents
+
+name "chef-fips"
+friendly_name "Chef Client with FIPS OpenSSL"
+
+if windows?
+ # NOTE: Ruby DevKit fundamentally CANNOT be installed into "Program Files"
+ # Native gems will use gcc which will barf on files with spaces,
+ # which is only fixable if everyone in the world fixes their Makefiles
+ install_dir "#{default_root}/opscode/#{name}"
+ package_name "chef-fips"
+else
+ install_dir "#{default_root}/#{name}"
+end
+
+# Global FIPS override flag.
+override :fips, enabled: true
+override :'ruby-windows', version: "2.0.0-p647"
+
+override :chef, version: "jdm/1.3-fips"
+override :ohai, version: "master"
+
+msi_upgrade_code = "819F5DB3-B818-4358-BB2B-54B8171D0A26"
+project_location_dir = "chef-fips"
+
+# Use chef's scripts for everything.
+resources_path "#{resources_path}/../chef"
diff --git a/omnibus/config/projects/chef.rb b/omnibus/config/projects/chef.rb
new file mode 100644
index 0000000000..b8b121e0d2
--- /dev/null
+++ b/omnibus/config/projects/chef.rb
@@ -0,0 +1,86 @@
+#
+# Copyright 2012-2014 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.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+name "chef"
+friendly_name "Chef Client"
+maintainer "Chef Software, Inc. <maintainers@chef.io>"
+homepage "https://www.chef.io"
+
+build_iteration 1
+build_version '12.6.0'
+
+if windows?
+ # NOTE: Ruby DevKit fundamentally CANNOT be installed into "Program Files"
+ # Native gems will use gcc which will barf on files with spaces,
+ # which is only fixable if everyone in the world fixes their Makefiles
+ install_dir "#{default_root}/opscode/#{name}"
+ package_name "chef-client"
+else
+ install_dir "#{default_root}/#{name}"
+end
+
+override :bundler, version: "1.10.6"
+override :ruby, version: "2.1.6"
+
+override :'ruby-windows', version: "2.0.0-p645"
+# Leave dev-kit pinned to 4.5 because 4.7 is 20MB larger and we don't want
+# to unnecessarily make the client any fatter.
+if windows_arch_i386?
+ override :'ruby-windows-devkit', version: "4.5.2-20111229-1559"
+end
+
+######
+# This points to jay's patched version for now to avoid a security
+# vulnerability and to allow pry to get installed on windows builds.
+# See the software definition for details.
+if windows?
+ override :rubygems, version: "jdm/2.4.8-patched"
+else
+ override :rubygems, version: "2.4.8"
+end
+
+# Chef Release version pinning
+override :chef, version: 'local_source'
+override :ohai, version: 'master'
+
+
+dependency "preparation"
+dependency "chef"
+dependency "shebang-cleanup"
+dependency "version-manifest"
+dependency "openssl-customization"
+
+package :rpm do
+ signing_passphrase ENV['OMNIBUS_RPM_SIGNING_PASSPHRASE']
+end
+
+proj_to_work_around_cleanroom = self
+package :pkg do
+ identifier "com.getchef.pkg.#{proj_to_work_around_cleanroom.name}"
+ signing_identity "Developer ID Installer: Chef Software, Inc. (EU3VF8YLX2)"
+end
+compress :dmg
+
+msi_upgrade_code = "D607A85C-BDFA-4F08-83ED-2ECB4DCD6BC5"
+project_location_dir = name
+package :msi do
+ fast_msi true
+ upgrade_code msi_upgrade_code
+ wix_candle_extension 'WixUtilExtension'
+ signing_identity "F74E1A68005E8A9C465C3D2FF7B41F3988F0EA09", machine_store: true
+ parameters ChefLogDllPath: windows_safe_path(gem_path("chef-[0-9]*-mingw32/ext/win32-eventlog/chef-log.dll")),
+ ProjectLocationDir: project_location_dir
+end
diff --git a/omnibus/files/mapfiles/solaris b/omnibus/files/mapfiles/solaris
new file mode 100644
index 0000000000..b33e54dcae
--- /dev/null
+++ b/omnibus/files/mapfiles/solaris
@@ -0,0 +1,19 @@
+$mapfile_version 2
+DEPEND_VERSIONS libnsl.so {
+ ALLOW = SUNW_1.1;
+ ALLOW = SUNWprivate_1.1;
+};
+DEPEND_VERSIONS libsocket.so {
+ ALLOW = SUNW_1.4;
+ ALLOW = SUNWprivate_1.1;
+};
+DEPEND_VERSIONS libdl.so {
+ ALLOW = SUNW_1.22.1;
+ ALLOW = SUNW_1.4;
+ ALLOW = SUNWprivate_1.1;
+};
+DEPEND_VERSIONS libc.so {
+ ALLOW = SUNW_1.22.1;
+ ALLOW = SUNW_1.4;
+ ALLOW = SUNWprivate_1.1;
+};
diff --git a/omnibus/files/openssl-customization/windows/ssl_env_hack.rb b/omnibus/files/openssl-customization/windows/ssl_env_hack.rb
new file mode 100644
index 0000000000..221854437e
--- /dev/null
+++ b/omnibus/files/openssl-customization/windows/ssl_env_hack.rb
@@ -0,0 +1,34 @@
+#
+# Copyright:: Copyright (c) 2014 Chef Software, Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# This script sets the SSL_CERT_FILE environment variable to the CA cert bundle
+# that ships with omnibus packages of Chef and Chef DK. If this environment
+# variable is already configured, this script is a no-op.
+#
+# This is required to make Chef tools use https URLs out of the box.
+
+unless ENV.key?("SSL_CERT_FILE")
+ base_dirs = File.dirname(__FILE__).split(File::SEPARATOR)
+
+ (base_dirs.length - 1).downto(0) do |i|
+ candidate_ca_bundle = File.join(base_dirs[0..i] + [ "ssl/certs/cacert.pem" ])
+ if File.exist?(candidate_ca_bundle)
+ ENV["SSL_CERT_FILE"] = candidate_ca_bundle
+ break
+ end
+ end
+end
diff --git a/omnibus/omnibus.rb b/omnibus/omnibus.rb
new file mode 100644
index 0000000000..3afa2ad84e
--- /dev/null
+++ b/omnibus/omnibus.rb
@@ -0,0 +1,54 @@
+#
+# This file is used to configure the Omnibus projects in this repo. It contains
+# some minimal configuration examples for working with Omnibus. For a full list
+# of configurable options, please see the documentation for +omnibus/config.rb+.
+#
+
+# Build internally
+# ------------------------------
+# By default, Omnibus uses system folders (like +/var+ and +/opt+) to build and
+# cache components. If you would to build everything internally, you can
+# uncomment the following options. This will prevent the need for root
+# permissions in most cases.
+#
+# Uncomment this line to change the default base directory to "local"
+# -------------------------------------------------------------------
+# base_dir './local'
+#
+# Alternatively you can tune the individual values
+# ------------------------------------------------
+# cache_dir './local/omnibus/cache'
+# git_cache_dir './local/omnibus/cache/git_cache'
+# source_dir './local/omnibus/src'
+# build_dir './local/omnibus/build'
+# package_dir './local/omnibus/pkg'
+# package_tmp './local/omnibus/pkg-tmp'
+
+# Windows architecture defaults - set to x86 unless otherwise specified.
+# ------------------------------
+windows_arch %w{x86 x64}.include?((ENV['OMNIBUS_WINDOWS_ARCH'] || '').downcase) ?
+ ENV['OMNIBUS_WINDOWS_ARCH'].downcase.to_sym : :x86
+
+# Disable git caching
+# ------------------------------
+# use_git_caching false
+
+# Enable S3 asset caching
+# ------------------------------
+use_s3_caching true
+s3_access_key ENV['AWS_ACCESS_KEY_ID']
+s3_secret_key ENV['AWS_SECRET_ACCESS_KEY']
+s3_bucket 'opscode-omnibus-cache'
+
+build_retries 3
+fetcher_retries 3
+fetcher_read_timeout 120
+
+# We limit this to 10 workers to eliminate transient timing issues in the
+# way Ruby (and other components) compiles on some more esoteric *nixes.
+workers 10
+
+# Load additional software
+# ------------------------------
+# software_gems ['omnibus-software', 'my-company-software']
+# local_software_dirs ['/path/to/local/software']
diff --git a/omnibus/package-scripts/angrychef/postinst b/omnibus/package-scripts/angrychef/postinst
new file mode 100755
index 0000000000..c0fc3f5525
--- /dev/null
+++ b/omnibus/package-scripts/angrychef/postinst
@@ -0,0 +1,115 @@
+#!/bin/sh
+# WARNING: REQUIRES /bin/sh
+#
+# - must run on /bin/sh on solaris 9
+# - must run on /bin/sh on AIX 6.x
+# - if you think you are a bash wizard, you probably do not understand
+# this programming language. do not touch.
+# - if you are under 40, get peer review from your elders.
+#
+# Install a full Opscode Client
+#
+
+PROGNAME=`basename $0`
+INSTALLER_DIR=/opt/angrychef
+CONFIG_DIR=/etc/chef
+USAGE="usage: $0 [-v validation_key] ([-o organization] || [-u url])"
+
+error_exit()
+{
+ echo "${PROGNAME}: ${1:-"Unknown Error"}" 1>&2
+ exit 1
+}
+
+is_darwin()
+{
+ uname -v | grep "^Darwin" 2>&1 >/dev/null
+}
+
+is_smartos()
+{
+ uname -v | grep "^joyent" 2>&1 >/dev/null
+}
+
+if is_smartos; then
+ PREFIX="/opt/local"
+elif is_darwin; then
+ PREFIX="/usr/local"
+ mkdir -p "$PREFIX/bin"
+else
+ PREFIX="/usr"
+fi
+
+validation_key=
+organization=
+chef_url=
+
+while getopts o:u:v: opt
+do
+ case "$opt" in
+ v) validation_key="${OPTARG}";;
+ o) organization="${OPTARG}"; chef_url="https://api.opscode.com/organizations/${OPTARG}";;
+ u) chef_url="${OPTARG}";;
+ \?) # unknown flag
+ echo >&2 ${USAGE}
+ exit 1;;
+ esac
+done
+shift `expr ${OPTIND} - 1`
+
+if [ "" != "$chef_url" ]; then
+ mkdir -p ${CONFIG_DIR} || error_exit "Cannot create ${CONFIG_DIR}!"
+ (
+ cat <<'EOP'
+log_level :info
+log_location STDOUT
+EOP
+ ) > ${CONFIG_DIR}/client.rb
+ if [ "" != "$chef_url" ]; then
+ echo "chef_server_url '${chef_url}'" >> ${CONFIG_DIR}/client.rb
+ fi
+ if [ "" != "$organization" ]; then
+ echo "validation_client_name '${organization}-validator'" >> ${CONFIG_DIR}/client.rb
+ fi
+ chmod 644 ${CONFIG_DIR}/client.rb
+fi
+
+if [ "" != "$validation_key" ]; then
+ cp ${validation_key} ${CONFIG_DIR}/validation.pem || error_exit "Cannot copy the validation key!"
+ chmod 600 ${CONFIG_DIR}/validation.pem
+fi
+
+# rm -f before ln -sf is required for solaris 9
+rm -f $PREFIX/bin/chef-client
+rm -f $PREFIX/bin/chef-solo
+rm -f $PREFIX/bin/chef-apply
+rm -f $PREFIX/bin/chef-shell
+rm -f $PREFIX/bin/knife
+rm -f $PREFIX/bin/shef
+rm -f $PREFIX/bin/ohai
+
+ln -sf $INSTALLER_DIR/bin/chef-solo $PREFIX/bin || error_exit "Cannot link chef-solo to $PREFIX/bin"
+if [ -f "$INSTALLER_DIR/bin/chef-apply" ]; then
+ ln -sf $INSTALLER_DIR/bin/chef-apply $PREFIX/bin || error_exit "Cannot link chef-apply to $PREFIX/bin"
+fi
+if [ -f "$INSTALLER_DIR/bin/chef-shell" ]; then
+ ln -sf $INSTALLER_DIR/bin/chef-shell $PREFIX/bin || error_exit "Cannot link chef-shell to $PREFIX/bin"
+fi
+ln -sf $INSTALLER_DIR/bin/knife $PREFIX/bin || error_exit "Cannot link knife to $PREFIX/bin"
+if [ -f "$INSTALLER_DIR/bin/shef" ]; then
+ ln -sf $INSTALLER_DIR/bin/shef $PREFIX/bin || error_exit "Cannot link shef to $PREFIX/bin"
+fi
+ln -sf $INSTALLER_DIR/bin/ohai $PREFIX/bin || error_exit "Cannot link ohai to $PREFIX/bin"
+
+# We test for the presence of /usr/bin/chef-client to know if this script succeeds, so this
+# must appear as the last real action in the script
+ln -sf $INSTALLER_DIR/bin/chef-client $PREFIX/bin || error_exit "Cannot link chef-client to $PREFIX/bin"
+
+# Ensure all files/directories in $INSTALLER_DIR are owned by root. This
+# has been fixed on new installs but upgrades from old installs need to
+# be manually fixed.
+chown -Rh 0:0 $INSTALLER_DIR
+
+echo "Thank you for installing Chef!"
+
+exit 0
diff --git a/omnibus/package-scripts/angrychef/postrm b/omnibus/package-scripts/angrychef/postrm
new file mode 100755
index 0000000000..724c082be7
--- /dev/null
+++ b/omnibus/package-scripts/angrychef/postrm
@@ -0,0 +1,42 @@
+#!/bin/sh
+# WARNING: REQUIRES /bin/sh
+#
+# - must run on /bin/sh on solaris 9
+# - must run on /bin/sh on AIX 6.x
+# - if you think you are a bash wizard, you probably do not understand
+# this programming language. do not touch.
+# - if you are under 40, get peer review from your elders.
+
+is_smartos() {
+ uname -v | grep "^joyent" 2>&1 >/dev/null
+}
+
+is_darwin()
+{
+ uname -v | grep "^Darwin" 2>&1 >/dev/null
+}
+
+if is_smartos; then
+ PREFIX="/opt/local"
+elif is_darwin; then
+ PREFIX="/usr/local"
+else
+ PREFIX="/usr"
+fi
+
+cleanup_symlinks() {
+ binaries="chef-client chef-solo chef-apply chef-shell knife shef ohai"
+ for binary in $binaries; do
+ rm -f $PREFIX/bin/$binary
+ done
+}
+
+# Clean up binary symlinks if they exist
+# see: http://tickets.opscode.com/browse/CHEF-3022
+if [ ! -f /etc/redhat-release -a ! -f /etc/fedora-release -a ! -f /etc/system-release -a ! -f /etc/SuSE-release ]; then
+ # not a redhat-ish RPM-based system
+ cleanup_symlinks
+elif [ "x$1" = "x0" ]; then
+ # RPM-based system and we're deinstalling rather than upgrading
+ cleanup_symlinks
+fi
diff --git a/omnibus/package-scripts/chef-fips/postinst b/omnibus/package-scripts/chef-fips/postinst
new file mode 100755
index 0000000000..6f13382b61
--- /dev/null
+++ b/omnibus/package-scripts/chef-fips/postinst
@@ -0,0 +1,115 @@
+#!/bin/sh
+# WARNING: REQUIRES /bin/sh
+#
+# - must run on /bin/sh on solaris 9
+# - must run on /bin/sh on AIX 6.x
+# - if you think you are a bash wizard, you probably do not understand
+# this programming language. do not touch.
+# - if you are under 40, get peer review from your elders.
+#
+# Install a full Opscode Client
+#
+
+PROGNAME=`basename $0`
+INSTALLER_DIR=/opt/chef-fips
+CONFIG_DIR=/etc/chef
+USAGE="usage: $0 [-v validation_key] ([-o organization] || [-u url])"
+
+error_exit()
+{
+ echo "${PROGNAME}: ${1:-"Unknown Error"}" 1>&2
+ exit 1
+}
+
+is_darwin()
+{
+ uname -v | grep "^Darwin" 2>&1 >/dev/null
+}
+
+is_smartos()
+{
+ uname -v | grep "^joyent" 2>&1 >/dev/null
+}
+
+if is_smartos; then
+ PREFIX="/opt/local"
+elif is_darwin; then
+ PREFIX="/usr/local"
+ mkdir -p "$PREFIX/bin"
+else
+ PREFIX="/usr"
+fi
+
+validation_key=
+organization=
+chef_url=
+
+while getopts o:u:v: opt
+do
+ case "$opt" in
+ v) validation_key="${OPTARG}";;
+ o) organization="${OPTARG}"; chef_url="https://api.opscode.com/organizations/${OPTARG}";;
+ u) chef_url="${OPTARG}";;
+ \?) # unknown flag
+ echo >&2 ${USAGE}
+ exit 1;;
+ esac
+done
+shift `expr ${OPTIND} - 1`
+
+if [ "" != "$chef_url" ]; then
+ mkdir -p ${CONFIG_DIR} || error_exit "Cannot create ${CONFIG_DIR}!"
+ (
+ cat <<'EOP'
+log_level :info
+log_location STDOUT
+EOP
+ ) > ${CONFIG_DIR}/client.rb
+ if [ "" != "$chef_url" ]; then
+ echo "chef_server_url '${chef_url}'" >> ${CONFIG_DIR}/client.rb
+ fi
+ if [ "" != "$organization" ]; then
+ echo "validation_client_name '${organization}-validator'" >> ${CONFIG_DIR}/client.rb
+ fi
+ chmod 644 ${CONFIG_DIR}/client.rb
+fi
+
+if [ "" != "$validation_key" ]; then
+ cp ${validation_key} ${CONFIG_DIR}/validation.pem || error_exit "Cannot copy the validation key!"
+ chmod 600 ${CONFIG_DIR}/validation.pem
+fi
+
+# rm -f before ln -sf is required for solaris 9
+rm -f $PREFIX/bin/chef-client
+rm -f $PREFIX/bin/chef-solo
+rm -f $PREFIX/bin/chef-apply
+rm -f $PREFIX/bin/chef-shell
+rm -f $PREFIX/bin/knife
+rm -f $PREFIX/bin/shef
+rm -f $PREFIX/bin/ohai
+
+ln -sf $INSTALLER_DIR/bin/chef-solo $PREFIX/bin || error_exit "Cannot link chef-solo to $PREFIX/bin"
+if [ -f "$INSTALLER_DIR/bin/chef-apply" ]; then
+ ln -sf $INSTALLER_DIR/bin/chef-apply $PREFIX/bin || error_exit "Cannot link chef-apply to $PREFIX/bin"
+fi
+if [ -f "$INSTALLER_DIR/bin/chef-shell" ]; then
+ ln -sf $INSTALLER_DIR/bin/chef-shell $PREFIX/bin || error_exit "Cannot link chef-shell to $PREFIX/bin"
+fi
+ln -sf $INSTALLER_DIR/bin/knife $PREFIX/bin || error_exit "Cannot link knife to $PREFIX/bin"
+if [ -f "$INSTALLER_DIR/bin/shef" ]; then
+ ln -sf $INSTALLER_DIR/bin/shef $PREFIX/bin || error_exit "Cannot link shef to $PREFIX/bin"
+fi
+ln -sf $INSTALLER_DIR/bin/ohai $PREFIX/bin || error_exit "Cannot link ohai to $PREFIX/bin"
+
+# We test for the presence of /usr/bin/chef-client to know if this script succeeds, so this
+# must appear as the last real action in the script
+ln -sf $INSTALLER_DIR/bin/chef-client $PREFIX/bin || error_exit "Cannot link chef-client to $PREFIX/bin"
+
+# Ensure all files/directories in $INSTALLER_DIR are owned by root. This
+# has been fixed on new installs but upgrades from old installs need to
+# be manually fixed.
+chown -Rh 0:0 $INSTALLER_DIR
+
+echo "Thank you for installing Chef!"
+
+exit 0
diff --git a/omnibus/package-scripts/chef-fips/postrm b/omnibus/package-scripts/chef-fips/postrm
new file mode 100755
index 0000000000..724c082be7
--- /dev/null
+++ b/omnibus/package-scripts/chef-fips/postrm
@@ -0,0 +1,42 @@
+#!/bin/sh
+# WARNING: REQUIRES /bin/sh
+#
+# - must run on /bin/sh on solaris 9
+# - must run on /bin/sh on AIX 6.x
+# - if you think you are a bash wizard, you probably do not understand
+# this programming language. do not touch.
+# - if you are under 40, get peer review from your elders.
+
+is_smartos() {
+ uname -v | grep "^joyent" 2>&1 >/dev/null
+}
+
+is_darwin()
+{
+ uname -v | grep "^Darwin" 2>&1 >/dev/null
+}
+
+if is_smartos; then
+ PREFIX="/opt/local"
+elif is_darwin; then
+ PREFIX="/usr/local"
+else
+ PREFIX="/usr"
+fi
+
+cleanup_symlinks() {
+ binaries="chef-client chef-solo chef-apply chef-shell knife shef ohai"
+ for binary in $binaries; do
+ rm -f $PREFIX/bin/$binary
+ done
+}
+
+# Clean up binary symlinks if they exist
+# see: http://tickets.opscode.com/browse/CHEF-3022
+if [ ! -f /etc/redhat-release -a ! -f /etc/fedora-release -a ! -f /etc/system-release -a ! -f /etc/SuSE-release ]; then
+ # not a redhat-ish RPM-based system
+ cleanup_symlinks
+elif [ "x$1" = "x0" ]; then
+ # RPM-based system and we're deinstalling rather than upgrading
+ cleanup_symlinks
+fi
diff --git a/omnibus/package-scripts/chef/postinst b/omnibus/package-scripts/chef/postinst
new file mode 100755
index 0000000000..88016f6c03
--- /dev/null
+++ b/omnibus/package-scripts/chef/postinst
@@ -0,0 +1,115 @@
+#!/bin/sh
+# WARNING: REQUIRES /bin/sh
+#
+# - must run on /bin/sh on solaris 9
+# - must run on /bin/sh on AIX 6.x
+# - if you think you are a bash wizard, you probably do not understand
+# this programming language. do not touch.
+# - if you are under 40, get peer review from your elders.
+#
+# Install a full Opscode Client
+#
+
+PROGNAME=`basename $0`
+INSTALLER_DIR=/opt/chef
+CONFIG_DIR=/etc/chef
+USAGE="usage: $0 [-v validation_key] ([-o organization] || [-u url])"
+
+error_exit()
+{
+ echo "${PROGNAME}: ${1:-"Unknown Error"}" 1>&2
+ exit 1
+}
+
+is_darwin()
+{
+ uname -v | grep "^Darwin" 2>&1 >/dev/null
+}
+
+is_smartos()
+{
+ uname -v | grep "^joyent" 2>&1 >/dev/null
+}
+
+if is_smartos; then
+ PREFIX="/opt/local"
+elif is_darwin; then
+ PREFIX="/usr/local"
+ mkdir -p "$PREFIX/bin"
+else
+ PREFIX="/usr"
+fi
+
+validation_key=
+organization=
+chef_url=
+
+while getopts o:u:v: opt
+do
+ case "$opt" in
+ v) validation_key="${OPTARG}";;
+ o) organization="${OPTARG}"; chef_url="https://api.opscode.com/organizations/${OPTARG}";;
+ u) chef_url="${OPTARG}";;
+ \?) # unknown flag
+ echo >&2 ${USAGE}
+ exit 1;;
+ esac
+done
+shift `expr ${OPTIND} - 1`
+
+if [ "" != "$chef_url" ]; then
+ mkdir -p ${CONFIG_DIR} || error_exit "Cannot create ${CONFIG_DIR}!"
+ (
+ cat <<'EOP'
+log_level :info
+log_location STDOUT
+EOP
+ ) > ${CONFIG_DIR}/client.rb
+ if [ "" != "$chef_url" ]; then
+ echo "chef_server_url '${chef_url}'" >> ${CONFIG_DIR}/client.rb
+ fi
+ if [ "" != "$organization" ]; then
+ echo "validation_client_name '${organization}-validator'" >> ${CONFIG_DIR}/client.rb
+ fi
+ chmod 644 ${CONFIG_DIR}/client.rb
+fi
+
+if [ "" != "$validation_key" ]; then
+ cp ${validation_key} ${CONFIG_DIR}/validation.pem || error_exit "Cannot copy the validation key!"
+ chmod 600 ${CONFIG_DIR}/validation.pem
+fi
+
+# rm -f before ln -sf is required for solaris 9
+rm -f $PREFIX/bin/chef-client
+rm -f $PREFIX/bin/chef-solo
+rm -f $PREFIX/bin/chef-apply
+rm -f $PREFIX/bin/chef-shell
+rm -f $PREFIX/bin/knife
+rm -f $PREFIX/bin/shef
+rm -f $PREFIX/bin/ohai
+
+ln -sf $INSTALLER_DIR/bin/chef-solo $PREFIX/bin || error_exit "Cannot link chef-solo to $PREFIX/bin"
+if [ -f "$INSTALLER_DIR/bin/chef-apply" ]; then
+ ln -sf $INSTALLER_DIR/bin/chef-apply $PREFIX/bin || error_exit "Cannot link chef-apply to $PREFIX/bin"
+fi
+if [ -f "$INSTALLER_DIR/bin/chef-shell" ]; then
+ ln -sf $INSTALLER_DIR/bin/chef-shell $PREFIX/bin || error_exit "Cannot link chef-shell to $PREFIX/bin"
+fi
+ln -sf $INSTALLER_DIR/bin/knife $PREFIX/bin || error_exit "Cannot link knife to $PREFIX/bin"
+if [ -f "$INSTALLER_DIR/bin/shef" ]; then
+ ln -sf $INSTALLER_DIR/bin/shef $PREFIX/bin || error_exit "Cannot link shef to $PREFIX/bin"
+fi
+ln -sf $INSTALLER_DIR/bin/ohai $PREFIX/bin || error_exit "Cannot link ohai to $PREFIX/bin"
+
+# We test for the presence of /usr/bin/chef-client to know if this script succeeds, so this
+# must appear as the last real action in the script
+ln -sf $INSTALLER_DIR/bin/chef-client $PREFIX/bin || error_exit "Cannot link chef-client to $PREFIX/bin"
+
+# Ensure all files/directories in $INSTALLER_DIR are owned by root. This
+# has been fixed on new installs but upgrades from old installs need to
+# be manually fixed.
+chown -Rh 0:0 $INSTALLER_DIR
+
+echo "Thank you for installing Chef!"
+
+exit 0
diff --git a/omnibus/package-scripts/chef/postrm b/omnibus/package-scripts/chef/postrm
new file mode 100755
index 0000000000..724c082be7
--- /dev/null
+++ b/omnibus/package-scripts/chef/postrm
@@ -0,0 +1,42 @@
+#!/bin/sh
+# WARNING: REQUIRES /bin/sh
+#
+# - must run on /bin/sh on solaris 9
+# - must run on /bin/sh on AIX 6.x
+# - if you think you are a bash wizard, you probably do not understand
+# this programming language. do not touch.
+# - if you are under 40, get peer review from your elders.
+
+is_smartos() {
+ uname -v | grep "^joyent" 2>&1 >/dev/null
+}
+
+is_darwin()
+{
+ uname -v | grep "^Darwin" 2>&1 >/dev/null
+}
+
+if is_smartos; then
+ PREFIX="/opt/local"
+elif is_darwin; then
+ PREFIX="/usr/local"
+else
+ PREFIX="/usr"
+fi
+
+cleanup_symlinks() {
+ binaries="chef-client chef-solo chef-apply chef-shell knife shef ohai"
+ for binary in $binaries; do
+ rm -f $PREFIX/bin/$binary
+ done
+}
+
+# Clean up binary symlinks if they exist
+# see: http://tickets.opscode.com/browse/CHEF-3022
+if [ ! -f /etc/redhat-release -a ! -f /etc/fedora-release -a ! -f /etc/system-release -a ! -f /etc/SuSE-release ]; then
+ # not a redhat-ish RPM-based system
+ cleanup_symlinks
+elif [ "x$1" = "x0" ]; then
+ # RPM-based system and we're deinstalling rather than upgrading
+ cleanup_symlinks
+fi
diff --git a/omnibus/resources/chef/dmg/background.png b/omnibus/resources/chef/dmg/background.png
new file mode 100644
index 0000000000..82c605ae51
--- /dev/null
+++ b/omnibus/resources/chef/dmg/background.png
Binary files differ
diff --git a/omnibus/resources/chef/dmg/icon.png b/omnibus/resources/chef/dmg/icon.png
new file mode 100644
index 0000000000..b65c309660
--- /dev/null
+++ b/omnibus/resources/chef/dmg/icon.png
Binary files differ
diff --git a/omnibus/resources/chef/msi/assets/LICENSE.rtf b/omnibus/resources/chef/msi/assets/LICENSE.rtf
new file mode 100644
index 0000000000..b18e6f59b8
--- /dev/null
+++ b/omnibus/resources/chef/msi/assets/LICENSE.rtf
@@ -0,0 +1,197 @@
+{\rtf1\ansi\deff0{\fonttbl{\f0\fnil\fcharset0 Courier New;}}
+
+{\*\generator Msftedit 5.41.21.2500;}\viewkind4\uc1\pard\qc\lang1033\f0\fs20 Apache License\par
+
+Version 2.0, January 2004\par
+
+http://www.apache.org/licenses/\par
+
+\pard\par
+
+TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\par
+
+\par
+
+1. Definitions.\par
+
+\par
+
+"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.\par
+
+\par
+
+"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.\par
+
+\par
+
+"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.\par
+
+\par
+
+"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.\par
+
+\par
+
+"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation, source, and configuration files.\par
+
+\par
+
+"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.\par
+
+\par
+
+"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).\par
+
+\par
+
+"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.\par
+
+\par
+
+"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."\par
+
+\par
+
+"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.\par
+
+\par
+
+2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.\par
+
+\par
+
+3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license plies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.\par
+
+\par
+
+4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:\par
+
+\par
+
+ (a) You must give any other recipients of the Work or\par
+
+ Derivative Works a copy of this License; and\par
+
+\par
+
+ (b) You must cause any modified files to carry prominent notices\par
+
+ stating that You changed the files; and\par
+
+\par
+
+ (c) You must retain, in the Source form of any Derivative Works\par
+
+ that You distribute, all copyright, patent, trademark, and\par
+
+ attribution notices from the Source form of the Work,\par
+
+ excluding those notices that do not pertain to any part of\par
+
+ the Derivative Works; and\par
+
+\par
+
+ (d) If the Work includes a "NOTICE" text file as part of its\par
+
+ distribution, then any Derivative Works that You distribute\par
+
+ must include a readable copy of the attribution notices\par
+
+ contained within such NOTICE file, excluding those notices\par
+
+ that do not pertain to any part of the Derivative Works, in\par
+
+ at least one of the following places: within a NOTICE text\par
+
+ file distributed as part of the Derivative Works; within the\par
+
+ Source form or documentation, if provided along with the\par
+
+ Derivative Works; or, within a display generated by the\par
+
+ Derivative Works, if and wherever such third-party notices\par
+
+ normally appear. The contents of the NOTICE file are for\par
+
+ informational purposes only and do not modify the License.\par
+
+ You may add Your own attribution notices within Derivative\par
+
+ Works that You distribute, alongside or as an addendum to the\par
+
+ NOTICE text from the Work, provided that such additional\par
+
+ attribution notices cannot be construed as modifying the\par
+
+ License.\par
+
+\par
+
+You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.\par
+
+\par
+
+5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.\par
+
+\par
+
+6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.\par
+
+\par
+
+7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.\par
+
+\par
+
+8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.\par
+
+\par
+
+9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.\par
+
+\par
+
+END OF TERMS AND CONDITIONS\par
+
+\par
+
+APPENDIX: How to apply the Apache License to your work.\par
+
+\par
+
+To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.\par
+
+\par
+
+ Copyright [yyyy] [name of copyright owner]\par
+
+\par
+
+ Licensed under the Apache License, Version 2.0 (the "License");\par
+
+ you may not use this file except in compliance with the License.\par
+
+ You may obtain a copy of the License at\par
+
+\par
+
+ http://www.apache.org/licenses/LICENSE-2.0\par
+
+\par
+
+ Unless required by applicable law or agreed to in writing, software\par
+
+ distributed under the License is distributed on an "AS IS" BASIS,\par
+
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\par
+
+ implied. See the License for the specific language governing\par
+
+ permissions and limitations under the License.\par
+
+\par
+
+}
+
+
diff --git a/omnibus/resources/chef/msi/assets/banner_background.bmp b/omnibus/resources/chef/msi/assets/banner_background.bmp
new file mode 100644
index 0000000000..5769a883c3
--- /dev/null
+++ b/omnibus/resources/chef/msi/assets/banner_background.bmp
Binary files differ
diff --git a/omnibus/resources/chef/msi/assets/dialog_background.bmp b/omnibus/resources/chef/msi/assets/dialog_background.bmp
new file mode 100644
index 0000000000..4dbe489e9c
--- /dev/null
+++ b/omnibus/resources/chef/msi/assets/dialog_background.bmp
Binary files differ
diff --git a/omnibus/resources/chef/msi/assets/oc.ico b/omnibus/resources/chef/msi/assets/oc.ico
new file mode 100644
index 0000000000..c4cee7bd75
--- /dev/null
+++ b/omnibus/resources/chef/msi/assets/oc.ico
Binary files differ
diff --git a/omnibus/resources/chef/msi/assets/oc_16x16.ico b/omnibus/resources/chef/msi/assets/oc_16x16.ico
new file mode 100644
index 0000000000..d3bd065a6a
--- /dev/null
+++ b/omnibus/resources/chef/msi/assets/oc_16x16.ico
Binary files differ
diff --git a/omnibus/resources/chef/msi/assets/oc_32x32.ico b/omnibus/resources/chef/msi/assets/oc_32x32.ico
new file mode 100644
index 0000000000..5eee0042c3
--- /dev/null
+++ b/omnibus/resources/chef/msi/assets/oc_32x32.ico
Binary files differ
diff --git a/omnibus/resources/chef/msi/localization-en-us.wxl.erb b/omnibus/resources/chef/msi/localization-en-us.wxl.erb
new file mode 100644
index 0000000000..767f615bb7
--- /dev/null
+++ b/omnibus/resources/chef/msi/localization-en-us.wxl.erb
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<WixLocalization Culture="en-us" xmlns="http://schemas.microsoft.com/wix/2006/localization">
+ <!-- http://wix.codeplex.com/SourceControl/changeset/view/792e101c5cf7#src%2fext%2fUIExtension%2fwixlib%2fWixUI_en-us.wxl -->
+ <String Id="LANG">1033</String>
+ <String Id="ProductName"><%= friendly_name %></String>
+ <String Id="ManufacturerName"><%= maintainer.encode(:xml => :attr) %></String>
+ <String Id="WelcomeDlgTitle">{\WixUI_Font_Bigger}Welcome to the [ProductName] Setup Wizard</String>
+
+ <String Id="LicenseAgreementDlgTitle">{\WixUI_Font_Title_White}End-User License Agreement</String>
+ <String Id="LicenseAgreementDlgDescription">{\WixUI_Font_Normal_White}Please read the following license agreement carefully</String>
+
+ <String Id="InstallDirDlgTitle">{\WixUI_Font_Title_White}Destination Folder</String>
+ <String Id="InstallDirDlgDescription">{\WixUI_Font_Normal_White}Click Next to install to the default folder or click Change to choose another.</String>
+
+ <String Id="ProgressDlgTitleInstalling">{\WixUI_Font_Title_White}Installing [ProductName]</String>
+
+ <String Id="VerifyReadyDlgInstallTitle">{\WixUI_Font_Title_White}Ready to install [ProductName]</String>
+
+ <!-- Service -->
+ <!-- Keep these in sync with the name and description in chef-service-manager -->
+ <String Id="ServiceDisplayName"><%= friendly_name %> Service</String>
+ <String Id="ServiceDescription">Runs <%= friendly_name %> on regular, configurable intervals.</String>
+ <String Id="FeatureMainName"><%= friendly_name %></String>
+ <String Id="FeatureServiceName"><%= friendly_name %> Service</String>
+ <String Id="FeaturePSModuleName"><%= friendly_name %> PowerShell wrappers</String>
+
+ <String Id="MinimumOSVersionMessage">This package requires minimum OS version: Windows 7/Windows Server 2008 R2 or greater.</String>
+ <String Id="DowngradeErrorMessage">A newer version of [ProductName] is already installed.</String>
+ <String Id="FileExtractionProgress">Extracting files, please wait...</String>
+</WixLocalization>
diff --git a/omnibus/resources/chef/msi/parameters.wxi.erb b/omnibus/resources/chef/msi/parameters.wxi.erb
new file mode 100644
index 0000000000..febd1738e2
--- /dev/null
+++ b/omnibus/resources/chef/msi/parameters.wxi.erb
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Include>
+ <?define VersionNumber="<%= version %>" ?>
+ <?define DisplayVersionNumber="<%= display_version %>" ?>
+ <?define UpgradeCode="<%= upgrade_code %>" ?>
+<% parameters.each do |key, value| -%>
+ <?define <%= key %>="<%= value %>" ?>
+<% end -%>
+</Include>
diff --git a/omnibus/resources/chef/msi/source.wxs.erb b/omnibus/resources/chef/msi/source.wxs.erb
new file mode 100644
index 0000000000..d9c05127ed
--- /dev/null
+++ b/omnibus/resources/chef/msi/source.wxs.erb
@@ -0,0 +1,171 @@
+<?xml version='1.0'?>
+<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
+
+ <!-- This is how we include wxi files -->
+ <?include "parameters.wxi" ?>
+
+ <!--
+ Id="*" is to enable upgrading. * means that the product ID will be autogenerated on each build.
+ Name is made of localized product name and version number.
+ -->
+ <Product Id="*" Name="!(loc.ProductName) v$(var.DisplayVersionNumber)" Language="!(loc.LANG)"
+ Version="$(var.VersionNumber)" Manufacturer="!(loc.ManufacturerName)" UpgradeCode="$(var.UpgradeCode)">
+
+ <!--
+ Define the minimum supported installer version (2.0).
+ The install should be done for the whole machine not just the current user
+ -->
+ <Package InstallerVersion="200" InstallPrivileges="elevated"
+ Compressed="yes" InstallScope="perMachine" />
+
+ <Media Id="1" Cabinet="ChefClient.cab" EmbedCab="yes" CompressionLevel="high" />
+
+ <!--
+ Uncomment launch condition below to check for minimum OS
+ 601 = Windows 7/Server 2008R2.
+ -->
+ <!-- Condition Message="!(loc.MinimumOSVersionMessage)">
+ <![CDATA[Installed OR VersionNT >= 601]]>
+ </Condition -->
+
+ <!-- We always do Major upgrades -->
+ <MajorUpgrade DowngradeErrorMessage="!(loc.DowngradeErrorMessage)" />
+
+ <!--
+ If fastmsi is set, custom actions will be invoked during install to unzip
+ project files, and during uninstall to remove the project folder
+ -->
+ <% if fastmsi %>
+ <SetProperty Id="FastUnzip"
+ Value="FASTZIPDIR=[INSTALLLOCATION];FASTZIPAPPNAME=$(var.ProjectLocationDir)"
+ Sequence="execute"
+ Before="FastUnzip" />
+
+ <CustomAction Id="FastUnzip"
+ BinaryKey="CustomActionFastMsiDLL"
+ DllEntry="FastUnzip"
+ Execute="deferred"
+ Impersonate="no"
+ Return="check" />
+
+ <Binary Id="CustomActionFastMsiDLL"
+ SourceFile="CustomActionFastMsi.CA.dll" />
+
+ <CustomAction Id="Cleanup"
+ Directory="INSTALLLOCATION"
+ ExeCommand="cmd /C &quot;rd /S /Q $(var.ProjectLocationDir)&quot;"
+ Execute="deferred"
+ Impersonate="no"
+ Return="ignore" />
+
+ <InstallExecuteSequence>
+ <Custom Action="FastUnzip" After="InstallFiles">NOT Installed</Custom>
+ <Custom Action="Cleanup" After="RemoveFiles">REMOVE~="ALL"</Custom>
+ </InstallExecuteSequence>
+
+ <UI>
+ <ProgressText Action="FastUnzip">!(loc.FileExtractionProgress)</ProgressText>
+ </UI>
+ <% end %>
+
+ <Directory Id="TARGETDIR" Name="SourceDir">
+ <Directory Id="WindowsVolume">
+ <!-- Service needs chef directory to be present. -->
+ <Directory Id="CONFIGLOCATION" Name="chef">
+ <Component Id="CONFIGLOCATIONDIR" Guid="{F66F6394-51A4-4C5D-908B-E55584473436}" >
+ <CreateFolder Directory="CONFIGLOCATION" />
+ </Component>
+ </Directory>
+ <Directory Id="INSTALLLOCATION" Name="opscode">
+ <Directory Id="PROJECTLOCATION" Name="$(var.ProjectLocationDir)" >
+ <Directory Id="PROJECTLOCATIONBIN" Name="bin" >
+ <Component Id="ChefClientPath" Guid="{7F663F88-55A2-4E20-82BF-8BD2E60BB83A}" >
+ <Environment Id="ClientPathEnvironment"
+ Name="PATH" Action="set" Part="last" System="yes" Value="[PROJECTLOCATIONBIN]" />
+ </Component>
+ </Directory>
+ <Directory Id="PSMODULES" Name="modules" >
+ <Component Id="ChefPSModulePath" Guid="{357DA654-F02E-430A-9EA6-A10554E3EF38}" >
+ <Environment Id="ChefPSModulePathEnvironment"
+ Name="PSModulePath" Action="set" Part="last" System="yes" Value="[PSMODULES]" />
+ </Component>
+ </Directory>
+ <Directory Id="EMBEDDED" Name="embedded" >
+ <Directory Id="EMBEDDEDBIN" Name="bin" >
+ <Component Id="ChefClientService" Guid="{69B2D8BE-4A47-4BE3-AEE8-83FAEB6E2FAF}" >
+ <File Id="RubyExecutable" Source="$(var.ProjectSourceDir)\embedded\bin\ruby.exe" KeyPath="yes" />
+ <ServiceInstall Name="chef-client" Type="ownProcess"
+ Start="auto" Vital="yes" ErrorControl="ignore"
+ Arguments="$(var.ProjectSourceDir)\bin\chef-windows-service"
+ DisplayName="!(loc.ServiceDisplayName)"
+ Description="!(loc.ServiceDescription)">
+ <ServiceDependency Id="Winmgmt" />
+ <ServiceConfig DelayedAutoStart="yes" OnInstall="yes" />
+ </ServiceInstall>
+ <ServiceControl Id="ControlChefClientService" Name="chef-client"
+ Remove="both" Stop="both" Wait="yes" />
+ </Component>
+ <Component Id="ChefClientLog" Guid="{8e492d59-3a0c-43fd-b889-e35dfa33da91}">
+ <util:EventSource xmlns:util="http://schemas.microsoft.com/wix/UtilExtension"
+ Name="Chef" Log="Application"
+ EventMessageFile="[PROJECTLOCATION]$(var.ChefLogDllPath)"
+ />
+ </Component>
+ </Directory>
+ </Directory>
+ </Directory>
+ </Directory>
+ </Directory>
+ </Directory>
+
+ <!-- Set the components defined in our fragment files that will be used for our feature -->
+ <Feature Id="ChefClientFeature" Title="!(loc.FeatureMainName)" Absent="disallow" AllowAdvertise="no" Level="1" ConfigurableDirectory="INSTALLLOCATION">
+ <ComponentGroupRef Id="ProjectDir" />
+ <ComponentRef Id="ChefClientPath" />
+ <ComponentRef Id="CONFIGLOCATIONDIR" />
+ <ComponentRef Id="ChefClientLog" />
+ </Feature>
+
+ <Feature Id="ChefPSModuleFeature" Title="!(loc.FeaturePSModuleName)" Level="1000" AllowAdvertise="no">
+ <ComponentRef Id="ChefPSModulePath" />
+ </Feature>
+
+ <Feature Id="ChefServiceFeature" Title="!(loc.FeatureServiceName)" Level="1000" AllowAdvertise="no">
+ <ComponentRef Id="ChefClientService" />
+ </Feature>
+
+ <!--
+ TODO:
+
+ * create initial Client config? ie C:\chef\client.rb?
+ * optionally install extra tools? ie git?
+
+ -->
+
+ <!--
+ UI Stuff
+ -->
+ <Icon Id="oc.ico" SourceFile="Resources\assets\oc_16x16.ico"/>
+ <Property Id="ARPPRODUCTICON" Value="oc.ico" />
+ <Property Id="ARPHELPLINK" Value="http://www.getchef.com/support/" />
+ <Property Id="WIXUI_INSTALLDIR" Value="INSTALLLOCATION" />
+
+ <UIRef Id="ChefClientUI_InstallDir"/>
+ <UI Id="ChefClientUI_InstallDir">
+ <UIRef Id="WixUI_FeatureTree"/>
+ <TextStyle Id="WixUI_Font_Normal_White" FaceName="Tahoma" Size="8" Red="255" Green="255" Blue="255" />
+ <TextStyle Id="WixUI_Font_Bigger_White" FaceName="Tahoma" Size="12" Red="255" Green="255" Blue="255" />
+ <TextStyle Id="WixUI_Font_Title_White" FaceName="Tahoma" Size="9" Bold="yes" Red="255" Green="255" Blue="255" />
+ </UI>
+
+ <WixVariable Id="WixUILicenseRtf" Value="Resources\assets\LICENSE.rtf" />
+ <WixVariable Id="WixUIDialogBmp" Value="Resources\assets\dialog_background.bmp" />
+ <WixVariable Id="WixUIBannerBmp" Value="Resources\assets\banner_background.bmp" />
+
+ <WixVariable Id="WixUIExclamationIco" Value="Resources\assets\oc_32x32.ico" />
+ <WixVariable Id="WixUIInfoIco" Value="Resources\assets\oc_32x32.ico" />
+ <WixVariable Id="WixUINewIco" Value="Resources\assets\oc_16x16.ico" />
+ <WixVariable Id="WixUIUpIco" Value="Resources\assets\oc_16x16.ico" />
+
+ </Product>
+</Wix>
diff --git a/omnibus/resources/chef/pkg/background.png b/omnibus/resources/chef/pkg/background.png
new file mode 100644
index 0000000000..027453ab8c
--- /dev/null
+++ b/omnibus/resources/chef/pkg/background.png
Binary files differ
diff --git a/omnibus/resources/chef/pkg/license.html.erb b/omnibus/resources/chef/pkg/license.html.erb
new file mode 100644
index 0000000000..21b7991abf
--- /dev/null
+++ b/omnibus/resources/chef/pkg/license.html.erb
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright <%= Time.new.year %> 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.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/omnibus/resources/chef/pkg/welcome.html.erb b/omnibus/resources/chef/pkg/welcome.html.erb
new file mode 100644
index 0000000000..04a02fb225
--- /dev/null
+++ b/omnibus/resources/chef/pkg/welcome.html.erb
@@ -0,0 +1,5 @@
+
+ This installer will help you install <%= friendly_name %> version <%= build_version %>.
+
+
+ You will be guided through the steps necessary to install this software.
diff --git a/spec/functional/file_content_management/deploy_strategies_spec.rb b/spec/functional/file_content_management/deploy_strategies_spec.rb
index 8a995d0e41..48aaa29fbf 100644
--- a/spec/functional/file_content_management/deploy_strategies_spec.rb
+++ b/spec/functional/file_content_management/deploy_strategies_spec.rb
@@ -126,7 +126,7 @@ shared_examples_for "a content deploy strategy" do
security_descriptor_invariants.inject({}) do |prop_map, property|
prop_map[property] = descriptor.send(property)
prop_map
- end
+ end
end
before do
diff --git a/spec/functional/resource/aixinit_service_spec.rb b/spec/functional/resource/aixinit_service_spec.rb
index 3d9216158e..3e19a16af0 100755
--- a/spec/functional/resource/aixinit_service_spec.rb
+++ b/spec/functional/resource/aixinit_service_spec.rb
@@ -38,7 +38,7 @@ describe Chef::Resource::Service, :requires_root, :aix_only do
def valide_symlinks(expected_output, run_level = nil, status = nil, priority = nil)
directory = []
- if priority.is_a?Hash
+ if priority.is_a? Hash
priority.each do |level,o|
directory << "/etc/rc.d/rc#{level}.d/#{(o[0] == :start ? 'S' : 'K')}#{o[1]}#{new_resource.service_name}"
end
diff --git a/spec/functional/resource/dsc_script_spec.rb b/spec/functional/resource/dsc_script_spec.rb
index dc7704481f..2e0830e02e 100644
--- a/spec/functional/resource/dsc_script_spec.rb
+++ b/spec/functional/resource/dsc_script_spec.rb
@@ -101,7 +101,7 @@ EOH
param($testregkeyname, $testregvaluename)
#{dsc_reg_code}
EOH
- }
+ }
let(:dsc_user_prefix) { 'dsc' }
let(:dsc_user_suffix) { 'chefx' }
@@ -186,7 +186,7 @@ environment "whatsmydir"
Ensure = 'Present'
}
EOH
-}
+ }
let(:dsc_config_name) {
dsc_test_resource_base.name
diff --git a/spec/functional/resource/mount_spec.rb b/spec/functional/resource/mount_spec.rb
index cb3fa453b9..4e9e8c3bdc 100644
--- a/spec/functional/resource/mount_spec.rb
+++ b/spec/functional/resource/mount_spec.rb
@@ -16,12 +16,13 @@
# limitations under the License.
#
+require 'spec_helper'
require 'functional/resource/base'
require 'chef/mixin/shell_out'
require 'tmpdir'
# run this test only for following platforms.
-include_flag = !(['ubuntu', 'centos', 'solaris2'].include?(ohai[:platform]))
+include_flag = !(['ubuntu', 'centos', 'aix', 'solaris2'].include?(ohai[:platform]))
describe Chef::Resource::Mount, :requires_root, :skip_travis, :external => include_flag do
# Disabled in travis because it refuses to let us mount a ramdisk. /dev/ramX does not
@@ -34,16 +35,13 @@ describe Chef::Resource::Mount, :requires_root, :skip_travis, :external => inclu
def setup_device_for_mount
# use ramdisk for creating a test device for mount.
# This can cleaner if we have chef resource/provider for ramdisk.
- # TODO: These tests only work in LPARs, not WPARs on AIX.
case ohai[:platform]
when "aix"
- ramdisk = shell_out!("mkramdisk 16M").stdout
-
- # identify device, for /dev/rramdisk0 it is /dev/ramdisk0
- device = ramdisk.tr("\n","").gsub(/\/rramdisk/, '/ramdisk')
-
- fstype = "jfs2"
- shell_out!("mkfs -V #{fstype} #{device}")
+ # On AIX, we can't create a ramdisk inside a WPAR, so we use
+ # a "namefs" mount against / to test
+ # https://www-304.ibm.com/support/knowledgecenter/ssw_aix_71/com.ibm.aix.performance/namefs_file_sys.htm
+ device = "/"
+ fstype = "namefs"
when "ubuntu", "centos"
device = "/dev/ram1"
shell_out("ls -1 /dev/ram*").stdout.each_line do |d|
@@ -63,15 +61,6 @@ describe Chef::Resource::Mount, :requires_root, :skip_travis, :external => inclu
[device, fstype]
end
- def cleanup_device(device)
- case ohai[:platform]
- when "aix"
- ramdisk = device.gsub(/\/ramdisk/, '/rramdisk')
- shell_out("rmramdisk #{ramdisk}")
- else
- end
- end
-
def cleanup_mount(mount_point)
shell_out("umount #{mount_point}")
end
@@ -149,7 +138,6 @@ describe Chef::Resource::Mount, :requires_root, :skip_travis, :external => inclu
after(:all) do
Dir.rmdir(@mount_point)
- cleanup_device(@device)
end
after(:each) do
@@ -175,7 +163,7 @@ describe Chef::Resource::Mount, :requires_root, :skip_travis, :external => inclu
mount_should_exist(new_resource.mount_point, new_resource.device)
new_resource.supports[:remount] = true
- new_resource.options "rw,log=NULL" if ohai[:platform] == 'aix'
+ new_resource.options "rw" if ohai[:platform] == 'aix'
new_resource.run_action(:remount)
mount_should_exist(new_resource.mount_point, new_resource.device, nil, (ohai[:platform] == 'aix') ? new_resource.options : nil)
diff --git a/spec/functional/resource/powershell_script_spec.rb b/spec/functional/resource/powershell_script_spec.rb
index 91b74fd752..d7e5b9888b 100644
--- a/spec/functional/resource/powershell_script_spec.rb
+++ b/spec/functional/resource/powershell_script_spec.rb
@@ -81,7 +81,7 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
# PowerShell 4.0 and later versions return a 32-bit signed value.
file = Tempfile.new(['foo', '.ps1'])
begin
- file.write "exit #{negative_exit_status.to_s}"
+ file.write "exit #{negative_exit_status}"
file.close
resource.code(". \"#{file.path}\"")
diff --git a/spec/functional/resource/registry_spec.rb b/spec/functional/resource/registry_spec.rb
index f112ad9b00..c0682fefc8 100644
--- a/spec/functional/resource/registry_spec.rb
+++ b/spec/functional/resource/registry_spec.rb
@@ -111,7 +111,7 @@ describe Chef::Resource::RegistryKey, :windows_only, :broken => true do
before do
@node.name("windowsbox")
- @rest_client = double("Chef::REST (mock)")
+ @rest_client = double("Chef::ServerAPI (mock)")
allow(@rest_client).to receive(:create_url).and_return("reports/nodes/windowsbox/runs/#{@run_id}");
allow(@rest_client).to receive(:raw_http_request).and_return({"result"=>"ok"});
allow(@rest_client).to receive(:post_rest).and_return({"uri"=>"https://example.com/reports/nodes/windowsbox/runs/#{@run_id}"});
diff --git a/spec/functional/resource/windows_package_spec.rb b/spec/functional/resource/windows_package_spec.rb
index f5fdc9ef3d..957f357846 100644
--- a/spec/functional/resource/windows_package_spec.rb
+++ b/spec/functional/resource/windows_package_spec.rb
@@ -37,11 +37,11 @@ describe Chef::Resource::WindowsPackage, :windows_only, :volatile do
new_resource
end
- describe "multi package scenario" do
+ describe "install package" do
let(:pkg_name) { 'Microsoft Visual C++ 2005 Redistributable' }
+ let(:pkg_checksum) { 'd6832398e3bc9156a660745f427dc1c2392ce4e9a872e04f41f62d0c6bae07a8' }
let(:pkg_path) { 'https://download.microsoft.com/download/6/B/B/6BB661D6-A8AE-4819-B79F-236472F6070C/vcredist_x86.exe' }
let(:pkg_checksum) { nil }
- let(:pkg_version) { '8.0.59193' }
let(:pkg_type) { :custom }
let(:pkg_options) { "/Q" }
@@ -57,6 +57,7 @@ describe Chef::Resource::WindowsPackage, :windows_only, :volatile do
context "installing additional version" do
let(:pkg_path) { 'https://download.microsoft.com/download/e/1/c/e1c773de-73ba-494a-a5ba-f24906ecf088/vcredist_x86.exe' }
+ let(:pkg_checksum) { 'eb00f891919d4f894ab725b158459db8834470c382dc60cd3c3ee2c6de6da92c' }
let(:pkg_version) { '8.0.56336' }
it "installs older version" do
@@ -127,11 +128,6 @@ describe Chef::Resource::WindowsPackage, :windows_only, :volatile do
let(:pkg_path) { 'http://iweb.dl.sourceforge.net/project/ultradefrag/stable-release/6.1.1/ultradefrag-6.1.1.bin.amd64.exe' }
let(:pkg_checksum) { '11d53ed4c426c8c867ad43f142b7904226ffd9938c02e37086913620d79e3c09' }
- it "finds the correct package version" do
- subject.run_action(:install)
- expect(subject.version).to eq('6.1.1')
- end
-
it "finds the correct installer type" do
subject.run_action(:install)
expect(subject.provider_for_action(:install).installer_type).to eq(:nsis)
@@ -143,11 +139,6 @@ describe Chef::Resource::WindowsPackage, :windows_only, :volatile do
let(:pkg_path) { 'http://mercurial.selenic.com/release/windows/Mercurial-3.6.1-x64.exe' }
let(:pkg_checksum) { 'febd29578cb6736163d232708b834a2ddd119aa40abc536b2c313fc5e1b5831d' }
- it "finds the correct package version" do
- subject.run_action(:install)
- expect(subject.version).to eq(nil) # Mercurial does not include versioning
- end
-
it "finds the correct installer type" do
subject.run_action(:install)
expect(subject.provider_for_action(:install).installer_type).to eq(:inno)
diff --git a/spec/functional/resource/windows_service_spec.rb b/spec/functional/resource/windows_service_spec.rb
index 90545429e5..9ee4adde87 100644
--- a/spec/functional/resource/windows_service_spec.rb
+++ b/spec/functional/resource/windows_service_spec.rb
@@ -23,7 +23,7 @@ describe Chef::Resource::WindowsService, :windows_only, :system_windows_service_
include_context "using Win32::Service"
let(:username) { "service_spec_user"}
- let(:qualified_username) { ".\\#{username}"}
+ let(:qualified_username) { "#{ENV['COMPUTERNAME']}\\#{username}"}
let(:password) { "1a2b3c4X!&narf"}
let(:user_resource) {
@@ -93,6 +93,9 @@ describe Chef::Resource::WindowsService, :windows_only, :system_windows_service_
service_resource.run_action(:start)
end
- it "raises an exception when it can't grant the logon privilege"
+ it "grants the user the log on as service right" do
+ service_resource.run_action(:start)
+ expect(Chef::ReservedNames::Win32::Security.get_account_right(qualified_username)).to include("SeServiceLogonRight")
+ end
end
end
diff --git a/spec/functional/tiny_server_spec.rb b/spec/functional/tiny_server_spec.rb
index 87be948a0d..d21248062a 100644
--- a/spec/functional/tiny_server_spec.rb
+++ b/spec/functional/tiny_server_spec.rb
@@ -70,8 +70,8 @@ describe TinyServer::Manager do
TinyServer::API.instance.get("/index", 200, "[\"hello\"]")
- rest = Chef::REST.new('http://localhost:9000', false, false)
- expect(rest.get_rest("index")).to eq(["hello"])
+ rest = Chef::HTTP.new('http://localhost:9000')
+ expect(rest.get("index")).to eq("[\"hello\"]")
@server.stop
end
diff --git a/spec/integration/knife/diff_spec.rb b/spec/integration/knife/diff_spec.rb
index 465383437f..b32a4580a1 100644
--- a/spec/integration/knife/diff_spec.rb
+++ b/spec/integration/knife/diff_spec.rb
@@ -59,8 +59,8 @@ D\t/roles/x.json
D\t/users/admin.json
D\t/users/x.json
EOM
+ end
end
- end
when_the_repository 'has an identical copy of each thing' do
@@ -354,8 +354,8 @@ D\t/roles/x.json
D\t/users/admin.json
D\t/users/x.json
EOM
+ end
end
- end
when_the_repository 'has an identical copy of each thing' do
before do
diff --git a/spec/support/shared/context/client.rb b/spec/support/shared/context/client.rb
index eb537e9889..cb387a9478 100644
--- a/spec/support/shared/context/client.rb
+++ b/spec/support/shared/context/client.rb
@@ -68,9 +68,9 @@ shared_context "a client run" do
let(:api_client_exists?) { false }
let(:enable_fork) { false }
- let(:http_cookbook_sync) { double("Chef::REST (cookbook sync)") }
- let(:http_node_load) { double("Chef::REST (node)") }
- let(:http_node_save) { double("Chef::REST (node save)") }
+ let(:http_cookbook_sync) { double("Chef::ServerAPI (cookbook sync)") }
+ let(:http_node_load) { double("Chef::ServerAPI (node)") }
+ let(:http_node_save) { double("Chef::ServerAPI (node save)") }
let(:runner) { instance_double("Chef::Runner") }
let(:audit_runner) { instance_double("Chef::Audit::Runner", :failed? => false) }
@@ -93,10 +93,11 @@ shared_context "a client run" do
def stub_for_node_load
# Client.register will then turn around create another
- # Chef::REST object, this time with the client key it got from the
+ # Chef::ServerAPI object, this time with the client key it got from the
# previous step.
- expect(Chef::REST).to receive(:new).
- with(Chef::Config[:chef_server_url], fqdn, Chef::Config[:client_key]).
+ expect(Chef::ServerAPI).to receive(:new).
+ with(Chef::Config[:chef_server_url], client_name: fqdn,
+ signing_key_filename: Chef::Config[:client_key]).
exactly(:once).
and_return(http_node_load)
@@ -115,7 +116,7 @@ shared_context "a client run" do
# ---Client#sync_cookbooks -- downloads the list of cookbooks to sync
#
expect_any_instance_of(Chef::CookbookSynchronizer).to receive(:sync_cookbooks)
- expect(Chef::REST).to receive(:new).with(Chef::Config[:chef_server_url]).and_return(http_cookbook_sync)
+ expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url]).and_return(http_cookbook_sync)
expect(http_cookbook_sync).to receive(:post).
with("environments/_default/cookbook_versions", {:run_list => []}).
and_return({})
@@ -175,8 +176,9 @@ shared_context "converge completed" do
allow(node).to receive(:data_for_save).and_return(node.for_json)
# --Client#save_updated_node
- expect(Chef::REST).to receive(:new).with(Chef::Config[:chef_server_url], fqdn, Chef::Config[:client_key], validate_utf8: false).and_return(http_node_save)
- expect(http_node_save).to receive(:put_rest).with("nodes/#{fqdn}", node.for_json).and_return(true)
+ expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], client_name: fqdn,
+ signing_key_filename: Chef::Config[:client_key], validate_utf8: false).and_return(http_node_save)
+ expect(http_node_save).to receive(:put).with("nodes/#{fqdn}", node.for_json).and_return(true)
end
end
diff --git a/spec/support/shared/unit/file_system_support.rb b/spec/support/shared/unit/file_system_support.rb
index 358f0c405c..3f9e6df3b9 100644
--- a/spec/support/shared/unit/file_system_support.rb
+++ b/spec/support/shared/unit/file_system_support.rb
@@ -56,7 +56,7 @@ module FileSystemSupport
def no_blocking_calls_allowed
[ Chef::ChefFS::FileSystem::MemoryFile, Chef::ChefFS::FileSystem::MemoryDir ].each do |c|
[ :children, :exists?, :read ].each do |m|
- allow_any_instance_of(c).to receive(m).and_raise("#{m.to_s} should not be called")
+ allow_any_instance_of(c).to receive(m).and_raise("#{m} should not be called")
end
end
end
diff --git a/spec/unit/api_client_spec.rb b/spec/unit/api_client_spec.rb
index a0e399b470..810c806af5 100644
--- a/spec/unit/api_client_spec.rb
+++ b/spec/unit/api_client_spec.rb
@@ -275,7 +275,7 @@ describe Chef::ApiClient do
describe "when requesting a new key" do
before do
- @http_client = double("Chef::REST mock")
+ @http_client = double("Chef::ServerAPI mock")
allow(Chef::ServerAPI).to receive(:new).and_return(@http_client)
end
diff --git a/spec/unit/audit/audit_reporter_spec.rb b/spec/unit/audit/audit_reporter_spec.rb
index 46c2a96b4c..1a8cee1cd5 100644
--- a/spec/unit/audit/audit_reporter_spec.rb
+++ b/spec/unit/audit/audit_reporter_spec.rb
@@ -57,7 +57,6 @@ describe Chef::Audit::AuditReporter do
before do
allow(reporter).to receive(:auditing_enabled?).and_return(true)
allow(reporter).to receive(:run_status).and_return(run_status)
- allow(rest).to receive(:create_url).and_return(true)
allow(rest).to receive(:post).and_return(true)
allow(reporter).to receive(:audit_data).and_return(audit_data)
allow(reporter).to receive(:run_status).and_return(run_status)
@@ -75,16 +74,12 @@ describe Chef::Audit::AuditReporter do
end
it "posts audit data to server endpoint" do
- endpoint = "api.opscode.us/orgname/controls"
headers = {
'X-Ops-Audit-Report-Protocol-Version' => Chef::Audit::AuditReporter::PROTOCOL_VERSION
}
- expect(rest).to receive(:create_url).
- with("controls").
- and_return(endpoint)
expect(rest).to receive(:post).
- with(endpoint, run_data, headers)
+ with("controls", run_data, headers)
reporter.run_completed(node)
end
@@ -255,7 +250,6 @@ EOM
context "when no prior exception is stored" do
it "reports no error" do
- expect(rest).to receive(:create_url)
expect(rest).to receive(:post)
reporter.run_failed(run_error)
expect(run_data).to_not have_key(:error)
@@ -268,7 +262,6 @@ EOM
end
it "reports the prior error" do
- expect(rest).to receive(:create_url)
expect(rest).to receive(:post)
reporter.run_failed(run_error)
expect(run_data).to have_key(:error)
diff --git a/spec/unit/client_spec.rb b/spec/unit/client_spec.rb
index c270ddc092..ca7440061e 100644
--- a/spec/unit/client_spec.rb
+++ b/spec/unit/client_spec.rb
@@ -23,7 +23,7 @@ require 'spec/support/shared/context/client'
require 'spec/support/shared/examples/client'
require 'chef/run_context'
-require 'chef/rest'
+require 'chef/server_api'
require 'rbconfig'
class FooError < RuntimeError
@@ -169,7 +169,7 @@ describe Chef::Client do
# ---Client#sync_cookbooks -- downloads the list of cookbooks to sync
#
expect_any_instance_of(Chef::CookbookSynchronizer).to receive(:sync_cookbooks)
- expect(Chef::REST).to receive(:new).with(Chef::Config[:chef_server_url]).and_return(http_cookbook_sync)
+ expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url]).and_return(http_cookbook_sync)
expect(http_cookbook_sync).to receive(:post).
with("environments/_default/cookbook_versions", {:run_list => ["override_recipe"]}).
and_return({})
@@ -203,7 +203,7 @@ describe Chef::Client do
# ---Client#sync_cookbooks -- downloads the list of cookbooks to sync
#
expect_any_instance_of(Chef::CookbookSynchronizer).to receive(:sync_cookbooks)
- expect(Chef::REST).to receive(:new).with(Chef::Config[:chef_server_url]).and_return(http_cookbook_sync)
+ expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url]).and_return(http_cookbook_sync)
expect(http_cookbook_sync).to receive(:post).
with("environments/_default/cookbook_versions", {:run_list => ["new_run_list_recipe"]}).
and_return({})
@@ -336,9 +336,9 @@ describe Chef::Client do
# build_node will call Node#expand! with server, which will
# eventually hit the server to expand the included role.
- mock_chef_rest = double("Chef::REST")
- expect(mock_chef_rest).to receive(:get_rest).with("roles/role_containing_cookbook1").and_return(role_containing_cookbook1)
- expect(Chef::REST).to receive(:new).and_return(mock_chef_rest)
+ mock_chef_rest = double("Chef::ServerAPI")
+ expect(mock_chef_rest).to receive(:get).with("roles/role_containing_cookbook1").and_return(role_containing_cookbook1.to_hash)
+ expect(Chef::ServerAPI).to receive(:new).and_return(mock_chef_rest)
# check pre-conditions.
expect(node[:roles]).to be_nil
@@ -372,9 +372,9 @@ describe Chef::Client do
test_env = Chef::Environment.new
test_env.name("A")
- mock_chef_rest = double("Chef::REST")
- expect(mock_chef_rest).to receive(:get_rest).with("environments/A").and_return(test_env)
- expect(Chef::REST).to receive(:new).and_return(mock_chef_rest)
+ mock_chef_rest = double("Chef::ServerAPI")
+ expect(mock_chef_rest).to receive(:get).with("environments/A").and_return(test_env)
+ expect(Chef::ServerAPI).to receive(:new).and_return(mock_chef_rest)
allow(client.policy_builder).to receive(:node).and_return(node)
client.policy_builder.select_implementation(node)
allow(client.policy_builder.implementation).to receive(:node).and_return(node)
diff --git a/spec/unit/cookbook/file_vendor_spec.rb b/spec/unit/cookbook/file_vendor_spec.rb
index 145541a63f..8bf2d3c2a3 100644
--- a/spec/unit/cookbook/file_vendor_spec.rb
+++ b/spec/unit/cookbook/file_vendor_spec.rb
@@ -23,7 +23,7 @@ describe Chef::Cookbook::FileVendor do
context "when configured to fetch files over http" do
- let(:http) { double("Chef::REST") }
+ let(:http) { double("Chef::ServerAPI") }
before do
file_vendor_class.fetch_from_remote(http)
diff --git a/spec/unit/cookbook/metadata_spec.rb b/spec/unit/cookbook/metadata_spec.rb
index f8e96ad475..633632b58c 100644
--- a/spec/unit/cookbook/metadata_spec.rb
+++ b/spec/unit/cookbook/metadata_spec.rb
@@ -582,7 +582,7 @@ describe Chef::Cookbook::Metadata do
expect {
metadata.attribute("db/mysql/databases", :type => "hash")
}.not_to raise_error
- end
+ end
it "should let required be required, recommended or optional" do
expect {
@@ -720,7 +720,7 @@ describe Chef::Cookbook::Metadata do
}
metadata.attribute("db/mysql/databases", attrs)
}.not_to raise_error
- end
+ end
it "should error if default is not a choice" do
expect {
@@ -891,31 +891,31 @@ describe Chef::Cookbook::Metadata do
:suggestions,
:conflicting,
:replacing].each do |to_check|
- it "should transform deprecated greater than syntax for :#{to_check.to_s}" do
+ it "should transform deprecated greater than syntax for :#{to_check}" do
@hash[to_check.to_s]["foo::bar"] = ">> 0.2"
deserial = Chef::Cookbook::Metadata.from_hash(@hash)
expect(deserial.send(to_check)["foo::bar"]).to eq('> 0.2')
end
- it "should transform deprecated less than syntax for :#{to_check.to_s}" do
+ it "should transform deprecated less than syntax for :#{to_check}" do
@hash[to_check.to_s]["foo::bar"] = "<< 0.2"
deserial = Chef::Cookbook::Metadata.from_hash(@hash)
expect(deserial.send(to_check)["foo::bar"]).to eq('< 0.2')
end
- it "should ignore multiple dependency constraints for :#{to_check.to_s}" do
+ it "should ignore multiple dependency constraints for :#{to_check}" do
@hash[to_check.to_s]["foo::bar"] = [ ">= 1.0", "<= 5.2" ]
deserial = Chef::Cookbook::Metadata.from_hash(@hash)
expect(deserial.send(to_check)["foo::bar"]).to eq([])
end
- it "should accept an empty array of dependency constraints for :#{to_check.to_s}" do
+ it "should accept an empty array of dependency constraints for :#{to_check}" do
@hash[to_check.to_s]["foo::bar"] = []
deserial = Chef::Cookbook::Metadata.from_hash(@hash)
expect(deserial.send(to_check)["foo::bar"]).to eq([])
end
- it "should accept single-element arrays of dependency constraints for :#{to_check.to_s}" do
+ it "should accept single-element arrays of dependency constraints for :#{to_check}" do
@hash[to_check.to_s]["foo::bar"] = [ ">= 2.0" ]
deserial = Chef::Cookbook::Metadata.from_hash(@hash)
expect(deserial.send(to_check)["foo::bar"]).to eq(">= 2.0")
diff --git a/spec/unit/cookbook/synchronizer_spec.rb b/spec/unit/cookbook/synchronizer_spec.rb
index 2b040f3c95..30ddaad1d7 100644
--- a/spec/unit/cookbook/synchronizer_spec.rb
+++ b/spec/unit/cookbook/synchronizer_spec.rb
@@ -38,7 +38,6 @@ describe Chef::CookbookCacheCleaner do
unused_template_files.each do |cbf|
expect(file_cache).to receive(:delete).with(cbf)
end
- cookbook_hash = {"valid1"=> {}, "valid2" => {}}
allow(cleaner).to receive(:cache).and_return(file_cache)
cleaner.cleanup_file_cache
end
@@ -224,8 +223,8 @@ describe Chef::CookbookSynchronizer do
and_return(false)
# Fetch and copy default.rb recipe
- expect(server_api).to receive(:get_rest).
- with('http://chef.example.com/abc123', true).
+ expect(server_api).to receive(:streaming_request).
+ with('http://chef.example.com/abc123').
and_return(cookbook_a_default_recipe_tempfile)
expect(file_cache).to receive(:move_to).
with("/tmp/cookbook_a_recipes_default_rb", "cookbooks/cookbook_a/recipes/default.rb")
@@ -234,8 +233,8 @@ describe Chef::CookbookSynchronizer do
and_return("/file-cache/cookbooks/cookbook_a/recipes/default.rb")
# Fetch and copy default.rb attribute file
- expect(server_api).to receive(:get_rest).
- with('http://chef.example.com/abc456', true).
+ expect(server_api).to receive(:streaming_request).
+ with('http://chef.example.com/abc456').
and_return(cookbook_a_default_attribute_tempfile)
expect(file_cache).to receive(:move_to).
with("/tmp/cookbook_a_attributes_default_rb", "cookbooks/cookbook_a/attributes/default.rb")
@@ -252,8 +251,8 @@ describe Chef::CookbookSynchronizer do
with("cookbooks/cookbook_a/templates/default/apache2.conf.erb").
and_return(false)
- expect(server_api).to receive(:get_rest).
- with('http://chef.example.com/megaman.conf', true).
+ expect(server_api).to receive(:streaming_request).
+ with('http://chef.example.com/megaman.conf').
and_return(cookbook_a_file_default_tempfile)
expect(file_cache).to receive(:move_to).
with("/tmp/cookbook_a_file_default_tempfile", "cookbooks/cookbook_a/files/default/megaman.conf")
@@ -261,8 +260,8 @@ describe Chef::CookbookSynchronizer do
with("cookbooks/cookbook_a/files/default/megaman.conf", false).
and_return("/file-cache/cookbooks/cookbook_a/default/megaman.conf")
- expect(server_api).to receive(:get_rest).
- with('http://chef.example.com/ffffff', true).
+ expect(server_api).to receive(:streaming_request).
+ with('http://chef.example.com/ffffff').
and_return(cookbook_a_template_default_tempfile)
expect(file_cache).to receive(:move_to).
with("/tmp/cookbook_a_template_default_tempfile", "cookbooks/cookbook_a/templates/default/apache2.conf.erb")
@@ -281,8 +280,8 @@ describe Chef::CookbookSynchronizer do
and_return(true)
# Fetch and copy default.rb recipe
- expect(server_api).to receive(:get_rest).
- with('http://chef.example.com/abc123', true).
+ expect(server_api).to receive(:streaming_request).
+ with('http://chef.example.com/abc123').
and_return(cookbook_a_default_recipe_tempfile)
expect(file_cache).to receive(:move_to).
with("/tmp/cookbook_a_recipes_default_rb", "cookbooks/cookbook_a/recipes/default.rb")
@@ -297,8 +296,8 @@ describe Chef::CookbookSynchronizer do
and_return("fff000")
# Fetch and copy default.rb attribute file
- expect(server_api).to receive(:get_rest).
- with('http://chef.example.com/abc456', true).
+ expect(server_api).to receive(:streaming_request).
+ with('http://chef.example.com/abc456').
and_return(cookbook_a_default_attribute_tempfile)
expect(file_cache).to receive(:move_to).
with("/tmp/cookbook_a_attributes_default_rb", "cookbooks/cookbook_a/attributes/default.rb")
@@ -323,8 +322,8 @@ describe Chef::CookbookSynchronizer do
and_return(true)
# Fetch and copy megaman.conf
- expect(server_api).to receive(:get_rest).
- with('http://chef.example.com/megaman.conf', true).
+ expect(server_api).to receive(:streaming_request).
+ with('http://chef.example.com/megaman.conf').
and_return(cookbook_a_file_default_tempfile)
expect(file_cache).to receive(:move_to).
with("/tmp/cookbook_a_file_default_tempfile", "cookbooks/cookbook_a/files/default/megaman.conf")
@@ -334,8 +333,8 @@ describe Chef::CookbookSynchronizer do
and_return("/file-cache/cookbooks/cookbook_a/default/megaman.conf")
# Fetch and copy apache2.conf template
- expect(server_api).to receive(:get_rest).
- with('http://chef.example.com/ffffff', true).
+ expect(server_api).to receive(:streaming_request).
+ with('http://chef.example.com/ffffff').
and_return(cookbook_a_template_default_tempfile)
expect(file_cache).to receive(:move_to).
with("/tmp/cookbook_a_template_default_tempfile", "cookbooks/cookbook_a/templates/default/apache2.conf.erb")
@@ -416,7 +415,7 @@ describe Chef::CookbookSynchronizer do
end
describe "when syncing cookbooks with the server" do
- let(:server_api) { double("Chef::REST (mock)") }
+ let(:server_api) { double("Chef::ServerAPI (mock)") }
let(:file_cache) { double("Chef::FileCache (mock)") }
@@ -442,8 +441,8 @@ describe Chef::CookbookSynchronizer do
it "does not fetch templates or cookbook files" do
# Implicitly tested in previous test; this test is just for behavior specification.
- expect(server_api).not_to receive(:get_rest).
- with('http://chef.example.com/ffffff', true)
+ expect(server_api).not_to receive(:streaming_request).
+ with('http://chef.example.com/ffffff')
synchronizer.sync_cookbooks
end
@@ -502,7 +501,7 @@ describe Chef::CookbookSynchronizer do
it "does not update files" do
expect(file_cache).not_to receive(:move_to)
- expect(server_api).not_to receive(:get_rest)
+ expect(server_api).not_to receive(:streaming_request)
synchronizer.sync_cookbooks
end
end
@@ -512,7 +511,7 @@ describe Chef::CookbookSynchronizer do
it "does not update files" do
expect(file_cache).not_to receive(:move_to)
- expect(server_api).not_to receive(:get_rest)
+ expect(server_api).not_to receive(:streaming_request)
synchronizer.sync_cookbooks
end
end
diff --git a/spec/unit/cookbook_loader_spec.rb b/spec/unit/cookbook_loader_spec.rb
index b1384bffe7..7234183a11 100644
--- a/spec/unit/cookbook_loader_spec.rb
+++ b/spec/unit/cookbook_loader_spec.rb
@@ -86,7 +86,7 @@ describe Chef::CookbookLoader do
seen = Array.new
cookbook_loader.each do |cookbook_name, cookbook|
seen << cookbook_name
- end
+ end
expect(seen[0]).to eq("angrybash")
expect(seen[1]).to eq("apache2")
expect(seen[2]).to eq("borken")
diff --git a/spec/unit/cookbook_uploader_spec.rb b/spec/unit/cookbook_uploader_spec.rb
index 76727c18e2..a08b6b29d0 100644
--- a/spec/unit/cookbook_uploader_spec.rb
+++ b/spec/unit/cookbook_uploader_spec.rb
@@ -20,7 +20,7 @@ require 'spec_helper'
describe Chef::CookbookUploader do
- let(:http_client) { double("Chef::REST") }
+ let(:http_client) { double("Chef::ServerAPI") }
let(:cookbook_loader) do
loader = Chef::CookbookLoader.new(File.join(CHEF_SPEC_DATA, "cookbooks"))
@@ -64,8 +64,8 @@ describe Chef::CookbookUploader do
end
it "creates an HTTP client with default configuration when not initialized with one" do
- default_http_client = double("Chef::REST")
- expect(Chef::REST).to receive(:new).with(Chef::Config[:chef_server_url]).and_return(default_http_client)
+ default_http_client = double("Chef::ServerAPI")
+ expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url]).and_return(default_http_client)
uploader = described_class.new(cookbooks_to_upload)
expect(uploader.rest).to eq(default_http_client)
end
diff --git a/spec/unit/data_bag_item_spec.rb b/spec/unit/data_bag_item_spec.rb
index 497817ecf1..47042aa7ba 100644
--- a/spec/unit/data_bag_item_spec.rb
+++ b/spec/unit/data_bag_item_spec.rb
@@ -214,7 +214,7 @@ describe Chef::DataBagItem do
end
describe "save" do
- let(:server) { instance_double(Chef::REST) }
+ let(:server) { instance_double(Chef::ServerAPI) }
let(:data_bag_item) {
data_bag_item = Chef::DataBagItem.new
@@ -225,18 +225,18 @@ describe Chef::DataBagItem do
}
before do
- expect(Chef::REST).to receive(:new).and_return(server)
+ expect(Chef::ServerAPI).to receive(:new).and_return(server)
end
it "should update the item when it already exists" do
- expect(server).to receive(:put_rest).with("data/books/heart_of_darkness", data_bag_item)
+ expect(server).to receive(:put).with("data/books/heart_of_darkness", data_bag_item)
data_bag_item.save
end
it "should create if the item is not found" do
exception = double("404 error", :code => "404")
- expect(server).to receive(:put_rest).and_raise(Net::HTTPServerException.new("foo", exception))
- expect(server).to receive(:post_rest).with("data/books", data_bag_item)
+ expect(server).to receive(:put).and_raise(Net::HTTPServerException.new("foo", exception))
+ expect(server).to receive(:post).with("data/books", data_bag_item)
data_bag_item.save
end
@@ -249,8 +249,8 @@ describe Chef::DataBagItem do
end
it "should not save" do
- expect(server).not_to receive(:put_rest)
- expect(server).not_to receive(:post_rest)
+ expect(server).not_to receive(:put)
+ expect(server).not_to receive(:post)
data_bag_item.data_bag("books")
data_bag_item.save
end
@@ -259,7 +259,7 @@ describe Chef::DataBagItem do
end
describe "destroy" do
- let(:server) { instance_double(Chef::REST) }
+ let(:server) { instance_double(Chef::ServerAPI) }
let(:data_bag_item) {
data_bag_item = Chef::DataBagItem.new
@@ -269,8 +269,8 @@ describe Chef::DataBagItem do
}
it "should set default parameters" do
- expect(Chef::REST).to receive(:new).and_return(server)
- expect(server).to receive(:delete_rest).with("data/a_baggy_bag/data_bag_item_a_baggy_bag_some_id")
+ expect(Chef::ServerAPI).to receive(:new).and_return(server)
+ expect(server).to receive(:delete).with("data/a_baggy_bag/data_bag_item_a_baggy_bag_some_id")
data_bag_item.destroy
end
@@ -283,21 +283,21 @@ describe Chef::DataBagItem do
end
describe "from an API call" do
- let(:http_client) { double("Chef::REST") }
+ let(:http_client) { double("Chef::ServerAPI") }
before do
- allow(Chef::REST).to receive(:new).and_return(http_client)
+ allow(Chef::ServerAPI).to receive(:new).and_return(http_client)
end
it "converts raw data to a data bag item" do
- expect(http_client).to receive(:get_rest).with("data/users/charlie").and_return(data_bag_item.to_hash)
+ expect(http_client).to receive(:get).with("data/users/charlie").and_return(data_bag_item.to_hash)
item = Chef::DataBagItem.load(:users, "charlie")
expect(item).to be_a_kind_of(Chef::DataBagItem)
expect(item).to eq(data_bag_item)
end
it "does not convert when a DataBagItem is returned from the API call" do
- expect(http_client).to receive(:get_rest).with("data/users/charlie").and_return(data_bag_item)
+ expect(http_client).to receive(:get).with("data/users/charlie").and_return(data_bag_item)
item = Chef::DataBagItem.load(:users, "charlie")
expect(item).to be_a_kind_of(Chef::DataBagItem)
expect(item).to equal(data_bag_item)
diff --git a/spec/unit/data_bag_spec.rb b/spec/unit/data_bag_spec.rb
index 13b835d120..a325b1260f 100644
--- a/spec/unit/data_bag_spec.rb
+++ b/spec/unit/data_bag_spec.rb
@@ -83,18 +83,18 @@ describe Chef::DataBag do
describe "when saving" do
before do
@data_bag.name('piggly_wiggly')
- @rest = double("Chef::REST")
- allow(Chef::REST).to receive(:new).and_return(@rest)
+ @rest = double("Chef::ServerAPI")
+ allow(Chef::ServerAPI).to receive(:new).and_return(@rest)
end
it "should silently proceed when the data bag already exists" do
exception = double("409 error", :code => "409")
- expect(@rest).to receive(:post_rest).and_raise(Net::HTTPServerException.new("foo", exception))
+ expect(@rest).to receive(:post).and_raise(Net::HTTPServerException.new("foo", exception))
@data_bag.save
end
it "should create the data bag" do
- expect(@rest).to receive(:post_rest).with("data", @data_bag)
+ expect(@rest).to receive(:post).with("data", @data_bag)
@data_bag.save
end
@@ -106,7 +106,7 @@ describe Chef::DataBag do
Chef::Config[:why_run] = false
end
it "should not save" do
- expect(@rest).not_to receive(:post_rest)
+ expect(@rest).not_to receive(:post)
@data_bag.save
end
end
@@ -116,18 +116,18 @@ describe Chef::DataBag do
describe "from an API call" do
before do
Chef::Config[:chef_server_url] = 'https://myserver.example.com'
- @http_client = double('Chef::REST')
+ @http_client = double('Chef::ServerAPI')
end
it "should get the data bag from the server" do
- expect(Chef::REST).to receive(:new).with('https://myserver.example.com').and_return(@http_client)
- expect(@http_client).to receive(:get_rest).with('data/foo')
+ expect(Chef::ServerAPI).to receive(:new).with('https://myserver.example.com').and_return(@http_client)
+ expect(@http_client).to receive(:get).with('data/foo')
Chef::DataBag.load('foo')
end
it "should return the data bag" do
- allow(Chef::REST).to receive(:new).and_return(@http_client)
- expect(@http_client).to receive(:get_rest).with('data/foo').and_return({'bar' => 'https://myserver.example.com/data/foo/bar'})
+ allow(Chef::ServerAPI).to receive(:new).and_return(@http_client)
+ expect(@http_client).to receive(:get).with('data/foo').and_return({'bar' => 'https://myserver.example.com/data/foo/bar'})
data_bag = Chef::DataBag.load('foo')
expect(data_bag).to eq({'bar' => 'https://myserver.example.com/data/foo/bar'})
end
diff --git a/spec/unit/encrypted_data_bag_item_spec.rb b/spec/unit/encrypted_data_bag_item_spec.rb
index 0a4306727b..b4d75d2480 100644
--- a/spec/unit/encrypted_data_bag_item_spec.rb
+++ b/spec/unit/encrypted_data_bag_item_spec.rb
@@ -67,7 +67,7 @@ describe Chef::EncryptedDataBagItem::Encryptor do
expect(final_data["encrypted_data"]).to eq encryptor.encrypted_data
expect(final_data["iv"]).to eq Base64.encode64(encryptor.iv)
expect(final_data["version"]).to eq 1
- expect(final_data["cipher"]).to eq"aes-256-cbc"
+ expect(final_data["cipher"]).to eq "aes-256-cbc"
end
end
diff --git a/spec/unit/environment_spec.rb b/spec/unit/environment_spec.rb
index 64617e0888..4116150d6e 100644
--- a/spec/unit/environment_spec.rb
+++ b/spec/unit/environment_spec.rb
@@ -365,8 +365,8 @@ describe Chef::Environment do
describe "api model" do
before(:each) do
- @rest = double("Chef::REST")
- allow(Chef::REST).to receive(:new).and_return(@rest)
+ @rest = double("Chef::ServerAPI")
+ allow(Chef::ServerAPI).to receive(:new).and_return(@rest)
@query = double("Chef::Search::Query")
allow(Chef::Search::Query).to receive(:new).and_return(@query)
end
@@ -382,7 +382,7 @@ describe Chef::Environment do
end
it "should return a hash of environment names and urls" do
- expect(@rest).to receive(:get_rest).and_return({ "one" => "http://foo" })
+ expect(@rest).to receive(:get).and_return({ "one" => "http://foo" })
r = Chef::Environment.list
expect(r["one"]).to eq("http://foo")
end
diff --git a/spec/unit/key_spec.rb b/spec/unit/key_spec.rb
index 94ebbf6ae8..66f5fb9b13 100644
--- a/spec/unit/key_spec.rb
+++ b/spec/unit/key_spec.rb
@@ -342,7 +342,7 @@ EOS
Chef::Config[:chef_server_root] = "http://www.example.com"
Chef::Config[:chef_server_url] = "http://www.example.com/organizations/test_org"
r = double('rest')
- allow(Chef::REST).to receive(:new).and_return(r)
+ allow(Chef::ServerAPI).to receive(:new).and_return(r)
r
end
@@ -362,13 +362,13 @@ EOS
let(:inflated_response) { {"foobar" => user_key} }
it "lists all keys" do
- expect(rest).to receive(:get_rest).with("users/#{user_key.actor}/keys").and_return(response)
+ expect(rest).to receive(:get).with("users/#{user_key.actor}/keys").and_return(response)
expect(Chef::Key.list_by_user("foobar")).to eq(response)
end
it "inflate all keys" do
allow(Chef::Key).to receive(:load_by_user).with(user_key.actor, "foobar").and_return(user_key)
- expect(rest).to receive(:get_rest).with("users/#{user_key.actor}/keys").and_return(response)
+ expect(rest).to receive(:get).with("users/#{user_key.actor}/keys").and_return(response)
expect(Chef::Key.list_by_user("foobar", true)).to eq(inflated_response)
end
@@ -379,13 +379,13 @@ EOS
let(:inflated_response) { {"foobar" => client_key} }
it "lists all keys" do
- expect(rest).to receive(:get_rest).with("clients/#{client_key.actor}/keys").and_return(response)
+ expect(rest).to receive(:get).with("clients/#{client_key.actor}/keys").and_return(response)
expect(Chef::Key.list_by_client("foobar")).to eq(response)
end
it "inflate all keys" do
allow(Chef::Key).to receive(:load_by_client).with(client_key.actor, "foobar").and_return(client_key)
- expect(rest).to receive(:get_rest).with("clients/#{user_key.actor}/keys").and_return(response)
+ expect(rest).to receive(:get).with("clients/#{user_key.actor}/keys").and_return(response)
expect(Chef::Key.list_by_client("foobar", true)).to eq(inflated_response)
end
@@ -408,7 +408,7 @@ EOS
end
it "creates a new key via the API with the fingerprint as the name" do
- expect(rest).to receive(:post_rest).with(url,
+ expect(rest).to receive(:post).with(url,
{"name" => "12:3e:33:73:0b:f4:ec:72:dc:f0:4c:51:62:27:08:76:96:24:f4:4a",
"public_key" => key.public_key,
"expiration_date" => key.expiration_date}).and_return({})
@@ -426,7 +426,7 @@ EOS
context "when create_key is false" do
it "creates a new key via the API" do
- expect(rest).to receive(:post_rest).with(url,
+ expect(rest).to receive(:post).with(url,
{"name" => key.name,
"public_key" => key.public_key,
"expiration_date" => key.expiration_date}).and_return({})
@@ -453,13 +453,13 @@ EOS
end
it "should create a new key via the API" do
- expect(rest).to receive(:post_rest).with(url, $expected_input).and_return({})
+ expect(rest).to receive(:post).with(url, $expected_input).and_return({})
key.create
end
context "when the server returns the private_key via key.create" do
before do
- allow(rest).to receive(:post_rest).with(url, $expected_input).and_return({"private_key" => "this_private_key"})
+ allow(rest).to receive(:post).with(url, $expected_input).and_return({"private_key" => "this_private_key"})
end
it "key.create returns the original key plus the private_key" do
@@ -512,7 +512,7 @@ EOS
end
it "should update the key via the API" do
- expect(rest).to receive(:put_rest).with(url, key.to_hash).and_return({})
+ expect(rest).to receive(:put).with(url, key.to_hash).and_return({})
key.update
end
end
@@ -523,7 +523,7 @@ EOS
end
it "passes @name in the body and the arg in the PUT URL" do
- expect(rest).to receive(:put_rest).with(update_name_url, key.to_hash).and_return({})
+ expect(rest).to receive(:put).with(update_name_url, key.to_hash).and_return({})
key.update("old_name")
end
end
@@ -532,7 +532,7 @@ EOS
before do
key.name "key_name"
key.create_key true
- allow(rest).to receive(:put_rest).with(url, key.to_hash).and_return({
+ allow(rest).to receive(:put).with(url, key.to_hash).and_return({
"key" => "key_name",
"public_key" => public_key_string
})
@@ -572,7 +572,7 @@ EOS
describe "load" do
shared_examples_for "load" do
it "should load a named key from the API" do
- expect(rest).to receive(:get_rest).with(url).and_return({"user" => "foobar", "name" => "test_key_name", "public_key" => public_key_string, "expiration_date" => "infinity"})
+ expect(rest).to receive(:get).with(url).and_return({"user" => "foobar", "name" => "test_key_name", "public_key" => public_key_string, "expiration_date" => "infinity"})
key = Chef::Key.send(load_method, "foobar", "test_key_name")
expect(key.actor).to eq("foobar")
expect(key.name).to eq("test_key_name")
@@ -610,7 +610,7 @@ EOS
end
context "when name is not missing" do
it "should delete the key via the API" do
- expect(rest).to receive(:delete_rest).with(url).and_return({})
+ expect(rest).to receive(:delete).with(url).and_return({})
key.destroy
end
end
diff --git a/spec/unit/knife/bootstrap/client_builder_spec.rb b/spec/unit/knife/bootstrap/client_builder_spec.rb
index f17a6af878..6812a24c91 100644
--- a/spec/unit/knife/bootstrap/client_builder_spec.rb
+++ b/spec/unit/knife/bootstrap/client_builder_spec.rb
@@ -32,7 +32,7 @@ describe Chef::Knife::Bootstrap::ClientBuilder do
let(:node_name) { "bevell.wat" }
- let(:rest) { double("Chef::REST") }
+ let(:rest) { double("Chef::ServerAPI") }
let(:client_builder) {
client_builder = Chef::Knife::Bootstrap::ClientBuilder.new(knife_config: knife_config, chef_config: chef_config, ui: ui)
@@ -53,14 +53,14 @@ describe Chef::Knife::Bootstrap::ClientBuilder do
end
it "exits when the node exists and the user does not want to delete" do
- expect(rest).to receive(:get_rest).with("nodes/#{node_name}")
+ expect(rest).to receive(:get).with("nodes/#{node_name}")
expect(ui.stdin).to receive(:readline).and_return('n')
expect { client_builder.run }.to raise_error(SystemExit)
end
it "exits when the client exists and the user does not want to delete" do
- expect(rest).to receive(:get_rest).with("nodes/#{node_name}").and_raise(exception_404)
- expect(rest).to receive(:get_rest).with("clients/#{node_name}")
+ expect(rest).to receive(:get).with("nodes/#{node_name}").and_raise(exception_404)
+ expect(rest).to receive(:get).with("clients/#{node_name}")
expect(ui.stdin).to receive(:readline).and_return('n')
expect { client_builder.run }.to raise_error(SystemExit)
end
@@ -74,30 +74,30 @@ describe Chef::Knife::Bootstrap::ClientBuilder do
end
it "when both the client and node do not exist it succeeds" do
- expect(rest).to receive(:get_rest).with("nodes/#{node_name}").and_raise(exception_404)
- expect(rest).to receive(:get_rest).with("clients/#{node_name}").and_raise(exception_404)
+ expect(rest).to receive(:get).with("nodes/#{node_name}").and_raise(exception_404)
+ expect(rest).to receive(:get).with("clients/#{node_name}").and_raise(exception_404)
expect { client_builder.run }.not_to raise_error
end
it "when we are allowed to delete an old node" do
- expect(rest).to receive(:get_rest).with("nodes/#{node_name}")
+ expect(rest).to receive(:get).with("nodes/#{node_name}")
expect(ui.stdin).to receive(:readline).and_return('y')
- expect(rest).to receive(:get_rest).with("clients/#{node_name}").and_raise(exception_404)
+ expect(rest).to receive(:get).with("clients/#{node_name}").and_raise(exception_404)
expect(rest).to receive(:delete).with("nodes/#{node_name}")
expect { client_builder.run }.not_to raise_error
end
it "when we are allowed to delete an old client" do
- expect(rest).to receive(:get_rest).with("nodes/#{node_name}").and_raise(exception_404)
- expect(rest).to receive(:get_rest).with("clients/#{node_name}")
+ expect(rest).to receive(:get).with("nodes/#{node_name}").and_raise(exception_404)
+ expect(rest).to receive(:get).with("clients/#{node_name}")
expect(ui.stdin).to receive(:readline).and_return('y')
expect(rest).to receive(:delete).with("clients/#{node_name}")
expect { client_builder.run }.not_to raise_error
end
it "when we are are allowed to delete both an old client and node" do
- expect(rest).to receive(:get_rest).with("nodes/#{node_name}")
- expect(rest).to receive(:get_rest).with("clients/#{node_name}")
+ expect(rest).to receive(:get).with("nodes/#{node_name}")
+ expect(rest).to receive(:get).with("clients/#{node_name}")
expect(ui.stdin).to receive(:readline).twice.and_return('y')
expect(rest).to receive(:delete).with("nodes/#{node_name}")
expect(rest).to receive(:delete).with("clients/#{node_name}")
@@ -143,7 +143,7 @@ describe Chef::Knife::Bootstrap::ClientBuilder do
expect(node).to receive(:save)
end
- let(:client_rest) { double("Chef::REST (client)") }
+ let(:client_rest) { double("Chef::ServerAPI (client)") }
let(:node) { double("Chef::Node") }
diff --git a/spec/unit/knife/configure_spec.rb b/spec/unit/knife/configure_spec.rb
index e3ea1f052c..89874cfdf9 100644
--- a/spec/unit/knife/configure_spec.rb
+++ b/spec/unit/knife/configure_spec.rb
@@ -6,7 +6,7 @@ describe Chef::Knife::Configure do
Chef::Config[:node_name] = "webmonkey.example.com"
@knife = Chef::Knife::Configure.new
- @rest_client = double("null rest client", :post_rest => { :result => :true })
+ @rest_client = double("null rest client", :post => { :result => :true })
allow(@knife).to receive(:rest).and_return(@rest_client)
@out = StringIO.new
diff --git a/spec/unit/knife/cookbook_bulk_delete_spec.rb b/spec/unit/knife/cookbook_bulk_delete_spec.rb
index 98cd06bbbc..7d6e851589 100644
--- a/spec/unit/knife/cookbook_bulk_delete_spec.rb
+++ b/spec/unit/knife/cookbook_bulk_delete_spec.rb
@@ -36,9 +36,9 @@ describe Chef::Knife::CookbookBulkDelete do
cookbook = Chef::CookbookVersion.new(cookbook_name)
@cookbooks[cookbook_name] = cookbook
end
- @rest = double("Chef::REST")
- allow(@rest).to receive(:get_rest).and_return(@cookbooks)
- allow(@rest).to receive(:delete_rest).and_return(true)
+ @rest = double("Chef::ServerAPI")
+ allow(@rest).to receive(:get).and_return(@cookbooks)
+ allow(@rest).to receive(:delete).and_return(true)
allow(@knife).to receive(:rest).and_return(@rest)
allow(Chef::CookbookVersion).to receive(:list).and_return(@cookbooks)
@@ -49,11 +49,11 @@ describe Chef::Knife::CookbookBulkDelete do
describe "when there are several cookbooks on the server" do
before do
@cheezburger = {'cheezburger' => {"url" => "file:///dev/null", "versions" => [{"url" => "file:///dev/null-cheez", "version" => "1.0.0"}]}}
- allow(@rest).to receive(:get_rest).with('cookbooks/cheezburger').and_return(@cheezburger)
+ allow(@rest).to receive(:get).with('cookbooks/cheezburger').and_return(@cheezburger)
@pizza = {'pizza' => {"url" => "file:///dev/null", "versions" => [{"url" => "file:///dev/null-pizza", "version" => "2.0.0"}]}}
- allow(@rest).to receive(:get_rest).with('cookbooks/pizza').and_return(@pizza)
+ allow(@rest).to receive(:get).with('cookbooks/pizza').and_return(@pizza)
@lasagna = {'lasagna' => {"url" => "file:///dev/null", "versions" => [{"url" => "file:///dev/null-lasagna", "version" => "3.0.0"}]}}
- allow(@rest).to receive(:get_rest).with('cookbooks/lasagna').and_return(@lasagna)
+ allow(@rest).to receive(:get).with('cookbooks/lasagna').and_return(@lasagna)
end
it "should print the cookbooks you are about to delete" do
@@ -69,14 +69,14 @@ describe Chef::Knife::CookbookBulkDelete do
it "should delete each cookbook" do
{"cheezburger" => "1.0.0", "pizza" => "2.0.0", "lasagna" => '3.0.0'}.each do |cookbook_name, version|
- expect(@rest).to receive(:delete_rest).with("cookbooks/#{cookbook_name}/#{version}")
+ expect(@rest).to receive(:delete).with("cookbooks/#{cookbook_name}/#{version}")
end
@knife.run
end
it "should only delete cookbooks that match the regex" do
@knife.name_args = ["cheezburger"]
- expect(@rest).to receive(:delete_rest).with('cookbooks/cheezburger/1.0.0')
+ expect(@rest).to receive(:delete).with('cookbooks/cheezburger/1.0.0')
@knife.run
end
end
diff --git a/spec/unit/knife/cookbook_delete_spec.rb b/spec/unit/knife/cookbook_delete_spec.rb
index 4e75a689e3..e9085e9512 100644
--- a/spec/unit/knife/cookbook_delete_spec.rb
+++ b/spec/unit/knife/cookbook_delete_spec.rb
@@ -134,19 +134,19 @@ describe Chef::Knife::CookbookDelete do
end
it 'should return the list of versions of the cookbook' do
- expect(@rest_mock).to receive(:get_rest).with('cookbooks/foobar').and_return(@cookbook_data)
+ expect(@rest_mock).to receive(:get).with('cookbooks/foobar').and_return(@cookbook_data)
expect(@knife.available_versions).to eq(['1.0.0', '1.1.0', '2.0.0'])
end
it 'should raise if an error other than HTTP 404 is returned' do
exception = Net::HTTPServerException.new('500 Internal Server Error', '500')
- expect(@rest_mock).to receive(:get_rest).and_raise(exception)
+ expect(@rest_mock).to receive(:get).and_raise(exception)
expect { @knife.available_versions }.to raise_error Net::HTTPServerException
end
describe "if the cookbook can't be found" do
before(:each) do
- expect(@rest_mock).to receive(:get_rest).
+ expect(@rest_mock).to receive(:get).
and_raise(Net::HTTPServerException.new('404 Not Found', '404'))
end
diff --git a/spec/unit/knife/cookbook_download_spec.rb b/spec/unit/knife/cookbook_download_spec.rb
index 7ca1adfcb5..8b85e52b75 100644
--- a/spec/unit/knife/cookbook_download_spec.rb
+++ b/spec/unit/knife/cookbook_download_spec.rb
@@ -69,8 +69,8 @@ describe Chef::Knife::CookbookDownload do
@cookbook_mock = double('cookbook')
allow(@cookbook_mock).to receive(:version).and_return('1.0.0')
allow(@cookbook_mock).to receive(:manifest).and_return(@manifest_data)
- expect(@rest_mock).to receive(:get_rest).with('cookbooks/foobar/1.0.0').
- and_return(@cookbook_mock)
+ expect(Chef::CookbookVersion).to receive(:load).with("foobar", "1.0.0").
+ and_return(@cookbook_mock)
end
it 'should determine which version if one was not explicitly specified'do
@@ -106,11 +106,10 @@ describe Chef::Knife::CookbookDownload do
end
@files_mocks.each_pair do |file, mock|
- expect(@rest_mock).to receive(:get_rest).with("http://example.org/files/#{file}", true).
+ expect(@rest_mock).to receive(:streaming_request).with("http://example.org/files/#{file}").
and_return(mock)
end
- expect(@rest_mock).to receive(:sign_on_redirect=).with(false).at_least(:once)
@files.each do |f|
expect(FileUtils).to receive(:mv).
with("/var/tmp/#{File.basename(f)}", "/var/tmp/chef/foobar-1.0.0/#{f}")
diff --git a/spec/unit/knife/cookbook_list_spec.rb b/spec/unit/knife/cookbook_list_spec.rb
index 559f700bb4..fc07c8af3f 100644
--- a/spec/unit/knife/cookbook_list_spec.rb
+++ b/spec/unit/knife/cookbook_list_spec.rb
@@ -37,7 +37,7 @@ describe Chef::Knife::CookbookList do
describe 'run' do
it 'should display the latest version of the cookbooks' do
- expect(@rest_mock).to receive(:get_rest).with('/cookbooks?num_versions=1').
+ expect(@rest_mock).to receive(:get).with('/cookbooks?num_versions=1').
and_return(@cookbook_data)
@knife.run
@cookbook_names.each do |item|
@@ -47,7 +47,7 @@ describe Chef::Knife::CookbookList do
it 'should query cookbooks for the configured environment' do
@knife.config[:environment] = 'production'
- expect(@rest_mock).to receive(:get_rest).
+ expect(@rest_mock).to receive(:get).
with('/environments/production/cookbooks?num_versions=1').
and_return(@cookbook_data)
@knife.run
@@ -56,7 +56,7 @@ describe Chef::Knife::CookbookList do
describe 'with -w or --with-uri' do
it 'should display the cookbook uris' do
@knife.config[:with_uri] = true
- allow(@rest_mock).to receive(:get_rest).and_return(@cookbook_data)
+ allow(@rest_mock).to receive(:get).and_return(@cookbook_data)
@knife.run
@cookbook_names.each do |item|
pattern = /#{Regexp.escape(@cookbook_data[item]['versions'].first['url'])}/
@@ -75,7 +75,7 @@ describe Chef::Knife::CookbookList do
it 'should display all versions of the cookbooks' do
@knife.config[:all_versions] = true
- expect(@rest_mock).to receive(:get_rest).with('/cookbooks?num_versions=all').
+ expect(@rest_mock).to receive(:get).with('/cookbooks?num_versions=all').
and_return(@cookbook_data)
@knife.run
@cookbook_names.each do |item|
diff --git a/spec/unit/knife/cookbook_show_spec.rb b/spec/unit/knife/cookbook_show_spec.rb
index bf480e3678..a06e53b9a1 100644
--- a/spec/unit/knife/cookbook_show_spec.rb
+++ b/spec/unit/knife/cookbook_show_spec.rb
@@ -25,7 +25,7 @@ describe Chef::Knife::CookbookShow do
@knife = Chef::Knife::CookbookShow.new
@knife.config = { }
@knife.name_args = [ "cookbook_name" ]
- @rest = double(Chef::REST)
+ @rest = double(Chef::ServerAPI)
allow(@knife).to receive(:rest).and_return(@rest)
allow(@knife).to receive(:pretty_print).and_return(true)
allow(@knife).to receive(:output).and_return(true)
@@ -56,14 +56,14 @@ describe Chef::Knife::CookbookShow do
end
it "should show the raw cookbook data" do
- expect(@rest).to receive(:get_rest).with("cookbooks/cookbook_name").and_return(@response)
+ expect(@rest).to receive(:get).with("cookbooks/cookbook_name").and_return(@response)
expect(@knife).to receive(:format_cookbook_list_for_display).with(@response)
@knife.run
end
it "should respect the user-supplied environment" do
@knife.config[:environment] = "foo"
- expect(@rest).to receive(:get_rest).with("environments/foo/cookbooks/cookbook_name").and_return(@response)
+ expect(@rest).to receive(:get).with("environments/foo/cookbooks/cookbook_name").and_return(@response)
expect(@knife).to receive(:format_cookbook_list_for_display).with(@response)
@knife.run
end
@@ -76,7 +76,7 @@ describe Chef::Knife::CookbookShow do
end
it "should show the specific part of a cookbook" do
- expect(@rest).to receive(:get_rest).with("cookbooks/cookbook_name/0.1.0").and_return(@response)
+ expect(@rest).to receive(:get).with("cookbooks/cookbook_name/0.1.0").and_return(@response)
expect(@knife).to receive(:output).with(@response)
@knife.run
end
@@ -101,7 +101,7 @@ describe Chef::Knife::CookbookShow do
end
it "should print the json of the part" do
- expect(@rest).to receive(:get_rest).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response)
+ expect(@rest).to receive(:get).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response)
expect(@knife).to receive(:output).with(@cookbook_response.manifest["recipes"])
@knife.run
end
@@ -125,8 +125,8 @@ describe Chef::Knife::CookbookShow do
end
it "should print the raw result of the request (likely a file!)" do
- expect(@rest).to receive(:get_rest).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response)
- expect(@rest).to receive(:get_rest).with("http://example.org/files/default.rb", true).and_return(StringIO.new(@response))
+ expect(@rest).to receive(:get).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response)
+ expect(@rest).to receive(:get).with("http://example.org/files/default.rb", true).and_return(StringIO.new(@response))
expect(@knife).to receive(:pretty_print).with(@response)
@knife.run
end
@@ -177,8 +177,8 @@ describe Chef::Knife::CookbookShow do
@knife.config[:platform] = "example_platform"
@knife.config[:platform_version] = "1.0"
@knife.config[:fqdn] = "examplehost.example.org"
- expect(@rest).to receive(:get_rest).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response)
- expect(@rest).to receive(:get_rest).with("http://example.org/files/1111", true).and_return(StringIO.new(@response))
+ expect(@rest).to receive(:get).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response)
+ expect(@rest).to receive(:get).with("http://example.org/files/1111", true).and_return(StringIO.new(@response))
expect(@knife).to receive(:pretty_print).with(@response)
@knife.run
end
@@ -189,8 +189,8 @@ describe Chef::Knife::CookbookShow do
@knife.config[:platform] = "ubuntu"
@knife.config[:platform_version] = "1.0"
@knife.config[:fqdn] = "differenthost.example.org"
- expect(@rest).to receive(:get_rest).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response)
- expect(@rest).to receive(:get_rest).with("http://example.org/files/3333", true).and_return(StringIO.new(@response))
+ expect(@rest).to receive(:get).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response)
+ expect(@rest).to receive(:get).with("http://example.org/files/3333", true).and_return(StringIO.new(@response))
expect(@knife).to receive(:pretty_print).with(@response)
@knife.run
end
@@ -201,8 +201,8 @@ describe Chef::Knife::CookbookShow do
@knife.config[:platform] = "ubuntu"
@knife.config[:platform_version] = "9.10"
@knife.config[:fqdn] = "differenthost.example.org"
- expect(@rest).to receive(:get_rest).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response)
- expect(@rest).to receive(:get_rest).with("http://example.org/files/2222", true).and_return(StringIO.new(@response))
+ expect(@rest).to receive(:get).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response)
+ expect(@rest).to receive(:get).with("http://example.org/files/2222", true).and_return(StringIO.new(@response))
expect(@knife).to receive(:pretty_print).with(@response)
@knife.run
end
@@ -210,8 +210,8 @@ describe Chef::Knife::CookbookShow do
describe "with none of the arguments, it should use the default" do
it "should pass them all" do
- expect(@rest).to receive(:get_rest).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response)
- expect(@rest).to receive(:get_rest).with("http://example.org/files/4444", true).and_return(StringIO.new(@response))
+ expect(@rest).to receive(:get).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response)
+ expect(@rest).to receive(:get).with("http://example.org/files/4444", true).and_return(StringIO.new(@response))
expect(@knife).to receive(:pretty_print).with(@response)
@knife.run
end
diff --git a/spec/unit/knife/cookbook_site_download_spec.rb b/spec/unit/knife/cookbook_site_download_spec.rb
index fdf4c2197b..35c6544d58 100644
--- a/spec/unit/knife/cookbook_site_download_spec.rb
+++ b/spec/unit/knife/cookbook_site_download_spec.rb
@@ -35,7 +35,7 @@ describe Chef::Knife::CookbookSiteDownload do
allow(@knife.ui).to receive(:stderr).and_return(@stderr)
allow(@knife).to receive(:noauth_rest).and_return(@noauth_rest)
- expect(@noauth_rest).to receive(:get_rest).
+ expect(@noauth_rest).to receive(:get).
with("#{@cookbook_api_url}/apache2").
and_return(@current_data)
end
@@ -66,10 +66,10 @@ describe Chef::Knife::CookbookSiteDownload do
context 'downloading the latest version' do
before do
- expect(@noauth_rest).to receive(:get_rest).
+ expect(@noauth_rest).to receive(:get).
with(@current_data['latest_version']).
and_return(@cookbook_data)
- expect(@noauth_rest).to receive(:get_rest).
+ expect(@noauth_rest).to receive(:get).
with(@cookbook_data['file'], true).
and_return(@temp_file)
end
@@ -131,10 +131,10 @@ describe Chef::Knife::CookbookSiteDownload do
end
it 'should download the desired version' do
- expect(@noauth_rest).to receive(:get_rest).
+ expect(@noauth_rest).to receive(:get).
with("#{@cookbook_api_url}/apache2/versions/#{@version_us}").
and_return(@cookbook_data)
- expect(@noauth_rest).to receive(:get_rest).
+ expect(@noauth_rest).to receive(:get).
with(@cookbook_data['file'], true).
and_return(@temp_file)
expect(FileUtils).to receive(:cp).with(@temp_file.path, @file)
diff --git a/spec/unit/knife/cookbook_site_share_spec.rb b/spec/unit/knife/cookbook_site_share_spec.rb
index a7caca9744..1b2ffd10fb 100644
--- a/spec/unit/knife/cookbook_site_share_spec.rb
+++ b/spec/unit/knife/cookbook_site_share_spec.rb
@@ -36,7 +36,7 @@ describe Chef::Knife::CookbookSiteShare do
allow(@cookbook_loader).to receive(:[]).and_return(@cookbook)
allow(Chef::CookbookLoader).to receive(:new).and_return(@cookbook_loader)
- @noauth_rest = double(Chef::REST)
+ @noauth_rest = double(Chef::ServerAPI)
allow(@knife).to receive(:noauth_rest).and_return(@noauth_rest)
@cookbook_uploader = Chef::CookbookUploader.new('herpderp', :rest => "norest")
@@ -78,21 +78,21 @@ describe Chef::Knife::CookbookSiteShare do
it 'should not fail when given only 1 argument and can determine category' do
@knife.name_args = ['cookbook_name']
- expect(@noauth_rest).to receive(:get_rest).with("https://supermarket.chef.io/api/v1/cookbooks/cookbook_name").and_return(@category_response)
+ expect(@noauth_rest).to receive(:get).with("https://supermarket.chef.io/api/v1/cookbooks/cookbook_name").and_return(@category_response)
expect(@knife).to receive(:do_upload)
@knife.run
end
it 'should print error and exit when given only 1 argument and cannot determine category' do
@knife.name_args = ['cookbook_name']
- expect(@noauth_rest).to receive(:get_rest).with("https://supermarket.chef.io/api/v1/cookbooks/cookbook_name").and_return(@bad_category_response)
+ expect(@noauth_rest).to receive(:get).with("https://supermarket.chef.io/api/v1/cookbooks/cookbook_name").and_return(@bad_category_response)
expect(@knife.ui).to receive(:fatal)
expect { @knife.run }.to raise_error(SystemExit)
end
- it 'should print error and exit when given only 1 argument and Chef::REST throws an exception' do
+ it 'should print error and exit when given only 1 argument and Chef::ServerAPI throws an exception' do
@knife.name_args = ['cookbook_name']
- expect(@noauth_rest).to receive(:get_rest).with("https://supermarket.chef.io/api/v1/cookbooks/cookbook_name") { raise Errno::ECONNREFUSED, "Connection refused" }
+ expect(@noauth_rest).to receive(:get).with("https://supermarket.chef.io/api/v1/cookbooks/cookbook_name") { raise Errno::ECONNREFUSED, "Connection refused" }
expect(@knife.ui).to receive(:fatal)
expect { @knife.run }.to raise_error(SystemExit)
end
diff --git a/spec/unit/knife/cookbook_site_unshare_spec.rb b/spec/unit/knife/cookbook_site_unshare_spec.rb
index ec46a8705c..aafb7c1507 100644
--- a/spec/unit/knife/cookbook_site_unshare_spec.rb
+++ b/spec/unit/knife/cookbook_site_unshare_spec.rb
@@ -26,8 +26,8 @@ describe Chef::Knife::CookbookSiteUnshare do
@knife.name_args = ['cookbook_name']
allow(@knife).to receive(:confirm).and_return(true)
- @rest = double('Chef::REST')
- allow(@rest).to receive(:delete_rest).and_return(true)
+ @rest = double('Chef::ServerAPI')
+ allow(@rest).to receive(:delete).and_return(true)
allow(@knife).to receive(:rest).and_return(@rest)
@stdout = StringIO.new
allow(@knife.ui).to receive(:stdout).and_return(@stdout)
@@ -50,20 +50,20 @@ describe Chef::Knife::CookbookSiteUnshare do
end
it 'should send a delete request to the cookbook site' do
- expect(@rest).to receive(:delete_rest)
+ expect(@rest).to receive(:delete)
@knife.run
end
it 'should log an error and exit when forbidden' do
exception = double('403 "Forbidden"', :code => '403')
- allow(@rest).to receive(:delete_rest).and_raise(Net::HTTPServerException.new('403 "Forbidden"', exception))
+ allow(@rest).to receive(:delete).and_raise(Net::HTTPServerException.new('403 "Forbidden"', exception))
expect(@knife.ui).to receive(:error)
expect { @knife.run }.to raise_error(SystemExit)
end
- it 'should re-raise any non-forbidden errors on delete_rest' do
+ it 'should re-raise any non-forbidden errors on delete' do
exception = double('500 "Application Error"', :code => '500')
- allow(@rest).to receive(:delete_rest).and_raise(Net::HTTPServerException.new('500 "Application Error"', exception))
+ allow(@rest).to receive(:delete).and_raise(Net::HTTPServerException.new('500 "Application Error"', exception))
expect { @knife.run }.to raise_error(Net::HTTPServerException)
end
diff --git a/spec/unit/knife/data_bag_create_spec.rb b/spec/unit/knife/data_bag_create_spec.rb
index c31c88577d..d022cc7f7d 100644
--- a/spec/unit/knife/data_bag_create_spec.rb
+++ b/spec/unit/knife/data_bag_create_spec.rb
@@ -28,7 +28,7 @@ describe Chef::Knife::DataBagCreate do
k
end
- let(:rest) { double("Chef::REST") }
+ let(:rest) { double("Chef::ServerAPI") }
let(:stdout) { StringIO.new }
let(:bag_name) { "sudoing_admins" }
@@ -58,7 +58,7 @@ describe Chef::Knife::DataBagCreate do
end
it "creates a data bag" do
- expect(rest).to receive(:post_rest).with("data", {"name" => bag_name})
+ expect(rest).to receive(:post).with("data", {"name" => bag_name})
expect(knife.ui).to receive(:info).with("Created data_bag[#{bag_name}]")
knife.run
@@ -75,8 +75,8 @@ describe Chef::Knife::DataBagCreate do
it "creates a data bag item" do
expect(knife).to receive(:create_object).and_yield(raw_hash)
expect(knife).to receive(:encryption_secret_provided?).and_return(false)
- expect(rest).to receive(:post_rest).with("data", {'name' => bag_name}).ordered
- expect(rest).to receive(:post_rest).with("data/#{bag_name}", item).ordered
+ expect(rest).to receive(:post).with("data", {'name' => bag_name}).ordered
+ expect(rest).to receive(:post).with("data/#{bag_name}", item).ordered
knife.run
end
@@ -99,8 +99,8 @@ describe Chef::Knife::DataBagCreate do
.to receive(:encrypt_data_bag_item)
.with(raw_hash, secret)
.and_return(encoded_data)
- expect(rest).to receive(:post_rest).with("data", {"name" => bag_name}).ordered
- expect(rest).to receive(:post_rest).with("data/#{bag_name}", item).ordered
+ expect(rest).to receive(:post).with("data", {"name" => bag_name}).ordered
+ expect(rest).to receive(:post).with("data/#{bag_name}", item).ordered
knife.run
end
diff --git a/spec/unit/knife/data_bag_edit_spec.rb b/spec/unit/knife/data_bag_edit_spec.rb
index 6f19b5e63e..f1bcae990b 100644
--- a/spec/unit/knife/data_bag_edit_spec.rb
+++ b/spec/unit/knife/data_bag_edit_spec.rb
@@ -37,7 +37,7 @@ describe Chef::Knife::DataBagEdit do
let(:db) { Chef::DataBagItem.from_hash(raw_hash)}
let(:raw_edited_hash) { {"login_name" => "rho", "id" => "item_name", "new_key" => "new_value"} }
- let(:rest) { double("Chef::REST") }
+ let(:rest) { double("Chef::ServerAPI") }
let(:stdout) { StringIO.new }
let(:bag_name) { "sudoing_admins" }
@@ -56,7 +56,7 @@ describe Chef::Knife::DataBagEdit do
expect(Chef::DataBagItem).to receive(:load).with(bag_name, item_name).and_return(db)
expect(knife).to receive(:encrypted?).with(db.raw_data).and_return(is_encrypted?)
expect(knife).to receive(:edit_data).with(data_to_edit).and_return(raw_edited_hash)
- expect(rest).to receive(:put_rest).with("data/#{bag_name}/#{item_name}", transmitted_hash).ordered
+ expect(rest).to receive(:put).with("data/#{bag_name}/#{item_name}", transmitted_hash).ordered
knife.run
end
diff --git a/spec/unit/knife/data_bag_from_file_spec.rb b/spec/unit/knife/data_bag_from_file_spec.rb
index 8b6502145c..dc65a3e64c 100644
--- a/spec/unit/knife/data_bag_from_file_spec.rb
+++ b/spec/unit/knife/data_bag_from_file_spec.rb
@@ -79,7 +79,7 @@ describe Chef::Knife::DataBagFromFile do
} }
let(:enc_data) { Chef::EncryptedDataBagItem.encrypt_data_bag_item(plain_data, secret) }
- let(:rest) { double("Chef::REST") }
+ let(:rest) { double("Chef::ServerAPI") }
let(:stdout) { StringIO.new }
let(:bag_name) { "sudoing_admins" }
diff --git a/spec/unit/knife/data_bag_show_spec.rb b/spec/unit/knife/data_bag_show_spec.rb
index 1125d99c2a..48a0071b49 100644
--- a/spec/unit/knife/data_bag_show_spec.rb
+++ b/spec/unit/knife/data_bag_show_spec.rb
@@ -39,7 +39,7 @@ describe Chef::Knife::DataBagShow do
k
end
- let(:rest) { double("Chef::REST") }
+ let(:rest) { double("Chef::ServerAPI") }
let(:stdout) { StringIO.new }
let(:bag_name) { "sudoing_admins" }
diff --git a/spec/unit/knife/environment_compare_spec.rb b/spec/unit/knife/environment_compare_spec.rb
index 6d4d3ead52..81ec19d7af 100644
--- a/spec/unit/knife/environment_compare_spec.rb
+++ b/spec/unit/knife/environment_compare_spec.rb
@@ -51,7 +51,7 @@ describe Chef::Knife::EnvironmentCompare do
'url' => "#{@base_url}/#{item}/1.0.1"}]}
end
- allow(@rest_double).to receive(:get_rest).with("/cookbooks?num_versions=1").and_return(@cookbook_data)
+ allow(@rest_double).to receive(:get).with("/cookbooks?num_versions=1").and_return(@cookbook_data)
@stdout = StringIO.new
allow(@knife.ui).to receive(:stdout).and_return(@stdout)
diff --git a/spec/unit/knife/index_rebuild_spec.rb b/spec/unit/knife/index_rebuild_spec.rb
index 6c3b60bd88..d8a0dd72d7 100644
--- a/spec/unit/knife/index_rebuild_spec.rb
+++ b/spec/unit/knife/index_rebuild_spec.rb
@@ -21,7 +21,7 @@ require 'spec_helper'
describe Chef::Knife::IndexRebuild do
let(:knife){Chef::Knife::IndexRebuild.new}
- let(:rest_client){double(Chef::REST)}
+ let(:rest_client){double(Chef::ServerAPI)}
let(:stub_rest!) do
expect(knife).to receive(:rest).and_return(rest_client)
@@ -45,7 +45,7 @@ describe Chef::Knife::IndexRebuild do
before(:each) do
stub_rest!
- allow(rest_client).to receive(:get_rest).and_raise(http_server_exception)
+ allow(rest_client).to receive(:get).and_raise(http_server_exception)
end
context "against a Chef 11 server" do
@@ -110,7 +110,7 @@ describe Chef::Knife::IndexRebuild do
let(:api_info){ {} }
let(:server_specific_stubs!) do
stub_rest!
- expect(rest_client).to receive(:post_rest).with("/search/reindex", {}).and_return("representative output")
+ expect(rest_client).to receive(:post).with("/search/reindex", {}).and_return("representative output")
expect(knife).not_to receive(:unsupported_server_message)
expect(knife).to receive(:deprecated_server_message)
expect(knife).to receive(:nag)
diff --git a/spec/unit/knife_spec.rb b/spec/unit/knife_spec.rb
index 5ab8e84eac..c2127fdfd5 100644
--- a/spec/unit/knife_spec.rb
+++ b/spec/unit/knife_spec.rb
@@ -156,8 +156,8 @@ describe Chef::Knife do
"Accept-Encoding"=>"gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
'X-Chef-Version' => Chef::VERSION,
"Host"=>"api.opscode.piab",
- "X-REMOTE-REQUEST-ID"=>request_id,
- 'X-Ops-Server-API-Version' => Chef::HTTP::Authenticator::DEFAULT_SERVER_API_VERSION}}
+ "X-REMOTE-REQUEST-ID"=>request_id
+ }}
let(:request_id) {"1234"}
@@ -201,7 +201,7 @@ describe Chef::Knife do
it "confirms that the headers include X-Remote-Request-Id" do
expect(Net::HTTP::Get).to receive(:new).with("/monkey", headers).and_return(request_mock)
- rest.get_rest("monkey")
+ rest.get("monkey")
end
end
diff --git a/spec/unit/mixin/command_spec.rb b/spec/unit/mixin/command_spec.rb
index 050b261256..cedabcbe49 100644
--- a/spec/unit/mixin/command_spec.rb
+++ b/spec/unit/mixin/command_spec.rb
@@ -53,7 +53,7 @@ describe Chef::Mixin::Command, :volatile do
popen4("ruby -e 'while gets; end'", :waitlast => true) do |pid, stdin, stdout, stderr|
(1..5).each { |i| stdin.puts "#{i}" }
end
- end
+ end
}.not_to raise_error
end
diff --git a/spec/unit/node_spec.rb b/spec/unit/node_spec.rb
index 76cf451323..d7cee80d40 100644
--- a/spec/unit/node_spec.rb
+++ b/spec/unit/node_spec.rb
@@ -1271,8 +1271,8 @@ describe Chef::Node do
describe "api model" do
before(:each) do
- @rest = double("Chef::REST")
- allow(Chef::REST).to receive(:new).and_return(@rest)
+ @rest = double("Chef::ServerAPI")
+ allow(Chef::ServerAPI).to receive(:new).and_return(@rest)
@query = double("Chef::Search::Query")
allow(Chef::Search::Query).to receive(:new).and_return(@query)
end
@@ -1281,6 +1281,7 @@ describe Chef::Node do
describe "inflated" do
it "should return a hash of node names and objects" do
n1 = double("Chef::Node", :name => "one")
+ allow(n1).to receive(:kind_of?).with(Chef::Node) { true }
expect(@query).to receive(:search).with(:node).and_yield(n1)
r = Chef::Node.list(true)
expect(r["one"]).to eq(n1)
@@ -1288,7 +1289,7 @@ describe Chef::Node do
end
it "should return a hash of node names and urls" do
- expect(@rest).to receive(:get_rest).and_return({ "one" => "http://foo" })
+ expect(@rest).to receive(:get).and_return({ "one" => "http://foo" })
r = Chef::Node.list
expect(r["one"]).to eq("http://foo")
end
@@ -1296,14 +1297,19 @@ describe Chef::Node do
describe "load" do
it "should load a node by name" do
- expect(@rest).to receive(:get_rest).with("nodes/monkey").and_return("foo")
- expect(Chef::Node.load("monkey")).to eq("foo")
+ node.from_file(File.expand_path("nodes/test.example.com.rb", CHEF_SPEC_DATA))
+ json = Chef::JSONCompat.to_json(node)
+ parsed = Chef::JSONCompat.parse(json)
+ expect(@rest).to receive(:get).with("nodes/test.example.com").and_return(parsed)
+ serialized_node = Chef::Node.load("test.example.com")
+ expect(serialized_node).to be_a_kind_of(Chef::Node)
+ expect(serialized_node.name).to eql(node.name)
end
end
describe "destroy" do
it "should destroy a node" do
- expect(@rest).to receive(:delete_rest).with("nodes/monkey").and_return("foo")
+ expect(@rest).to receive(:delete).with("nodes/monkey").and_return("foo")
node.name("monkey")
node.destroy
end
@@ -1313,15 +1319,15 @@ describe Chef::Node do
it "should update a node if it already exists" do
node.name("monkey")
allow(node).to receive(:data_for_save).and_return({})
- expect(@rest).to receive(:put_rest).with("nodes/monkey", {}).and_return("foo")
+ expect(@rest).to receive(:put).with("nodes/monkey", {}).and_return("foo")
node.save
end
it "should not try and create if it can update" do
node.name("monkey")
allow(node).to receive(:data_for_save).and_return({})
- expect(@rest).to receive(:put_rest).with("nodes/monkey", {}).and_return("foo")
- expect(@rest).not_to receive(:post_rest)
+ expect(@rest).to receive(:put).with("nodes/monkey", {}).and_return("foo")
+ expect(@rest).not_to receive(:post)
node.save
end
@@ -1329,8 +1335,8 @@ describe Chef::Node do
node.name("monkey")
allow(node).to receive(:data_for_save).and_return({})
exception = double("404 error", :code => "404")
- expect(@rest).to receive(:put_rest).and_raise(Net::HTTPServerException.new("foo", exception))
- expect(@rest).to receive(:post_rest).with("nodes", {})
+ expect(@rest).to receive(:put).and_raise(Net::HTTPServerException.new("foo", exception))
+ expect(@rest).to receive(:post).with("nodes", {})
node.save
end
@@ -1343,8 +1349,8 @@ describe Chef::Node do
end
it "should not save" do
node.name("monkey")
- expect(@rest).not_to receive(:put_rest)
- expect(@rest).not_to receive(:post_rest)
+ expect(@rest).not_to receive(:put)
+ expect(@rest).not_to receive(:post)
node.save
end
end
@@ -1388,7 +1394,7 @@ describe Chef::Node do
node.name("picky-monkey")
allow(node).to receive(:for_json).and_return(data)
- expect(@rest).to receive(:put_rest).with("nodes/picky-monkey", selected_data).and_return("foo")
+ expect(@rest).to receive(:put).with("nodes/picky-monkey", selected_data).and_return("foo")
node.save
end
@@ -1422,7 +1428,7 @@ describe Chef::Node do
node.name("falsey-monkey")
allow(node).to receive(:for_json).and_return(data)
- expect(@rest).to receive(:put_rest).with("nodes/falsey-monkey", selected_data).and_return("foo")
+ expect(@rest).to receive(:put).with("nodes/falsey-monkey", selected_data).and_return("foo")
node.save
end
@@ -1445,7 +1451,7 @@ describe Chef::Node do
node.name("picky-monkey")
allow(node).to receive(:for_json).and_return(data)
- expect(@rest).to receive(:put_rest).with("nodes/picky-monkey", selected_data).and_return("foo")
+ expect(@rest).to receive(:put).with("nodes/picky-monkey", selected_data).and_return("foo")
node.save
end
end
@@ -1461,12 +1467,12 @@ describe Chef::Node do
context "and the server supports policyfile attributes in node JSON" do
it "creates the object normally" do
- expect(@rest).to receive(:post_rest).with("nodes", node.for_json)
+ expect(@rest).to receive(:post).with("nodes", node.for_json)
node.create
end
it "saves the node object normally" do
- expect(@rest).to receive(:put_rest).with("nodes/example-node", node.for_json)
+ expect(@rest).to receive(:put).with("nodes/example-node", node.for_json)
node.save
end
end
@@ -1514,8 +1520,8 @@ describe Chef::Node do
context "when the node exists" do
it "falls back to saving without policyfile attributes" do
- expect(@rest).to receive(:put_rest).with("nodes/example-node", node.for_json).and_raise(http_exception)
- expect(@rest).to receive(:put_rest).with("nodes/example-node", trimmed_node).and_return(@node)
+ expect(@rest).to receive(:put).with("nodes/example-node", node.for_json).and_raise(http_exception)
+ expect(@rest).to receive(:put).with("nodes/example-node", trimmed_node).and_return(@node)
expect { node.save }.to_not raise_error
end
@@ -1536,15 +1542,15 @@ describe Chef::Node do
end
it "falls back to saving without policyfile attributes" do
- expect(@rest).to receive(:put_rest).with("nodes/example-node", node.for_json).and_raise(http_exception)
- expect(@rest).to receive(:put_rest).with("nodes/example-node", trimmed_node).and_raise(http_exception_404)
- expect(@rest).to receive(:post_rest).with("nodes", trimmed_node).and_return(@node)
+ expect(@rest).to receive(:put).with("nodes/example-node", node.for_json).and_raise(http_exception)
+ expect(@rest).to receive(:put).with("nodes/example-node", trimmed_node).and_raise(http_exception_404)
+ expect(@rest).to receive(:post).with("nodes", trimmed_node).and_return(@node)
node.save
end
it "creates the node without policyfile attributes" do
- expect(@rest).to receive(:post_rest).with("nodes", node.for_json).and_raise(http_exception)
- expect(@rest).to receive(:post_rest).with("nodes", trimmed_node).and_return(@node)
+ expect(@rest).to receive(:post).with("nodes", node.for_json).and_raise(http_exception)
+ expect(@rest).to receive(:post).with("nodes", trimmed_node).and_return(@node)
node.create
end
end
diff --git a/spec/unit/org_spec.rb b/spec/unit/org_spec.rb
index cd6cc94d91..97e1b87704 100644
--- a/spec/unit/org_spec.rb
+++ b/spec/unit/org_spec.rb
@@ -136,7 +136,7 @@ describe Chef::Org do
let(:rest) do
Chef::Config[:chef_server_root] = "http://www.example.com"
r = double('rest')
- allow(Chef::REST).to receive(:new).and_return(r)
+ allow(Chef::ServerAPI).to receive(:new).and_return(r)
r
end
@@ -151,27 +151,27 @@ describe Chef::Org do
let(:inflated_response) { {"foobar" => org } }
it "lists all orgs" do
- expect(rest).to receive(:get_rest).with("organizations").and_return(response)
+ expect(rest).to receive(:get).with("organizations").and_return(response)
expect(Chef::Org.list).to eq(response)
end
it "inflate all orgs" do
allow(Chef::Org).to receive(:load).with("foobar").and_return(org)
- expect(rest).to receive(:get_rest).with("organizations").and_return(response)
+ expect(rest).to receive(:get).with("organizations").and_return(response)
expect(Chef::Org.list(true)).to eq(inflated_response)
end
end
describe "create" do
it "creates a new org via the API" do
- expect(rest).to receive(:post_rest).with("organizations", {:name => "foobar", :full_name => "foo bar bat"}).and_return({})
+ expect(rest).to receive(:post).with("organizations", {:name => "foobar", :full_name => "foo bar bat"}).and_return({})
org.create
end
end
describe "read" do
it "loads a named org from the API" do
- expect(rest).to receive(:get_rest).with("organizations/foobar").and_return({"name" => "foobar", "full_name" => "foo bar bat", "private_key" => "private"})
+ expect(rest).to receive(:get).with("organizations/foobar").and_return({"name" => "foobar", "full_name" => "foo bar bat", "private_key" => "private"})
org = Chef::Org.load("foobar")
expect(org.name).to eq("foobar")
expect(org.full_name).to eq("foo bar bat")
@@ -181,14 +181,14 @@ describe Chef::Org do
describe "update" do
it "updates an existing org on via the API" do
- expect(rest).to receive(:put_rest).with("organizations/foobar", {:name => "foobar", :full_name => "foo bar bat"}).and_return({})
+ expect(rest).to receive(:put).with("organizations/foobar", {:name => "foobar", :full_name => "foo bar bat"}).and_return({})
org.update
end
end
describe "destroy" do
it "deletes the specified org via the API" do
- expect(rest).to receive(:delete_rest).with("organizations/foobar")
+ expect(rest).to receive(:delete).with("organizations/foobar")
org.destroy
end
end
diff --git a/spec/unit/policy_builder/expand_node_object_spec.rb b/spec/unit/policy_builder/expand_node_object_spec.rb
index 306d677108..944d4d3387 100644
--- a/spec/unit/policy_builder/expand_node_object_spec.rb
+++ b/spec/unit/policy_builder/expand_node_object_spec.rb
@@ -290,7 +290,7 @@ describe Chef::PolicyBuilder::ExpandNodeObject do
node
end
- let(:chef_http) { double("Chef::REST") }
+ let(:chef_http) { double("Chef::ServerAPI") }
let(:cookbook_resolve_url) { "environments/#{node.chef_environment}/cookbook_versions" }
let(:cookbook_resolve_post_data) { {:run_list=>["first::default", "second::default"]} }
@@ -298,7 +298,8 @@ describe Chef::PolicyBuilder::ExpandNodeObject do
# cookbook_hash is just a hash, but since we're passing it between mock
# objects, we get a little better test strictness by using a double (which
# will have object equality rather than semantic equality #== semantics).
- let(:cookbook_hash) { double("cookbook hash", :each => nil) }
+ let(:cookbook_hash) { double("cookbook hash") }
+ let(:expanded_cookbook_hash) { double("expanded cookbook hash", :each => nil) }
let(:cookbook_synchronizer) { double("CookbookSynchronizer") }
@@ -310,8 +311,9 @@ describe Chef::PolicyBuilder::ExpandNodeObject do
run_list_expansion = policy_builder.run_list_expansion
+ expect(cookbook_hash).to receive(:inject).and_return(expanded_cookbook_hash)
expect(chef_http).to receive(:post).with(cookbook_resolve_url, cookbook_resolve_post_data).and_return(cookbook_hash)
- expect(Chef::CookbookSynchronizer).to receive(:new).with(cookbook_hash, events).and_return(cookbook_synchronizer)
+ expect(Chef::CookbookSynchronizer).to receive(:new).with(expanded_cookbook_hash, events).and_return(cookbook_synchronizer)
expect(cookbook_synchronizer).to receive(:sync_cookbooks)
expect_any_instance_of(Chef::RunContext).to receive(:load).with(run_list_expansion)
diff --git a/spec/unit/policy_builder/policyfile_spec.rb b/spec/unit/policy_builder/policyfile_spec.rb
index ed893260c2..3dfa8d9802 100644
--- a/spec/unit/policy_builder/policyfile_spec.rb
+++ b/spec/unit/policy_builder/policyfile_spec.rb
@@ -98,10 +98,10 @@ describe Chef::PolicyBuilder::Policyfile do
let(:err_namespace) { Chef::PolicyBuilder::Policyfile }
it "configures a Chef HTTP API client" do
- http = double("Chef::REST")
+ http = double("Chef::ServerAPI")
server_url = "https://api.opscode.com/organizations/example"
Chef::Config[:chef_server_url] = server_url
- expect(Chef::REST).to receive(:new).with(server_url).and_return(http)
+ expect(Chef::ServerAPI).to receive(:new).with(server_url).and_return(http)
expect(policy_builder.http_api).to eq(http)
end
@@ -151,7 +151,7 @@ describe Chef::PolicyBuilder::Policyfile do
describe "loading policy data" do
- let(:http_api) { double("Chef::REST") }
+ let(:http_api) { double("Chef::ServerAPI") }
let(:configured_environment) { nil }
diff --git a/spec/unit/provider/group/groupadd_spec.rb b/spec/unit/provider/group/groupadd_spec.rb
index 94150b7a88..47021a9af3 100644
--- a/spec/unit/provider/group/groupadd_spec.rb
+++ b/spec/unit/provider/group/groupadd_spec.rb
@@ -42,7 +42,7 @@ describe Chef::Provider::Group::Groupadd, "set_options" do
}
field_list.each do |attribute, option|
- it "should check for differences in #{attribute.to_s} between the current and new resources" do
+ it "should check for differences in #{attribute} between the current and new resources" do
expect(@new_resource).to receive(attribute)
expect(@current_resource).to receive(attribute)
@provider.set_options
@@ -145,7 +145,7 @@ describe Chef::Provider::Group::Groupadd do
[:add_member, :remove_member, :set_members].each do |m|
it "should raise an error when calling #{m}" do
- expect { @provider.send(m, [ ]) }.to raise_error(Chef::Exceptions::Group, "you must override #{m} in #{@provider.to_s}")
+ expect { @provider.send(m, [ ]) }.to raise_error(Chef::Exceptions::Group, "you must override #{m} in #{@provider}")
end
end
diff --git a/spec/unit/provider/group/pw_spec.rb b/spec/unit/provider/group/pw_spec.rb
index af74b3b2ce..531d0a52a2 100644
--- a/spec/unit/provider/group/pw_spec.rb
+++ b/spec/unit/provider/group/pw_spec.rb
@@ -119,7 +119,7 @@ describe Chef::Provider::Group::Pw do
end
end
- describe"load_current_resource" do
+ describe "load_current_resource" do
before (:each) do
@provider.action = :create
@provider.load_current_resource
diff --git a/spec/unit/provider/group/usermod_spec.rb b/spec/unit/provider/group/usermod_spec.rb
index 3f06e9ebf1..a11d790d07 100644
--- a/spec/unit/provider/group/usermod_spec.rb
+++ b/spec/unit/provider/group/usermod_spec.rb
@@ -65,7 +65,7 @@ describe Chef::Provider::Group::Usermod do
@provider.load_current_resource
@provider.instance_variable_set("@group_exists", true)
@provider.action = :modify
- expect { @provider.run_action(@provider.process_resource_requirements) }.to raise_error(Chef::Exceptions::Group, "setting group members directly is not supported by #{@provider.to_s}, must set append true in group")
+ expect { @provider.run_action(@provider.process_resource_requirements) }.to raise_error(Chef::Exceptions::Group, "setting group members directly is not supported by #{@provider}, must set append true in group")
end
it "should raise an error when excluded_members are set" do
@@ -75,7 +75,7 @@ describe Chef::Provider::Group::Usermod do
@provider.action = :modify
allow(@new_resource).to receive(:append).and_return(true)
allow(@new_resource).to receive(:excluded_members).and_return(["someone"])
- expect { @provider.run_action(@provider.process_resource_requirements) }.to raise_error(Chef::Exceptions::Group, "excluded_members is not supported by #{@provider.to_s}")
+ expect { @provider.run_action(@provider.process_resource_requirements) }.to raise_error(Chef::Exceptions::Group, "excluded_members is not supported by #{@provider}")
end
platforms.each do |platform, flags|
diff --git a/spec/unit/provider/http_request_spec.rb b/spec/unit/provider/http_request_spec.rb
index a84dd5e2a0..980458abd3 100644
--- a/spec/unit/provider/http_request_spec.rb
+++ b/spec/unit/provider/http_request_spec.rb
@@ -34,7 +34,7 @@ describe Chef::Provider::HttpRequest do
describe "load_current_resource" do
- it "should set up a Chef::REST client, with no authentication" do
+ it "should set up a Chef::ServerAPI client, with no authentication" do
expect(Chef::HTTP::Simple).to receive(:new).with(@new_resource.url)
@provider.load_current_resource
end
@@ -45,7 +45,7 @@ describe Chef::Provider::HttpRequest do
# run_action(x) forces load_current_resource to run;
# that would overwrite our supplied mock Chef::Rest # object
allow(@provider).to receive(:load_current_resource).and_return(true)
- @http = double("Chef::REST")
+ @http = double("Chef::ServerAPI")
@provider.http = @http
end
diff --git a/spec/unit/provider/ifconfig_spec.rb b/spec/unit/provider/ifconfig_spec.rb
index 4940f19a45..90109ca1c0 100644
--- a/spec/unit/provider/ifconfig_spec.rb
+++ b/spec/unit/provider/ifconfig_spec.rb
@@ -39,7 +39,7 @@ describe Chef::Provider::Ifconfig do
@provider.instance_variable_set("@status", status)
@provider.current_resource = @current_resource
- end
+ end
describe Chef::Provider::Ifconfig, "load_current_resource" do
before do
@status = double(:stdout => "", :exitstatus => 1)
diff --git a/spec/unit/provider/mdadm_spec.rb b/spec/unit/provider/mdadm_spec.rb
index 77ed5798a8..38401b7225 100644
--- a/spec/unit/provider/mdadm_spec.rb
+++ b/spec/unit/provider/mdadm_spec.rb
@@ -107,7 +107,7 @@ describe Chef::Provider::Mdadm do
expect(@provider).not_to receive(:shell_out!)
@provider.run_action(:assemble)
expect(@new_resource).not_to be_updated_by_last_action
- end
+ end
end
describe "when stopping the metadevice" do
diff --git a/spec/unit/provider/mount/mount_spec.rb b/spec/unit/provider/mount/mount_spec.rb
index dd13a62796..124d51b367 100644
--- a/spec/unit/provider/mount/mount_spec.rb
+++ b/spec/unit/provider/mount/mount_spec.rb
@@ -244,7 +244,7 @@ describe Chef::Provider::Mount::Mount do
@provider.load_current_resource
expect(@provider.current_resource.enabled).to be_falsey
- end
+ end
it "should set enabled to false if the mount point is not last in fstab" do
line_1 = "#{@new_resource.device} #{@new_resource.mount_point} ext3 defaults 1 2\n"
diff --git a/spec/unit/provider/package/chocolatey_spec.rb b/spec/unit/provider/package/chocolatey_spec.rb
new file mode 100644
index 0000000000..b2e1d2daaf
--- /dev/null
+++ b/spec/unit/provider/package/chocolatey_spec.rb
@@ -0,0 +1,450 @@
+#
+# Author:: Adam Jacob (<adam@opscode.com>)
+# Copyright:: Copyright (c) 2008-2015 Chef Software, Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+require 'spec_helper'
+
+describe Chef::Provider::Package::Chocolatey do
+ let(:timeout) { 900 }
+
+ let(:new_resource) { Chef::Resource::ChocolateyPackage.new("git") }
+
+ let(:provider) do
+ node = Chef::Node.new
+ events = Chef::EventDispatch::Dispatcher.new
+ run_context = Chef::RunContext.new(node, {}, events)
+ Chef::Provider::Package::Chocolatey.new(new_resource, run_context)
+ end
+
+ let(:choco_exe) { 'C:\ProgramData\chocolatey\bin\choco.exe' }
+
+ # installed packages (ConEmu is upgradable)
+ let(:local_list_stdout) do
+ <<-EOF
+chocolatey|0.9.9.11
+ConEmu|15.10.25.0
+ EOF
+ end
+
+ before do
+ allow(provider).to receive(:choco_exe).and_return(choco_exe)
+ local_list_obj = double(:stdout => local_list_stdout)
+ allow(provider).to receive(:shell_out!).with("#{choco_exe} list -l -r", {:timeout => timeout}).and_return(local_list_obj)
+ end
+
+ def allow_remote_list(package_names, args = nil)
+ remote_list_stdout = <<-EOF
+chocolatey|0.9.9.11
+ConEmu|15.10.25.1
+git|2.6.2
+munin-node|1.6.1.20130823
+ EOF
+ remote_list_obj = double(stdout: remote_list_stdout)
+ allow(provider).to receive(:shell_out!).with("#{choco_exe} list -ar #{package_names.join ' '}#{args}", {timeout: timeout}).and_return(remote_list_obj)
+ end
+
+ describe "#initialize" do
+ it "should return the correct class" do
+ expect(provider).to be_kind_of(Chef::Provider::Package::Chocolatey)
+ end
+
+ it "should support arrays" do
+ expect(provider.use_multipackage_api?).to be true
+ end
+ end
+
+ describe "#candidate_version" do
+ it "should set the candidate_version correctly" do
+ allow_remote_list(["git"])
+ expect(provider.candidate_version).to eql(["2.6.2"])
+ end
+
+ it "should set the candidate_version to nil if there is no candidate" do
+ allow_remote_list(["vim"])
+ new_resource.package_name("vim")
+ expect(provider.candidate_version).to eql([nil])
+ end
+
+ it "should set the candidate_version correctly when there are two packages to install" do
+ allow_remote_list(["ConEmu", "chocolatey"])
+ new_resource.package_name(["ConEmu", "chocolatey"])
+ expect(provider.candidate_version).to eql(["15.10.25.1", "0.9.9.11"])
+ end
+
+ it "should set the candidate_version correctly when only the first is installable" do
+ allow_remote_list(["ConEmu", "vim"])
+ new_resource.package_name(["ConEmu", "vim"])
+ expect(provider.candidate_version).to eql(["15.10.25.1", nil])
+ end
+
+ it "should set the candidate_version correctly when only the last is installable" do
+ allow_remote_list(["vim", "chocolatey"])
+ new_resource.package_name(["vim", "chocolatey"])
+ expect(provider.candidate_version).to eql([nil, "0.9.9.11"])
+ end
+
+ it "should set the candidate_version correctly when neither are is installable" do
+ allow_remote_list(["vim", "ruby"])
+ new_resource.package_name(["vim", "ruby"])
+ expect(provider.candidate_version).to eql([nil, nil])
+ end
+ end
+
+ describe "#load_current_resource" do
+ it "should return a current_resource" do
+ expect(provider.load_current_resource).to be_kind_of(Chef::Resource::ChocolateyPackage)
+ end
+
+ it "should set the current_resource#package_name" do
+ provider.load_current_resource
+ expect(provider.current_resource.package_name).to eql(["git"])
+ end
+
+ it "should load and downcase names in the installed_packages hash" do
+ provider.load_current_resource
+ expect(provider.send(:installed_packages)).to eql(
+ {"chocolatey"=>"0.9.9.11", "conemu"=>"15.10.25.0"}
+ )
+ end
+
+ it "should load and downcase names in the available_packages hash" do
+ allow_remote_list(["git"])
+ provider.load_current_resource
+ expect(provider.send(:available_packages)).to eql(
+ {"chocolatey"=>"0.9.9.11", "conemu"=>"15.10.25.1", "git"=>"2.6.2", "munin-node" => "1.6.1.20130823"}
+ )
+ end
+
+ it "should set the current_resource.version to nil when the package is not installed" do
+ provider.load_current_resource
+ expect(provider.current_resource.version).to eql([nil])
+ end
+
+ it "should set the current_resource.version to the installed version when the package is installed" do
+ new_resource.package_name("ConEmu")
+ provider.load_current_resource
+ expect(provider.current_resource.version).to eql(["15.10.25.0"])
+ end
+
+ it "should set the current_resource.version when there are two packages that are installed" do
+ new_resource.package_name(["ConEmu", "chocolatey"])
+ provider.load_current_resource
+ expect(provider.current_resource.version).to eql(["15.10.25.0", "0.9.9.11"])
+ end
+
+ it "should set the current_resource.version correctly when only the first is installed" do
+ new_resource.package_name(["ConEmu", "git"])
+ provider.load_current_resource
+ expect(provider.current_resource.version).to eql(["15.10.25.0", nil])
+ end
+
+ it "should set the current_resource.version correctly when only the last is installed" do
+ new_resource.package_name(["git", "chocolatey"])
+ provider.load_current_resource
+ expect(provider.current_resource.version).to eql([nil, "0.9.9.11"])
+ end
+
+ it "should set the current_resource.version correctly when none are installed" do
+ new_resource.package_name(["git", "vim"])
+ provider.load_current_resource
+ expect(provider.current_resource.version).to eql([nil, nil])
+ end
+ end
+
+ describe "#action_install" do
+ it "should install a single package" do
+ allow_remote_list(["git"])
+ provider.load_current_resource
+ expect(provider).to receive(:shell_out!).with("#{choco_exe} install -y git", {:timeout=>timeout}).and_return(double)
+ provider.run_action(:install)
+ expect(new_resource).to be_updated_by_last_action
+ end
+
+ context "when changing the timeout to 3600" do
+ let(:timeout) { 3600 }
+ it "sets the timeout on shell_out commands" do
+ allow_remote_list(["git"])
+ new_resource.timeout(timeout)
+ provider.load_current_resource
+ expect(provider).to receive(:shell_out!).with("#{choco_exe} install -y git", {:timeout=>timeout}).and_return(double)
+ provider.run_action(:install)
+ expect(new_resource).to be_updated_by_last_action
+ end
+ end
+
+ it "should not install packages that are up-to-date" do
+ allow_remote_list(["chocolatey"])
+ new_resource.package_name("chocolatey")
+ provider.load_current_resource
+ expect(provider).not_to receive(:install_package)
+ provider.run_action(:install)
+ expect(new_resource).not_to be_updated_by_last_action
+ end
+
+ it "should not upgrade packages" do
+ allow_remote_list(["ConEmu"])
+ new_resource.package_name("ConEmu")
+ provider.load_current_resource
+ expect(provider).not_to receive(:install_package)
+ provider.run_action(:install)
+ expect(new_resource).not_to be_updated_by_last_action
+ end
+
+ it "should upgrade packages when given a version pin" do
+ allow_remote_list(["ConEmu"])
+ new_resource.package_name("ConEmu")
+ new_resource.version("15.10.25.1")
+ provider.load_current_resource
+ expect(provider).to receive(:shell_out!).with("#{choco_exe} install -y -version 15.10.25.1 ConEmu", {:timeout=>timeout}).and_return(double)
+ provider.run_action(:install)
+ expect(new_resource).to be_updated_by_last_action
+ end
+
+ it "should handle complicated cases when the name/version array is pruned" do
+ # chocolatey will be pruned by the superclass out of the args to install_package and we
+ # implicitly test that we correctly pick up new_resource.version[1] instead of
+ # new_version.resource[0]
+ allow_remote_list(["chocolatey", "ConEmu"])
+ new_resource.package_name(["chocolatey", "ConEmu"])
+ new_resource.version([nil, "15.10.25.1"])
+ provider.load_current_resource
+ expect(provider).to receive(:shell_out!).with("#{choco_exe} install -y -version 15.10.25.1 ConEmu", {:timeout=>timeout}).and_return(double)
+ provider.run_action(:install)
+ expect(new_resource).to be_updated_by_last_action
+ end
+
+ it "should be case-insensitive" do
+ allow_remote_list(["conemu"])
+ new_resource.package_name("conemu")
+ new_resource.version("15.10.25.1")
+ provider.load_current_resource
+ expect(provider).to receive(:shell_out!).with("#{choco_exe} install -y -version 15.10.25.1 conemu", {:timeout=>timeout}).and_return(double)
+ provider.run_action(:install)
+ expect(new_resource).to be_updated_by_last_action
+ end
+
+ it "should split up commands when given two packages, one with a version pin" do
+ allow_remote_list(["ConEmu", "git"])
+ new_resource.package_name(["ConEmu", "git"])
+ new_resource.version(["15.10.25.1", nil])
+ provider.load_current_resource
+ expect(provider).to receive(:shell_out!).with("#{choco_exe} install -y -version 15.10.25.1 ConEmu", {:timeout=>timeout}).and_return(double)
+ expect(provider).to receive(:shell_out!).with("#{choco_exe} install -y git", {:timeout=>timeout}).and_return(double)
+ provider.run_action(:install)
+ expect(new_resource).to be_updated_by_last_action
+ end
+
+ it "should do multipackage installs when given two packages without constraints" do
+ allow_remote_list(["git", "munin-node"])
+ new_resource.package_name(["git", "munin-node"])
+ provider.load_current_resource
+ expect(provider).to receive(:shell_out!).with("#{choco_exe} install -y git munin-node", {:timeout=>timeout}).and_return(double)
+ provider.run_action(:install)
+ expect(new_resource).to be_updated_by_last_action
+ end
+
+ context "when passing a source argument" do
+ it "should pass options into the install command" do
+ allow_remote_list(["git"], " -source localpackages")
+ new_resource.source("localpackages")
+ provider.load_current_resource
+ expect(provider).to receive(:shell_out!).with("#{choco_exe} install -y -source localpackages git", {:timeout=>timeout}).and_return(double)
+ provider.run_action(:install)
+ expect(new_resource).to be_updated_by_last_action
+ end
+ end
+
+ it "should pass options into the install command" do
+ allow_remote_list(["git"])
+ new_resource.options("-force")
+ provider.load_current_resource
+ expect(provider).to receive(:shell_out!).with("#{choco_exe} install -y -force git", {:timeout=>timeout}).and_return(double)
+ provider.run_action(:install)
+ expect(new_resource).to be_updated_by_last_action
+ end
+
+ it "installing a package that does not exist throws an error" do
+ allow_remote_list(["package-does-not-exist"])
+ new_resource.package_name("package-does-not-exist")
+ provider.load_current_resource
+ expect { provider.run_action(:install) }.to raise_error(Chef::Exceptions::Package)
+ end
+
+ it "installing a package version that does not exist throws an error" do
+ allow_remote_list(["git"])
+ new_resource.package_name("git")
+ new_resource.version("2.7.0")
+ provider.load_current_resource
+ expect { provider.run_action(:install) }.to raise_error(Chef::Exceptions::Package)
+ end
+
+ it "installing multiple packages with a package that does not exist throws an error" do
+ allow_remote_list(["git", "package-does-not-exist"])
+ new_resource.package_name(["git", "package-does-not-exist"])
+ provider.load_current_resource
+ expect { provider.run_action(:install) }.to raise_error(Chef::Exceptions::Package)
+ end
+
+ context "alternate source" do
+ it "installing a package that does not exist throws an error" do
+ allow_remote_list(["package-does-not-exist"], " -source alternate_source")
+ new_resource.package_name("package-does-not-exist")
+ new_resource.source("alternate_source")
+ provider.load_current_resource
+ expect { provider.run_action(:install) }.to raise_error(Chef::Exceptions::Package)
+ end
+ end
+ end
+
+ describe "#action_upgrade" do
+ it "should install a package that is not installed" do
+ allow_remote_list(["git"])
+ provider.load_current_resource
+ expect(provider).to receive(:shell_out!).with("#{choco_exe} upgrade -y git", {:timeout=>timeout}).and_return(double)
+ provider.run_action(:upgrade)
+ expect(new_resource).to be_updated_by_last_action
+ end
+
+ it "should upgrade a package that is installed but upgradable" do
+ allow_remote_list(["ConEmu"])
+ new_resource.package_name("ConEmu")
+ provider.load_current_resource
+ expect(provider).to receive(:shell_out!).with("#{choco_exe} upgrade -y ConEmu", {:timeout=>timeout}).and_return(double)
+ provider.run_action(:upgrade)
+ expect(new_resource).to be_updated_by_last_action
+ end
+
+ it "should be case insensitive" do
+ allow_remote_list(["conemu"])
+ new_resource.package_name("conemu")
+ provider.load_current_resource
+ expect(provider).to receive(:shell_out!).with("#{choco_exe} upgrade -y conemu", {:timeout=>timeout}).and_return(double)
+ provider.run_action(:upgrade)
+ expect(new_resource).to be_updated_by_last_action
+ end
+
+ it "should not install a package that is up-to-date" do
+ allow_remote_list(["chocolatey"])
+ new_resource.package_name("chocolatey")
+ provider.load_current_resource
+ expect(provider).not_to receive(:shell_out!).with("#{choco_exe} upgrade -y chocolatey", {:timeout=>timeout})
+ provider.run_action(:upgrade)
+ expect(new_resource).not_to be_updated_by_last_action
+ end
+
+ it "version pins work as well" do
+ allow_remote_list(["git"])
+ new_resource.version("2.6.2")
+ provider.load_current_resource
+ expect(provider).to receive(:shell_out!).with("#{choco_exe} upgrade -y -version 2.6.2 git", {:timeout=>timeout})
+ provider.run_action(:upgrade)
+ expect(new_resource).to be_updated_by_last_action
+ end
+
+ it "upgrading multiple packages uses a single command" do
+ allow_remote_list(["conemu", "git"])
+ new_resource.package_name(["conemu", "git"])
+ expect(provider).to receive(:shell_out!).with("#{choco_exe} upgrade -y conemu git", {:timeout=>timeout}).and_return(double)
+ provider.run_action(:upgrade)
+ expect(new_resource).to be_updated_by_last_action
+ end
+
+ it "upgrading a package that does not exist throws an error" do
+ allow_remote_list(["package-does-not-exist"])
+ new_resource.package_name("package-does-not-exist")
+ provider.load_current_resource
+ expect { provider.run_action(:upgrade) }.to raise_error(Chef::Exceptions::Package)
+ end
+
+ it "upgrading multiple packages with a package that does not exist throws an error" do
+ allow_remote_list(["git", "package-does-not-exist"])
+ new_resource.package_name(["git", "package-does-not-exist"])
+ provider.load_current_resource
+ expect { provider.run_action(:upgrade) }.to raise_error(Chef::Exceptions::Package)
+ end
+
+ context "alternate source" do
+ it "installing a package that does not exist throws an error" do
+ allow_remote_list(["package-does-not-exist"], " -source alternate_source")
+ new_resource.package_name("package-does-not-exist")
+ new_resource.source("alternate_source")
+ provider.load_current_resource
+ expect { provider.run_action(:upgrade) }.to raise_error(Chef::Exceptions::Package)
+ end
+ end
+ end
+
+ describe "#action_remove" do
+ it "does nothing when the package is already removed" do
+ allow_remote_list(["git"])
+ provider.load_current_resource
+ expect(provider).not_to receive(:remove_package)
+ provider.run_action(:remove)
+ expect(new_resource).not_to be_updated_by_last_action
+ end
+
+ it "does nothing when all the packages are already removed" do
+ allow_remote_list(["git", "package-does-not-exist"])
+ new_resource.package_name(["git", "package-does-not-exist"])
+ provider.load_current_resource
+ expect(provider).not_to receive(:remove_package)
+ provider.run_action(:remove)
+ expect(new_resource).not_to be_updated_by_last_action
+ end
+
+ it "removes a package" do
+ allow_remote_list(["ConEmu"])
+ new_resource.package_name("ConEmu")
+ provider.load_current_resource
+ expect(provider).to receive(:shell_out!).with("#{choco_exe} uninstall -y ConEmu", {:timeout=>timeout}).and_return(double)
+ provider.run_action(:remove)
+ expect(new_resource).to be_updated_by_last_action
+ end
+
+ it "is case-insensitive" do
+ allow_remote_list(["conemu"])
+ new_resource.package_name("conemu")
+ provider.load_current_resource
+ expect(provider).to receive(:shell_out!).with("#{choco_exe} uninstall -y conemu", {:timeout=>timeout}).and_return(double)
+ provider.run_action(:remove)
+ expect(new_resource).to be_updated_by_last_action
+ end
+
+ it "removes a single package when its the only one installed" do
+ pending "this is a bug in the superclass"
+ allow_remote_list(["git", "conemu"])
+ new_resource.package_name(["git", "conemu"])
+ provider.load_current_resource
+ expect(provider).to receive(:shell_out!).with("#{choco_exe} uninstall -y conemu", {:timeout=>timeout}).and_return(double)
+ provider.run_action(:remove)
+ expect(new_resource).to be_updated_by_last_action
+ end
+ end
+
+ describe "#action_uninstall" do
+ it "should call :remove with a deprecation warning" do
+ Chef::Config[:treat_deprecation_warnings_as_errors] = false
+ expect(Chef::Log).to receive(:deprecation).with(/please use :remove/)
+ allow_remote_list(["ConEmu"])
+ new_resource.package_name("ConEmu")
+ provider.load_current_resource
+ expect(provider).to receive(:remove_package)
+ provider.run_action(:uninstall)
+ expect(new_resource).to be_updated_by_last_action
+ end
+ end
+end
diff --git a/spec/unit/provider/package/windows/exe_spec.rb b/spec/unit/provider/package/windows/exe_spec.rb
index 730df5e067..677ab87f29 100644
--- a/spec/unit/provider/package/windows/exe_spec.rb
+++ b/spec/unit/provider/package/windows/exe_spec.rb
@@ -53,12 +53,8 @@ describe Chef::Provider::Package::Windows::Exe do
entries
end
let(:provider) { Chef::Provider::Package::Windows::Exe.new(new_resource, :nsis, uninstall_entry) }
- let(:file_version) { nil }
- let(:product_version) { nil }
- let(:version_info) { instance_double("Chef::ReservedNames::Win32::File::Version_info", FileVersion: file_version, ProductVersion: product_version) }
before(:each) do
- allow(Chef::ReservedNames::Win32::File).to receive(:version_info).and_return(version_info)
allow(::File).to receive(:exist?).with(Chef::Util::PathHelper.canonical_path(resource_source, false)).and_return(true)
end
@@ -103,73 +99,13 @@ describe Chef::Provider::Package::Windows::Exe do
end
end
- context "file version is empty" do
- let(:file_version) { '' }
-
- it "returns nil" do
- expect(provider.package_version).to eql(nil)
- end
-
- it "returns the version of a package if given" do
- new_resource.version('v55555')
- expect(provider.package_version).to eql('v55555')
- end
- end
-
- context "both file and product version are in installer" do
- let(:file_version) { '1.1.1' }
- let(:product_version) { '1.1' }
-
- it "returns the file version" do
- expect(provider.package_version).to eql('1.1.1')
- end
-
- it "returns the version of a package if given" do
- new_resource.version('v55555')
- expect(provider.package_version).to eql('v55555')
- end
- end
-
- context "only file version is in installer" do
- let(:file_version) { '1.1.1' }
-
- it "returns the file version" do
- expect(provider.package_version).to eql('1.1.1')
- end
-
- it "returns the version of a package if given" do
- new_resource.version('v55555')
- expect(provider.package_version).to eql('v55555')
- end
+ it "returns the version attribute if given" do
+ new_resource.version('v55555')
+ expect(provider.package_version).to eql('v55555')
end
- context "only product version is in installer" do
- let(:product_version) { '1.1' }
-
- it "returns the product version" do
- expect(provider.package_version).to eql('1.1')
- end
-
- it "returns the version of a package if given" do
- new_resource.version('v55555')
- expect(provider.package_version).to eql('v55555')
- end
- end
-
- context "no version info is in installer" do
- let(:file_version) { nil }
- let(:product_version) { nil }
-
- it "returns the version of a package" do
- new_resource.version('v55555')
- expect(provider.package_version).to eql('v55555')
- end
- end
-
- context "no version info is in installer and none in attribute" do
- it "returns the version of a package" do
- expect(provider.package_version).to eql(nil)
- end
+ it "returns nil if no version given" do
+ expect(provider.package_version).to eql(nil)
end
end
diff --git a/spec/unit/provider/package/yum_spec.rb b/spec/unit/provider/package/yum_spec.rb
index b37a675bf2..41118b70fb 100644
--- a/spec/unit/provider/package/yum_spec.rb
+++ b/spec/unit/provider/package/yum_spec.rb
@@ -261,7 +261,7 @@ describe Chef::Provider::Package::Yum do
allow(@yum_cache).to receive(:installed_version) do |package_name, arch|
# nothing installed for package_name/new_package_name
nil
- end
+ end
allow(@yum_cache).to receive(:candidate_version) do |package_name, arch|
if package_name == "testing.noarch"
nil
diff --git a/spec/unit/provider/package/zypper_spec.rb b/spec/unit/provider/package/zypper_spec.rb
index 661bca4c1b..5fb3abe875 100644
--- a/spec/unit/provider/package/zypper_spec.rb
+++ b/spec/unit/provider/package/zypper_spec.rb
@@ -1,6 +1,6 @@
#
# Author:: Adam Jacob (<adam@opscode.com>)
-# Copyright:: Copyright (c) 2008 Opscode, Inc.
+# Copyright:: Copyright (c) 2008-2015 Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/spec/unit/provider/service/gentoo_service_spec.rb b/spec/unit/provider/service/gentoo_service_spec.rb
index 0aa7bf4529..b4155f9628 100644
--- a/spec/unit/provider/service/gentoo_service_spec.rb
+++ b/spec/unit/provider/service/gentoo_service_spec.rb
@@ -100,7 +100,7 @@ describe Chef::Provider::Service::Gentoo do
end
end
- end
+ end
it "should return the current_resource" do
expect(@provider.load_current_resource).to eq(@current_resource)
diff --git a/spec/unit/provider/service/openbsd_service_spec.rb b/spec/unit/provider/service/openbsd_service_spec.rb
index d3c150a14b..8118e9b3ee 100644
--- a/spec/unit/provider/service/openbsd_service_spec.rb
+++ b/spec/unit/provider/service/openbsd_service_spec.rb
@@ -250,7 +250,7 @@ describe Chef::Provider::Service::Openbsd do
current_resource.running(false)
allow(provider).to receive(:service_enable_variable_name).and_return "#{new_resource.service_name}_enable"
expect(::File).to receive(:open).with("/etc/rc.d/#{new_resource.service_name}")
- end
+ end
it "should create a current resource with the name of the new resource" do
expect(Chef::Resource::Service).to receive(:new).and_return(current_resource)
diff --git a/spec/unit/provider/service/windows_spec.rb b/spec/unit/provider/service/windows_spec.rb
index 4c9f5b3377..34140fdd7b 100644
--- a/spec/unit/provider/service/windows_spec.rb
+++ b/spec/unit/provider/service/windows_spec.rb
@@ -30,6 +30,7 @@ describe Chef::Provider::Service::Windows, "load_current_resource" do
prvdr.current_resource = Chef::Resource::WindowsService.new("current-chef")
prvdr
end
+ let(:service_right) { Chef::Provider::Service::Windows::SERVICE_RIGHT }
before(:all) do
Win32::Service = Class.new
@@ -46,6 +47,7 @@ describe Chef::Provider::Service::Windows, "load_current_resource" do
double("ConfigStruct", :start_type => "auto start"))
allow(Win32::Service).to receive(:exists?).and_return(true)
allow(Win32::Service).to receive(:configure).and_return(Win32::Service)
+ allow(Chef::ReservedNames::Win32::Security).to receive(:get_account_right).and_return([])
end
after(:each) do
@@ -164,6 +166,13 @@ describe Chef::Provider::Service::Windows, "load_current_resource" do
expect(provider).to receive(:grant_service_logon).and_return(true)
provider.start_service
end
+
+ it "does not grant user SeServiceLogonRight if it already has it" do
+ expect(Win32::Service).to receive(:start)
+ expect(Chef::ReservedNames::Win32::Security).to receive(:get_account_right).with("wallace").and_return([service_right])
+ expect(Chef::ReservedNames::Win32::Security).not_to receive(:add_account_right).with("wallace", service_right)
+ provider.start_service
+ end
end
end
@@ -417,37 +426,19 @@ describe Chef::Provider::Service::Windows, "load_current_resource" do
include_context "testing private methods"
let(:username) { "unit_test_user" }
- let(:success_string) { "The task has completed successfully.\r\nSee logfile etc." }
- let(:failure_string) { "Look on my works, ye Mighty, and despair!" }
- let(:command) {
- dbfile = provider.grant_dbfile_name(username)
- policyfile = provider.grant_policyfile_name(username)
- logfile = provider.grant_logfile_name(username)
-
- %Q{secedit.exe /configure /db "#{dbfile}" /cfg "#{policyfile}" /areas USER_RIGHTS SECURITYPOLICY SERVICES /log "#{logfile}"}
- }
- let(:shellout_env) { {:environment=>{"LC_ALL"=>"en_US.UTF-8"}} }
- before {
- expect_any_instance_of(described_class).to receive(:shell_out).with(command).and_call_original
- expect_any_instance_of(Mixlib::ShellOut).to receive(:run_command).and_return(nil)
- }
-
- after {
- # only needed for the second test.
- ::File.delete(provider.grant_policyfile_name(username)) rescue nil
- ::File.delete(provider.grant_logfile_name(username)) rescue nil
- ::File.delete(provider.grant_dbfile_name(username)) rescue nil
- }
-
- it "calls Mixlib::Shellout with the correct command string" do
- expect_any_instance_of(Mixlib::ShellOut).to receive(:exitstatus).and_return(0)
+ it "calls win32 api to grant user SeServiceLogonRight" do
+ expect(Chef::ReservedNames::Win32::Security).to receive(:add_account_right).with(username, service_right)
expect(provider.grant_service_logon(username)).to equal true
end
- it "raises an exception when the grant command fails" do
- expect_any_instance_of(Mixlib::ShellOut).to receive(:exitstatus).and_return(1)
- expect_any_instance_of(Mixlib::ShellOut).to receive(:stdout).and_return(failure_string)
+ it "strips '.\' from user name when sending to win32 api" do
+ expect(Chef::ReservedNames::Win32::Security).to receive(:add_account_right).with(username, service_right)
+ expect(provider.grant_service_logon(".\\#{username}")).to equal true
+ end
+
+ it "raises an exception when the grant fails" do
+ expect(Chef::ReservedNames::Win32::Security).to receive(:add_account_right).and_raise(Chef::Exceptions::Win32APIError, "barf")
expect { provider.grant_service_logon(username) }.to raise_error(Chef::Exceptions::Service)
end
end
diff --git a/spec/unit/resource/chocolatey_package_spec.rb b/spec/unit/resource/chocolatey_package_spec.rb
new file mode 100644
index 0000000000..38f1d2905c
--- /dev/null
+++ b/spec/unit/resource/chocolatey_package_spec.rb
@@ -0,0 +1,67 @@
+#
+# Author:: Adam Jacob (<adam@opscode.com>)
+# Copyright:: Copyright (c) 2008-2015 Chef Software, Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+require 'spec_helper'
+
+describe Chef::Resource::ChocolateyPackage do
+
+ let(:resource) { Chef::Resource::ChocolateyPackage.new("fakey_fakerton") }
+
+ it "should create a new Chef::Resource::ChocolateyPackage" do
+ expect(resource).to be_a_kind_of(Chef::Resource)
+ expect(resource).to be_a_kind_of(Chef::Resource::Package)
+ expect(resource).to be_a_instance_of(Chef::Resource::ChocolateyPackage)
+ end
+
+ it "should have a resource name of :python" do
+ expect(resource.resource_name).to eql(:chocolatey_package)
+ end
+
+ it "should coerce its name to a package_name array" do
+ expect(resource.package_name).to eql(["fakey_fakerton"])
+ end
+
+ it "the package_name setter should coerce to arrays" do
+ resource.package_name("git")
+ expect(resource.package_name).to eql(["git"])
+ end
+
+ it "the package_name setter should accept arrays" do
+ resource.package_name(["git", "unzip"])
+ expect(resource.package_name).to eql(["git", "unzip"])
+ end
+
+ it "the name should accept arrays" do
+ resource = Chef::Resource::ChocolateyPackage.new(["git", "unzip"])
+ expect(resource.package_name).to eql(["git", "unzip"])
+ end
+
+ it "the default version should be nil" do
+ expect(resource.version).to eql(nil)
+ end
+
+ it "the version setter should coerce to arrays" do
+ resource.version("1.2.3")
+ expect(resource.version).to eql(["1.2.3"])
+ end
+
+ it "the version setter should accept arrays" do
+ resource.version(["1.2.3", "4.5.6"])
+ expect(resource.version).to eql(["1.2.3", "4.5.6"])
+ end
+end
diff --git a/spec/unit/resource/deploy_spec.rb b/spec/unit/resource/deploy_spec.rb
index 5b6a452784..2338e37173 100644
--- a/spec/unit/resource/deploy_spec.rb
+++ b/spec/unit/resource/deploy_spec.rb
@@ -31,7 +31,7 @@ describe Chef::Resource::Deploy do
class << self
def resource_has_a_string_attribute(attr_name)
- it "has a String attribute for #{attr_name.to_s}" do
+ it "has a String attribute for #{attr_name}" do
@resource.send(attr_name, "this is a string")
expect(@resource.send(attr_name)).to eql("this is a string")
expect {@resource.send(attr_name, 8675309)}.to raise_error(ArgumentError)
@@ -39,7 +39,7 @@ describe Chef::Resource::Deploy do
end
def resource_has_a_boolean_attribute(attr_name, opts={:defaults_to=>false})
- it "has a Boolean attribute for #{attr_name.to_s}" do
+ it "has a Boolean attribute for #{attr_name}" do
expect(@resource.send(attr_name)).to eql(opts[:defaults_to])
@resource.send(attr_name, !opts[:defaults_to])
expect(@resource.send(attr_name)).to eql( !opts[:defaults_to] )
diff --git a/spec/unit/resource/env_spec.rb b/spec/unit/resource/env_spec.rb
index 9bee07c593..60e85ac31e 100644
--- a/spec/unit/resource/env_spec.rb
+++ b/spec/unit/resource/env_spec.rb
@@ -39,7 +39,7 @@ describe Chef::Resource::Env do
end
{ :create => false, :delete => false, :modify => false, :flibber => true }.each do |action,bad_value|
- it "should #{bad_value ? 'not' : ''} accept #{action.to_s}" do
+ it "should #{bad_value ? 'not' : ''} accept #{action}" do
if bad_value
expect { @resource.action action }.to raise_error(ArgumentError)
else
diff --git a/spec/unit/resource/link_spec.rb b/spec/unit/resource/link_spec.rb
index 0246fcd13b..220ad735bd 100644
--- a/spec/unit/resource/link_spec.rb
+++ b/spec/unit/resource/link_spec.rb
@@ -40,7 +40,7 @@ describe Chef::Resource::Link do
end
{ :create => false, :delete => false, :blues => true }.each do |action,bad_value|
- it "should #{bad_value ? 'not' : ''} accept #{action.to_s}" do
+ it "should #{bad_value ? 'not' : ''} accept #{action}" do
if bad_value
expect { @resource.action action }.to raise_error(ArgumentError)
else
diff --git a/spec/unit/resource_reporter_spec.rb b/spec/unit/resource_reporter_spec.rb
index f2c0b8fd8b..da29cdcc02 100644
--- a/spec/unit/resource_reporter_spec.rb
+++ b/spec/unit/resource_reporter_spec.rb
@@ -36,8 +36,8 @@ describe Chef::ResourceReporter do
before do
@node = Chef::Node.new
@node.name("spitfire")
- @rest_client = double("Chef::REST (mock)")
- allow(@rest_client).to receive(:post_rest).and_return(true)
+ @rest_client = double("Chef::ServerAPI (mock)")
+ allow(@rest_client).to receive(:post).and_return(true)
@resource_reporter = Chef::ResourceReporter.new(@rest_client)
@new_resource = Chef::Resource::File.new("/tmp/a-file.txt")
@cookbook_name = "monkey"
@@ -92,9 +92,8 @@ describe Chef::ResourceReporter do
context "when chef fails" do
before do
- allow(@rest_client).to receive(:create_url).and_return("reports/nodes/spitfire/runs/#{@run_id}");
- allow(@rest_client).to receive(:raw_http_request).and_return({"result"=>"ok"});
- allow(@rest_client).to receive(:post_rest).and_return({"uri"=>"https://example.com/reports/nodes/spitfire/runs/#{@run_id}"});
+ allow(@rest_client).to receive(:raw_request).and_return({"result"=>"ok"});
+ allow(@rest_client).to receive(:post).and_return({"uri"=>"https://example.com/reports/nodes/spitfire/runs/#{@run_id}"});
end
@@ -208,7 +207,7 @@ describe Chef::ResourceReporter do
@resource_reporter.resource_completed(@implementation_resource)
@resource_reporter.resource_updated(@new_resource, :create)
@resource_reporter.resource_completed(@new_resource)
- end
+ end
it "does not collect data about the nested resource" do
expect(@resource_reporter.updated_resources.size).to eq(1)
@@ -260,9 +259,8 @@ describe Chef::ResourceReporter do
describe "when generating a report for the server" do
before do
- allow(@rest_client).to receive(:create_url).and_return("reports/nodes/spitfire/runs/#{@run_id}");
- allow(@rest_client).to receive(:raw_http_request).and_return({"result"=>"ok"});
- allow(@rest_client).to receive(:post_rest).and_return({"uri"=>"https://example.com/reports/nodes/spitfire/runs/#{@run_id}"});
+ allow(@rest_client).to receive(:raw_request).and_return({"result"=>"ok"});
+ allow(@rest_client).to receive(:post).and_return({"uri"=>"https://example.com/reports/nodes/spitfire/runs/#{@run_id}"});
@resource_reporter.run_started(@run_status)
end
@@ -592,7 +590,7 @@ describe Chef::ResourceReporter do
# 404 getting the run_id
@response = Net::HTTPNotFound.new("a response body", "404", "Not Found")
@error = Net::HTTPServerException.new("404 message", @response)
- expect(@rest_client).to receive(:post_rest).
+ expect(@rest_client).to receive(:post).
with("reports/nodes/spitfire/runs", {:action => :start, :run_id => @run_id,
:start_time => @start_time.to_s},
{'X-Ops-Reporting-Protocol-Version' => Chef::ResourceReporter::PROTOCOL_VERSION}).
@@ -606,7 +604,7 @@ describe Chef::ResourceReporter do
it "does not send a resource report to the server" do
@resource_reporter.run_started(@run_status)
- expect(@rest_client).not_to receive(:post_rest)
+ expect(@rest_client).not_to receive(:post)
@resource_reporter.run_completed(@node)
end
@@ -622,7 +620,7 @@ describe Chef::ResourceReporter do
# 500 getting the run_id
@response = Net::HTTPInternalServerError.new("a response body", "500", "Internal Server Error")
@error = Net::HTTPServerException.new("500 message", @response)
- expect(@rest_client).to receive(:post_rest).
+ expect(@rest_client).to receive(:post).
with("reports/nodes/spitfire/runs", {:action => :start, :run_id => @run_id, :start_time => @start_time.to_s},
{'X-Ops-Reporting-Protocol-Version' => Chef::ResourceReporter::PROTOCOL_VERSION}).
and_raise(@error)
@@ -635,7 +633,7 @@ describe Chef::ResourceReporter do
it "does not send a resource report to the server" do
@resource_reporter.run_started(@run_status)
- expect(@rest_client).not_to receive(:post_rest)
+ expect(@rest_client).not_to receive(:post)
@resource_reporter.run_completed(@node)
end
@@ -652,7 +650,7 @@ describe Chef::ResourceReporter do
# 500 getting the run_id
@response = Net::HTTPInternalServerError.new("a response body", "500", "Internal Server Error")
@error = Net::HTTPServerException.new("500 message", @response)
- expect(@rest_client).to receive(:post_rest).
+ expect(@rest_client).to receive(:post).
with("reports/nodes/spitfire/runs", {:action => :start, :run_id => @run_id, :start_time => @start_time.to_s},
{'X-Ops-Reporting-Protocol-Version' => Chef::ResourceReporter::PROTOCOL_VERSION}).
and_raise(@error)
@@ -673,7 +671,7 @@ describe Chef::ResourceReporter do
context "after creating the run history document" do
before do
response = {"uri"=>"https://example.com/reports/nodes/spitfire/runs/@run_id"}
- expect(@rest_client).to receive(:post_rest).
+ expect(@rest_client).to receive(:post).
with("reports/nodes/spitfire/runs", {:action => :start, :run_id => @run_id, :start_time => @start_time.to_s},
{'X-Ops-Reporting-Protocol-Version' => Chef::ResourceReporter::PROTOCOL_VERSION}).
and_return(response)
@@ -693,16 +691,10 @@ describe Chef::ResourceReporter do
allow(@resource_reporter).to receive(:end_time).and_return(@end_time)
@expected_data = @resource_reporter.prepare_run_data
- post_url = "https://chef_server/example_url"
response = {"result"=>"ok"}
- expect(@rest_client).to receive(:create_url).
- with("reports/nodes/spitfire/runs/#{@run_id}").
- ordered.
- and_return(post_url)
- expect(@rest_client).to receive(:raw_http_request).ordered do |method, url, headers, data|
+ expect(@rest_client).to receive(:raw_request).ordered do |method, url, headers, data|
expect(method).to eq(:POST)
- expect(url).to eq(post_url)
expect(headers).to eq({'Content-Encoding' => 'gzip',
'X-Ops-Reporting-Protocol-Version' => Chef::ResourceReporter::PROTOCOL_VERSION
})
@@ -720,8 +712,6 @@ describe Chef::ResourceReporter do
before do
@enable_reporting_url_fatals = Chef::Config[:enable_reporting_url_fatals]
Chef::Config[:enable_reporting_url_fatals] = true
- # this call doesn't matter for this context
- allow(@rest_client).to receive(:create_url)
end
after do
@@ -731,7 +721,7 @@ describe Chef::ResourceReporter do
it "should log 4xx errors" do
response = Net::HTTPClientError.new("forbidden", "403", "Forbidden")
error = Net::HTTPServerException.new("403 message", response)
- allow(@rest_client).to receive(:raw_http_request).and_raise(error)
+ allow(@rest_client).to receive(:raw_request).and_raise(error)
expect(Chef::Log).to receive(:error).with(/403/)
@resource_reporter.post_reporting_data
@@ -740,14 +730,14 @@ describe Chef::ResourceReporter do
it "should log error 5xx errors" do
response = Net::HTTPServerError.new("internal error", "500", "Internal Server Error")
error = Net::HTTPFatalError.new("500 message", response)
- allow(@rest_client).to receive(:raw_http_request).and_raise(error)
+ allow(@rest_client).to receive(:raw_request).and_raise(error)
expect(Chef::Log).to receive(:error).with(/500/)
@resource_reporter.post_reporting_data
end
it "should log if a socket error happens" do
- allow(@rest_client).to receive(:raw_http_request).and_raise(SocketError.new("test socket error"))
+ allow(@rest_client).to receive(:raw_request).and_raise(SocketError.new("test socket error"))
expect(Chef::Log).to receive(:error).with(/test socket error/)
@resource_reporter.post_reporting_data
@@ -755,7 +745,7 @@ describe Chef::ResourceReporter do
end
it "should raise if an unkwown error happens" do
- allow(@rest_client).to receive(:raw_http_request).and_raise(Exception.new)
+ allow(@rest_client).to receive(:raw_request).and_raise(Exception.new)
expect {
@resource_reporter.post_reporting_data
diff --git a/spec/unit/resource_spec.rb b/spec/unit/resource_spec.rb
index 59951941d7..856ec07b9e 100644
--- a/spec/unit/resource_spec.rb
+++ b/spec/unit/resource_spec.rb
@@ -743,6 +743,12 @@ describe Chef::Resource do
expect(resource.should_skip?(:purr)).to be_truthy
end
+ it "should return false when only_if is met and also not_if is not met" do
+ resource.only_if { true }
+ resource.not_if { false }
+ expect(resource.should_skip?(:purr)).to be_falsey
+ end
+
it "should return true when one of multiple only_if's is not met" do
resource.only_if { true }
resource.only_if { false }
@@ -757,6 +763,20 @@ describe Chef::Resource do
expect(resource.should_skip?(:purr)).to be_truthy
end
+ it "should return false when all of multiple only_if's are met" do
+ resource.only_if { true }
+ resource.only_if { true }
+ resource.only_if { true }
+ expect(resource.should_skip?(:purr)).to be_falsey
+ end
+
+ it "should return false when all of multiple not_if's are not met" do
+ resource.not_if { false }
+ resource.not_if { false }
+ resource.not_if { false }
+ expect(resource.should_skip?(:purr)).to be_falsey
+ end
+
it "should return true when action is :nothing" do
expect(resource.should_skip?(:nothing)).to be_truthy
end
@@ -981,14 +1001,14 @@ describe Chef::Resource do
it "when set to false should show compiled resource for failed resource" do
expect { resource_file.run_action(action) }.to raise_error { |err|
expect(compiled_resource_data(resource_file, action, err)).to match 'path "/nonexistent/CHEF-5098/file"'
- }
+ }
end
it "when set to true should show compiled resource for failed resource" do
resource_file.sensitive true
expect { resource_file.run_action(action) }.to raise_error { |err|
expect(compiled_resource_data(resource_file, action, err)).to eql("suppressed sensitive resource output")
- }
+ }
end
end
diff --git a/spec/unit/role_spec.rb b/spec/unit/role_spec.rb
index ecc7945a08..6e9b133c50 100644
--- a/spec/unit/role_spec.rb
+++ b/spec/unit/role_spec.rb
@@ -201,7 +201,7 @@ describe Chef::Role do
describe "and it has per-environment run lists" do
before do
@role.env_run_lists("_default" => ['one', 'two', 'role[a]'], "production" => ['role[monitoring]', 'role[auditing]', 'role[apache]'], "dev" => ["role[nginx]"])
- @serialized_role = Chef::JSONCompat.from_json(Chef::JSONCompat.to_json(@role), :create_additions => false)
+ @serialized_role = Chef::JSONCompat.parse(Chef::JSONCompat.to_json(@role), :create_additions => false)
end
it "includes the per-environment run lists" do
@@ -229,7 +229,7 @@ describe Chef::Role do
@role.run_list('one', 'two', 'role[a]')
@role.default_attributes({ 'el_groupo' => 'nuevo' })
@role.override_attributes({ 'deloused' => 'in the comatorium' })
- @deserial = Chef::JSONCompat.from_json(Chef::JSONCompat.to_json(@role))
+ @deserial = Chef::Role.from_hash(Chef::JSONCompat.parse(Chef::JSONCompat.to_json(@role)))
end
it "should deserialize to a Chef::Role object" do
diff --git a/spec/unit/run_list_spec.rb b/spec/unit/run_list_spec.rb
index e150579431..634b5c54cf 100644
--- a/spec/unit/run_list_spec.rb
+++ b/spec/unit/run_list_spec.rb
@@ -172,10 +172,11 @@ describe Chef::RunList do
@role.run_list "one", "two"
@role.default_attributes :one => :two
@role.override_attributes :three => :four
+ @role.env_run_list["production"] = Chef::RunList.new( "one", "two", "five")
allow(Chef::Role).to receive(:load).and_return(@role)
- @rest = double("Chef::REST", { :get_rest => @role, :url => "/" })
- allow(Chef::REST).to receive(:new).and_return(@rest)
+ @rest = double("Chef::ServerAPI", { :get => @role.to_hash, :url => "/" })
+ allow(Chef::ServerAPI).to receive(:new).and_return(@rest)
@run_list << "role[stubby]"
@run_list << "kitty"
@@ -196,21 +197,17 @@ describe Chef::RunList do
describe "from the chef server" do
it "should load the role from the chef server" do
- #@rest.should_receive(:get_rest).with("roles/stubby")
+ #@rest.should_receive(:get).with("roles/stubby")
expansion = @run_list.expand("_default", "server")
expect(expansion.recipes).to eq(['one', 'two', 'kitty'])
end
it "should default to expanding from the server" do
- expect(@rest).to receive(:get_rest).with("roles/stubby")
+ expect(@rest).to receive(:get).with("roles/stubby")
@run_list.expand("_default")
end
describe "with an environment set" do
- before do
- @role.env_run_list["production"] = Chef::RunList.new( "one", "two", "five")
- end
-
it "expands the run list using the environment specific run list" do
expansion = @run_list.expand("production", "server")
expect(expansion.recipes).to eq(%w{one two five kitty})
@@ -218,7 +215,7 @@ describe Chef::RunList do
describe "and multiply nested roles" do
before do
- @multiple_rest_requests = double("Chef::REST")
+ @multiple_rest_requests = double("Chef::ServerAPI")
@role.env_run_list["production"] << "role[prod-base]"
@@ -233,10 +230,10 @@ describe Chef::RunList do
end
it "expands the run list using the specified environment for all nested roles" do
- allow(Chef::REST).to receive(:new).and_return(@multiple_rest_requests)
- expect(@multiple_rest_requests).to receive(:get_rest).with("roles/stubby").and_return(@role)
- expect(@multiple_rest_requests).to receive(:get_rest).with("roles/prod-base").and_return(@role_prod_base)
- expect(@multiple_rest_requests).to receive(:get_rest).with("roles/nested-deeper").and_return(@role_nested_deeper)
+ allow(Chef::ServerAPI).to receive(:new).and_return(@multiple_rest_requests)
+ expect(@multiple_rest_requests).to receive(:get).with("roles/stubby").and_return(@role.to_hash)
+ expect(@multiple_rest_requests).to receive(:get).with("roles/prod-base").and_return(@role_prod_base.to_hash)
+ expect(@multiple_rest_requests).to receive(:get).with("roles/nested-deeper").and_return(@role_nested_deeper.to_hash)
expansion = @run_list.expand("production", "server")
expect(expansion.recipes).to eq(%w{one two five prod-secret-sauce kitty})
diff --git a/spec/unit/search/query_spec.rb b/spec/unit/search/query_spec.rb
index f85b1760d4..c390f658bc 100644
--- a/spec/unit/search/query_spec.rb
+++ b/spec/unit/search/query_spec.rb
@@ -20,7 +20,7 @@ require 'spec_helper'
require 'chef/search/query'
describe Chef::Search::Query do
- let(:rest) { double("Chef::REST") }
+ let(:rest) { double("Chef::ServerAPI") }
let(:query) { Chef::Search::Query.new }
shared_context "filtered search" do
@@ -76,8 +76,8 @@ describe Chef::Search::Query do
end
before(:each) do
- allow(Chef::REST).to receive(:new).and_return(rest)
- allow(rest).to receive(:get_rest).and_return(response)
+ allow(Chef::ServerAPI).to receive(:new).and_return(rest)
+ allow(rest).to receive(:get).and_return(response)
end
describe "search" do
@@ -91,6 +91,7 @@ describe Chef::Search::Query do
{ "name" => "my-name-is-node",
"chef_environment" => "elysium",
"platform" => "rhel",
+ "run_list" => [],
"automatic" => {
"languages" => {
"ruby" => {
@@ -104,6 +105,7 @@ describe Chef::Search::Query do
{ "name" => "my-name-is-jonas",
"chef_environment" => "hades",
"platform" => "rhel",
+ "run_list" => [],
"automatic" => {
"languages" => {
"ruby" => {
@@ -117,6 +119,7 @@ describe Chef::Search::Query do
{ "name" => "my-name-is-flipper",
"chef_environment" => "elysium",
"platform" => "rhel",
+ "run_list" => [],
"automatic" => {
"languages" => {
"ruby" => {
@@ -130,6 +133,7 @@ describe Chef::Search::Query do
{ "name" => "my-name-is-butters",
"chef_environment" => "moon",
"platform" => "rhel",
+ "run_list" => [],
"automatic" => {
"languages" => {
"ruby" => {
@@ -173,27 +177,27 @@ describe Chef::Search::Query do
end
it "queries for every object of a type by default" do
- expect(rest).to receive(:get_rest).with("search/node?q=*:*&sort=X_CHEF_id_CHEF_X%20asc&start=0").and_return(response)
+ expect(rest).to receive(:get).with("search/node?q=*:*&sort=X_CHEF_id_CHEF_X%20asc&start=0").and_return(response)
query.search(:node)
end
it "allows a custom query" do
- expect(rest).to receive(:get_rest).with("search/node?q=platform:rhel&sort=X_CHEF_id_CHEF_X%20asc&start=0").and_return(response)
+ expect(rest).to receive(:get).with("search/node?q=platform:rhel&sort=X_CHEF_id_CHEF_X%20asc&start=0").and_return(response)
query.search(:node, "platform:rhel")
end
it "lets you set a sort order" do
- expect(rest).to receive(:get_rest).with("search/node?q=platform:rhel&sort=id%20desc&start=0").and_return(response)
+ expect(rest).to receive(:get).with("search/node?q=platform:rhel&sort=id%20desc&start=0").and_return(response)
query.search(:node, "platform:rhel", sort: "id desc")
end
it "lets you set a starting object" do
- expect(rest).to receive(:get_rest).with("search/node?q=platform:rhel&sort=X_CHEF_id_CHEF_X%20asc&start=2").and_return(response)
+ expect(rest).to receive(:get).with("search/node?q=platform:rhel&sort=X_CHEF_id_CHEF_X%20asc&start=2").and_return(response)
query.search(:node, "platform:rhel", start: 2)
end
it "lets you set how many rows to return" do
- expect(rest).to receive(:get_rest).with("search/node?q=platform:rhel&sort=X_CHEF_id_CHEF_X%20asc&start=0&rows=40").and_return(response)
+ expect(rest).to receive(:get).with("search/node?q=platform:rhel&sort=X_CHEF_id_CHEF_X%20asc&start=0&rows=40").and_return(response)
query.search(:node, "platform:rhel", rows: 40)
end
@@ -211,27 +215,27 @@ describe Chef::Search::Query do
it "calls a block for each object in the response" do
@call_me = double("blocky")
- response["rows"].each { |r| expect(@call_me).to receive(:do).with(r) }
+ response["rows"].each { |r| expect(@call_me).to receive(:do).with(Chef::Node.from_hash(r)) }
query.search(:node) { |r| @call_me.do(r) }
end
it "pages through the responses" do
@call_me = double("blocky")
- response["rows"].each { |r| expect(@call_me).to receive(:do).with(r) }
+ response["rows"].each { |r| expect(@call_me).to receive(:do).with(Chef::Node.from_hash(r)) }
query.search(:node, "*:*", sort: nil, start: 0, rows: 4) { |r| @call_me.do(r) }
end
it "sends multiple API requests when the server indicates there is more data" do
- expect(rest).to receive(:get_rest).with(query_string).and_return(big_response)
- expect(rest).to receive(:get_rest).with(query_string_continue).and_return(big_response_end)
+ expect(rest).to receive(:get).with(query_string).and_return(big_response)
+ expect(rest).to receive(:get).with(query_string_continue).and_return(big_response_end)
query.search(:node, "platform:rhel") do |r|
nil
end
end
it "paginates correctly in the face of filtered nodes" do
- expect(rest).to receive(:get_rest).with(query_string_with_rows).and_return(big_response_empty)
- expect(rest).to receive(:get_rest).with(query_string_continue_with_rows).and_return(big_response_end)
+ expect(rest).to receive(:get).with(query_string_with_rows).and_return(big_response_empty)
+ expect(rest).to receive(:get).with(query_string_continue_with_rows).and_return(big_response_end)
query.search(:node, "platform:rhel", rows: 4) do |r|
nil
end
@@ -242,7 +246,7 @@ describe Chef::Search::Query do
let(:filter_key) { :filter_result }
before(:each) do
- expect(rest).to receive(:post_rest).with(query_string, args[filter_key]).and_return(response)
+ expect(rest).to receive(:post).with(query_string, args[filter_key]).and_return(response)
end
it "returns start" do
@@ -276,7 +280,7 @@ describe Chef::Search::Query do
end
it "returns an array of filtered hashes" do
- expect(rest).to receive(:post_rest).with(query_string, args[filter_key]).and_return(response)
+ expect(rest).to receive(:post).with(query_string, args[filter_key]).and_return(response)
results = query.partial_search(:node, "platform:rhel", args)
expect(results[0]).to match_array(response_rows)
end
diff --git a/spec/unit/shell/shell_session_spec.rb b/spec/unit/shell/shell_session_spec.rb
index d72e3fa1bb..d1cedb3236 100644
--- a/spec/unit/shell/shell_session_spec.rb
+++ b/spec/unit/shell/shell_session_spec.rb
@@ -50,7 +50,7 @@ end
describe Shell::ClientSession do
before do
Chef::Config[:shell_config] = { :override_runlist => [Chef::RunList::RunListItem.new('shell::override')] }
- @chef_rest = double("Chef::REST")
+ @chef_rest = double("Chef::ServerAPI")
@session = Shell::ClientSession.instance
@node = Chef::Node.build("foo")
@session.node = @node
@@ -67,7 +67,7 @@ describe Shell::ClientSession do
@expansion = Chef::RunList::RunListExpansion.new(@node.chef_environment, [])
expect(@node.run_list).to receive(:expand).with(@node.chef_environment).and_return(@expansion)
- expect(Chef::REST).to receive(:new).with(Chef::Config[:chef_server_url]).and_return(@chef_rest)
+ expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url]).and_return(@chef_rest)
@session.rebuild_context
end
diff --git a/spec/unit/user_v1_spec.rb b/spec/unit/user_v1_spec.rb
index 8fd370a010..a981de1d8c 100644
--- a/spec/unit/user_v1_spec.rb
+++ b/spec/unit/user_v1_spec.rb
@@ -539,8 +539,8 @@ describe Chef::UserV1 do
before (:each) do
@user = Chef::UserV1.new
@user.username "foobar"
- @http_client = double("Chef::REST mock")
- allow(Chef::REST).to receive(:new).and_return(@http_client)
+ @http_client = double("Chef::ServerAPI mock")
+ allow(Chef::ServerAPI).to receive(:new).and_return(@http_client)
end
describe "list" do
diff --git a/tasks/external_tests.rb b/tasks/external_tests.rb
index 305088646c..69c0712a12 100644
--- a/tasks/external_tests.rb
+++ b/tasks/external_tests.rb
@@ -51,7 +51,8 @@ EXTERNAL_PROJECTS = {
"chefspec" => "rake",
"chef-rewind" => "rake spec",
"poise" => "rake spec",
- "halite" => "rake spec"
+ "halite" => "rake spec",
+ "knife-windows" => "rake unit_spec"
}
task :external_specs => EXTERNAL_PROJECTS.keys.map { |g| :"#{g.sub("-","_")}_spec" }