chef 12.3.0 → 12.4.0.rc.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +86 -7
- data/distro/common/markdown/man1/chef-shell.mkd +4 -4
- data/distro/common/markdown/man1/knife-bootstrap.mkd +1 -1
- data/distro/common/markdown/man1/knife-client.mkd +1 -1
- data/distro/common/markdown/man1/knife-configure.mkd +1 -1
- data/distro/common/markdown/man1/knife-cookbook-site.mkd +1 -1
- data/distro/common/markdown/man1/knife-cookbook.mkd +4 -4
- data/distro/common/markdown/man1/knife-data-bag.mkd +1 -1
- data/distro/common/markdown/man1/knife-environment.mkd +3 -3
- data/distro/common/markdown/man1/knife-exec.mkd +1 -1
- data/distro/common/markdown/man1/knife-index.mkd +1 -1
- data/distro/common/markdown/man1/knife-node.mkd +1 -1
- data/distro/common/markdown/man1/knife-role.mkd +3 -3
- data/distro/common/markdown/man1/knife-search.mkd +2 -2
- data/distro/common/markdown/man1/knife-ssh.mkd +1 -1
- data/distro/common/markdown/man1/knife-status.mkd +1 -1
- data/distro/common/markdown/man1/knife-tag.mkd +1 -1
- data/distro/common/markdown/man1/knife.mkd +2 -2
- data/distro/common/markdown/man8/chef-client.mkd +1 -2
- data/distro/common/markdown/man8/chef-expander.mkd +1 -2
- data/distro/common/markdown/man8/chef-expanderctl.mkd +1 -2
- data/distro/common/markdown/man8/chef-server-webui.mkd +1 -1
- data/distro/common/markdown/man8/chef-server.mkd +1 -2
- data/distro/common/markdown/man8/chef-solo.mkd +2 -2
- data/distro/common/markdown/man8/chef-solr.mkd +1 -1
- data/lib/chef/client.rb +2 -2
- data/lib/chef/config.rb +17 -709
- data/lib/chef/cookbook/metadata.rb +9 -5
- data/lib/chef/cookbook_loader.rb +1 -1
- data/lib/chef/cookbook_site_streaming_uploader.rb +2 -18
- data/lib/chef/dsl/definitions.rb +44 -0
- data/lib/chef/dsl/recipe.rb +50 -35
- data/lib/chef/dsl/resources.rb +28 -0
- data/lib/chef/event_dispatch/dispatcher.rb +2 -0
- data/lib/chef/event_loggers/windows_eventlog.rb +1 -11
- data/lib/chef/exceptions.rb +4 -0
- data/lib/chef/file_access_control/unix.rb +5 -0
- data/lib/chef/formatters/error_inspectors/api_error_formatting.rb +17 -0
- data/lib/chef/formatters/error_inspectors/compile_error_inspector.rb +21 -9
- data/lib/chef/formatters/error_inspectors/cookbook_resolve_error_inspector.rb +2 -0
- data/lib/chef/formatters/error_inspectors/cookbook_sync_error_inspector.rb +2 -0
- data/lib/chef/formatters/error_inspectors/node_load_error_inspector.rb +2 -0
- data/lib/chef/formatters/error_inspectors/registration_error_inspector.rb +4 -0
- data/lib/chef/formatters/error_inspectors/resource_failure_inspector.rb +11 -1
- data/lib/chef/formatters/error_inspectors/run_list_expansion_error_inspector.rb +2 -0
- data/lib/chef/http/authenticator.rb +3 -0
- data/lib/chef/http/basic_client.rb +10 -6
- data/lib/chef/http/json_input.rb +6 -1
- data/lib/chef/key.rb +271 -0
- data/lib/chef/knife.rb +11 -1
- data/lib/chef/knife/bootstrap.rb +6 -0
- data/lib/chef/knife/bootstrap/templates/chef-full.erb +166 -23
- data/lib/chef/knife/client_key_create.rb +67 -0
- data/lib/chef/knife/client_key_delete.rb +76 -0
- data/lib/chef/knife/client_key_edit.rb +80 -0
- data/lib/chef/knife/client_key_list.rb +69 -0
- data/lib/chef/knife/client_key_show.rb +76 -0
- data/lib/chef/knife/key_create.rb +108 -0
- data/lib/chef/knife/key_create_base.rb +50 -0
- data/lib/chef/knife/key_delete.rb +55 -0
- data/lib/chef/knife/key_edit.rb +114 -0
- data/lib/chef/knife/key_edit_base.rb +55 -0
- data/lib/chef/knife/key_list.rb +88 -0
- data/lib/chef/knife/key_list_base.rb +45 -0
- data/lib/chef/knife/key_show.rb +53 -0
- data/lib/chef/knife/ssh.rb +26 -28
- data/lib/chef/knife/user_key_create.rb +69 -0
- data/lib/chef/knife/user_key_delete.rb +76 -0
- data/lib/chef/knife/user_key_edit.rb +80 -0
- data/lib/chef/knife/user_key_list.rb +69 -0
- data/lib/chef/knife/user_key_show.rb +76 -0
- data/lib/chef/log.rb +2 -0
- data/lib/chef/log/syslog.rb +46 -0
- data/lib/chef/log/winevt.rb +99 -0
- data/lib/chef/mixin/provides.rb +8 -1
- data/lib/chef/mixin/unformatter.rb +32 -0
- data/lib/chef/mixin/uris.rb +33 -0
- data/lib/chef/mixin/wstring.rb +31 -0
- data/lib/chef/node.rb +21 -2
- data/lib/chef/platform/provider_mapping.rb +8 -4
- data/lib/chef/platform/query_helpers.rb +1 -5
- data/lib/chef/platform/service_helpers.rb +21 -21
- data/lib/chef/provider.rb +33 -0
- data/lib/chef/provider/cron/unix.rb +1 -0
- data/lib/chef/provider/file.rb +5 -3
- data/lib/chef/provider/lwrp_base.rb +76 -58
- data/lib/chef/provider/ohai.rb +1 -0
- data/lib/chef/provider/package.rb +7 -4
- data/lib/chef/provider/package/aix.rb +1 -0
- data/lib/chef/provider/package/smartos.rb +5 -5
- data/lib/chef/provider/package/windows.rb +90 -6
- data/lib/chef/provider/package/yum.rb +102 -32
- data/lib/chef/provider/reboot.rb +1 -0
- data/lib/chef/provider/registry_key.rb +2 -0
- data/lib/chef/provider/remote_file.rb +1 -0
- data/lib/chef/provider/remote_file/content.rb +5 -1
- data/lib/chef/provider/remote_file/fetcher.rb +22 -8
- data/lib/chef/provider/remote_file/network_file.rb +48 -0
- data/lib/chef/provider/service/aix.rb +13 -12
- data/lib/chef/provider_resolver.rb +87 -0
- data/lib/chef/providers.rb +1 -0
- data/lib/chef/resource.rb +67 -8
- data/lib/chef/resource/bash.rb +1 -0
- data/lib/chef/resource/bff_package.rb +1 -2
- data/lib/chef/resource/breakpoint.rb +1 -0
- data/lib/chef/resource/csh.rb +1 -0
- data/lib/chef/resource/deploy.rb +1 -0
- data/lib/chef/resource/erl_call.rb +1 -0
- data/lib/chef/resource/execute.rb +1 -0
- data/lib/chef/resource/file.rb +18 -0
- data/lib/chef/resource/http_request.rb +1 -0
- data/lib/chef/resource/ifconfig.rb +1 -2
- data/lib/chef/resource/log.rb +1 -2
- data/lib/chef/resource/lwrp_base.rb +106 -87
- data/lib/chef/resource/ohai.rb +1 -0
- data/lib/chef/resource/package.rb +1 -0
- data/lib/chef/resource/perl.rb +1 -0
- data/lib/chef/resource/portage_package.rb +1 -0
- data/lib/chef/resource/python.rb +1 -0
- data/lib/chef/resource/reboot.rb +2 -0
- data/lib/chef/resource/registry_key.rb +1 -0
- data/lib/chef/resource/remote_file.rb +1 -1
- data/lib/chef/resource/route.rb +1 -2
- data/lib/chef/resource/ruby.rb +1 -0
- data/lib/chef/resource/ruby_block.rb +1 -0
- data/lib/chef/resource/scm.rb +1 -0
- data/lib/chef/resource/script.rb +1 -0
- data/lib/chef/resource/service.rb +1 -0
- data/lib/chef/resource/subversion.rb +1 -0
- data/lib/chef/resource/whyrun_safe_ruby_block.rb +1 -0
- data/lib/chef/resource/windows_package.rb +24 -2
- data/lib/chef/resource/windows_script.rb +1 -0
- data/lib/chef/resource/yum_package.rb +1 -1
- data/lib/chef/resource_definition.rb +1 -0
- data/lib/chef/resource_reporter.rb +3 -10
- data/lib/chef/resource_resolver.rb +20 -10
- data/lib/chef/run_context.rb +1 -0
- data/lib/chef/run_list/versioned_recipe_list.rb +18 -0
- data/lib/chef/run_status.rb +2 -4
- data/lib/chef/shell.rb +1 -1
- data/lib/chef/util/path_helper.rb +3 -204
- data/lib/chef/util/windows/net_user.rb +73 -118
- data/lib/chef/version.rb +8 -4
- data/lib/chef/win32/api.rb +2 -1
- data/lib/chef/win32/api/installer.rb +1 -1
- data/lib/chef/win32/api/net.rb +115 -2
- data/lib/chef/win32/api/security.rb +24 -0
- data/lib/chef/win32/api/unicode.rb +1 -1
- data/lib/chef/win32/eventlog.rb +31 -0
- data/lib/chef/win32/net.rb +190 -0
- data/lib/chef/win32/security.rb +51 -2
- data/lib/chef/win32/security/sid.rb +17 -0
- data/spec/data/lwrp/providers/buck_passer.rb +18 -2
- data/spec/data/lwrp/providers/buck_passer_2.rb +18 -2
- data/spec/data/lwrp/providers/embedded_resource_accesses_providers_scope.rb +14 -2
- data/spec/data/lwrp_override/resources/foo.rb +5 -0
- data/spec/functional/knife/ssh_spec.rb +2 -2
- data/spec/functional/rebooter_spec.rb +1 -1
- data/spec/functional/resource/aixinit_service_spec.rb +1 -1
- data/spec/functional/resource/user/windows_spec.rb +125 -0
- data/spec/functional/shell_spec.rb +25 -10
- data/spec/functional/win32/sid_spec.rb +55 -0
- data/spec/integration/client/client_spec.rb +53 -29
- data/spec/integration/knife/deps_spec.rb +8 -14
- data/spec/integration/knife/upload_spec.rb +18 -0
- data/spec/integration/recipes/lwrp_inline_resources_spec.rb +1 -1
- data/spec/integration/recipes/provider_choice.rb +41 -0
- data/spec/integration/recipes/recipe_dsl_spec.rb +259 -0
- data/spec/spec_helper.rb +6 -1
- data/spec/support/key_helpers.rb +104 -0
- data/spec/support/lib/chef/resource/cat.rb +1 -0
- data/spec/support/lib/chef/resource/one_two_three_four.rb +2 -0
- data/spec/support/lib/chef/resource/zen_follower.rb +1 -0
- data/spec/support/lib/chef/resource/zen_master.rb +2 -0
- data/spec/support/mock/platform.rb +1 -1
- data/spec/support/pedant/Gemfile.lock +67 -0
- data/spec/support/shared/functional/securable_resource.rb +34 -12
- data/spec/support/shared/integration/integration_helper.rb +6 -5
- data/spec/support/shared/unit/provider/file.rb +31 -8
- data/spec/unit/application/client_spec.rb +2 -2
- data/spec/unit/client_spec.rb +21 -4
- data/spec/unit/cookbook/cookbook_version_loader_spec.rb +1 -1
- data/spec/unit/cookbook/metadata_spec.rb +15 -0
- data/spec/unit/cookbook/syntax_check_spec.rb +1 -1
- data/spec/unit/cookbook_loader_spec.rb +1 -1
- data/spec/unit/cookbook_site_streaming_uploader_spec.rb +0 -21
- data/spec/unit/data_bag_spec.rb +1 -1
- data/spec/unit/event_dispatch/dispatcher_spec.rb +61 -0
- data/spec/unit/formatters/error_inspectors/api_error_formatting_spec.rb +75 -0
- data/spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb +149 -112
- data/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb +7 -0
- data/spec/unit/guard_interpreter/resource_guard_interpreter_spec.rb +1 -1
- data/spec/unit/http/authenticator_spec.rb +69 -0
- data/spec/unit/http/basic_client_spec.rb +16 -0
- data/spec/unit/key_spec.rb +634 -0
- data/spec/unit/knife/bootstrap_spec.rb +14 -1
- data/spec/unit/knife/core/subcommand_loader_spec.rb +1 -1
- data/spec/unit/knife/core/ui_spec.rb +1 -1
- data/spec/unit/knife/data_bag_from_file_spec.rb +1 -1
- data/spec/unit/knife/environment_from_file_spec.rb +1 -1
- data/spec/unit/knife/key_create_spec.rb +224 -0
- data/spec/unit/knife/key_delete_spec.rb +135 -0
- data/spec/unit/knife/key_edit_spec.rb +267 -0
- data/spec/unit/knife/key_helper.rb +74 -0
- data/spec/unit/knife/key_list_spec.rb +216 -0
- data/spec/unit/knife/key_show_spec.rb +126 -0
- data/spec/unit/knife/ssh_spec.rb +23 -26
- data/spec/unit/knife_spec.rb +33 -1
- data/spec/unit/log/syslog_spec.rb +53 -0
- data/spec/unit/log/winevt_spec.rb +55 -0
- data/spec/unit/lwrp_spec.rb +105 -51
- data/spec/unit/mixin/path_sanity_spec.rb +2 -2
- data/spec/unit/mixin/template_spec.rb +2 -2
- data/spec/unit/mixin/unformatter_spec.rb +61 -0
- data/spec/unit/mixin/uris_spec.rb +45 -0
- data/spec/unit/platform/query_helpers_spec.rb +1 -1
- data/spec/unit/policy_builder/policyfile_spec.rb +7 -3
- data/spec/unit/provider/deploy/revision_spec.rb +1 -1
- data/spec/unit/provider/deploy_spec.rb +1 -1
- data/spec/unit/provider/directory_spec.rb +1 -1
- data/spec/unit/provider/execute_spec.rb +1 -1
- data/spec/unit/provider/package/aix_spec.rb +20 -8
- data/spec/unit/provider/package/smartos_spec.rb +50 -40
- data/spec/unit/provider/package/windows_spec.rb +104 -25
- data/spec/unit/provider/package/yum_spec.rb +111 -1
- data/spec/unit/provider/package_spec.rb +6 -0
- data/spec/unit/provider/remote_file/fetcher_spec.rb +20 -1
- data/spec/unit/provider/remote_file/network_file_spec.rb +45 -0
- data/spec/unit/provider/service/aix_service_spec.rb +26 -11
- data/spec/unit/provider/user/dscl_spec.rb +1 -1
- data/spec/unit/provider_spec.rb +20 -0
- data/spec/unit/recipe_spec.rb +1 -1
- data/spec/unit/resource/batch_spec.rb +1 -0
- data/spec/unit/resource/powershell_spec.rb +1 -0
- data/spec/unit/resource/remote_file_spec.rb +10 -0
- data/spec/unit/resource/windows_package_spec.rb +16 -2
- data/spec/unit/resource_spec.rb +40 -24
- data/spec/unit/rest_spec.rb +10 -20
- data/spec/unit/role_spec.rb +1 -1
- data/spec/unit/run_context_spec.rb +31 -0
- data/spec/unit/shell_spec.rb +4 -4
- data/tasks/external_tests.rb +29 -0
- data/tasks/rspec.rb +14 -1
- metadata +105 -28
- data/spec/unit/config_spec.rb +0 -544
- data/spec/unit/util/path_helper_spec.rb +0 -255
data/lib/chef/resource/scm.rb
CHANGED
data/lib/chef/resource/script.rb
CHANGED
@@ -16,6 +16,7 @@
|
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
18
|
|
19
|
+
require 'chef/mixin/uris'
|
19
20
|
require 'chef/resource/package'
|
20
21
|
require 'chef/provider/package/windows'
|
21
22
|
require 'chef/win32/error' if RUBY_PLATFORM =~ /mswin|mingw|windows/
|
@@ -23,6 +24,7 @@ require 'chef/win32/error' if RUBY_PLATFORM =~ /mswin|mingw|windows/
|
|
23
24
|
class Chef
|
24
25
|
class Resource
|
25
26
|
class WindowsPackage < Chef::Resource::Package
|
27
|
+
include Chef::Mixin::Uris
|
26
28
|
|
27
29
|
provides :package, os: "windows"
|
28
30
|
provides :windows_package, os: "windows"
|
@@ -69,10 +71,30 @@ class Chef
|
|
69
71
|
@source
|
70
72
|
else
|
71
73
|
raise ArgumentError, "Bad type for WindowsPackage resource, use a String" unless arg.is_a?(String)
|
72
|
-
|
73
|
-
|
74
|
+
if uri_scheme?(arg)
|
75
|
+
@source = arg
|
76
|
+
else
|
77
|
+
@source = Chef::Util::PathHelper.canonical_path(arg, false)
|
78
|
+
end
|
74
79
|
end
|
75
80
|
end
|
81
|
+
|
82
|
+
def checksum(arg=nil)
|
83
|
+
set_or_return(
|
84
|
+
:checksum,
|
85
|
+
arg,
|
86
|
+
:kind_of => [ String ]
|
87
|
+
)
|
88
|
+
end
|
89
|
+
|
90
|
+
def remote_file_attributes(arg=nil)
|
91
|
+
set_or_return(
|
92
|
+
:remote_file_attributes,
|
93
|
+
arg,
|
94
|
+
:kind_of => [ Hash ]
|
95
|
+
)
|
96
|
+
end
|
97
|
+
|
76
98
|
end
|
77
99
|
end
|
78
100
|
end
|
@@ -59,11 +59,11 @@ class Chef
|
|
59
59
|
# attrs.
|
60
60
|
def for_json
|
61
61
|
as_hash = {}
|
62
|
-
as_hash["type"] = new_resource.
|
62
|
+
as_hash["type"] = new_resource.resource_name.to_sym
|
63
63
|
as_hash["name"] = new_resource.name.to_s
|
64
64
|
as_hash["id"] = new_resource.identity.to_s
|
65
|
-
as_hash["after"] =
|
66
|
-
as_hash["before"] = current_resource ?
|
65
|
+
as_hash["after"] = new_resource.state_for_resource_reporter
|
66
|
+
as_hash["before"] = current_resource ? current_resource.state_for_resource_reporter : {}
|
67
67
|
as_hash["duration"] = (elapsed_time * 1000).to_i.to_s
|
68
68
|
as_hash["delta"] = new_resource.diff if new_resource.respond_to?("diff")
|
69
69
|
as_hash["delta"] = "" if as_hash["delta"].nil?
|
@@ -89,13 +89,6 @@ class Chef
|
|
89
89
|
def success?
|
90
90
|
!self.exception
|
91
91
|
end
|
92
|
-
|
93
|
-
def state(r)
|
94
|
-
r.class.state_attrs.inject({}) do |state_attrs, attr_name|
|
95
|
-
state_attrs[attr_name] = r.send(attr_name)
|
96
|
-
state_attrs
|
97
|
-
end
|
98
|
-
end
|
99
92
|
end # End class ResouceReport
|
100
93
|
|
101
94
|
attr_reader :updated_resources
|
@@ -18,9 +18,11 @@
|
|
18
18
|
|
19
19
|
require 'chef/exceptions'
|
20
20
|
require 'chef/platform/resource_priority_map'
|
21
|
+
require 'chef/mixin/convert_to_class_name'
|
21
22
|
|
22
23
|
class Chef
|
23
24
|
class ResourceResolver
|
25
|
+
include Chef::Mixin::ConvertToClassName
|
24
26
|
|
25
27
|
attr_reader :node
|
26
28
|
attr_reader :resource
|
@@ -28,7 +30,7 @@ class Chef
|
|
28
30
|
|
29
31
|
def initialize(node, resource)
|
30
32
|
@node = node
|
31
|
-
@resource = resource
|
33
|
+
@resource = resource.to_sym
|
32
34
|
end
|
33
35
|
|
34
36
|
# return a deterministically sorted list of Chef::Resource subclasses
|
@@ -37,8 +39,8 @@ class Chef
|
|
37
39
|
end
|
38
40
|
|
39
41
|
def resolve
|
40
|
-
maybe_dynamic_resource_resolution
|
41
|
-
maybe_chef_platform_lookup
|
42
|
+
maybe_dynamic_resource_resolution ||
|
43
|
+
maybe_chef_platform_lookup
|
42
44
|
end
|
43
45
|
|
44
46
|
# this cut looks at if the resource can handle the resource type on the node
|
@@ -47,21 +49,29 @@ class Chef
|
|
47
49
|
resources.select do |klass|
|
48
50
|
klass.provides?(node, resource)
|
49
51
|
end.sort {|a,b| a.to_s <=> b.to_s }
|
50
|
-
|
52
|
+
end
|
53
|
+
|
54
|
+
#
|
55
|
+
# Resolve a resource by name.
|
56
|
+
#
|
57
|
+
# @param resource_name [Symbol] The resource DSL name (e.g. `:file`)
|
58
|
+
# @param node [Chef::Node] The node on which the resource will run.
|
59
|
+
#
|
60
|
+
def self.resolve(resource_name, node: Chef.node)
|
61
|
+
new(node, resource_name).resolve
|
51
62
|
end
|
52
63
|
|
53
64
|
private
|
54
65
|
|
55
66
|
# try dynamically finding a resource based on querying the resources to see what they support
|
56
|
-
def maybe_dynamic_resource_resolution(
|
57
|
-
# log this so we know what resources will work for the generic resource on the node (early cut)
|
67
|
+
def maybe_dynamic_resource_resolution # log this so we know what resources will work for the generic resource on the node (early cut)
|
58
68
|
Chef::Log.debug "resources for generic #{resource} resource enabled on node include: #{enabled_handlers}"
|
59
69
|
|
60
70
|
# if none of the resources specifically support the resource, we still need to pick one of the resources that are
|
61
71
|
# enabled on the node to handle the why-run use case.
|
62
72
|
handlers = enabled_handlers
|
63
73
|
|
64
|
-
if handlers.
|
74
|
+
if handlers.size >= 2
|
65
75
|
# this magic stack ranks the resources by where they appear in the resource_priority_map
|
66
76
|
priority_list = [ get_priority_array(node, resource) ].flatten.compact
|
67
77
|
handlers = handlers.sort_by { |x| i = priority_list.index x; i.nil? ? Float::INFINITY : i }
|
@@ -70,14 +80,14 @@ class Chef
|
|
70
80
|
# entry for this resource is missing -- we should probably raise here and force resolution of the ambiguity.
|
71
81
|
Chef::Log.warn "Ambiguous resource precedence: #{handlers}, please use Chef.set_resource_priority_array to provide determinism"
|
72
82
|
end
|
73
|
-
handlers = [
|
83
|
+
handlers = handlers[0..0]
|
74
84
|
end
|
75
85
|
|
76
86
|
Chef::Log.debug "resources that survived replacement include: #{handlers}"
|
77
87
|
|
78
88
|
raise Chef::Exceptions::AmbiguousResourceResolution.new(resource, handlers) if handlers.count >= 2
|
79
89
|
|
80
|
-
Chef::Log.debug "dynamic resource resolver FAILED to resolve a
|
90
|
+
Chef::Log.debug "dynamic resource resolver FAILED to resolve a resource" if handlers.empty?
|
81
91
|
|
82
92
|
return nil if handlers.empty?
|
83
93
|
|
@@ -85,7 +95,7 @@ class Chef
|
|
85
95
|
end
|
86
96
|
|
87
97
|
# try the old static lookup of resources by mangling name to resource klass
|
88
|
-
def maybe_chef_platform_lookup
|
98
|
+
def maybe_chef_platform_lookup
|
89
99
|
Chef::Resource.resource_matching_short_name(resource)
|
90
100
|
end
|
91
101
|
|
data/lib/chef/run_context.rb
CHANGED
@@ -63,6 +63,24 @@ class Chef
|
|
63
63
|
end
|
64
64
|
end
|
65
65
|
end
|
66
|
+
|
67
|
+
# Get an array of strings of the fully-qualified recipe names (with ::default appended) and
|
68
|
+
# with the versions in "NAME@VERSION" format.
|
69
|
+
#
|
70
|
+
# @return [Array] Array of strings with fully-qualified recipe names
|
71
|
+
def with_fully_qualified_names_and_version_constraints
|
72
|
+
self.map do |recipe_name|
|
73
|
+
ret = if recipe_name.include?('::')
|
74
|
+
recipe_name
|
75
|
+
else
|
76
|
+
"#{recipe_name}::default"
|
77
|
+
end
|
78
|
+
if @versions[recipe_name]
|
79
|
+
ret << "@#{@versions[recipe_name]}"
|
80
|
+
end
|
81
|
+
ret
|
82
|
+
end
|
83
|
+
end
|
66
84
|
end
|
67
85
|
end
|
68
86
|
end
|
data/lib/chef/run_status.rb
CHANGED
@@ -39,15 +39,13 @@ class Chef::RunStatus
|
|
39
39
|
|
40
40
|
attr_accessor :run_id
|
41
41
|
|
42
|
+
attr_accessor :node
|
43
|
+
|
42
44
|
def initialize(node, events)
|
43
45
|
@node = node
|
44
46
|
@events = events
|
45
47
|
end
|
46
48
|
|
47
|
-
def node
|
48
|
-
@node
|
49
|
-
end
|
50
|
-
|
51
49
|
# sets +start_time+ to the current time.
|
52
50
|
def start_clock
|
53
51
|
@start_time = Time.now
|
data/lib/chef/shell.rb
CHANGED
@@ -110,7 +110,7 @@ module Shell
|
|
110
110
|
|
111
111
|
conf.prompt_c = "chef#{leader(m)} > "
|
112
112
|
conf.return_format = " => %s \n"
|
113
|
-
conf.prompt_i = "chef#{leader(m)} > "
|
113
|
+
conf.prompt_i = "chef#{leader(m)} (#{Chef::VERSION})> "
|
114
114
|
conf.prompt_n = "chef#{leader(m)} ?> "
|
115
115
|
conf.prompt_s = "chef#{leader(m)}%l> "
|
116
116
|
conf.use_tracer = false
|
@@ -16,212 +16,11 @@
|
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
18
|
|
19
|
+
require 'chef-config/path_helper'
|
20
|
+
|
19
21
|
class Chef
|
20
22
|
class Util
|
21
|
-
|
22
|
-
# Maximum characters in a standard Windows path (260 including drive letter and NUL)
|
23
|
-
WIN_MAX_PATH = 259
|
24
|
-
|
25
|
-
def self.dirname(path)
|
26
|
-
if Chef::Platform.windows?
|
27
|
-
# Find the first slash, not counting trailing slashes
|
28
|
-
end_slash = path.size
|
29
|
-
loop do
|
30
|
-
slash = path.rindex(/[#{Regexp.escape(File::SEPARATOR)}#{Regexp.escape(path_separator)}]/, end_slash - 1)
|
31
|
-
if !slash
|
32
|
-
return end_slash == path.size ? '.' : path_separator
|
33
|
-
elsif slash == end_slash - 1
|
34
|
-
end_slash = slash
|
35
|
-
else
|
36
|
-
return path[0..slash-1]
|
37
|
-
end
|
38
|
-
end
|
39
|
-
else
|
40
|
-
::File.dirname(path)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
BACKSLASH = '\\'.freeze
|
45
|
-
|
46
|
-
def self.path_separator
|
47
|
-
if Chef::Platform.windows?
|
48
|
-
File::ALT_SEPARATOR || BACKSLASH
|
49
|
-
else
|
50
|
-
File::SEPARATOR
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def self.join(*args)
|
55
|
-
args.flatten.inject do |joined_path, component|
|
56
|
-
# Joined path ends with /
|
57
|
-
joined_path = joined_path.sub(/[#{Regexp.escape(File::SEPARATOR)}#{Regexp.escape(path_separator)}]+$/, '')
|
58
|
-
component = component.sub(/^[#{Regexp.escape(File::SEPARATOR)}#{Regexp.escape(path_separator)}]+/, '')
|
59
|
-
joined_path += "#{path_separator}#{component}"
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def self.validate_path(path)
|
64
|
-
if Chef::Platform.windows?
|
65
|
-
unless printable?(path)
|
66
|
-
msg = "Path '#{path}' contains non-printable characters. Check that backslashes are escaped with another backslash (e.g. C:\\\\Windows) in double-quoted strings."
|
67
|
-
Chef::Log.error(msg)
|
68
|
-
raise Chef::Exceptions::ValidationFailed, msg
|
69
|
-
end
|
70
|
-
|
71
|
-
if windows_max_length_exceeded?(path)
|
72
|
-
Chef::Log.debug("Path '#{path}' is longer than #{WIN_MAX_PATH}, prefixing with'\\\\?\\'")
|
73
|
-
path.insert(0, "\\\\?\\")
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
path
|
78
|
-
end
|
79
|
-
|
80
|
-
def self.windows_max_length_exceeded?(path)
|
81
|
-
# Check to see if paths without the \\?\ prefix are over the maximum allowed length for the Windows API
|
82
|
-
# http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247%28v=vs.85%29.aspx
|
83
|
-
unless path =~ /^\\\\?\\/
|
84
|
-
if path.length > WIN_MAX_PATH
|
85
|
-
return true
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
false
|
90
|
-
end
|
91
|
-
|
92
|
-
def self.printable?(string)
|
93
|
-
# returns true if string is free of non-printable characters (escape sequences)
|
94
|
-
# this returns false for whitespace escape sequences as well, e.g. \n\t
|
95
|
-
if string =~ /[^[:print:]]/
|
96
|
-
false
|
97
|
-
else
|
98
|
-
true
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
# Produces a comparable path.
|
103
|
-
def self.canonical_path(path, add_prefix=true)
|
104
|
-
# First remove extra separators and resolve any relative paths
|
105
|
-
abs_path = File.absolute_path(path)
|
106
|
-
|
107
|
-
if Chef::Platform.windows?
|
108
|
-
# Add the \\?\ API prefix on Windows unless add_prefix is false
|
109
|
-
# Downcase on Windows where paths are still case-insensitive
|
110
|
-
abs_path.gsub!(::File::SEPARATOR, path_separator)
|
111
|
-
if add_prefix && abs_path !~ /^\\\\?\\/
|
112
|
-
abs_path.insert(0, "\\\\?\\")
|
113
|
-
end
|
114
|
-
|
115
|
-
abs_path.downcase!
|
116
|
-
end
|
117
|
-
|
118
|
-
abs_path
|
119
|
-
end
|
120
|
-
|
121
|
-
def self.cleanpath(path)
|
122
|
-
path = Pathname.new(path).cleanpath.to_s
|
123
|
-
# ensure all forward slashes are backslashes
|
124
|
-
if Chef::Platform.windows?
|
125
|
-
path = path.gsub(File::SEPARATOR, path_separator)
|
126
|
-
end
|
127
|
-
path
|
128
|
-
end
|
129
|
-
|
130
|
-
def self.paths_eql?(path1, path2)
|
131
|
-
canonical_path(path1) == canonical_path(path2)
|
132
|
-
end
|
133
|
-
|
134
|
-
# Paths which may contain glob-reserved characters need
|
135
|
-
# to be escaped before globbing can be done.
|
136
|
-
# http://stackoverflow.com/questions/14127343
|
137
|
-
def self.escape_glob(*parts)
|
138
|
-
path = cleanpath(join(*parts))
|
139
|
-
path.gsub(/[\\\{\}\[\]\*\?]/) { |x| "\\"+x }
|
140
|
-
end
|
141
|
-
|
142
|
-
def self.relative_path_from(from, to)
|
143
|
-
pathname = Pathname.new(Chef::Util::PathHelper.cleanpath(to)).relative_path_from(Pathname.new(Chef::Util::PathHelper.cleanpath(from)))
|
144
|
-
end
|
145
|
-
|
146
|
-
# Retrieves the "home directory" of the current user while trying to ascertain the existence
|
147
|
-
# of said directory. The path returned uses / for all separators (the ruby standard format).
|
148
|
-
# If the home directory doesn't exist or an error is otherwise encountered, nil is returned.
|
149
|
-
#
|
150
|
-
# If a set of path elements is provided, they are appended as-is to the home path if the
|
151
|
-
# homepath exists.
|
152
|
-
#
|
153
|
-
# If an optional block is provided, the joined path is passed to that block if the home path is
|
154
|
-
# valid and the result of the block is returned instead.
|
155
|
-
#
|
156
|
-
# Home-path discovery is performed once. If a path is discovered, that value is memoized so
|
157
|
-
# that subsequent calls to home_dir don't bounce around.
|
158
|
-
#
|
159
|
-
# See self.all_homes.
|
160
|
-
def self.home(*args)
|
161
|
-
@@home_dir ||= self.all_homes { |p| break p }
|
162
|
-
if @@home_dir
|
163
|
-
path = File.join(@@home_dir, *args)
|
164
|
-
block_given? ? (yield path) : path
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
# See self.home. This method performs a similar operation except that it yields all the different
|
169
|
-
# possible values of 'HOME' that one could have on this platform. Hence, on windows, if
|
170
|
-
# HOMEDRIVE\HOMEPATH and USERPROFILE are different, the provided block will be called twice.
|
171
|
-
# This method goes out and checks the existence of each location at the time of the call.
|
172
|
-
#
|
173
|
-
# The return is a list of all the returned values from each block invocation or a list of paths
|
174
|
-
# if no block is provided.
|
175
|
-
def self.all_homes(*args)
|
176
|
-
paths = []
|
177
|
-
if Chef::Platform.windows?
|
178
|
-
# By default, Ruby uses the the following environment variables to determine Dir.home:
|
179
|
-
# HOME
|
180
|
-
# HOMEDRIVE HOMEPATH
|
181
|
-
# USERPROFILE
|
182
|
-
# Ruby only checks to see if the variable is specified - not if the directory actually exists.
|
183
|
-
# On Windows, HOMEDRIVE HOMEPATH can point to a different location (such as an unavailable network mounted drive)
|
184
|
-
# while USERPROFILE points to the location where the user application settings and profile are stored. HOME
|
185
|
-
# is not defined as an environment variable (usually). If the home path actually uses UNC, then the prefix is
|
186
|
-
# HOMESHARE instead of HOMEDRIVE.
|
187
|
-
#
|
188
|
-
# We instead walk down the following and only include paths that actually exist.
|
189
|
-
# HOME
|
190
|
-
# HOMEDRIVE HOMEPATH
|
191
|
-
# HOMESHARE HOMEPATH
|
192
|
-
# USERPROFILE
|
193
|
-
|
194
|
-
paths << ENV['HOME']
|
195
|
-
paths << ENV['HOMEDRIVE'] + ENV['HOMEPATH'] if ENV['HOMEDRIVE'] && ENV['HOMEPATH']
|
196
|
-
paths << ENV['HOMESHARE'] + ENV['HOMEPATH'] if ENV['HOMESHARE'] && ENV['HOMEPATH']
|
197
|
-
paths << ENV['USERPROFILE']
|
198
|
-
end
|
199
|
-
paths << Dir.home if ENV['HOME']
|
200
|
-
|
201
|
-
# Depending on what environment variables we're using, the slashes can go in any which way.
|
202
|
-
# Just change them all to / to keep things consistent.
|
203
|
-
# Note: Maybe this is a bad idea on some unixy systems where \ might be a valid character depending on
|
204
|
-
# the particular brand of kool-aid you consume. This code assumes that \ and / are both
|
205
|
-
# path separators on any system being used.
|
206
|
-
paths = paths.map { |home_path| home_path.gsub(path_separator, ::File::SEPARATOR) if home_path }
|
207
|
-
|
208
|
-
# Filter out duplicate paths and paths that don't exist.
|
209
|
-
valid_paths = paths.select { |home_path| home_path && Dir.exists?(home_path) }
|
210
|
-
valid_paths = valid_paths.uniq
|
211
|
-
|
212
|
-
# Join all optional path elements at the end.
|
213
|
-
# If a block is provided, invoke it - otherwise just return what we've got.
|
214
|
-
joined_paths = valid_paths.map { |home_path| File.join(home_path, *args) }
|
215
|
-
if block_given?
|
216
|
-
joined_paths.each { |p| yield p }
|
217
|
-
else
|
218
|
-
joined_paths
|
219
|
-
end
|
220
|
-
end
|
221
|
-
end
|
23
|
+
PathHelper = ChefConfig::PathHelper
|
222
24
|
end
|
223
25
|
end
|
224
26
|
|
225
|
-
# Break a require loop when require chef/util/path_helper
|
226
|
-
require 'chef/platform'
|
227
|
-
require 'chef/exceptions'
|