summaryrefslogtreecommitdiff
path: root/lib/chef
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chef')
-rw-r--r--lib/chef/api_client.rb3
-rw-r--r--lib/chef/application.rb1
-rw-r--r--lib/chef/application/apply.rb1
-rw-r--r--lib/chef/application/client.rb7
-rw-r--r--lib/chef/chef_fs/chef_fs_data_store.rb26
-rw-r--r--lib/chef/chef_fs/config.rb34
-rw-r--r--lib/chef/chef_fs/data_handler/data_handler_base.rb2
-rw-r--r--lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb2
-rw-r--r--lib/chef/chef_fs/file_system/chef_server/rest_list_entry.rb2
-rw-r--r--lib/chef/cookbook/metadata.rb1
-rw-r--r--lib/chef/cookbook_version.rb1
-rw-r--r--lib/chef/data_bag.rb1
-rw-r--r--lib/chef/data_bag_item.rb1
-rw-r--r--lib/chef/environment.rb4
-rw-r--r--lib/chef/formatters/doc.rb1
-rw-r--r--lib/chef/formatters/minimal.rb3
-rw-r--r--lib/chef/http/authenticator.rb13
-rw-r--r--lib/chef/key.rb5
-rw-r--r--lib/chef/knife.rb1
-rw-r--r--lib/chef/knife/bootstrap.rb5
-rw-r--r--lib/chef/knife/core/bootstrap_context.rb4
-rw-r--r--lib/chef/knife/core/object_loader.rb2
-rw-r--r--lib/chef/local_mode.rb2
-rw-r--r--lib/chef/node.rb1
-rw-r--r--lib/chef/org.rb5
-rw-r--r--lib/chef/property.rb3
-rw-r--r--lib/chef/provider/package/zypper.rb95
-rw-r--r--lib/chef/rest.rb2
-rw-r--r--lib/chef/role.rb1
-rw-r--r--lib/chef/server_api.rb6
-rw-r--r--lib/chef/user.rb5
-rw-r--r--lib/chef/user_v1.rb5
32 files changed, 178 insertions, 67 deletions
diff --git a/lib/chef/api_client.rb b/lib/chef/api_client.rb
index 9def6199b7..cea9dd8176 100644
--- a/lib/chef/api_client.rb
+++ b/lib/chef/api_client.rb
@@ -141,6 +141,7 @@ class Chef
end
def self.json_create(data)
+ Chef.log_deprecation("Auto inflation of JSON data is deprecated. Please use Chef::ApiClient#from_hash")
from_hash(data)
end
@@ -176,7 +177,7 @@ class Chef
if response.kind_of?(Chef::ApiClient)
response
else
- json_create(response)
+ from_hash(response)
end
end
diff --git a/lib/chef/application.rb b/lib/chef/application.rb
index 4562d84a5d..a4d4fc209d 100644
--- a/lib/chef/application.rb
+++ b/lib/chef/application.rb
@@ -84,6 +84,7 @@ class Chef
parse_options
load_config_file
Chef::Config.export_proxies
+ Chef::Config.init_openssl
end
# Parse the config file
diff --git a/lib/chef/application/apply.rb b/lib/chef/application/apply.rb
index f6348a951b..42b2d5fc9a 100644
--- a/lib/chef/application/apply.rb
+++ b/lib/chef/application/apply.rb
@@ -125,6 +125,7 @@ class Chef::Application::Apply < Chef::Application
Chef::Config.merge!(config)
configure_logging
Chef::Config.export_proxies
+ Chef::Config.init_openssl
parse_json
end
diff --git a/lib/chef/application/client.rb b/lib/chef/application/client.rb
index ba357b420d..5b124b60a7 100644
--- a/lib/chef/application/client.rb
+++ b/lib/chef/application/client.rb
@@ -274,6 +274,11 @@ class Chef::Application::Client < Chef::Application
:description => "Whether a local mode (-z) server binds to a port",
:boolean => true
+ option :fips,
+ :long => "--fips",
+ :description => "Enable fips mode",
+ :boolean => true
+
IMMEDIATE_RUN_SIGNAL = "1".freeze
attr_reader :chef_client_json
@@ -287,6 +292,8 @@ class Chef::Application::Client < Chef::Application
set_specific_recipes
+ Chef::Config[:fips] = config[:fips] if config.has_key? :fips
+
Chef::Config[:chef_server_url] = config[:chef_server_url] if config.has_key? :chef_server_url
Chef::Config.local_mode = config[:local_mode] if config.has_key?(:local_mode)
diff --git a/lib/chef/chef_fs/chef_fs_data_store.rb b/lib/chef/chef_fs/chef_fs_data_store.rb
index 634faaec7e..59c2699cca 100644
--- a/lib/chef/chef_fs/chef_fs_data_store.rb
+++ b/lib/chef/chef_fs/chef_fs_data_store.rb
@@ -126,6 +126,24 @@ class Chef
# - `delete(association_requests/NAME)` -> `get(/invitations.json)`, remove name, `set(/invitations.json)`
#
class ChefFSDataStore
+
+ # The base directories in a Chef Repo; even when these don't exist, a
+ # matching GET for these objects will return an empty list instead of a
+ # 404.
+ BASE_DIRNAMES = %w{
+ clients
+ cookbooks
+ data
+ environments
+ nodes
+ roles
+ users
+ containers
+ groups
+ policy_groups
+ policies
+ }.freeze
+
#
# Create a new ChefFSDataStore
#
@@ -469,7 +487,11 @@ class Chef
# LIST /policies
elsif path == [ "policies" ]
with_entry([ path[0] ]) do |policies|
- policies.children.map { |policy| policy.name[0..-6].rpartition("-")[0] }.uniq
+ begin
+ policies.children.map { |policy| policy.name[0..-6].rpartition("-")[0] }.uniq
+ rescue Chef::ChefFS::FileSystem::NotFoundError
+ []
+ end
end
# LIST /policies/POLICY/revisions
@@ -741,7 +763,7 @@ class Chef
end
def path_always_exists?(path)
- return path.length == 1 && %w{clients cookbooks data environments nodes roles users}.include?(path[0])
+ return path.length == 1 && BASE_DIRNAMES.include?(path[0])
end
def with_entry(path)
diff --git a/lib/chef/chef_fs/config.rb b/lib/chef/chef_fs/config.rb
index 07c014e2ab..a376c42cc5 100644
--- a/lib/chef/chef_fs/config.rb
+++ b/lib/chef/chef_fs/config.rb
@@ -47,6 +47,34 @@ class Chef
INFLECTIONS.each { |k,v| k.freeze; v.freeze }
INFLECTIONS.freeze
+ # ChefFS supports three modes of operation: "static", "everything", and
+ # "hosted_everything". These names are antiquated since Chef 12 moved
+ # multi-tenant and RBAC to the open source product. In practice, they
+ # mean:
+ #
+ # * static: just static objects that are included in a traditional
+ # chef-repo, with no support for anything introduced in Chef 12 or
+ # later.
+ # * everything: all of the objects supported by the open source Chef
+ # Server 11.x
+ # * hosted_everything: (the name comes from Hosted Chef) supports
+ # everything in Chef Server 12 and later, including RBAC objects and
+ # Policyfile objects.
+ #
+ # The "static" and "everything" modes are used for backup and
+ # upgrade/migration of older Chef Servers, so they should be considered
+ # frozen in time.
+
+ CHEF_11_OSS_STATIC_OBJECTS = %w{cookbooks cookbook_artifacts data_bags environments roles}.freeze
+ CHEF_11_OSS_DYNAMIC_OBJECTS = %w{clients nodes users}.freeze
+ RBAC_OBJECT_NAMES = %w{acls containers groups }.freeze
+ CHEF_12_OBJECTS = %w{ cookbook_artifacts policies policy_groups }.freeze
+
+ STATIC_MODE_OBJECT_NAMES = CHEF_11_OSS_STATIC_OBJECTS
+ EVERYTHING_MODE_OBJECT_NAMES = (CHEF_11_OSS_STATIC_OBJECTS + CHEF_11_OSS_DYNAMIC_OBJECTS).freeze
+ HOSTED_EVERYTHING_MODE_OBJECT_NAMES = (EVERYTHING_MODE_OBJECT_NAMES + RBAC_OBJECT_NAMES + CHEF_12_OBJECTS).freeze
+
+
#
# Create a new Config object which can produce a chef_fs and local_fs.
#
@@ -234,11 +262,11 @@ class Chef
result = {}
case @chef_config[:repo_mode]
when "static"
- object_names = %w{cookbooks data_bags environments roles}
+ object_names = STATIC_MODE_OBJECT_NAMES
when "hosted_everything"
- object_names = %w{acls clients cookbooks cookbook_artifacts containers data_bags environments groups nodes roles policies policy_groups}
+ object_names = HOSTED_EVERYTHING_MODE_OBJECT_NAMES
else
- object_names = %w{clients cookbooks data_bags environments nodes roles users}
+ object_names = EVERYTHING_MODE_OBJECT_NAMES
end
object_names.each do |object_name|
# cookbooks -> cookbook_path
diff --git a/lib/chef/chef_fs/data_handler/data_handler_base.rb b/lib/chef/chef_fs/data_handler/data_handler_base.rb
index 53936979e3..41c5dd13e2 100644
--- a/lib/chef/chef_fs/data_handler/data_handler_base.rb
+++ b/lib/chef/chef_fs/data_handler/data_handler_base.rb
@@ -117,7 +117,7 @@ class Chef
# Turn a JSON hash into a bona fide Chef object (like Chef::Node).
#
def chef_object(object)
- chef_class.json_create(object)
+ chef_class.from_hash(object)
end
#
diff --git a/lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb b/lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb
index 18bf748d87..fb3c185145 100644
--- a/lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb
+++ b/lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb
@@ -188,7 +188,7 @@ class Chef
old_retry_count = Chef::Config[:http_retry_count]
begin
Chef::Config[:http_retry_count] = 0
- @chef_object ||= Chef::CookbookVersion.json_create(root.get_json(api_path))
+ @chef_object ||= Chef::CookbookVersion.from_hash(root.get_json(api_path))
ensure
Chef::Config[:http_retry_count] = old_retry_count
end
diff --git a/lib/chef/chef_fs/file_system/chef_server/rest_list_entry.rb b/lib/chef/chef_fs/file_system/chef_server/rest_list_entry.rb
index 692b6cfc73..cfc9e43955 100644
--- a/lib/chef/chef_fs/file_system/chef_server/rest_list_entry.rb
+++ b/lib/chef/chef_fs/file_system/chef_server/rest_list_entry.rb
@@ -102,7 +102,7 @@ class Chef
def chef_object
# REST will inflate the Chef object using json_class
- data_handler.json_class.json_create(read)
+ data_handler.json_class.from_hash(read)
end
def minimize_value(value)
diff --git a/lib/chef/cookbook/metadata.rb b/lib/chef/cookbook/metadata.rb
index 530254eead..bdba94d4f0 100644
--- a/lib/chef/cookbook/metadata.rb
+++ b/lib/chef/cookbook/metadata.rb
@@ -25,6 +25,7 @@ require "chef/mixin/params_validate"
require "chef/log"
require "chef/version_class"
require "chef/version_constraint"
+require "chef/version_constraint/platform"
require "chef/json_compat"
class Chef
diff --git a/lib/chef/cookbook_version.rb b/lib/chef/cookbook_version.rb
index 28f817c8ba..19150464ba 100644
--- a/lib/chef/cookbook_version.rb
+++ b/lib/chef/cookbook_version.rb
@@ -476,6 +476,7 @@ class Chef
end
def self.json_create(o)
+ Chef.log_deprecation("Auto inflation of JSON data is deprecated. Please use Chef::CookbookVersion#from_hash")
from_hash(o)
end
diff --git a/lib/chef/data_bag.rb b/lib/chef/data_bag.rb
index 66771d325f..38b3d4fdf5 100644
--- a/lib/chef/data_bag.rb
+++ b/lib/chef/data_bag.rb
@@ -80,6 +80,7 @@ class Chef
# Create a Chef::Role from JSON
def self.json_create(o)
+ Chef.log_deprecation("Auto inflation of JSON data is deprecated. Please use Chef::DataBag#from_hash")
from_hash(o)
end
diff --git a/lib/chef/data_bag_item.rb b/lib/chef/data_bag_item.rb
index 8688693568..facf6c89f4 100644
--- a/lib/chef/data_bag_item.rb
+++ b/lib/chef/data_bag_item.rb
@@ -142,6 +142,7 @@ class Chef
# Create a Chef::DataBagItem from JSON
def self.json_create(o)
+ Chef.log_deprecation("Auto inflation of JSON data is deprecated. Please use Chef::DataBagItem#from_hash")
from_hash(o)
end
diff --git a/lib/chef/environment.rb b/lib/chef/environment.rb
index e41f2b66ac..042cde5bd5 100644
--- a/lib/chef/environment.rb
+++ b/lib/chef/environment.rb
@@ -217,6 +217,7 @@ class Chef
end
def self.json_create(o)
+ Chef.log_deprecation("Auto inflation of JSON data is deprecated. Please use Chef::Environment#from_hash")
from_hash(o)
end
@@ -260,7 +261,8 @@ class Chef
if File.exists?(js_file)
# from_json returns object.class => json_class in the JSON.
- Chef::JSONCompat.from_json(IO.read(js_file))
+ hash = Chef::JSONCompat.parse(IO.read(js_file))
+ from_hash(hash)
elsif File.exists?(rb_file)
environment = Chef::Environment.new
environment.name(name)
diff --git a/lib/chef/formatters/doc.rb b/lib/chef/formatters/doc.rb
index 5510956754..ab450cdeac 100644
--- a/lib/chef/formatters/doc.rb
+++ b/lib/chef/formatters/doc.rb
@@ -43,6 +43,7 @@ class Chef
def run_start(version)
puts_line "Starting Chef Client, version #{version}"
+ puts_line "OpenSSL FIPS 140 mode enabled" if Chef::Config[:fips]
end
def total_resources
diff --git a/lib/chef/formatters/minimal.rb b/lib/chef/formatters/minimal.rb
index 2e32968b4b..94fbfd3818 100644
--- a/lib/chef/formatters/minimal.rb
+++ b/lib/chef/formatters/minimal.rb
@@ -29,7 +29,8 @@ class Chef
# Called at the very start of a Chef Run
def run_start(version)
- puts "Starting Chef Client, version #{version}"
+ puts_line "Starting Chef Client, version #{version}"
+ puts_line "OpenSSL FIPS 140 mode enabled" if Chef::Config[:fips]
end
# Called at the end of the Chef run.
diff --git a/lib/chef/http/authenticator.rb b/lib/chef/http/authenticator.rb
index 02074171f8..ab4804c964 100644
--- a/lib/chef/http/authenticator.rb
+++ b/lib/chef/http/authenticator.rb
@@ -47,8 +47,8 @@ class Chef
end
def handle_request(method, url, headers={}, data=false)
- headers.merge!(authentication_headers(method, url, data)) if sign_requests?
headers.merge!({"X-Ops-Server-API-Version" => @api_version})
+ headers.merge!(authentication_headers(method, url, data, headers)) if sign_requests?
[method, url, headers, data]
end
@@ -90,12 +90,17 @@ class Chef
raise Chef::Exceptions::InvalidPrivateKey, msg
end
- def authentication_headers(method, url, json_body=nil)
- request_params = {:http_method => method, :path => url.path, :body => json_body, :host => "#{url.host}:#{url.port}"}
+ def authentication_headers(method, url, json_body=nil, headers=nil)
+ request_params = {
+ :http_method => method,
+ :path => url.path,
+ :body => json_body,
+ :host => "#{url.host}:#{url.port}",
+ :headers => headers,
+ }
request_params[:body] ||= ""
auth_credentials.signature_headers(request_params)
end
-
end
end
end
diff --git a/lib/chef/key.rb b/lib/chef/key.rb
index ba5613e35e..141a444d57 100644
--- a/lib/chef/key.rb
+++ b/lib/chef/key.rb
@@ -222,8 +222,9 @@ class Chef
Chef::Key.from_hash(Chef::JSONCompat.from_json(json))
end
- class << self
- alias_method :json_create, :from_json
+ def self.json_create(json)
+ Chef.log_deprecation("Auto inflation of JSON data is deprecated. Please use Chef::Key#from_json or one of the load_by methods.")
+ Chef::Key.from_json(json)
end
def self.list_by_user(actor, inflate=false)
diff --git a/lib/chef/knife.rb b/lib/chef/knife.rb
index a070c6c858..5cfcc7182a 100644
--- a/lib/chef/knife.rb
+++ b/lib/chef/knife.rb
@@ -398,6 +398,7 @@ class Chef
merge_configs
apply_computed_config
Chef::Config.export_proxies
+ Chef::Config.init_openssl
# This has to be after apply_computed_config so that Mixlib::Log is configured
Chef::Log.info("Using configuration from #{config[:config_file]}") if config[:config_file]
end
diff --git a/lib/chef/knife/bootstrap.rb b/lib/chef/knife/bootstrap.rb
index 23ec98e563..4db6c22f2e 100644
--- a/lib/chef/knife/bootstrap.rb
+++ b/lib/chef/knife/bootstrap.rb
@@ -250,6 +250,11 @@ class Chef
Chef::Config[:knife][:bootstrap_vault_item]
}
+ option :fips,
+ :long => "--fips",
+ :description => "Set openssl to run in fips mode",
+ :boolean => true
+
def initialize(argv=[])
super
@client_builder = Chef::Knife::Bootstrap::ClientBuilder.new(
diff --git a/lib/chef/knife/core/bootstrap_context.rb b/lib/chef/knife/core/bootstrap_context.rb
index b0a759dd05..46ade9f00f 100644
--- a/lib/chef/knife/core/bootstrap_context.rb
+++ b/lib/chef/knife/core/bootstrap_context.rb
@@ -120,6 +120,10 @@ validation_client_name "#{@chef_config[:validation_client_name]}"
client_rb << %Q{trusted_certs_dir "/etc/chef/trusted_certs"\n}
end
+ if @config[:fips]
+ client_rb << %Q{fips true\n}
+ end
+
client_rb
end
diff --git a/lib/chef/knife/core/object_loader.rb b/lib/chef/knife/core/object_loader.rb
index 69c2428bd4..063c192728 100644
--- a/lib/chef/knife/core/object_loader.rb
+++ b/lib/chef/knife/core/object_loader.rb
@@ -93,7 +93,7 @@ class Chef
if @klass == Chef::DataBagItem
r
else
- @klass.json_create(r)
+ @klass.from_hash(r)
end
when /\.rb$/
r = klass.new
diff --git a/lib/chef/local_mode.rb b/lib/chef/local_mode.rb
index 53234ec7d5..82d9cdee32 100644
--- a/lib/chef/local_mode.rb
+++ b/lib/chef/local_mode.rb
@@ -65,6 +65,8 @@ class Chef
server_options = {}
server_options[:data_store] = data_store
server_options[:log_level] = Chef::Log.level
+ server_options[:osc_compat] = Chef::Config.chef_zero.osc_compat
+ server_options[:single_org] = Chef::Config.chef_zero.single_org
server_options[:host] = Chef::Config.chef_zero.host
server_options[:port] = parse_port(Chef::Config.chef_zero.port)
diff --git a/lib/chef/node.rb b/lib/chef/node.rb
index d7b0bf5948..b9ef200e91 100644
--- a/lib/chef/node.rb
+++ b/lib/chef/node.rb
@@ -532,6 +532,7 @@ class Chef
# Create a Chef::Node from JSON
def self.json_create(o)
+ Chef.log_deprecation("Auto inflation of JSON data is deprecated. Please use Chef::Node#from_hash")
from_hash(o)
end
diff --git a/lib/chef/org.rb b/lib/chef/org.rb
index 33a986dc3b..434113e315 100644
--- a/lib/chef/org.rb
+++ b/lib/chef/org.rb
@@ -124,8 +124,9 @@ class Chef
Chef::Org.from_hash(Chef::JSONCompat.from_json(json))
end
- class <<self
- alias_method :json_create, :from_json
+ def self.json_create(json)
+ Chef.log_deprecation("Auto inflation of JSON data is deprecated. Please use Chef::Org#from_json or Chef::Org#load.")
+ Chef::Org.from_json(json)
end
def self.load(org_name)
diff --git a/lib/chef/property.rb b/lib/chef/property.rb
index 8ff4ecc7fc..8b5c6560a9 100644
--- a/lib/chef/property.rb
+++ b/lib/chef/property.rb
@@ -320,7 +320,8 @@ class Chef
resource.resource_initializing &&
resource.respond_to?(:enclosing_provider) &&
resource.enclosing_provider &&
- resource.enclosing_provider.respond_to?(name)
+ resource.enclosing_provider.new_resource &&
+ resource.enclosing_provider.new_resource.respond_to?(name)
Chef::Log.warn("#{Chef::Log.caller_location}: property #{name} is declared in both #{resource} and #{resource.enclosing_provider}. Use new_resource.#{name} instead. At #{Chef::Log.caller_location}")
end
diff --git a/lib/chef/provider/package/zypper.rb b/lib/chef/provider/package/zypper.rb
index 9b0aaf322a..fe8358c654 100644
--- a/lib/chef/provider/package/zypper.rb
+++ b/lib/chef/provider/package/zypper.rb
@@ -2,7 +2,7 @@
#
# Authors:: Adam Jacob (<adam@opscode.com>)
# Ionuț Arțăriși (<iartarisi@suse.cz>)
-# Copyright:: Copyright (c) 2008 Opscode, Inc.
+# Copyright:: Copyright (c) 2008-2015 Chef Software, Inc.
# Copyright (c) 2013 SUSE Linux GmbH
# License:: Apache License, Version 2.0
#
@@ -20,70 +20,74 @@
#
require "chef/provider/package"
-require "chef/mixin/command"
-require "chef/resource/package"
-require "singleton"
+require "chef/resource/zypper_package"
class Chef
class Provider
class Package
class Zypper < Chef::Provider::Package
+ use_multipackage_api
provides :package, platform_family: "suse"
provides :zypper_package, os: "linux"
- def load_current_resource
- @current_resource = Chef::Resource::ZypperPackage.new(new_resource.name)
- current_resource.package_name(new_resource.package_name)
-
- is_installed=false
- is_out_of_date=false
- version=""
- oud_version=""
+ def get_versions(package_name)
+ candidate_version = current_version = nil
+ is_installed = false
Chef::Log.debug("#{new_resource} checking zypper")
- status = shell_out_with_timeout("zypper --non-interactive info #{new_resource.package_name}")
+ status = shell_out_with_timeout!("zypper --non-interactive info #{package_name}")
status.stdout.each_line do |line|
case line
when /^Version: (.+)$/
- version = $1
+ candidate_version = $1
Chef::Log.debug("#{new_resource} version #{$1}")
when /^Installed: Yes$/
is_installed=true
Chef::Log.debug("#{new_resource} is installed")
-
- when /^Installed: No$/
- is_installed=false
- Chef::Log.debug("#{new_resource} is not installed")
when /^Status: out-of-date \(version (.+) installed\)$/
- is_out_of_date=true
- oud_version=$1
+ current_version=$1
Chef::Log.debug("#{new_resource} out of date version #{$1}")
end
end
+ current_version = candidate_version if is_installed
+ { current_version: current_version, candidate_version: candidate_version }
+ end
- if is_installed==false
- @candidate_version=version
- end
-
- if is_installed==true
- if is_out_of_date==true
- current_resource.version(oud_version)
- @candidate_version=version
- else
- current_resource.version(version)
- @candidate_version=version
+ def versions
+ @versions =
+ begin
+ raw_versions = package_name_array.map do |package_name|
+ get_versions(package_name)
+ end
+ Hash[*package_name_array.zip(raw_versions).flatten]
end
+ end
+
+ def get_candidate_versions
+ package_name_array.map do |package_name|
+ versions[package_name][:candidate_version]
end
+ end
- unless status.exitstatus == 0
- raise Chef::Exceptions::Package, "zypper failed - #{status.inspect}!"
+ def get_current_versions
+ package_name_array.map do |package_name|
+ versions[package_name][:current_version]
end
+ end
+
+ def load_current_resource
+ @current_resource = Chef::Resource::ZypperPackage.new(new_resource.name)
+ current_resource.package_name(new_resource.package_name)
+
+ @candidate_version = get_candidate_versions
+ current_resource.version(get_current_versions)
current_resource
end
- def zypper_version()
- `zypper -V 2>&1`.scan(/\d+/).join(".").to_f
+ def zypper_version
+ @zypper_version ||=
+ `zypper -V 2>&1`.scan(/\d+/).join(".").to_f
end
def install_package(name, version)
@@ -91,6 +95,7 @@ class Chef
end
def upgrade_package(name, version)
+ # `zypper install` upgrades packages, we rely on the idempotency checks to get action :install behavior
install_package(name, version)
end
@@ -103,13 +108,19 @@ class Chef
end
private
- def zypper_package(command, pkgname, version)
- version = "=#{version}" unless version.nil? || version.empty?
+
+ def zip(names, versions)
+ names.zip(versions).map do |n, v|
+ (v.nil? || v.empty?) ? n : "#{n}=#{v}"
+ end
+ end
+
+ def zypper_package(command, names, versions)
+ zipped_names = zip(names, versions)
if zypper_version < 1.0
- shell_out_with_timeout!("zypper#{gpg_checks} #{command} -y #{pkgname}")
+ shell_out_with_timeout!(a_to_s("zypper", gpg_checks, command, "-y", names))
else
- shell_out_with_timeout!("zypper --non-interactive#{gpg_checks} "+
- "#{command} #{pkgname}#{version}")
+ shell_out_with_timeout!(a_to_s("zypper --non-interactive", gpg_checks, command, zipped_names))
end
end
@@ -118,12 +129,12 @@ class Chef
when true
""
when false
- " --no-gpg-checks"
+ "--no-gpg-checks"
when nil
Chef::Log.warn("Chef::Config[:zypper_check_gpg] was not set. " +
"All packages will be installed without gpg signature checks. " +
"This is a security hazard.")
- " --no-gpg-checks"
+ "--no-gpg-checks"
end
end
end
diff --git a/lib/chef/rest.rb b/lib/chef/rest.rb
index 96a563e034..73cd0d68a9 100644
--- a/lib/chef/rest.rb
+++ b/lib/chef/rest.rb
@@ -59,6 +59,8 @@ class Chef
# HTTP GET request to http://localhost:4000/nodes
def initialize(url, client_name=Chef::Config[:node_name], signing_key_filename=Chef::Config[:client_key], options={})
+ Chef.log_deprecation("Chef::REST is deprecated. Please use Chef::ServerAPI, or investigate Ridley or ChefAPI.")
+
signing_key_filename = nil if chef_zero_uri?(url)
options = options.dup
diff --git a/lib/chef/role.rb b/lib/chef/role.rb
index fa76129af2..d607a1be98 100644
--- a/lib/chef/role.rb
+++ b/lib/chef/role.rb
@@ -171,6 +171,7 @@ class Chef
# Create a Chef::Role from JSON
def self.json_create(o)
+ Chef.log_deprecation("Auto inflation of JSON data is deprecated. Please use Chef::Role#from_hash")
from_hash(o)
end
diff --git a/lib/chef/server_api.rb b/lib/chef/server_api.rb
index b7e460fa6e..35f81f88b2 100644
--- a/lib/chef/server_api.rb
+++ b/lib/chef/server_api.rb
@@ -48,6 +48,12 @@ class Chef
# responses.
use Chef::HTTP::ValidateContentLength
+ # for back compat with Chef::REST, expose `<verb>_rest` as an alias to `<verb>`
+ alias :get_rest :get
+ alias :delete_rest :delete
+ alias :post_rest :post
+ alias :put_rest :put
+
# 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.
diff --git a/lib/chef/user.rb b/lib/chef/user.rb
index 37a104a537..bcbce76bf2 100644
--- a/lib/chef/user.rb
+++ b/lib/chef/user.rb
@@ -154,8 +154,9 @@ class Chef
Chef::User.from_hash(Chef::JSONCompat.from_json(json))
end
- class << self
- alias_method :json_create, :from_json
+ def self.json_create(json)
+ Chef.log_deprecation("Auto inflation of JSON data is deprecated. Please use Chef::User#from_json or Chef::User#load.")
+ Chef::User.from_json(json)
end
def self.list(inflate=false)
diff --git a/lib/chef/user_v1.rb b/lib/chef/user_v1.rb
index 133087a089..bb594e3564 100644
--- a/lib/chef/user_v1.rb
+++ b/lib/chef/user_v1.rb
@@ -276,8 +276,9 @@ class Chef
Chef::UserV1.from_hash(Chef::JSONCompat.from_json(json))
end
- class << self
- alias_method :json_create, :from_json
+ def self.json_create(json)
+ Chef.log_deprecation("Auto inflation of JSON data is deprecated. Please use Chef::UserV1#from_json or Chef::UserV1#load.")
+ Chef::UserV1.from_json(json)
end
def self.list(inflate=false)