chef 12.4.0.rc.0-universal-mingw32 → 12.4.0.rc.2-universal-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +12 -1
- data/lib/chef/api_client.rb +130 -26
- data/lib/chef/application.rb +0 -1
- data/lib/chef/application/client.rb +8 -19
- data/lib/chef/audit/audit_reporter.rb +12 -7
- data/lib/chef/audit/logger.rb +36 -0
- data/lib/chef/audit/runner.rb +4 -2
- data/lib/chef/chef_class.rb +62 -11
- data/lib/chef/client.rb +587 -207
- data/lib/chef/config.rb +0 -1
- data/lib/chef/dsl/recipe.rb +45 -56
- data/lib/chef/dsl/resources.rb +3 -2
- data/lib/chef/event_dispatch/base.rb +7 -2
- data/lib/chef/exceptions.rb +4 -1
- data/lib/chef/file_content_management/deploy/mv_windows.rb +16 -6
- data/lib/chef/formatters/doc.rb +15 -7
- data/lib/chef/formatters/error_inspectors/api_error_formatting.rb +10 -7
- data/lib/chef/guard_interpreter/default_guard_interpreter.rb +2 -0
- data/lib/chef/guard_interpreter/resource_guard_interpreter.rb +4 -1
- data/lib/chef/http/authenticator.rb +7 -2
- data/lib/chef/knife.rb +16 -4
- data/lib/chef/knife/client_create.rb +55 -31
- data/lib/chef/knife/core/generic_presenter.rb +1 -1
- data/lib/chef/knife/core/subcommand_loader.rb +1 -1
- data/lib/chef/knife/osc_user_create.rb +97 -0
- data/lib/chef/knife/osc_user_delete.rb +51 -0
- data/lib/chef/knife/osc_user_edit.rb +58 -0
- data/lib/chef/knife/osc_user_list.rb +47 -0
- data/lib/chef/knife/osc_user_reregister.rb +64 -0
- data/lib/chef/knife/osc_user_show.rb +54 -0
- data/lib/chef/knife/user_create.rb +95 -36
- data/lib/chef/knife/user_delete.rb +52 -2
- data/lib/chef/knife/user_edit.rb +37 -7
- data/lib/chef/knife/user_list.rb +3 -0
- data/lib/chef/knife/user_reregister.rb +39 -8
- data/lib/chef/knife/user_show.rb +30 -1
- data/lib/chef/mixin/api_version_request_handling.rb +66 -0
- data/lib/chef/mixin/convert_to_class_name.rb +10 -4
- data/lib/chef/mixin/deprecation.rb +24 -0
- data/lib/chef/mixin/powershell_out.rb +98 -0
- data/lib/chef/mixin/provides.rb +5 -18
- data/lib/chef/mixin/uris.rb +11 -0
- data/lib/chef/mixin/windows_architecture_helper.rb +5 -2
- data/lib/chef/mixin/windows_env_helper.rb +11 -2
- data/lib/chef/node_map.rb +130 -75
- data/lib/chef/osc_user.rb +194 -0
- data/lib/chef/platform/provider_mapping.rb +2 -269
- data/lib/chef/platform/provider_priority_map.rb +6 -69
- data/lib/chef/platform/query_helpers.rb +5 -0
- data/lib/chef/platform/resource_priority_map.rb +12 -15
- data/lib/chef/policy_builder/policyfile.rb +1 -0
- data/lib/chef/provider.rb +19 -0
- data/lib/chef/provider/directory.rb +3 -0
- data/lib/chef/provider/dsc_resource.rb +8 -1
- data/lib/chef/provider/file.rb +1 -0
- data/lib/chef/provider/group/aix.rb +1 -0
- data/lib/chef/provider/group/dscl.rb +1 -1
- data/lib/chef/provider/group/gpasswd.rb +1 -0
- data/lib/chef/provider/group/groupmod.rb +1 -1
- data/lib/chef/provider/group/pw.rb +1 -0
- data/lib/chef/provider/group/suse.rb +2 -0
- data/lib/chef/provider/group/usermod.rb +2 -1
- data/lib/chef/provider/group/windows.rb +1 -1
- data/lib/chef/provider/ifconfig.rb +2 -0
- data/lib/chef/provider/ifconfig/aix.rb +1 -0
- data/lib/chef/provider/ifconfig/debian.rb +2 -0
- data/lib/chef/provider/ifconfig/redhat.rb +1 -0
- data/lib/chef/provider/lwrp_base.rb +4 -0
- data/lib/chef/provider/mount.rb +0 -1
- data/lib/chef/provider/mount/aix.rb +1 -0
- data/lib/chef/provider/mount/mount.rb +2 -0
- data/lib/chef/provider/mount/solaris.rb +2 -0
- data/lib/chef/provider/package.rb +55 -0
- data/lib/chef/provider/package/aix.rb +7 -7
- data/lib/chef/provider/package/apt.rb +3 -3
- data/lib/chef/provider/package/dpkg.rb +4 -4
- data/lib/chef/provider/package/easy_install.rb +5 -5
- data/lib/chef/provider/package/freebsd/base.rb +2 -2
- data/lib/chef/provider/package/freebsd/pkg.rb +6 -6
- data/lib/chef/provider/package/freebsd/pkgng.rb +5 -5
- data/lib/chef/provider/package/freebsd/port.rb +4 -4
- data/lib/chef/provider/package/homebrew.rb +2 -2
- data/lib/chef/provider/package/ips.rb +4 -4
- data/lib/chef/provider/package/macports.rb +5 -6
- data/lib/chef/provider/package/openbsd.rb +4 -5
- data/lib/chef/provider/package/pacman.rb +4 -4
- data/lib/chef/provider/package/portage.rb +2 -0
- data/lib/chef/provider/package/rpm.rb +7 -8
- data/lib/chef/provider/package/rubygems.rb +5 -12
- data/lib/chef/provider/package/smartos.rb +4 -4
- data/lib/chef/provider/package/solaris.rb +7 -7
- data/lib/chef/provider/package/windows/msi.rb +1 -1
- data/lib/chef/provider/package/yum.rb +4 -6
- data/lib/chef/provider/package/zypper.rb +16 -14
- data/lib/chef/provider/powershell_script.rb +129 -47
- data/lib/chef/provider/remote_file/content.rb +4 -1
- data/lib/chef/provider/remote_file/local_file.rb +10 -4
- data/lib/chef/provider/service.rb +44 -0
- data/lib/chef/provider/service/freebsd.rb +1 -1
- data/lib/chef/provider/service/init.rb +1 -0
- data/lib/chef/provider/service/macosx.rb +1 -1
- data/lib/chef/provider/service/windows.rb +0 -1
- data/lib/chef/provider/user.rb +1 -1
- data/lib/chef/provider/user/aix.rb +3 -2
- data/lib/chef/provider/user/pw.rb +1 -0
- data/lib/chef/provider/user/solaris.rb +2 -0
- data/lib/chef/provider/user/useradd.rb +1 -0
- data/lib/chef/provider_resolver.rb +87 -134
- data/lib/chef/resource.rb +274 -68
- data/lib/chef/resource/apt_package.rb +0 -2
- data/lib/chef/resource/bash.rb +0 -2
- data/lib/chef/resource/batch.rb +1 -1
- data/lib/chef/resource/bff_package.rb +0 -7
- data/lib/chef/resource/breakpoint.rb +3 -6
- data/lib/chef/resource/chef_gem.rb +0 -3
- data/lib/chef/resource/cookbook_file.rb +1 -3
- data/lib/chef/resource/cron.rb +2 -4
- data/lib/chef/resource/csh.rb +0 -2
- data/lib/chef/resource/deploy.rb +9 -6
- data/lib/chef/resource/deploy_revision.rb +0 -14
- data/lib/chef/resource/directory.rb +2 -4
- data/lib/chef/resource/dpkg_package.rb +0 -5
- data/lib/chef/resource/dsc_resource.rb +2 -3
- data/lib/chef/resource/dsc_script.rb +2 -3
- data/lib/chef/resource/easy_install_package.rb +0 -7
- data/lib/chef/resource/env.rb +3 -3
- data/lib/chef/resource/erl_call.rb +2 -5
- data/lib/chef/resource/execute.rb +2 -4
- data/lib/chef/resource/file.rb +2 -4
- data/lib/chef/resource/freebsd_package.rb +0 -5
- data/lib/chef/resource/gem_package.rb +0 -3
- data/lib/chef/resource/git.rb +0 -3
- data/lib/chef/resource/group.rb +2 -4
- data/lib/chef/resource/homebrew_package.rb +0 -2
- data/lib/chef/resource/http_request.rb +3 -4
- data/lib/chef/resource/ifconfig.rb +3 -4
- data/lib/chef/resource/ips_package.rb +2 -2
- data/lib/chef/resource/link.rb +3 -5
- data/lib/chef/resource/log.rb +2 -4
- data/lib/chef/resource/lwrp_base.rb +10 -61
- data/lib/chef/resource/macosx_service.rb +1 -2
- data/lib/chef/resource/macports_package.rb +0 -7
- data/lib/chef/resource/mdadm.rb +2 -5
- data/lib/chef/resource/mount.rb +2 -4
- data/lib/chef/resource/ohai.rb +2 -4
- data/lib/chef/resource/openbsd_package.rb +0 -6
- data/lib/chef/resource/package.rb +9 -6
- data/lib/chef/resource/pacman_package.rb +0 -7
- data/lib/chef/resource/paludis_package.rb +2 -3
- data/lib/chef/resource/perl.rb +0 -3
- data/lib/chef/resource/portage_package.rb +0 -3
- data/lib/chef/resource/powershell_script.rb +1 -2
- data/lib/chef/resource/python.rb +0 -3
- data/lib/chef/resource/reboot.rb +1 -3
- data/lib/chef/resource/registry_key.rb +3 -5
- data/lib/chef/resource/remote_directory.rb +3 -5
- data/lib/chef/resource/remote_file.rb +4 -5
- data/lib/chef/resource/route.rb +3 -5
- data/lib/chef/resource/rpm_package.rb +0 -2
- data/lib/chef/resource/ruby.rb +0 -4
- data/lib/chef/resource/ruby_block.rb +2 -4
- data/lib/chef/resource/scm.rb +3 -5
- data/lib/chef/resource/script.rb +0 -3
- data/lib/chef/resource/service.rb +3 -5
- data/lib/chef/resource/smartos_package.rb +0 -9
- data/lib/chef/resource/solaris_package.rb +0 -10
- data/lib/chef/resource/subversion.rb +1 -3
- data/lib/chef/resource/template.rb +0 -4
- data/lib/chef/resource/timestamped_deploy.rb +0 -4
- data/lib/chef/resource/user.rb +2 -5
- data/lib/chef/resource/whyrun_safe_ruby_block.rb +0 -7
- data/lib/chef/resource/windows_package.rb +3 -3
- data/lib/chef/resource/windows_script.rb +2 -2
- data/lib/chef/resource/windows_service.rb +3 -3
- data/lib/chef/resource/yum_package.rb +0 -3
- data/lib/chef/resource/zypper_package.rb +27 -0
- data/lib/chef/resource_builder.rb +7 -0
- data/lib/chef/resource_reporter.rb +1 -1
- data/lib/chef/resource_resolver.rb +108 -62
- data/lib/chef/resources.rb +1 -0
- data/lib/chef/rest.rb +1 -0
- data/lib/chef/server_api.rb +2 -0
- data/lib/chef/user.rb +193 -42
- data/lib/chef/util/backup.rb +9 -1
- data/lib/chef/util/path_helper.rb +0 -1
- data/lib/chef/version.rb +1 -1
- data/spec/functional/audit/runner_spec.rb +22 -42
- data/spec/functional/mixin/powershell_out_spec.rb +43 -0
- data/spec/functional/resource/execute_spec.rb +9 -2
- data/spec/functional/resource/file_spec.rb +25 -0
- data/spec/functional/resource/group_spec.rb +5 -0
- data/spec/functional/resource/link_spec.rb +5 -11
- data/spec/functional/resource/powershell_spec.rb +40 -5
- data/spec/functional/resource/user/useradd_spec.rb +10 -18
- data/spec/integration/recipes/lwrp_spec.rb +57 -0
- data/spec/integration/recipes/provider_choice.rb +2 -7
- data/spec/integration/recipes/recipe_dsl_spec.rb +517 -19
- data/spec/spec_helper.rb +1 -1
- data/spec/support/lib/chef/provider/openldap_includer.rb +29 -0
- data/spec/support/lib/chef/resource/cat.rb +0 -2
- data/spec/support/lib/chef/resource/one_two_three_four.rb +0 -6
- data/spec/support/lib/chef/resource/openldap_includer.rb +27 -0
- data/spec/support/lib/chef/resource/with_state.rb +0 -9
- data/spec/support/lib/chef/resource/zen_follower.rb +0 -6
- data/spec/support/lib/chef/resource/zen_master.rb +1 -6
- data/spec/support/shared/context/client.rb +277 -0
- data/spec/support/shared/examples/client.rb +53 -0
- data/spec/support/shared/functional/file_resource.rb +0 -4
- data/spec/support/shared/functional/securable_resource.rb +0 -24
- data/spec/support/shared/functional/securable_resource_with_reporting.rb +4 -4
- data/spec/support/shared/functional/windows_script.rb +1 -1
- data/spec/support/shared/unit/api_versioning.rb +77 -0
- data/spec/support/shared/unit/knife_shared.rb +40 -0
- data/spec/support/shared/unit/user_and_client_shared.rb +115 -0
- data/spec/unit/api_client_spec.rb +189 -14
- data/spec/unit/application/client_spec.rb +0 -5
- data/spec/unit/audit/audit_reporter_spec.rb +58 -14
- data/spec/unit/audit/logger_spec.rb +42 -0
- data/spec/unit/audit/runner_spec.rb +2 -2
- data/spec/unit/chef_fs/file_pattern_spec.rb +3 -15
- data/spec/unit/client_spec.rb +58 -374
- data/spec/unit/cookbook_spec.rb +0 -9
- data/spec/unit/cookbook_version_spec.rb +0 -20
- data/spec/unit/deprecation_spec.rb +55 -0
- data/spec/unit/dsl/resources_spec.rb +85 -0
- data/spec/unit/exceptions_spec.rb +2 -2
- data/spec/unit/file_content_management/deploy/mv_windows_spec.rb +60 -0
- data/spec/unit/formatters/doc_spec.rb +46 -0
- data/spec/unit/formatters/error_inspectors/api_error_formatting_spec.rb +12 -10
- data/spec/unit/guard_interpreter/resource_guard_interpreter_spec.rb +8 -0
- data/spec/unit/http/authenticator_spec.rb +11 -2
- data/spec/unit/knife/client_create_spec.rb +122 -51
- data/spec/unit/knife/core/subcommand_loader_spec.rb +19 -3
- data/spec/unit/knife/core/ui_spec.rb +14 -0
- data/spec/unit/knife/osc_user_create_spec.rb +93 -0
- data/spec/unit/knife/osc_user_delete_spec.rb +44 -0
- data/spec/unit/knife/osc_user_edit_spec.rb +52 -0
- data/spec/unit/knife/osc_user_list_spec.rb +37 -0
- data/spec/unit/knife/osc_user_reregister_spec.rb +58 -0
- data/spec/unit/knife/osc_user_show_spec.rb +46 -0
- data/spec/unit/knife/user_create_spec.rb +177 -51
- data/spec/unit/knife/user_delete_spec.rb +34 -8
- data/spec/unit/knife/user_edit_spec.rb +31 -12
- data/spec/unit/knife/user_list_spec.rb +7 -3
- data/spec/unit/knife/user_reregister_spec.rb +38 -17
- data/spec/unit/knife/user_show_spec.rb +35 -11
- data/spec/unit/knife_spec.rb +10 -4
- data/spec/unit/lwrp_spec.rb +228 -54
- data/spec/unit/mixin/api_version_request_handling_spec.rb +127 -0
- data/spec/unit/mixin/command_spec.rb +1 -2
- data/spec/unit/mixin/powershell_out_spec.rb +70 -0
- data/spec/unit/mixin/uris_spec.rb +23 -11
- data/spec/unit/node_map_spec.rb +4 -1
- data/spec/unit/osc_user_spec.rb +276 -0
- data/spec/unit/platform_spec.rb +0 -60
- data/spec/unit/provider/deploy_spec.rb +1 -1
- data/spec/unit/provider/directory_spec.rb +199 -135
- data/spec/unit/provider/ifconfig/debian_spec.rb +0 -10
- data/spec/unit/provider/package/aix_spec.rb +16 -16
- data/spec/unit/provider/package/dpkg_spec.rb +2 -2
- data/spec/unit/provider/package/freebsd/pkg_spec.rb +13 -13
- data/spec/unit/provider/package/freebsd/pkgng_spec.rb +9 -9
- data/spec/unit/provider/package/freebsd/port_spec.rb +7 -7
- data/spec/unit/provider/package/ips_spec.rb +22 -22
- data/spec/unit/provider/package/macports_spec.rb +10 -10
- data/spec/unit/provider/package/openbsd_spec.rb +4 -26
- data/spec/unit/provider/package/pacman_spec.rb +5 -5
- data/spec/unit/provider/package/rpm_spec.rb +14 -14
- data/spec/unit/provider/package/rubygems_spec.rb +10 -44
- data/spec/unit/provider/package/smartos_spec.rb +4 -4
- data/spec/unit/provider/package/solaris_spec.rb +11 -11
- data/spec/unit/provider/package/zypper_spec.rb +125 -90
- data/spec/unit/provider/package_spec.rb +34 -0
- data/spec/unit/provider/powershell_spec.rb +53 -11
- data/spec/unit/provider/remote_directory_spec.rb +2 -2
- data/spec/unit/provider/remote_file/local_file_spec.rb +25 -6
- data/spec/unit/provider/service/freebsd_service_spec.rb +0 -12
- data/spec/unit/provider/user_spec.rb +3 -3
- data/spec/unit/provider_resolver_spec.rb +463 -327
- data/spec/unit/recipe_spec.rb +42 -15
- data/spec/unit/resource/breakpoint_spec.rb +1 -1
- data/spec/unit/resource/erl_call_spec.rb +1 -1
- data/spec/unit/resource/file_spec.rb +1 -1
- data/spec/unit/resource/ifconfig_spec.rb +10 -6
- data/spec/unit/resource/remote_file_spec.rb +5 -0
- data/spec/unit/resource/route_spec.rb +1 -1
- data/spec/unit/resource/ruby_block_spec.rb +2 -2
- data/spec/unit/resource/template_spec.rb +1 -1
- data/spec/unit/resource/timestamped_deploy_spec.rb +1 -2
- data/spec/unit/resource/windows_service_spec.rb +1 -1
- data/spec/unit/resource_spec.rb +99 -13
- data/spec/unit/rest_spec.rb +5 -5
- data/spec/unit/run_context_spec.rb +41 -0
- data/spec/unit/runner_spec.rb +2 -2
- data/spec/unit/user_spec.rb +406 -93
- data/tasks/maintainers.rb +69 -0
- metadata +37 -4
data/lib/chef/mixin/provides.rb
CHANGED
@@ -4,30 +4,17 @@ require 'chef/mixin/descendants_tracker'
|
|
4
4
|
class Chef
|
5
5
|
module Mixin
|
6
6
|
module Provides
|
7
|
+
# TODO no longer needed, remove or deprecate?
|
7
8
|
include Chef::Mixin::DescendantsTracker
|
8
9
|
|
9
|
-
def node_map
|
10
|
-
@node_map ||= Chef::NodeMap.new
|
11
|
-
end
|
12
|
-
|
13
10
|
def provides(short_name, opts={}, &block)
|
14
|
-
|
15
|
-
# YAGNI: this is probably completely unnecessary and can be removed?
|
16
|
-
Chef::Log.deprecation "Passing a non-Symbol to Chef::Resource#provides will be removed"
|
17
|
-
if short_name.kind_of?(String)
|
18
|
-
short_name.downcase!
|
19
|
-
short_name.gsub!(/\s/, "_")
|
20
|
-
end
|
21
|
-
short_name = short_name.to_sym
|
22
|
-
end
|
23
|
-
node_map.set(short_name, true, opts, &block)
|
11
|
+
raise NotImplementedError, :provides
|
24
12
|
end
|
25
13
|
|
26
14
|
# Check whether this resource provides the resource_name DSL for the given
|
27
|
-
# node
|
28
|
-
def provides?(node,
|
29
|
-
|
30
|
-
node_map.get(node, resource_name)
|
15
|
+
# node. TODO remove this when we stop checking unregistered things.
|
16
|
+
def provides?(node, resource)
|
17
|
+
raise NotImplementedError, :provides?
|
31
18
|
end
|
32
19
|
|
33
20
|
# Get the list of recipe DSL this resource is responsible for on the given
|
data/lib/chef/mixin/uris.rb
CHANGED
@@ -28,6 +28,17 @@ class Chef
|
|
28
28
|
# From open-uri
|
29
29
|
!!(%r{\A[A-Za-z][A-Za-z0-9+\-\.]*://} =~ source)
|
30
30
|
end
|
31
|
+
|
32
|
+
|
33
|
+
def as_uri(source)
|
34
|
+
begin
|
35
|
+
URI.parse(source)
|
36
|
+
rescue URI::InvalidURIError
|
37
|
+
Chef::Log.warn("#{source} was an invalid URI. Trying to escape invalid characters")
|
38
|
+
URI.parse(URI.escape(source))
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
31
42
|
end
|
32
43
|
end
|
33
44
|
end
|
@@ -42,7 +42,7 @@ class Chef
|
|
42
42
|
is_i386_process_on_x86_64_windows?
|
43
43
|
end
|
44
44
|
|
45
|
-
def with_os_architecture(node)
|
45
|
+
def with_os_architecture(node, architecture: nil)
|
46
46
|
node ||= begin
|
47
47
|
os_arch = ENV['PROCESSOR_ARCHITEW6432'] ||
|
48
48
|
ENV['PROCESSOR_ARCHITECTURE']
|
@@ -51,9 +51,12 @@ class Chef
|
|
51
51
|
n[:kernel][:machine] = os_arch == 'AMD64' ? :x86_64 : :i386
|
52
52
|
end
|
53
53
|
end
|
54
|
+
|
55
|
+
architecture ||= node_windows_architecture(node)
|
56
|
+
|
54
57
|
wow64_redirection_state = nil
|
55
58
|
|
56
|
-
if wow64_architecture_override_required?(node,
|
59
|
+
if wow64_architecture_override_required?(node, architecture)
|
57
60
|
wow64_redirection_state = disable_wow64_file_redirection(node)
|
58
61
|
end
|
59
62
|
|
@@ -21,11 +21,11 @@ require 'chef/exceptions'
|
|
21
21
|
require 'chef/platform/query_helpers'
|
22
22
|
require 'chef/win32/error' if Chef::Platform.windows?
|
23
23
|
require 'chef/win32/api/system' if Chef::Platform.windows?
|
24
|
+
require 'chef/win32/api/unicode' if Chef::Platform.windows?
|
24
25
|
|
25
26
|
class Chef
|
26
27
|
module Mixin
|
27
28
|
module WindowsEnvHelper
|
28
|
-
|
29
29
|
if Chef::Platform.windows?
|
30
30
|
include Chef::ReservedNames::Win32::API::System
|
31
31
|
end
|
@@ -39,7 +39,16 @@ class Chef
|
|
39
39
|
|
40
40
|
def broadcast_env_change
|
41
41
|
flags = SMTO_BLOCK | SMTO_ABORTIFHUNG | SMTO_NOTIMEOUTIFNOTHUNG
|
42
|
-
|
42
|
+
# for why two calls, see:
|
43
|
+
# http://stackoverflow.com/questions/4968373/why-doesnt-sendmessagetimeout-update-the-environment-variables
|
44
|
+
if ( SendMessageTimeoutA(HWND_BROADCAST, WM_SETTINGCHANGE, 0, FFI::MemoryPointer.from_string('Environment').address, flags, 5000, nil) == 0 )
|
45
|
+
Chef::ReservedNames::Win32::Error.raise!
|
46
|
+
end
|
47
|
+
if ( SendMessageTimeoutW(HWND_BROADCAST, WM_SETTINGCHANGE, 0, FFI::MemoryPointer.from_string(
|
48
|
+
Chef::ReservedNames::Win32::Unicode.utf8_to_wide('Environment')
|
49
|
+
).address, flags, 5000, nil) == 0 )
|
50
|
+
Chef::ReservedNames::Win32::Error.raise!
|
51
|
+
end
|
43
52
|
end
|
44
53
|
|
45
54
|
def expand_path(path)
|
data/lib/chef/node_map.rb
CHANGED
@@ -19,128 +19,183 @@
|
|
19
19
|
class Chef
|
20
20
|
class NodeMap
|
21
21
|
|
22
|
-
|
23
|
-
:on_platform,
|
24
|
-
:on_platforms,
|
25
|
-
:platform,
|
26
|
-
:os,
|
27
|
-
:platform_family,
|
28
|
-
]
|
29
|
-
|
30
|
-
DEPRECATED_OPTS = [
|
31
|
-
:on_platform,
|
32
|
-
:on_platforms,
|
33
|
-
]
|
34
|
-
|
22
|
+
#
|
35
23
|
# Create a new NodeMap
|
36
24
|
#
|
37
25
|
def initialize
|
38
26
|
@map = {}
|
39
27
|
end
|
40
28
|
|
29
|
+
#
|
41
30
|
# Set a key/value pair on the map with a filter. The filter must be true
|
42
31
|
# when applied to the node in order to retrieve the value.
|
43
32
|
#
|
44
33
|
# @param key [Object] Key to store
|
45
34
|
# @param value [Object] Value associated with the key
|
46
35
|
# @param filters [Hash] Node filter options to apply to key retrieval
|
36
|
+
#
|
47
37
|
# @yield [node] Arbitrary node filter as a block which takes a node argument
|
38
|
+
#
|
48
39
|
# @return [NodeMap] Returns self for possible chaining
|
49
40
|
#
|
50
|
-
def set(key, value,
|
51
|
-
|
52
|
-
|
41
|
+
def set(key, value, platform: nil, platform_version: nil, platform_family: nil, os: nil, on_platform: nil, on_platforms: nil, canonical: nil, &block)
|
42
|
+
Chef::Log.deprecation "The on_platform option to node_map has been deprecated" if on_platform
|
43
|
+
Chef::Log.deprecation "The on_platforms option to node_map has been deprecated" if on_platforms
|
44
|
+
platform ||= on_platform || on_platforms
|
45
|
+
filters = { platform: platform, platform_version: platform_version, platform_family: platform_family, os: os }
|
46
|
+
new_matcher = { filters: filters, block: block, value: value, canonical: canonical }
|
53
47
|
@map[key] ||= []
|
54
|
-
#
|
55
|
-
#
|
56
|
-
#
|
57
|
-
|
48
|
+
# Decide where to insert the matcher; the new value is preferred over
|
49
|
+
# anything more specific (see `priority_of`) and is preferred over older
|
50
|
+
# values of the same specificity. (So all other things being equal,
|
51
|
+
# newest wins.)
|
52
|
+
insert_at = nil
|
53
|
+
@map[key].each_with_index do |matcher, index|
|
54
|
+
if specificity(new_matcher) >= specificity(matcher)
|
55
|
+
insert_at = index
|
56
|
+
break
|
57
|
+
end
|
58
|
+
end
|
59
|
+
if insert_at
|
60
|
+
@map[key].insert(insert_at, new_matcher)
|
61
|
+
else
|
62
|
+
@map[key] << new_matcher
|
63
|
+
end
|
58
64
|
self
|
59
65
|
end
|
60
66
|
|
67
|
+
#
|
61
68
|
# Get a value from the NodeMap via applying the node to the filters that
|
62
69
|
# were set on the key.
|
63
70
|
#
|
64
|
-
# @param node [Chef::Node] The Chef::Node object for the run
|
71
|
+
# @param node [Chef::Node] The Chef::Node object for the run, or `nil` to
|
72
|
+
# ignore all filters.
|
65
73
|
# @param key [Object] Key to look up
|
74
|
+
# @param canonical [Boolean] `true` or `false` to match canonical or
|
75
|
+
# non-canonical values only. `nil` to ignore canonicality. Default: `nil`
|
76
|
+
#
|
66
77
|
# @return [Object] Value
|
67
78
|
#
|
68
|
-
def get(node, key)
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
79
|
+
def get(node, key, canonical: nil)
|
80
|
+
raise ArgumentError, "first argument must be a Chef::Node" unless node.is_a?(Chef::Node) || node.nil?
|
81
|
+
list(node, key, canonical: canonical).first
|
82
|
+
end
|
83
|
+
|
84
|
+
#
|
85
|
+
# List all matches for the given node and key from the NodeMap, from
|
86
|
+
# most-recently added to oldest.
|
87
|
+
#
|
88
|
+
# @param node [Chef::Node] The Chef::Node object for the run, or `nil` to
|
89
|
+
# ignore all filters.
|
90
|
+
# @param key [Object] Key to look up
|
91
|
+
# @param canonical [Boolean] `true` or `false` to match canonical or
|
92
|
+
# non-canonical values only. `nil` to ignore canonicality. Default: `nil`
|
93
|
+
#
|
94
|
+
# @return [Object] Value
|
95
|
+
#
|
96
|
+
def list(node, key, canonical: nil)
|
97
|
+
raise ArgumentError, "first argument must be a Chef::Node" unless node.is_a?(Chef::Node) || node.nil?
|
98
|
+
return [] unless @map.has_key?(key)
|
99
|
+
@map[key].select do |matcher|
|
100
|
+
node_matches?(node, matcher) && canonical_matches?(canonical, matcher)
|
101
|
+
end.map { |matcher| matcher[:value] }
|
102
|
+
end
|
103
|
+
|
104
|
+
# Seriously, don't use this, it's nearly certain to change on you
|
105
|
+
# @return remaining
|
106
|
+
# @api private
|
107
|
+
def delete_canonical(key, value)
|
108
|
+
remaining = @map[key]
|
109
|
+
if remaining
|
110
|
+
remaining.delete_if { |matcher| matcher[:canonical] && Array(matcher[:value]) == Array(value) }
|
111
|
+
if remaining.empty?
|
112
|
+
@map.delete(key)
|
113
|
+
remaining = nil
|
76
114
|
end
|
77
115
|
end
|
78
|
-
|
116
|
+
remaining
|
79
117
|
end
|
80
118
|
|
81
119
|
private
|
82
120
|
|
83
|
-
#
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
121
|
+
#
|
122
|
+
# Gives a value for "how specific" the matcher is.
|
123
|
+
# Things which specify more specific filters get a higher number
|
124
|
+
# (platform_version > platform > platform_family > os); things
|
125
|
+
# with a block have higher specificity than similar things without
|
126
|
+
# a block.
|
127
|
+
#
|
128
|
+
def specificity(matcher)
|
129
|
+
if matcher[:filters][:platform_version]
|
130
|
+
specificity = 8
|
131
|
+
elsif matcher[:filters][:platform]
|
132
|
+
specificity = 6
|
133
|
+
elsif matcher[:filters][:platform_family]
|
134
|
+
specificity = 4
|
135
|
+
elsif matcher[:filters][:os]
|
136
|
+
specificity = 2
|
137
|
+
else
|
138
|
+
specificity = 0
|
88
139
|
end
|
140
|
+
specificity += 1 if matcher[:block]
|
141
|
+
specificity
|
89
142
|
end
|
90
143
|
|
91
|
-
#
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
144
|
+
#
|
145
|
+
# Succeeds if:
|
146
|
+
# - no negative matches (!value)
|
147
|
+
# - at least one positive match (value or :all), or no positive filters
|
148
|
+
#
|
149
|
+
def matches_black_white_list?(node, filters, attribute)
|
150
|
+
# It's super common for the filter to be nil. Catch that so we don't
|
151
|
+
# spend any time here.
|
152
|
+
return true if !filters[attribute]
|
153
|
+
filter_values = Array(filters[attribute])
|
154
|
+
value = node[attribute]
|
97
155
|
|
98
|
-
|
99
|
-
|
100
|
-
# We support strings prefaced by '!' to mean 'not'. In particular, this is most useful
|
101
|
-
# for os matching on '!windows'.
|
102
|
-
negative_matches = filter.select { |f| f[0] == '!' }
|
103
|
-
return true if !negative_matches.empty? && negative_matches.include?('!' + param)
|
156
|
+
# Split the blacklist and whitelist
|
157
|
+
blacklist, whitelist = filter_values.partition { |v| v.is_a?(String) && v.start_with?('!') }
|
104
158
|
|
105
|
-
#
|
106
|
-
|
107
|
-
positive_matches = filter.reject { |f| f[0] == '!' || f == :all }
|
108
|
-
return true if !positive_matches.empty? && !positive_matches.include?(param)
|
159
|
+
# If any blacklist value matches, we don't match
|
160
|
+
return false if blacklist.any? { |v| v[1..-1] == value }
|
109
161
|
|
110
|
-
#
|
111
|
-
|
162
|
+
# If the whitelist is empty, or anything matches, we match.
|
163
|
+
whitelist.empty? || whitelist.any? { |v| v == :all || v == value }
|
112
164
|
end
|
113
165
|
|
114
|
-
def
|
115
|
-
|
166
|
+
def matches_version_list?(node, filters, attribute)
|
167
|
+
# It's super common for the filter to be nil. Catch that so we don't
|
168
|
+
# spend any time here.
|
169
|
+
return true if !filters[attribute]
|
170
|
+
filter_values = Array(filters[attribute])
|
171
|
+
value = node[attribute]
|
116
172
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
# effectively joined by 'or'.
|
121
|
-
|
122
|
-
os_filter = [ filters[:os] ].flatten.compact
|
123
|
-
unless os_filter.empty?
|
124
|
-
return false if negative_match(os_filter, node[:os])
|
125
|
-
end
|
126
|
-
|
127
|
-
platform_family_filter = [ filters[:platform_family] ].flatten.compact
|
128
|
-
unless platform_family_filter.empty?
|
129
|
-
return false if negative_match(platform_family_filter, node[:platform_family])
|
130
|
-
end
|
131
|
-
|
132
|
-
# :on_platform and :on_platforms here are synonyms which are deprecated
|
133
|
-
platform_filter = [ filters[:platform] || filters[:on_platform] || filters[:on_platforms] ].flatten.compact
|
134
|
-
unless platform_filter.empty?
|
135
|
-
return false if negative_match(platform_filter, node[:platform])
|
173
|
+
filter_values.empty? ||
|
174
|
+
Array(filter_values).any? do |v|
|
175
|
+
Chef::VersionConstraint::Platform.new(v).include?(value)
|
136
176
|
end
|
177
|
+
end
|
137
178
|
|
138
|
-
|
179
|
+
def filters_match?(node, filters)
|
180
|
+
matches_black_white_list?(node, filters, :os) &&
|
181
|
+
matches_black_white_list?(node, filters, :platform_family) &&
|
182
|
+
matches_black_white_list?(node, filters, :platform) &&
|
183
|
+
matches_version_list?(node, filters, :platform_version)
|
139
184
|
end
|
140
185
|
|
141
186
|
def block_matches?(node, block)
|
142
187
|
return true if block.nil?
|
143
188
|
block.call node
|
144
189
|
end
|
190
|
+
|
191
|
+
def node_matches?(node, matcher)
|
192
|
+
return true if !node
|
193
|
+
filters_match?(node, matcher[:filters]) && block_matches?(node, matcher[:block])
|
194
|
+
end
|
195
|
+
|
196
|
+
def canonical_matches?(canonical, matcher)
|
197
|
+
return true if canonical.nil?
|
198
|
+
!!canonical == !!matcher[:canonical]
|
199
|
+
end
|
145
200
|
end
|
146
201
|
end
|
@@ -0,0 +1,194 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Steven Danna (steve@opscode.com)
|
3
|
+
# Copyright:: Copyright 2012 Opscode, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
require 'chef/config'
|
19
|
+
require 'chef/mixin/params_validate'
|
20
|
+
require 'chef/mixin/from_file'
|
21
|
+
require 'chef/mash'
|
22
|
+
require 'chef/json_compat'
|
23
|
+
require 'chef/search/query'
|
24
|
+
|
25
|
+
# TODO
|
26
|
+
# DEPRECATION NOTE
|
27
|
+
# This class was previously Chef::User. It is the code to support the User object
|
28
|
+
# corrosponding to the Open Source Chef Server 11 and only still exists to support
|
29
|
+
# users still on OSC 11.
|
30
|
+
#
|
31
|
+
# Chef::User now supports Chef Server 12.
|
32
|
+
#
|
33
|
+
# New development should occur in Chef::User.
|
34
|
+
# This file and corrosponding osc_user knife files
|
35
|
+
# should be removed once client support for Open Source Chef Server 11 expires.
|
36
|
+
class Chef
|
37
|
+
class OscUser
|
38
|
+
|
39
|
+
include Chef::Mixin::FromFile
|
40
|
+
include Chef::Mixin::ParamsValidate
|
41
|
+
|
42
|
+
def initialize
|
43
|
+
@name = ''
|
44
|
+
@public_key = nil
|
45
|
+
@private_key = nil
|
46
|
+
@password = nil
|
47
|
+
@admin = false
|
48
|
+
end
|
49
|
+
|
50
|
+
def name(arg=nil)
|
51
|
+
set_or_return(:name, arg,
|
52
|
+
:regex => /^[a-z0-9\-_]+$/)
|
53
|
+
end
|
54
|
+
|
55
|
+
def admin(arg=nil)
|
56
|
+
set_or_return(:admin,
|
57
|
+
arg, :kind_of => [TrueClass, FalseClass])
|
58
|
+
end
|
59
|
+
|
60
|
+
def public_key(arg=nil)
|
61
|
+
set_or_return(:public_key,
|
62
|
+
arg, :kind_of => String)
|
63
|
+
end
|
64
|
+
|
65
|
+
def private_key(arg=nil)
|
66
|
+
set_or_return(:private_key,
|
67
|
+
arg, :kind_of => String)
|
68
|
+
end
|
69
|
+
|
70
|
+
def password(arg=nil)
|
71
|
+
set_or_return(:password,
|
72
|
+
arg, :kind_of => String)
|
73
|
+
end
|
74
|
+
|
75
|
+
def to_hash
|
76
|
+
result = {
|
77
|
+
"name" => @name,
|
78
|
+
"public_key" => @public_key,
|
79
|
+
"admin" => @admin
|
80
|
+
}
|
81
|
+
result["private_key"] = @private_key if @private_key
|
82
|
+
result["password"] = @password if @password
|
83
|
+
result
|
84
|
+
end
|
85
|
+
|
86
|
+
def to_json(*a)
|
87
|
+
Chef::JSONCompat.to_json(to_hash, *a)
|
88
|
+
end
|
89
|
+
|
90
|
+
def destroy
|
91
|
+
Chef::REST.new(Chef::Config[:chef_server_url]).delete_rest("users/#{@name}")
|
92
|
+
end
|
93
|
+
|
94
|
+
def create
|
95
|
+
payload = {:name => self.name, :admin => self.admin, :password => self.password }
|
96
|
+
payload[:public_key] = public_key if public_key
|
97
|
+
new_user =Chef::REST.new(Chef::Config[:chef_server_url]).post_rest("users", payload)
|
98
|
+
Chef::OscUser.from_hash(self.to_hash.merge(new_user))
|
99
|
+
end
|
100
|
+
|
101
|
+
def update(new_key=false)
|
102
|
+
payload = {:name => name, :admin => admin}
|
103
|
+
payload[:private_key] = new_key if new_key
|
104
|
+
payload[:password] = password if password
|
105
|
+
updated_user = Chef::REST.new(Chef::Config[:chef_server_url]).put_rest("users/#{name}", payload)
|
106
|
+
Chef::OscUser.from_hash(self.to_hash.merge(updated_user))
|
107
|
+
end
|
108
|
+
|
109
|
+
def save(new_key=false)
|
110
|
+
begin
|
111
|
+
create
|
112
|
+
rescue Net::HTTPServerException => e
|
113
|
+
if e.response.code == "409"
|
114
|
+
update(new_key)
|
115
|
+
else
|
116
|
+
raise e
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def reregister
|
122
|
+
r = Chef::REST.new(Chef::Config[:chef_server_url])
|
123
|
+
reregistered_self = r.put_rest("users/#{name}", { :name => name, :admin => admin, :private_key => true })
|
124
|
+
private_key(reregistered_self["private_key"])
|
125
|
+
self
|
126
|
+
end
|
127
|
+
|
128
|
+
def to_s
|
129
|
+
"user[#{@name}]"
|
130
|
+
end
|
131
|
+
|
132
|
+
def inspect
|
133
|
+
"Chef::OscUser name:'#{name}' admin:'#{admin.inspect}'" +
|
134
|
+
"public_key:'#{public_key}' private_key:#{private_key}"
|
135
|
+
end
|
136
|
+
|
137
|
+
# Class Methods
|
138
|
+
|
139
|
+
def self.from_hash(user_hash)
|
140
|
+
user = Chef::OscUser.new
|
141
|
+
user.name user_hash['name']
|
142
|
+
user.private_key user_hash['private_key'] if user_hash.key?('private_key')
|
143
|
+
user.password user_hash['password'] if user_hash.key?('password')
|
144
|
+
user.public_key user_hash['public_key']
|
145
|
+
user.admin user_hash['admin']
|
146
|
+
user
|
147
|
+
end
|
148
|
+
|
149
|
+
def self.from_json(json)
|
150
|
+
Chef::OscUser.from_hash(Chef::JSONCompat.from_json(json))
|
151
|
+
end
|
152
|
+
|
153
|
+
class << self
|
154
|
+
alias_method :json_create, :from_json
|
155
|
+
end
|
156
|
+
|
157
|
+
def self.list(inflate=false)
|
158
|
+
response = Chef::REST.new(Chef::Config[:chef_server_url]).get_rest('users')
|
159
|
+
users = if response.is_a?(Array)
|
160
|
+
transform_ohc_list_response(response) # OHC/OPC
|
161
|
+
else
|
162
|
+
response # OSC
|
163
|
+
end
|
164
|
+
if inflate
|
165
|
+
users.inject({}) do |user_map, (name, _url)|
|
166
|
+
user_map[name] = Chef::OscUser.load(name)
|
167
|
+
user_map
|
168
|
+
end
|
169
|
+
else
|
170
|
+
users
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
def self.load(name)
|
175
|
+
response = Chef::REST.new(Chef::Config[:chef_server_url]).get_rest("users/#{name}")
|
176
|
+
Chef::OscUser.from_hash(response)
|
177
|
+
end
|
178
|
+
|
179
|
+
# Gross. Transforms an API response in the form of:
|
180
|
+
# [ { "user" => { "username" => USERNAME }}, ...]
|
181
|
+
# into the form
|
182
|
+
# { "USERNAME" => "URI" }
|
183
|
+
def self.transform_ohc_list_response(response)
|
184
|
+
new_response = Hash.new
|
185
|
+
response.each do |u|
|
186
|
+
name = u['user']['username']
|
187
|
+
new_response[name] = Chef::Config[:chef_server_url] + "/users/#{name}"
|
188
|
+
end
|
189
|
+
new_response
|
190
|
+
end
|
191
|
+
|
192
|
+
private_class_method :transform_ohc_list_response
|
193
|
+
end
|
194
|
+
end
|