summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/chef.rb3
-rw-r--r--lib/chef/application/solo.rb1
-rw-r--r--lib/chef/chef_fs/file_system/chef_server/rest_list_entry.rb15
-rw-r--r--lib/chef/client.rb11
-rw-r--r--lib/chef/constants.rb2
-rw-r--r--lib/chef/dsl/method_missing.rb75
-rw-r--r--lib/chef/dsl/recipe.rb5
-rw-r--r--lib/chef/dsl/resources.rb6
-rw-r--r--lib/chef/knife/search.rb7
-rw-r--r--lib/chef/mixin/params_validate.rb11
-rw-r--r--lib/chef/node/attribute.rb12
-rw-r--r--lib/chef/node/immutable_collections.rb10
-rw-r--r--lib/chef/node/mixin/immutablize_array.rb2
-rw-r--r--lib/chef/node/mixin/immutablize_hash.rb2
-rw-r--r--lib/chef/node_map.rb7
-rw-r--r--lib/chef/platform/provider_mapping.rb169
-rw-r--r--lib/chef/property.rb120
-rw-r--r--lib/chef/provider.rb15
-rw-r--r--lib/chef/provider/service/solaris.rb6
-rw-r--r--lib/chef/provider_resolver.rb7
-rw-r--r--lib/chef/recipe.rb10
-rw-r--r--lib/chef/resource.rb9
-rw-r--r--lib/chef/resource/service.rb10
-rw-r--r--lib/chef/rest.rb210
-rw-r--r--lib/chef/run_context.rb23
-rw-r--r--lib/chef/search/query.rb17
-rw-r--r--lib/chef/shell.rb37
-rw-r--r--lib/chef/shell/shell_session.rb16
-rw-r--r--lib/chef/shell_out.rb13
-rw-r--r--lib/chef/tasks/chef_repo.rake200
-rw-r--r--lib/chef/util/windows/net_user.rb2
-rw-r--r--lib/chef/version.rb2
-rw-r--r--lib/chef/win32/security/sid.rb5
33 files changed, 164 insertions, 876 deletions
diff --git a/lib/chef.rb b/lib/chef.rb
index 3e161dc365..3d6b783253 100644
--- a/lib/chef.rb
+++ b/lib/chef.rb
@@ -1,6 +1,6 @@
#
# Author:: Adam Jacob (<adam@chef.io>)
-# Copyright:: Copyright 2008-2016, Chef Software Inc.
+# Copyright:: Copyright 2008-2017, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -24,7 +24,6 @@ require "chef/log"
require "chef/config"
require "chef/providers"
require "chef/resources"
-require "chef/shell_out"
require "chef/daemon"
diff --git a/lib/chef/application/solo.rb b/lib/chef/application/solo.rb
index 1481338a9c..2705a930ae 100644
--- a/lib/chef/application/solo.rb
+++ b/lib/chef/application/solo.rb
@@ -23,7 +23,6 @@ require "chef/client"
require "chef/config"
require "chef/daemon"
require "chef/log"
-require "chef/rest"
require "chef/config_fetcher"
require "fileutils"
require "chef/mixin/shell_out"
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 8f9e554526..c16c5ad4d7 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
@@ -30,6 +30,7 @@ class Chef
def initialize(name, parent, exists = nil)
super(name, parent)
@exists = exists
+ @this_object_cache = nil
end
def data_handler
@@ -69,7 +70,7 @@ class Chef
def exists?
if @exists.nil?
begin
- rest.get(api_path)
+ @this_object_cache = rest.get(api_path)
@exists = true
rescue Net::HTTPServerException => e
if e.response.code == "404"
@@ -85,6 +86,8 @@ class Chef
end
def delete(recurse)
+ # free up cache - it will be hydrated on next check for exists?
+ @this_object_cache = nil
rest.delete(api_path)
rescue Timeout::Error => e
raise Chef::ChefFS::FileSystem::OperationFailedError.new(:delete, self, e, "Timeout deleting: #{e}")
@@ -97,12 +100,12 @@ class Chef
end
def read
+ # Minimize the value (get rid of defaults) so the results don't look terrible
Chef::JSONCompat.to_json_pretty(minimize_value(_read_json))
end
def _read_json
- # Minimize the value (get rid of defaults) so the results don't look terrible
- root.get_json(api_path)
+ @this_object_cache ? JSON.parse(@this_object_cache) : root.get_json(api_path)
rescue Timeout::Error => e
raise Chef::ChefFS::FileSystem::OperationFailedError.new(:read, self, e, "Timeout reading: #{e}")
rescue Net::HTTPServerException => e
@@ -151,6 +154,9 @@ class Chef
other_value = minimize_value(other_value)
other_value_json = Chef::JSONCompat.to_json_pretty(other_value)
+ # free up cache - it will be hydrated on next check for exists?
+ @this_object_cache = nil
+
[ value == other_value, value_json, other_value_json ]
end
@@ -159,6 +165,9 @@ class Chef
end
def write(file_contents)
+ # free up cache - it will be hydrated on next check for exists?
+ @this_object_cache = nil
+
begin
object = Chef::JSONCompat.parse(file_contents)
rescue Chef::Exceptions::JSON::ParseError => e
diff --git a/lib/chef/client.rb b/lib/chef/client.rb
index c064d33209..b219fdfdd6 100644
--- a/lib/chef/client.rb
+++ b/lib/chef/client.rb
@@ -3,7 +3,7 @@
# Author:: Christopher Walters (<cw@chef.io>)
# Author:: Christopher Brown (<cb@chef.io>)
# Author:: Tim Hinderliter (<tim@chef.io>)
-# Copyright:: Copyright 2008-2016, Chef Software, Inc.
+# Copyright:: Copyright 2008-2017, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -894,15 +894,6 @@ class Chef
#
STDERR_FD = STDERR
- #
- # Deprecated writers
- #
-
- include Chef::Mixin::Deprecation
- deprecated_attr_writer :ohai, "There is no alternative. Leave ohai alone!"
- deprecated_attr_writer :rest, "There is no alternative. Leave rest alone!"
- deprecated_attr :runner, "There is no alternative. Leave runner alone!"
-
private
attr_reader :override_runlist
diff --git a/lib/chef/constants.rb b/lib/chef/constants.rb
index f32c3e6654..d75b632173 100644
--- a/lib/chef/constants.rb
+++ b/lib/chef/constants.rb
@@ -1,6 +1,6 @@
#
# Author:: John Keiser <jkeiser@chef.io>
-# Copyright:: Copyright 2015-2016, Chef Software Inc.
+# Copyright:: Copyright 2015-2017, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/lib/chef/dsl/method_missing.rb b/lib/chef/dsl/method_missing.rb
deleted file mode 100644
index 2917a54ee8..0000000000
--- a/lib/chef/dsl/method_missing.rb
+++ /dev/null
@@ -1,75 +0,0 @@
-#--
-# Copyright:: Copyright 2008-2016 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.
-#
-
-class Chef
- module DSL
- # @deprecated scheduled to die in a Chef 13 fire
- module MethodMissing
- def describe_self_for_error
- if respond_to?(:name)
- %Q{`#{self.class} "#{name}"'}
- elsif respond_to?(:recipe_name)
- %Q{`#{self.class} "#{recipe_name}"'}
- else
- to_s
- end
- end
-
- # DEPRECATED:
- # method_missing must live for backcompat purposes until Chef 13.
- def method_missing(method_symbol, *args, &block)
- #
- # If there is already DSL for this, someone must have called
- # method_missing manually. Not a fan. Not. A. Fan.
- #
- if respond_to?(method_symbol)
- Chef.deprecated(:internal_api, "Calling method_missing(#{method_symbol.inspect}) directly is deprecated in Chef 12 and will be removed in Chef 13. Use public_send() or send() instead.")
- return send(method_symbol, *args, &block)
- end
-
- #
- # If a definition exists, then Chef::DSL::Definitions.add_definition was
- # never called. DEPRECATED.
- #
- if run_context.definitions.has_key?(method_symbol.to_sym)
- Chef.deprecated(:internal_api, "Definition #{method_symbol} (#{run_context.definitions[method_symbol.to_sym]}) was added to the run_context without calling Chef::DSL::Definitions.add_definition(#{method_symbol.to_sym.inspect}). This will become required in Chef 13.")
- Chef::DSL::Definitions.add_definition(method_symbol)
- return send(method_symbol, *args, &block)
- end
-
- #
- # See if the resource exists anyway. If the user had set
- # Chef::Resource::Blah = <resource>, a deprecation warning will be
- # emitted and the DSL method 'blah' will be added to the DSL.
- #
- resource_class = Chef::ResourceResolver.resolve(method_symbol, node: run_context ? run_context.node : nil)
- if resource_class
- Chef::DSL::Resources.add_resource_dsl(method_symbol)
- return send(method_symbol, *args, &block)
- end
-
- begin
- super
- rescue NoMethodError
- raise NoMethodError, "No resource or method named `#{method_symbol}' for #{describe_self_for_error}"
- rescue NameError
- raise NameError, "No resource, method, or local variable named `#{method_symbol}' for #{describe_self_for_error}"
- end
- end
- end
- end
-end
diff --git a/lib/chef/dsl/recipe.rb b/lib/chef/dsl/recipe.rb
index e2bd070179..dedf291857 100644
--- a/lib/chef/dsl/recipe.rb
+++ b/lib/chef/dsl/recipe.rb
@@ -1,7 +1,7 @@
#--
# Author:: Adam Jacob (<adam@chef.io>)
# Author:: Christopher Walters (<cw@chef.io>)
-# Copyright:: Copyright 2008-2016 Chef Software, Inc.
+# Copyright:: Copyright 2008-2017, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -27,7 +27,6 @@ require "chef/dsl/reboot_pending"
require "chef/dsl/audit"
require "chef/dsl/powershell"
require "chef/dsl/core"
-require "chef/dsl/method_missing"
require "chef/mixin/lazy_module_include"
class Chef
@@ -60,8 +59,6 @@ class Chef
include Chef::DSL::Powershell
include Chef::DSL::Resources
include Chef::DSL::Definitions
- # method_missing will disappear in Chef 13
- include Chef::DSL::MethodMissing
extend Chef::Mixin::LazyModuleInclude
def resource_class_for(snake_case_name)
diff --git a/lib/chef/dsl/resources.rb b/lib/chef/dsl/resources.rb
index 8a4e7968f2..36ec018500 100644
--- a/lib/chef/dsl/resources.rb
+++ b/lib/chef/dsl/resources.rb
@@ -39,12 +39,6 @@ class Chef
declare_resource(#{dsl_name.inspect}, args[0], created_at: caller[0], &block)
end
EOM
- rescue SyntaxError
- # Handle the case where dsl_name has spaces, etc.
- define_method(dsl_name.to_sym) do |*args, &block|
- Chef.deprecated(:internal_api, "Cannot create resource #{dsl_name} with more than one argument. All arguments except the name (#{args[0].inspect}) will be ignored. This will cause an error in Chef 13. Arguments: #{args}") if args.size > 1
- declare_resource(dsl_name, args[0], created_at: caller[0], &block)
- end
end
def self.remove_resource_dsl(dsl_name)
diff --git a/lib/chef/knife/search.rb b/lib/chef/knife/search.rb
index 046d1c7c52..7fc76b28c0 100644
--- a/lib/chef/knife/search.rb
+++ b/lib/chef/knife/search.rb
@@ -37,12 +37,6 @@ class Chef
banner "knife search INDEX QUERY (options)"
- option :sort,
- :short => "-o SORT",
- :long => "--sort SORT",
- :description => "The order to sort the results in",
- :default => nil
-
option :start,
:short => "-b ROW",
:long => "--start ROW",
@@ -92,7 +86,6 @@ class Chef
result_count = 0
search_args = Hash.new
- search_args[:sort] = config[:sort] if config[:sort]
search_args[:start] = config[:start] if config[:start]
search_args[:rows] = config[:rows] if config[:rows]
if config[:filter_result]
diff --git a/lib/chef/mixin/params_validate.rb b/lib/chef/mixin/params_validate.rb
index 0db058c3ab..d90e38b916 100644
--- a/lib/chef/mixin/params_validate.rb
+++ b/lib/chef/mixin/params_validate.rb
@@ -1,6 +1,6 @@
#
# Author:: Adam Jacob (<adam@chef.io>)
-# Copyright:: Copyright 2008-2016, Chef Software Inc.
+# Copyright:: Copyright 2008-2017, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -18,6 +18,7 @@
require "chef/constants"
require "chef/property"
require "chef/delayed_evaluator"
+require "chef/exceptions"
class Chef
module Mixin
@@ -332,7 +333,7 @@ class Chef
def _pv_name_property(opts, key, is_name_property = true)
if is_name_property
if opts[key].nil?
- raise CannotValidateStaticallyError, "name_property cannot be evaluated without a resource." if self == Chef::Mixin::ParamsValidate
+ raise Exceptions::CannotValidateStaticallyError, "name_property cannot be evaluated without a resource." if self == Chef::Mixin::ParamsValidate
opts[key] = instance_variable_get(:"@name")
end
end
@@ -404,7 +405,7 @@ class Chef
passed = to_be.any? do |tb|
case tb
when Proc
- raise CannotValidateStaticallyError, "is: proc { } must be evaluated once for each resource" if self == Chef::Mixin::ParamsValidate
+ raise Exceptions::CannotValidateStaticallyError, "is: proc { } must be evaluated once for each resource" if self == Chef::Mixin::ParamsValidate
instance_exec(value, &tb)
when Property
begin
@@ -448,10 +449,10 @@ class Chef
#
def _pv_coerce(opts, key, coercer)
if opts.has_key?(key.to_s)
- raise CannotValidateStaticallyError, "coerce must be evaluated for each resource." if self == Chef::Mixin::ParamsValidate
+ raise Exceptions::CannotValidateStaticallyError, "coerce must be evaluated for each resource." if self == Chef::Mixin::ParamsValidate
opts[key.to_s] = instance_exec(opts[key], &coercer)
elsif opts.has_key?(key.to_sym)
- raise CannotValidateStaticallyError, "coerce must be evaluated for each resource." if self == Chef::Mixin::ParamsValidate
+ raise Exceptions::CannotValidateStaticallyError, "coerce must be evaluated for each resource." if self == Chef::Mixin::ParamsValidate
opts[key.to_sym] = instance_exec(opts[key], &coercer)
end
end
diff --git a/lib/chef/node/attribute.rb b/lib/chef/node/attribute.rb
index 761694e010..57d1b0a4d3 100644
--- a/lib/chef/node/attribute.rb
+++ b/lib/chef/node/attribute.rb
@@ -216,16 +216,12 @@ class Chef
# that precedence level, +value+ will be the symbol +:not_present+.
def debug_value(*args)
COMPONENTS.map do |component|
- ivar = instance_variable_get(component)
- value = args.inject(ivar) do |so_far, key|
- if so_far == :not_present
- :not_present
- elsif so_far.has_key?(key)
- so_far[key]
- else
+ value =
+ begin
+ instance_variable_get(component).read!(*args)
+ rescue
:not_present
end
- end
[component.to_s.sub(/^@/, ""), value]
end
end
diff --git a/lib/chef/node/immutable_collections.rb b/lib/chef/node/immutable_collections.rb
index 13a8aefe97..be9285a755 100644
--- a/lib/chef/node/immutable_collections.rb
+++ b/lib/chef/node/immutable_collections.rb
@@ -22,8 +22,14 @@ require "chef/node/mixin/immutablize_hash"
class Chef
class Node
-
module Immutablize
+ # For elements like Fixnums, true, nil...
+ def safe_dup(e)
+ e.dup
+ rescue TypeError
+ e
+ end
+
def immutablize(value)
case value
when Hash
@@ -31,7 +37,7 @@ class Chef
when Array
ImmutableArray.new(value, __root__, __node__, __precedence__)
else
- value
+ safe_dup(value).freeze
end
end
end
diff --git a/lib/chef/node/mixin/immutablize_array.rb b/lib/chef/node/mixin/immutablize_array.rb
index cfa7266b9a..bd330cf8a9 100644
--- a/lib/chef/node/mixin/immutablize_array.rb
+++ b/lib/chef/node/mixin/immutablize_array.rb
@@ -1,5 +1,5 @@
#--
-# Copyright:: Copyright 2016, Chef Software, Inc.
+# Copyright:: Copyright 2016-2017, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/lib/chef/node/mixin/immutablize_hash.rb b/lib/chef/node/mixin/immutablize_hash.rb
index f09e6944fc..f6b22ed7d7 100644
--- a/lib/chef/node/mixin/immutablize_hash.rb
+++ b/lib/chef/node/mixin/immutablize_hash.rb
@@ -1,5 +1,5 @@
#--
-# Copyright:: Copyright 2016, Chef Software, Inc.
+# Copyright:: Copyright 2016-2017, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/lib/chef/node_map.rb b/lib/chef/node_map.rb
index 552c90b8d1..7a1a09ae24 100644
--- a/lib/chef/node_map.rb
+++ b/lib/chef/node_map.rb
@@ -1,6 +1,6 @@
#
# Author:: Lamont Granquist (<lamont@chef.io>)
-# Copyright:: Copyright 2014-2016, Chef Software, Inc.
+# Copyright:: Copyright 2014-2017, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -31,10 +31,7 @@ class Chef
#
# @return [NodeMap] Returns self for possible chaining
#
- def set(key, value, platform: nil, platform_version: nil, platform_family: nil, os: nil, on_platform: nil, on_platforms: nil, canonical: nil, override: nil, &block)
- Chef.deprecated(:internal_api, "The on_platform option to node_map has been deprecated") if on_platform
- Chef.deprecated(:internal_api, "The on_platforms option to node_map has been deprecated") if on_platforms
- platform ||= on_platform || on_platforms
+ def set(key, value, platform: nil, platform_version: nil, platform_family: nil, os: nil, canonical: nil, override: nil, &block)
filters = {}
filters[:platform] = platform if platform
filters[:platform_version] = platform_version if platform_version
diff --git a/lib/chef/platform/provider_mapping.rb b/lib/chef/platform/provider_mapping.rb
index 55e831c343..5dbe0bdab4 100644
--- a/lib/chef/platform/provider_mapping.rb
+++ b/lib/chef/platform/provider_mapping.rb
@@ -1,6 +1,6 @@
#
# Author:: Adam Jacob (<adam@chef.io>)
-# Copyright:: Copyright 2008-2016, Chef Software Inc.
+# Copyright:: Copyright 2008-2017, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -26,45 +26,6 @@ class Chef
class Platform
class << self
- attr_writer :platforms
-
- def platforms
- @platforms ||= { default: {} }
- end
-
- include Chef::Mixin::ParamsValidate
-
- def find(name, version)
- Chef.deprecated(:chef_platform_methods, "#{self.name}.find is deprecated")
- provider_map = platforms[:default].clone
-
- name_sym = name
- if name.kind_of?(String)
- name = name.downcase
- name.gsub!(/\s/, "_")
- name_sym = name.to_sym
- end
-
- if platforms.has_key?(name_sym)
- platform_versions = platforms[name_sym].select { |k, v| k != :default }
- if platforms[name_sym].has_key?(:default)
- provider_map.merge!(platforms[name_sym][:default])
- end
- platform_versions.each do |platform_version, provider|
- begin
- version_constraint = Chef::VersionConstraint::Platform.new(platform_version)
- if version_constraint.include?(version)
- Chef::Log.debug("Platform #{name} version #{version} found")
- provider_map.merge!(provider)
- end
- rescue Chef::Exceptions::InvalidPlatformVersion
- Chef::Log.debug("Chef::Version::Comparable does not know how to parse the platform version: #{version}")
- end
- end
- end
- provider_map
- end
-
def find_platform_and_version(node)
platform = nil
version = nil
@@ -89,134 +50,6 @@ class Chef
[platform, version]
end
-
- def provider_for_resource(resource, action = :nothing)
- Chef.deprecated(:chef_platform_methods, "#{name}.provider_for_resource is deprecated")
- node = resource.run_context && resource.run_context.node
- raise ArgumentError, "Cannot find the provider for a resource with no run context set" unless node
- provider = find_provider_for_node(node, resource).new(resource, resource.run_context)
- provider.action = action
- provider
- end
-
- def provider_for_node(node, resource_type)
- raise NotImplementedError, "#{name} no longer supports #provider_for_node"
- end
-
- def find_provider_for_node(node, resource_type)
- Chef.deprecated(:chef_platform_methods, "#{name}.find_provider_for_node is deprecated")
- platform, version = find_platform_and_version(node)
- find_provider(platform, version, resource_type)
- end
-
- def set(args)
- Chef.deprecated(:chef_platform_methods, "#{name}.set is deprecated")
- validate(
- args,
- {
- :platform => {
- :kind_of => Symbol,
- :required => false,
- },
- :version => {
- :kind_of => String,
- :required => false,
- },
- :resource => {
- :kind_of => Symbol,
- },
- :provider => {
- :kind_of => [ String, Symbol, Class ],
- },
- }
- )
- if args.has_key?(:platform)
- if args.has_key?(:version)
- if platforms.has_key?(args[:platform])
- if platforms[args[:platform]].has_key?(args[:version])
- platforms[args[:platform]][args[:version]][args[:resource].to_sym] = args[:provider]
- else
- platforms[args[:platform]][args[:version]] = {
- args[:resource].to_sym => args[:provider],
- }
- end
- else
- platforms[args[:platform]] = {
- args[:version] => {
- args[:resource].to_sym => args[:provider],
- },
- }
- end
- else
- if platforms.has_key?(args[:platform])
- if platforms[args[:platform]].has_key?(:default)
- platforms[args[:platform]][:default][args[:resource].to_sym] = args[:provider]
- elsif args[:platform] == :default
- platforms[:default][args[:resource].to_sym] = args[:provider]
- else
- platforms[args[:platform]] = { :default => { args[:resource].to_sym => args[:provider] } }
- end
- else
- platforms[args[:platform]] = {
- :default => {
- args[:resource].to_sym => args[:provider],
- },
- }
- end
- end
- else
- if platforms.has_key?(:default)
- platforms[:default][args[:resource].to_sym] = args[:provider]
- else
- platforms[:default] = {
- args[:resource].to_sym => args[:provider],
- }
- end
- end
- end
-
- def find_provider(platform, version, resource_type)
- Chef.deprecated(:chef_platform_methods, "#{name}.find_provider is deprecated")
- provider_klass = explicit_provider(platform, version, resource_type) ||
- platform_provider(platform, version, resource_type) ||
- resource_matching_provider(platform, version, resource_type)
-
- raise Chef::Exceptions::ProviderNotFound, "Cannot find a provider for #{resource_type} on #{platform} version #{version}" if provider_klass.nil?
-
- provider_klass
- end
-
- private
-
- def explicit_provider(platform, version, resource_type)
- resource_type.kind_of?(Chef::Resource) ? resource_type.provider : nil
- end
-
- def platform_provider(platform, version, resource_type)
- pmap = Chef::Platform.find(platform, version)
- rtkey = resource_type.kind_of?(Chef::Resource) ? resource_type.resource_name.to_sym : resource_type
- pmap.has_key?(rtkey) ? pmap[rtkey] : nil
- end
-
- include Chef::Mixin::ConvertToClassName
-
- def resource_matching_provider(platform, version, resource_type)
- if resource_type.kind_of?(Chef::Resource)
- class_name = if resource_type.class.name
- resource_type.class.name.split("::").last
- else
- convert_to_class_name(resource_type.resource_name.to_s)
- end
-
- if Chef::Provider.const_defined?(class_name, false)
- Chef::Log.warn("Class Chef::Provider::#{class_name} does not declare 'provides #{convert_to_snake_case(class_name).to_sym.inspect}'.")
- Chef::Log.warn("This will no longer work in Chef 13: you must use 'provides' to use the resource's DSL.")
- return Chef::Provider.const_get(class_name, false)
- end
- end
- nil
- end
-
end
end
end
diff --git a/lib/chef/property.rb b/lib/chef/property.rb
index ac226bc815..c6f72e15a7 100644
--- a/lib/chef/property.rb
+++ b/lib/chef/property.rb
@@ -74,7 +74,7 @@ class Chef
# return `true` if the property is set *or* if `name` is set.
# @option options [Boolean] :nillable `true` opt-in to Chef-13 style behavior where
# attempting to set a nil value will really set a nil value instead of issuing
- # a warning and operating like a getter
+ # a warning and operating like a getter [DEPRECATED]
# @option options [Object] :default The value this property
# will return if the user does not set one. If this is `lazy`, it will
# be run in the context of the instance (and able to access other
@@ -264,32 +264,8 @@ class Chef
#
def call(resource, value = NOT_PASSED)
if value == NOT_PASSED
- return get(resource)
- end
-
- if value.nil? && !nillable?
- # In Chef 12, value(nil) does a *get* instead of a set, so we
- # warn if the value would have been changed. In Chef 13, it will be
- # equivalent to value = nil.
- result = get(resource, nil_set: true)
-
- # Warn about this becoming a set in Chef 13.
- begin
- input_to_stored_value(resource, value)
- # If nil is valid, and it would change the value, warn that this will change to a set.
- if !result.nil?
- Chef.deprecated(:custom_resource, "An attempt was made to change #{name} from #{result.inspect} to nil by calling #{name}(nil). In Chef 12, this does a get rather than a set. In Chef 13, this will change to set the value to nil.")
- end
- rescue Chef::Exceptions::DeprecatedFeatureError
- raise
- rescue
- # If nil is invalid, warn that this will become an error.
- Chef.deprecated(:custom_resource, "nil is an invalid value for #{self}. In Chef 13, this warning will change to an error. Error: #{$!}")
- end
-
- result
+ get(resource)
else
- # Anything else, such as myprop(value) is a set
set(resource, value)
end
end
@@ -318,10 +294,11 @@ class Chef
#
def get(resource, nil_set: false)
# If it's set, return it (and evaluate any lazy values)
+ value = nil
+
if is_set?(resource)
value = get_value(resource)
value = stored_value_to_output(resource, value)
-
else
# We are getting the default value.
@@ -366,13 +343,14 @@ class Chef
if !value.frozen? && !value.nil?
set_value(resource, value)
end
-
- value
-
- elsif required?
- raise Chef::Exceptions::ValidationFailed, "#{name} is required"
end
end
+
+ if value.nil? && required?
+ raise Chef::Exceptions::ValidationFailed, "#{name} is required"
+ else
+ value
+ end
end
#
@@ -391,7 +369,13 @@ class Chef
# this property.
#
def set(resource, value)
- set_value(resource, input_to_stored_value(resource, value))
+ value = set_value(resource, input_to_stored_value(resource, value))
+
+ if value.nil? && required?
+ raise Chef::Exceptions::ValidationFailed, "#{name} is required"
+ else
+ value
+ end
end
#
@@ -444,8 +428,8 @@ class Chef
#
def coerce(resource, value)
if options.has_key?(:coerce)
- # If we have no default value, `nil` is never coerced or validated
- unless !has_default? && value.nil?
+ # nil is never coerced
+ unless value.nil?
value = exec_in_resource(resource, options[:coerce], value)
end
end
@@ -466,8 +450,8 @@ class Chef
# this property.
#
def validate(resource, value)
- # If we have no default value, `nil` is never coerced or validated
- unless value.nil? && !has_default?
+ # nils are not validated unless we have an explicit default value
+ if !value.nil? || has_default?
if resource
resource.validate({ name => value }, { name => validation_options })
else
@@ -509,12 +493,15 @@ class Chef
# be using the existing getter/setter to manipulate it instead.
return if !instance_variable_name
- # We deprecate any attempt to create a property that already exists as a
- # method in some Classes that we know would cause our users problems.
- # For example, creating a `hash` property could cause issues when adding
- # a Chef::Resource instance to an data structure that expects to be able
- # to call the `#hash` method and get back an appropriate Fixnum.
- emit_property_redefinition_deprecations
+ # Properties may override existing properties up the inheritance heirarchy, but
+ # properties must not override inherited methods like Object#hash. When the Resource is
+ # placed into the resource collection the ruby Hash object will call the
+ # Object#hash method on the resource, and overriding that with a property will cause
+ # very confusing results.
+ if property_redefines_method?
+ resource_name = declared_in.respond_to?(:resource_name) ? declared_in.resource_name : declared_in
+ raise ArgumentError, "Property `#{name}` of resource `#{resource_name}` overwrites an existing method."
+ end
# We prefer this form because the property name won't show up in the
# stack trace if you use `define_method`.
@@ -528,16 +515,6 @@ class Chef
self.class.properties[#{name.inspect}].set(self, value)
end
EOM
- rescue SyntaxError
- # If the name is not a valid ruby name, we use define_method.
- declared_in.define_method(name) do |value = NOT_PASSED, &block|
- raise "Property `#{name}` of `#{self}` was incorrectly passed a block! Possible property-resource collision. To call a resource named `#{name}` either rename the property or else use `declare_resource(:#{name}, ...)`" if block
- self.class.properties[name].call(self, value)
- end
- declared_in.define_method("#{name}=") do |value, &block|
- raise "Property `#{name}` of `#{self}` was incorrectly passed a block! Possible property-resource collision. To call a resource named `#{name}` either rename the property or else use `declare_resource(:#{name}, ...)`" if block
- self.class.properties[name].set(self, value)
- end
end
#
@@ -630,28 +607,23 @@ class Chef
private
- def emit_property_redefinition_deprecations
+ def property_redefines_method?
# We only emit deprecations if this property already exists as an instance method.
# Weeding out class methods avoids unnecessary deprecations such Chef::Resource
# defining a `name` property when there's an already-existing `name` method
# for a Module.
- return unless declared_in.instance_methods.include?(name)
+ return false unless declared_in.instance_methods.include?(name)
# Only emit deprecations for some well-known classes. This will still
# allow more advanced users to subclass their own custom resources and
# override their own properties.
- return unless [ Object, BasicObject, Kernel, Chef::Resource ].include?(declared_in.instance_method(name).owner)
+ return false unless [ Object, BasicObject, Kernel, Chef::Resource ].include?(declared_in.instance_method(name).owner)
# Allow top-level Chef::Resource proprties, such as `name`, to be overridden.
# As of this writing, `name` is the only Chef::Resource property created with the
# `property` definition, but this will allow for future properties to be extended
# as needed.
- return if Chef::Resource.properties.keys.include?(name)
-
- # Emit the deprecation.
- resource_name = declared_in.respond_to?(:resource_name) ? declared_in.resource_name : declared_in
- Chef.deprecated(:property_name_collision, "Property `#{name}` of resource `#{resource_name}` overwrites an existing method. " \
- "Please use a different property name. This will raise an exception in Chef 13.")
+ !Chef::Resource.properties.keys.include?(name)
end
def exec_in_resource(resource, proc, *args)
@@ -688,31 +660,9 @@ class Chef
# valid.
def coerce_and_validate(resource, value, is_default: false)
result = coerce(resource, value)
- begin
- # If the input is from a default, we need to emit an invalid default warning on validate.
- validate(resource, result)
- rescue Chef::Exceptions::CannotValidateStaticallyError
- # This one gets re-raised
- raise
- rescue
- # Anything else is just an invalid default: in those cases, we just
- # warn and return the (possibly coerced) value to the user.
- if is_default
- if value.nil?
- Chef.deprecated(:custom_resource, "Default value nil is invalid for property #{self}. Possible fixes: 1. Remove 'default: nil' if nil means 'undefined'. 2. Set a valid default value if there is a reasonable one. 3. Allow nil as a valid value of your property (for example, 'property #{name.inspect}, [ String, nil ], default: nil'). Error: #{$!}")
- else
- Chef.deprecated(:custom_resource, "Default value #{value.inspect} is invalid for property #{self}. In Chef 13 this will become an error: #{$!}.")
- end
- else
- raise
- end
- end
+ validate(resource, result)
result
end
-
- def nillable?
- !!options[:nillable]
- end
end
end
diff --git a/lib/chef/provider.rb b/lib/chef/provider.rb
index 0ec441202c..bdc1114f0d 100644
--- a/lib/chef/provider.rb
+++ b/lib/chef/provider.rb
@@ -379,16 +379,11 @@ class Chef
def action(name, &block)
# We need the block directly in a method so that `super` works
define_method("compile_action_#{name}", &block)
- # We try hard to use `def` because define_method doesn't show the method name in the stack.
- begin
- class_eval <<-EOM
- def action_#{name}
- compile_and_converge_action { compile_action_#{name} }
- end
- EOM
- rescue SyntaxError
- define_method("action_#{name}") { send("compile_action_#{name}") }
- end
+ class_eval <<-EOM
+ def action_#{name}
+ compile_and_converge_action { compile_action_#{name} }
+ end
+ EOM
end
end
end
diff --git a/lib/chef/provider/service/solaris.rb b/lib/chef/provider/service/solaris.rb
index f7f8eaf31b..c560bed011 100644
--- a/lib/chef/provider/service/solaris.rb
+++ b/lib/chef/provider/service/solaris.rb
@@ -56,11 +56,13 @@ class Chef
def enable_service
shell_out!(default_init_command, "clear", @new_resource.service_name) if @maintenance
- shell_out!(default_init_command, "enable", "-s", @new_resource.service_name)
+ enable_flags = [ "-s", @new_resource.options ].flatten.compact
+ shell_out!(default_init_command, "enable", *enable_flags, @new_resource.service_name)
end
def disable_service
- shell_out!(default_init_command, "disable", "-s", @new_resource.service_name)
+ disable_flags = [ "-s", @new_resource.options ].flatten.compact
+ shell_out!(default_init_command, "disable", *disable_flags, @new_resource.service_name)
end
alias_method :stop_service, :disable_service
diff --git a/lib/chef/provider_resolver.rb b/lib/chef/provider_resolver.rb
index 2eb4d72ba5..439a7e9f5f 100644
--- a/lib/chef/provider_resolver.rb
+++ b/lib/chef/provider_resolver.rb
@@ -59,7 +59,7 @@ class Chef
def resolve
maybe_explicit_provider(resource) ||
maybe_dynamic_provider_resolution(resource, action) ||
- maybe_chef_platform_lookup(resource)
+ raise(Chef::Exceptions::ProviderNotFound, "Cannot find a provider for #{resource} on #{node["platform"]} version #{node["platform_version"]}")
end
# Does NOT call provides? on the resource (it is assumed this is being
@@ -126,11 +126,6 @@ class Chef
handler
end
- # try the old static lookup of providers by platform
- def maybe_chef_platform_lookup(resource)
- Chef::Platform.find_provider_for_node(node, resource)
- end
-
def priority_map
Chef.provider_priority_map
end
diff --git a/lib/chef/recipe.rb b/lib/chef/recipe.rb
index 77d82f83ab..967703b629 100644
--- a/lib/chef/recipe.rb
+++ b/lib/chef/recipe.rb
@@ -1,7 +1,7 @@
#--
# Author:: Adam Jacob (<adam@chef.io>)
# Author:: Christopher Walters (<cw@chef.io>)
-# Copyright:: Copyright 2008-2016, Chef Software Inc.
+# Copyright:: Copyright 2008-2017, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -104,5 +104,13 @@ class Chef
run_context.node.tags.delete(tag)
end
end
+
+ def to_s
+ "cookbook: #{cookbook_name ? cookbook_name : "(none)"}, recipe: #{recipe_name ? recipe_name : "(none)"} "
+ end
+
+ def inspect
+ to_s
+ end
end
end
diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb
index f8cea08076..b0e3a372e8 100644
--- a/lib/chef/resource.rb
+++ b/lib/chef/resource.rb
@@ -504,15 +504,6 @@ class Chef
end
#
- # Since there are collisions with LWRP parameters named 'state' this
- # method is not used by the resource_reporter and is most likely unused.
- # It certainly cannot be relied upon and cannot be fixed.
- #
- # @deprecated
- #
- alias_method :state, :state_for_resource_reporter
-
- #
# The value of the identity of this resource.
#
# - If there are no identity properties on the resource, `name` is returned.
diff --git a/lib/chef/resource/service.rb b/lib/chef/resource/service.rb
index d9f0969ecb..0231964fdf 100644
--- a/lib/chef/resource/service.rb
+++ b/lib/chef/resource/service.rb
@@ -18,6 +18,7 @@
#
require "chef/resource"
+require "shellwords"
class Chef
class Resource
@@ -40,6 +41,7 @@ class Chef
@enabled = nil
@running = nil
@masked = nil
+ @options = nil
@parameters = nil
@pattern = service_name
@start_command = nil
@@ -155,6 +157,14 @@ class Chef
)
end
+ def options(arg = nil)
+ set_or_return(
+ :options,
+ arg.respond_to?(:split) ? arg.shellsplit : arg,
+ :kind_of => [ Array, String ]
+ )
+ end
+
# Priority arguments can have two forms:
#
# - a simple number, in which the default start runlevels get
diff --git a/lib/chef/rest.rb b/lib/chef/rest.rb
deleted file mode 100644
index 0705ca9f5a..0000000000
--- a/lib/chef/rest.rb
+++ /dev/null
@@ -1,210 +0,0 @@
-#--
-# Author:: Adam Jacob (<adam@chef.io>)
-# Author:: Thom May (<thom@clearairturbulence.org>)
-# Author:: Nuo Yan (<nuo@chef.io>)
-# Author:: Christopher Brown (<cb@chef.io>)
-# Author:: Christopher Walters (<cw@chef.io>)
-# Copyright:: Copyright 2009-2016, 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 "tempfile"
-require "chef/http"
-class Chef
- class HTTP; end
- class REST < HTTP; end
-end
-
-require "chef/http/authenticator"
-require "chef/http/decompressor"
-require "chef/http/json_input"
-require "chef/http/json_to_model_output"
-require "chef/http/cookie_manager"
-require "chef/http/validate_content_length"
-require "chef/config"
-require "chef/exceptions"
-require "chef/platform/query_helpers"
-require "chef/http/remote_request_id"
-require "chef/chef_class"
-
-class Chef
-
- # == Chef::REST
- # Chef's custom REST client with built-in JSON support and RSA signed header
- # authentication.
- class REST < HTTP
-
- # Backwards compatibility for things that use
- # Chef::REST::RESTRequest or its constants
- RESTRequest = HTTP::HTTPRequest
-
- attr_accessor :url, :cookies, :sign_on_redirect, :redirect_limit
-
- attr_reader :authenticator
-
- # Create a REST client object. The supplied +url+ is used as the base for
- # all subsequent requests. For example, when initialized with a base url
- # http://localhost:4000, a call to +get_rest+ with 'nodes' will make an
- # 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.deprecated(:chef_rest, "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
- options[:client_name] = client_name
- options[:signing_key_filename] = signing_key_filename
-
- super(url, options)
-
- @decompressor = Decompressor.new(options)
- @authenticator = Authenticator.new(options)
- @request_id = RemoteRequestID.new(options)
-
- @middlewares << JSONInput.new(options)
- @middlewares << JSONToModelOutput.new(options)
- @middlewares << CookieManager.new(options)
- @middlewares << @decompressor
- @middlewares << @authenticator
- @middlewares << @request_id
-
- # ValidateContentLength should come after Decompressor
- # because the order of middlewares is reversed when handling
- # responses.
- @middlewares << ValidateContentLength.new(options)
- end
-
- def signing_key_filename
- authenticator.signing_key_filename
- end
-
- def auth_credentials
- authenticator.auth_credentials
- end
-
- def client_name
- authenticator.client_name
- end
-
- def signing_key
- authenticator.raw_key
- end
-
- def sign_requests?
- authenticator.sign_requests?
- end
-
- # Send an HTTP GET request to the path
- #
- # Using this method to +fetch+ a file is considered deprecated.
- #
- # === Parameters
- # path:: The path to GET
- # raw:: Whether you want the raw body returned, or JSON inflated. Defaults
- # to JSON inflated.
- def get(path, raw = false, headers = {})
- if raw
- streaming_request(path, headers)
- else
- request(:GET, path, headers)
- end
- end
-
- alias :get_rest :get
-
- alias :delete_rest :delete
-
- alias :post_rest :post
-
- alias :put_rest :put
-
- # Streams a download to a tempfile, then yields the tempfile to a block.
- # After the download, the tempfile will be closed and unlinked.
- # If you rename the tempfile, it will not be deleted.
- # Beware that if the server streams infinite content, this method will
- # stream it until you run out of disk space.
- def fetch(path, headers = {})
- streaming_request(create_url(path), headers) { |tmp_file| yield tmp_file }
- end
-
- alias :api_request :request
-
- # Do a HTTP request where no middleware is loaded (e.g. JSON input/output
- # conversion) but the standard Chef Authentication headers are added to the
- # request.
- def raw_http_request(method, path, headers, data)
- url = create_url(path)
- method, url, headers, data = @authenticator.handle_request(method, url, headers, data)
- method, url, headers, data = @request_id.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
-
- # Deprecated:
- # Responsibilities of this method have been split up. The #http_client is
- # now responsible for making individual requests, while
- # #retrying_http_errors handles error/retry logic.
- def retriable_http_request(method, url, req_body, headers)
- rest_request = Chef::HTTP::HTTPRequest.new(method, url, req_body, headers)
-
- Chef::Log.debug("Sending HTTP request via #{method} to #{url.host}:#{url.port}#{rest_request.path}")
-
- retrying_http_errors(url) do
- yield rest_request
- end
- end
-
- # Customized streaming behavior; sets the accepted content type to "*/*"
- # if not otherwise specified for compatibility purposes
- def streaming_request(url, headers, &block)
- headers["Accept"] ||= "*/*"
- super
- end
-
- alias :retriable_rest_request :retriable_http_request
-
- def follow_redirect
- unless @sign_on_redirect
- @authenticator.sign_request = false
- end
- super
- ensure
- @authenticator.sign_request = true
- end
-
- public :create_url
-
- ############################################################################
- # DEPRECATED
- ############################################################################
-
- def decompress_body(body)
- @decompressor.decompress_body(body)
- end
-
- def authentication_headers(method, url, json_body = nil)
- authenticator.authentication_headers(method, url, json_body)
- end
-
- end
-end
diff --git a/lib/chef/run_context.rb b/lib/chef/run_context.rb
index 6d84b7773d..a606585e80 100644
--- a/lib/chef/run_context.rb
+++ b/lib/chef/run_context.rb
@@ -2,7 +2,7 @@
# Author:: Adam Jacob (<adam@chef.io>)
# Author:: Christopher Walters (<cw@chef.io>)
# Author:: Tim Hinderliter (<tim@chef.io>)
-# Copyright:: Copyright 2008-2016, Chef Software Inc.
+# Copyright:: Copyright 2008-2017, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -576,27 +576,6 @@ ERROR_MESSAGE
attr_reader :loaded_attributes_hash
attr_reader :loaded_recipes_hash
- module Deprecated
- ###
- # These need to be settable so deploy can run a resource_collection
- # independent of any cookbooks via +recipe_eval+
- def audits=(value)
- Chef.deprecated(:internal_api, "Setting run_context.audits will be removed in a future Chef. Use run_context.create_child to create a new RunContext instead.")
- @audits = value
- end
-
- def immediate_notification_collection=(value)
- Chef.deprecated(:internal_api, "Setting run_context.immediate_notification_collection will be removed in a future Chef. Use run_context.create_child to create a new RunContext instead.")
- @immediate_notification_collection = value
- end
-
- def delayed_notification_collection=(value)
- Chef.deprecated(:internal_api, "Setting run_context.delayed_notification_collection will be removed in a future Chef. Use run_context.create_child to create a new RunContext instead.")
- @delayed_notification_collection = value
- end
- end
- prepend Deprecated
-
#
# A child run context. Delegates all root context calls to its parent.
#
diff --git a/lib/chef/search/query.rb b/lib/chef/search/query.rb
index fb77238ced..7357dbf6be 100644
--- a/lib/chef/search/query.rb
+++ b/lib/chef/search/query.rb
@@ -106,10 +106,12 @@ class Chef
return args.first if args.first.is_a?(Hash)
args_h = Hash.new
- args_h[:sort] = args[0] if args[0]
- args_h[:start] = args[1] if args[1]
- args_h[:rows] = args[2]
- args_h[:filter_result] = args[3]
+ # If we have 4 arguments, the first is the now-removed sort option, so
+ # just ignore it.
+ args.pop(0) if args.length == 4
+ args_h[:start] = args[0] if args[0]
+ args_h[:rows] = args[1]
+ args_h[:filter_result] = args[2]
args_h
end
@@ -119,16 +121,15 @@ class Chef
s && Addressable::URI.encode_component(s.to_s, QUERY_PARAM_VALUE)
end
- def create_query_string(type, query, rows, start, sort)
+ def create_query_string(type, query, rows, start)
qstr = "search/#{type}?q=#{escape_value(query)}"
- qstr += "&sort=#{escape_value(sort)}" if sort
qstr += "&start=#{escape_value(start)}" if start
qstr += "&rows=#{escape_value(rows)}" if rows
qstr
end
- def call_rest_service(type, query: "*:*", rows: nil, start: 0, sort: "X_CHEF_id_CHEF_X asc", filter_result: nil)
- query_string = create_query_string(type, query, rows, start, sort)
+ def call_rest_service(type, query: "*:*", rows: nil, start: 0, filter_result: nil)
+ query_string = create_query_string(type, query, rows, start)
if filter_result
response = rest.post(query_string, filter_result)
diff --git a/lib/chef/shell.rb b/lib/chef/shell.rb
index e8c3704553..b4c0277c57 100644
--- a/lib/chef/shell.rb
+++ b/lib/chef/shell.rb
@@ -27,6 +27,7 @@ require "chef/config"
require "chef/config_fetcher"
require "chef/shell/shell_session"
+require "chef/workstation_config_loader"
require "chef/shell/ext"
require "chef/json_compat"
require "chef/util/path_helper"
@@ -62,6 +63,12 @@ module Shell
irb = IRB::Irb.new
+ if solo_mode?
+ # Setup the mocked ChefServer
+ Chef::Config.local_mode = true
+ Chef::LocalMode.setup_server_connectivity
+ end
+
init(irb.context.main)
irb_conf[:IRB_RC].call(irb.context) if irb_conf[:IRB_RC]
@@ -74,6 +81,13 @@ module Shell
catch(:IRB_EXIT) do
irb.eval_input
end
+ ensure
+ # We destroy the mocked ChefServer
+ Chef::LocalMode.destroy_server_connectivity if solo_mode?
+ end
+
+ def self.solo_mode?
+ Chef::Config[:solo]
end
def self.setup_logger
@@ -167,8 +181,9 @@ module Shell
def self.client_type
type = Shell::StandAloneSession
- type = Shell::SoloSession if Chef::Config[:shell_solo]
- type = Shell::ClientSession if Chef::Config[:client]
+ type = Shell::SoloSession if solo_mode?
+ type = Shell::SoloLegacySession if Chef::Config[:solo_legacy_shell]
+ type = Shell::ClientSession if Chef::Config[:client]
type = Shell::DoppelGangerSession if Chef::Config[:doppelganger]
type
end
@@ -196,8 +211,10 @@ module Shell
When no CONFIG is specified, chef-shell attempts to load a default configuration file:
* If a NAMED_CONF is given, chef-shell will load ~/.chef/NAMED_CONF/chef_shell.rb
* If no NAMED_CONF is given chef-shell will load ~/.chef/chef_shell.rb if it exists
-* chef-shell falls back to loading /etc/chef/client.rb or /etc/chef/solo.rb if -z or
- -s options are given and no chef_shell.rb can be found.
+* If no chef_shell.rb can be found, chef-shell falls back to load:
+ /etc/chef/client.rb if -z option is given.
+ /etc/chef/solo.rb if --solo-legacy-mode option is given.
+ .chef/knife.rb if -s option is given.
FOOTER
option :config_file,
@@ -226,7 +243,7 @@ FOOTER
:default => true,
:boolean => true
- option :shell_solo,
+ option :solo_shell,
:short => "-s",
:long => "--solo",
:description => "chef-solo session",
@@ -239,6 +256,12 @@ FOOTER
:description => "chef-client session",
:boolean => true
+ option :solo_legacy_shell,
+ :long => "--solo-legacy-mode",
+ :description => "chef-solo legacy session",
+ :boolean => true,
+ :proc => proc { Chef::Config[:solo_legacy_mode] = true }
+
option :json_attribs,
:short => "-j JSON_ATTRIBS",
:long => "--json-attributes JSON_ATTRIBS",
@@ -313,10 +336,12 @@ FOOTER
config_file_to_try
elsif dot_chef_dir && ::File.exist?(File.join(dot_chef_dir, "chef_shell.rb"))
File.join(dot_chef_dir, "chef_shell.rb")
- elsif config[:solo]
+ elsif config[:solo_legacy_shell]
Chef::Config.platform_specific_path("/etc/chef/solo.rb")
elsif config[:client]
Chef::Config.platform_specific_path("/etc/chef/client.rb")
+ elsif config[:solo_shell]
+ Chef::WorkstationConfigLoader.new(nil, Chef::Log).config_location
else
nil
end
diff --git a/lib/chef/shell/shell_session.rb b/lib/chef/shell/shell_session.rb
index 3034e1cf5d..41d5bd64a0 100644
--- a/lib/chef/shell/shell_session.rb
+++ b/lib/chef/shell/shell_session.rb
@@ -159,9 +159,9 @@ module Shell
end
- class SoloSession < ShellSession
+ class SoloLegacySession < ShellSession
- session_type :solo
+ session_type :solo_legacy_mode
def definitions
@run_context.definitions
@@ -191,10 +191,14 @@ module Shell
end
- class ClientSession < SoloSession
+ class ClientSession < ShellSession
session_type :client
+ def definitions
+ @run_context.definitions
+ end
+
def save_node
@client.save_node
end
@@ -223,6 +227,12 @@ module Shell
end
+ class SoloSession < ClientSession
+
+ session_type :solo
+
+ end
+
class DoppelGangerClient < Chef::Client
attr_reader :node_name
diff --git a/lib/chef/shell_out.rb b/lib/chef/shell_out.rb
deleted file mode 100644
index 54ff718e8e..0000000000
--- a/lib/chef/shell_out.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-require "mixlib/shellout"
-
-class Chef
- class ShellOut < Mixlib::ShellOut
-
- def initialize(*args)
- Chef::Log.warn("Chef::ShellOut is deprecated, please use Mixlib::ShellOut")
- called_from = caller[0..3].inject("Called from:\n") { |msg, trace_line| msg << " #{trace_line}\n" }
- Chef::Log.warn(called_from)
- super
- end
- end
-end
diff --git a/lib/chef/tasks/chef_repo.rake b/lib/chef/tasks/chef_repo.rake
deleted file mode 100644
index 543bd8d864..0000000000
--- a/lib/chef/tasks/chef_repo.rake
+++ /dev/null
@@ -1,200 +0,0 @@
-#
-# Author:: Adam Jacob (<adam@chef.io>)
-# Copyright:: Copyright 2008-2016, Chef Software Inc.
-# Copyright:: Copyright 2014-2016, 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.
-#
-TOPDIR = "."
-require "rake"
-
-desc "By default, print deprecation notice"
-task :default do
- puts deprecation_notice
-end
-
-desc "Install the latest copy of the repository on this Chef Server"
-task :install do
- puts deprecation_notice
- puts "The `install` rake task, which included the `update`, `roles`, and"
- puts "`upload_cookbooks` rake tasks is replaced by the `knife upload`"
- puts 'sub-command. The notion of "installing" the chef-repo to the Chef'
- puts "Server. Previously the `install` task would manage server and"
- puts "client configuration. This will not work at all on Chef Server 11+"
- puts "and client configuration should be managed with the `chef-client`"
- puts "cookbook."
-end
-
-desc "Update your repository from source control"
-task :update do
- puts deprecation_notice
- puts "The `update` rake task previously updated the chef-repo from"
- puts "the detected version control system, either svn or git. However,"
- puts "it has not been recommended for users for years. Most users in"
- puts "the community use `git`, so the Subversion functionality is not"
- puts "required, and `git pull` is sufficient for many workflows. The"
- puts "world of git workflows is rather different now than it was when"
- puts "this rake task was created."
-end
-
-desc "Create a new cookbook (with COOKBOOK=name, optional CB_PREFIX=site-)"
-task :new_cookbook do
- cb = ENV["COOKBOOK"] || "my_cookbook_name"
- puts deprecation_notice
- puts "The `new_cookbook` rake task is replaced by the ChefDK cookbook"
- puts "generator. To generate a new cookbook run:"
- puts
- puts "chef generate cookbook #{ENV['COOKBOOK']}"
- puts
- puts "Or, if you are not using ChefDK, use `knife cookbook create`:"
- puts
- puts "knife cookbook create #{ENV['COOKBOOK']}"
-end
-
-desc "Create a new self-signed SSL certificate for FQDN=foo.example.com"
-task :ssl_cert do
- puts deprecation_notice
- puts "The `ssl_cert` rake task is superseded by using the CHEF-maintained"
- puts '`openssl` cookbook\'s `openssl_x509` resource which can generate'
- puts "self-signed certificate chains as convergent resources."
- puts
- puts "https://supermarket.getchef.com/cookbooks/openssl"
-end
-
-desc "Build cookbook metadata.json from metadata.rb"
-task :metadata do
- puts deprecation_notice
- puts "The `metadata` rake task is not recommended. Cookbook"
- puts "`metadata.json` is automatically generated from `metadata.rb`"
- puts "by `knife` when uploading cookbooks to the Chef Server."
-end
-
-desc "Update roles"
-task :roles do
- puts deprecation_notice
- puts "The `roles` rake task is not recommended. If you are using Ruby"
- puts "role files (roles/*.rb), you can upload them all with:"
- puts
- puts "knife role from file roles/*"
- puts
- puts "If you are using JSON role files (roles/*.json), you can upload"
- puts "them all with:"
- puts
- puts "knife upload roles/*.json"
-end
-
-desc "Update a specific role"
-task :role do
- puts deprecation_notice
- puts "The `role` rake task is not recommended. If you are using Ruby"
- puts "role files, you can upload a single role with:"
- puts
- puts "knife role from file rolename.rb"
- puts
- puts "If you are using JSON role files, you can upload a single role with"
- puts
- puts "knife upload roles/rolename.json"
-end
-
-desc "Upload all cookbooks"
-task :upload_cookbooks do
- puts deprecation_notice
- puts deprecated_cookbook_upload
-end
-
-desc "Upload a single cookbook"
-task :upload_cookbook do
- puts deprecation_notice
- puts deprecated_cookbook_upload
-end
-
-desc "Test all cookbooks"
-task :test_cookbooks do
- puts deprecation_notice
- puts "The `test_cookbooks` rake task is no longer recommended. Previously"
- puts "it only performed a syntax check, and did no other kind of testing,"
- puts "and the Chef Community has a rich ecosystem of testing tools for"
- puts "various purposes:"
- puts
- puts "- knife cookbook test will perform a syntax check, as this task did"
- puts " before."
- puts "- rubocop and foodcritic will perform lint checking for Ruby and"
- puts " Chef cookbook style according to community standards."
- puts "- ChefSpec will perform unit testing"
- puts "- Test Kitchen will perform convergence and post-convergence"
- puts " testing on virtual machines."
-end
-
-desc "Test a single cookbook"
-task :test_cookbook => [:test_cookbooks]
-
-namespace :databag do
- desc "Upload a single databag"
- task :upload do
- puts deprecation_notice
- puts "The `data_bags:upload` task is not recommended. You should use"
- puts "the `knife upload` sub-command for uploading data bag items."
- puts
- puts "knife upload data_bags/bagname/itemname.json"
- end
-
- desc "Upload all databags"
- task :upload_all do
- puts deprecation_notice
- puts "The `data_bags:upload_all` task is not recommended. You should"
- puts "use the `knife upload` sub-command for uploading data bag items."
- puts
- puts "knife upload data_bags/*"
- end
-
- desc "Create a databag"
- task :create do
- puts deprecation_notice
- puts deprecated_data_bag_creation
- end
-
- desc "Create a databag item stub"
- task :create_item do
- puts deprecation_notice
- puts deprecated_data_bag_creation
- end
-end
-
-def deprecation_notice
- %Q{*************************************************
-NOTICE: Chef Repository Rake Tasks Are Deprecated
-*************************************************
-}
-end
-
-def deprecated_cookbook_upload
- %Q{
-The `upload_cookbook` and `upload_cookbooks` rake tasks are not
-recommended. These tasks are replaced by other, better workflow
-tools, such as `knife cookbook upload`, `knife upload`, or `berks`
-}
-end
-
-def deprecated_data_bag_creation
- %Q{
-The `data_bags:create` and `data_bags:create_item` tasks are not
-recommended. You should create data bag items as JSON files in the data_bags
-directory, with a sub-directory for each bag, and use `knife upload` to
-upload them. For example, if you have a data bags named `users`, with
-`finn`, and `jake` items, you would have:
-
-./data_bags/users/finn.json
-./data-bags/users/jake.json
-}
-end
diff --git a/lib/chef/util/windows/net_user.rb b/lib/chef/util/windows/net_user.rb
index f9f8f011af..059a04d59a 100644
--- a/lib/chef/util/windows/net_user.rb
+++ b/lib/chef/util/windows/net_user.rb
@@ -112,7 +112,7 @@ class Chef::Util::Windows::NetUser < Chef::Util::Windows
def add(args)
transformed_args = transform_usri3(args)
NetUser.net_user_add_l3(nil, transformed_args)
- NetUser.net_local_group_add_member(nil, "Users", args[:name])
+ NetUser.net_local_group_add_member(nil, Chef::ReservedNames::Win32::Security::SID.BuiltinUsers.account_simple_name, args[:name])
end
# FIXME: yard with @yield
diff --git a/lib/chef/version.rb b/lib/chef/version.rb
index 02690cc650..67f2c57adb 100644
--- a/lib/chef/version.rb
+++ b/lib/chef/version.rb
@@ -21,7 +21,7 @@
class Chef
CHEF_ROOT = File.expand_path("../..", __FILE__)
- VERSION = "13.0.43"
+ VERSION = "13.0.63"
end
#
diff --git a/lib/chef/win32/security/sid.rb b/lib/chef/win32/security/sid.rb
index 983166ac70..c77616853c 100644
--- a/lib/chef/win32/security/sid.rb
+++ b/lib/chef/win32/security/sid.rb
@@ -59,6 +59,11 @@ class Chef
Chef::ReservedNames::Win32::Security.lookup_account_sid(self)
end
+ def account_simple_name
+ domain, name, use = account
+ name
+ end
+
def account_name
domain, name, use = account
(!domain.nil? && domain.length > 0) ? "#{domain}\\#{name}" : name