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
@@ -22,13 +22,10 @@ require 'chef/provider/package/yum'
|
|
22
22
|
class Chef
|
23
23
|
class Resource
|
24
24
|
class YumPackage < Chef::Resource::Package
|
25
|
-
|
26
|
-
provides :yum_package
|
27
25
|
provides :package, os: "linux", platform_family: [ "rhel", "fedora" ]
|
28
26
|
|
29
27
|
def initialize(name, run_context=nil)
|
30
28
|
super
|
31
|
-
@resource_name = :yum_package
|
32
29
|
@flush_cache = { :before => false, :after => false }
|
33
30
|
@allow_downgrade = false
|
34
31
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Joe Williams (<joe@joetify.com>)
|
3
|
+
# Copyright:: Copyright (c) 2009 Joe Williams
|
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
|
+
|
19
|
+
require 'chef/resource/package'
|
20
|
+
|
21
|
+
class Chef
|
22
|
+
class Resource
|
23
|
+
class ZypperPackage < Chef::Resource::Package
|
24
|
+
provides :package, platform_family: "suse"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -18,6 +18,10 @@
|
|
18
18
|
|
19
19
|
# NOTE: this was extracted from the Recipe DSL mixin, relevant specs are in spec/unit/recipe_spec.rb
|
20
20
|
|
21
|
+
require 'chef/exceptions'
|
22
|
+
require 'chef/resource'
|
23
|
+
require 'chef/log'
|
24
|
+
|
21
25
|
class Chef
|
22
26
|
class ResourceBuilder
|
23
27
|
attr_reader :type
|
@@ -46,6 +50,9 @@ class Chef
|
|
46
50
|
raise ArgumentError, "You must supply a name when declaring a #{type} resource" if name.nil?
|
47
51
|
|
48
52
|
@resource = resource_class.new(name, run_context)
|
53
|
+
if resource.resource_name.nil?
|
54
|
+
raise Chef::Exceptions::InvalidResourceSpecification, "#{resource}.resource_name is `nil`! Did you forget to put `provides :blah` or `resource_name :blah` in your resource class?"
|
55
|
+
end
|
49
56
|
resource.source_line = created_at
|
50
57
|
resource.declared_type = type
|
51
58
|
|
@@ -18,94 +18,140 @@
|
|
18
18
|
|
19
19
|
require 'chef/exceptions'
|
20
20
|
require 'chef/platform/resource_priority_map'
|
21
|
-
require 'chef/mixin/convert_to_class_name'
|
22
21
|
|
23
22
|
class Chef
|
24
23
|
class ResourceResolver
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
24
|
+
#
|
25
|
+
# Resolve a resource by name.
|
26
|
+
#
|
27
|
+
# @param resource_name [Symbol] The resource DSL name (e.g. `:file`).
|
28
|
+
# @param node [Chef::Node] The node against which to resolve. `nil` causes
|
29
|
+
# platform filters to be ignored.
|
30
|
+
#
|
31
|
+
def self.resolve(resource_name, node: nil, canonical: nil)
|
32
|
+
new(node, resource_name, canonical: canonical).resolve
|
34
33
|
end
|
35
34
|
|
36
|
-
#
|
37
|
-
|
38
|
-
|
35
|
+
#
|
36
|
+
# Resolve a list of all resources that implement the given DSL (in order of
|
37
|
+
# preference).
|
38
|
+
#
|
39
|
+
# @param resource_name [Symbol] The resource DSL name (e.g. `:file`).
|
40
|
+
# @param node [Chef::Node] The node against which to resolve. `nil` causes
|
41
|
+
# platform filters to be ignored.
|
42
|
+
# @param canonical [Boolean] `true` or `false` to match canonical or
|
43
|
+
# non-canonical values only. `nil` to ignore canonicality.
|
44
|
+
#
|
45
|
+
def self.list(resource_name, node: nil, canonical: nil)
|
46
|
+
new(node, resource_name, canonical: canonical).list
|
39
47
|
end
|
40
48
|
|
41
|
-
def resolve
|
42
|
-
maybe_dynamic_resource_resolution ||
|
43
|
-
maybe_chef_platform_lookup
|
44
|
-
end
|
45
49
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
50
|
+
include Chef::Mixin::ConvertToClassName
|
51
|
+
|
52
|
+
# @api private
|
53
|
+
attr_reader :node
|
54
|
+
# @api private
|
55
|
+
attr_reader :resource_name
|
56
|
+
# @api private
|
57
|
+
def resource
|
58
|
+
Chef::Log.deprecation("Chef::ResourceResolver.resource deprecated. Use resource_name instead.")
|
59
|
+
resource_name
|
52
60
|
end
|
61
|
+
# @api private
|
62
|
+
attr_reader :action
|
63
|
+
# @api private
|
64
|
+
attr_reader :canonical
|
53
65
|
|
54
66
|
#
|
55
|
-
#
|
67
|
+
# Create a resolver.
|
56
68
|
#
|
57
|
-
# @param
|
58
|
-
#
|
69
|
+
# @param node [Chef::Node] The node against which to resolve. `nil` causes
|
70
|
+
# platform filters to be ignored.
|
71
|
+
# @param resource_name [Symbol] The resource DSL name (e.g. `:file`).
|
72
|
+
# @param canonical [Boolean] `true` or `false` to match canonical or
|
73
|
+
# non-canonical values only. `nil` to ignore canonicality. Default: `nil`
|
59
74
|
#
|
60
|
-
|
61
|
-
|
75
|
+
# @api private use Chef::ResourceResolver.resolve or .list instead.
|
76
|
+
def initialize(node, resource_name, canonical: nil)
|
77
|
+
@node = node
|
78
|
+
@resource_name = resource_name.to_sym
|
79
|
+
@canonical = canonical
|
62
80
|
end
|
63
81
|
|
64
|
-
private
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
Chef::Log.debug "resources for generic #{resource} resource enabled on node include: #{enabled_handlers}"
|
69
|
-
|
70
|
-
# if none of the resources specifically support the resource, we still need to pick one of the resources that are
|
71
|
-
# enabled on the node to handle the why-run use case.
|
72
|
-
handlers = enabled_handlers
|
73
|
-
|
74
|
-
if handlers.size >= 2
|
75
|
-
# this magic stack ranks the resources by where they appear in the resource_priority_map
|
76
|
-
priority_list = [ get_priority_array(node, resource) ].flatten.compact
|
77
|
-
handlers = handlers.sort_by { |x| i = priority_list.index x; i.nil? ? Float::INFINITY : i }
|
78
|
-
if priority_list.index(handlers.first).nil?
|
79
|
-
# if we had more than one and we picked one with a precidence of infinity that means that the resource_priority_map
|
80
|
-
# entry for this resource is missing -- we should probably raise here and force resolution of the ambiguity.
|
81
|
-
Chef::Log.warn "Ambiguous resource precedence: #{handlers}, please use Chef.set_resource_priority_array to provide determinism"
|
82
|
-
end
|
83
|
-
handlers = handlers[0..0]
|
84
|
-
end
|
82
|
+
# @api private use Chef::ResourceResolver.resolve instead.
|
83
|
+
def resolve
|
84
|
+
# log this so we know what resources will work for the generic resource on the node (early cut)
|
85
|
+
Chef::Log.debug "Resources for generic #{resource_name} resource enabled on node include: #{prioritized_handlers}"
|
85
86
|
|
86
|
-
|
87
|
+
handler = prioritized_handlers.first
|
87
88
|
|
88
|
-
|
89
|
+
if handler
|
90
|
+
Chef::Log.debug "Resource for #{resource_name} is #{handler}"
|
91
|
+
else
|
92
|
+
Chef::Log.debug "Dynamic resource resolver FAILED to resolve a resource for #{resource_name}"
|
93
|
+
end
|
89
94
|
|
90
|
-
|
95
|
+
handler
|
96
|
+
end
|
91
97
|
|
92
|
-
|
98
|
+
# @api private
|
99
|
+
def list
|
100
|
+
Chef::Log.debug "Resources for generic #{resource_name} resource enabled on node include: #{prioritized_handlers}"
|
101
|
+
prioritized_handlers
|
102
|
+
end
|
93
103
|
|
94
|
-
|
104
|
+
#
|
105
|
+
# Whether this DSL is provided by the given resource_class.
|
106
|
+
#
|
107
|
+
# @api private
|
108
|
+
def provided_by?(resource_class)
|
109
|
+
!prioritized_handlers.include?(resource_class)
|
95
110
|
end
|
96
111
|
|
97
|
-
|
98
|
-
|
99
|
-
|
112
|
+
protected
|
113
|
+
|
114
|
+
def priority_map
|
115
|
+
Chef::Platform::ResourcePriorityMap.instance
|
100
116
|
end
|
101
117
|
|
102
|
-
|
103
|
-
|
104
|
-
|
118
|
+
def prioritized_handlers
|
119
|
+
@prioritized_handlers ||=
|
120
|
+
priority_map.list_handlers(node, resource_name, canonical: canonical)
|
105
121
|
end
|
106
122
|
|
107
|
-
|
108
|
-
Chef::
|
123
|
+
module Deprecated
|
124
|
+
# return a deterministically sorted list of Chef::Resource subclasses
|
125
|
+
# @deprecated Now prioritized_handlers does its own work (more efficiently)
|
126
|
+
def resources
|
127
|
+
Chef::Resource.sorted_descendants
|
128
|
+
end
|
129
|
+
|
130
|
+
# A list of all handlers
|
131
|
+
# @deprecated Now prioritized_handlers does its own work
|
132
|
+
def enabled_handlers
|
133
|
+
Chef::Log.deprecation("enabled_handlers is deprecated. If you are implementing a ResourceResolver, use provided_handlers. If you are not, use Chef::ResourceResolver.list(#{resource_name.inspect}, node: <node>)")
|
134
|
+
resources.select { |klass| klass.provides?(node, resource_name) }
|
135
|
+
end
|
136
|
+
|
137
|
+
protected
|
138
|
+
|
139
|
+
# A list of all handlers for the given DSL. If there are no handlers in
|
140
|
+
# the map, we still check all descendants of Chef::Resource for backwards
|
141
|
+
# compatibility purposes.
|
142
|
+
def prioritized_handlers
|
143
|
+
@prioritized_handlers ||= super ||
|
144
|
+
resources.select do |klass|
|
145
|
+
# Don't bother calling provides? unless it's overridden. We already
|
146
|
+
# know prioritized_handlers
|
147
|
+
if klass.method(:provides?).owner != Chef::Resource && klass.provides?(node, resource_name)
|
148
|
+
Chef::Log.deprecation("Resources #{provided.join(", ")} are marked as providing DSL #{resource_name}, but provides #{resource_name.inspect} was never called!")
|
149
|
+
Chef::Log.deprecation("In Chef 13, this will break: you must call provides to mark the names you provide, even if you also override provides? yourself.")
|
150
|
+
true
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
109
154
|
end
|
155
|
+
prepend Deprecated
|
110
156
|
end
|
111
157
|
end
|
data/lib/chef/resources.rb
CHANGED
@@ -80,6 +80,7 @@ require 'chef/resource/windows_package'
|
|
80
80
|
require 'chef/resource/yum_package'
|
81
81
|
require 'chef/resource/lwrp_base'
|
82
82
|
require 'chef/resource/bff_package'
|
83
|
+
require 'chef/resource/zypper_package'
|
83
84
|
|
84
85
|
begin
|
85
86
|
# Optional resources chef_node, chef_client, machine, machine_image, etc.
|
data/lib/chef/rest.rb
CHANGED
data/lib/chef/server_api.rb
CHANGED
data/lib/chef/user.rb
CHANGED
@@ -21,29 +21,85 @@ require 'chef/mixin/from_file'
|
|
21
21
|
require 'chef/mash'
|
22
22
|
require 'chef/json_compat'
|
23
23
|
require 'chef/search/query'
|
24
|
+
require 'chef/mixin/api_version_request_handling'
|
25
|
+
require 'chef/exceptions'
|
26
|
+
require 'chef/server_api'
|
24
27
|
|
28
|
+
# OSC 11 BACKWARDS COMPATIBILITY NOTE (remove after OSC 11 support ends)
|
29
|
+
#
|
30
|
+
# In general, Chef::User is no longer expected to support Open Source Chef 11 Server requests.
|
31
|
+
# The object that handles those requests has been moved to the Chef::OscUser namespace.
|
32
|
+
#
|
33
|
+
# Exception: self.list is backwards compatible with OSC 11
|
25
34
|
class Chef
|
26
35
|
class User
|
27
36
|
|
28
37
|
include Chef::Mixin::FromFile
|
29
38
|
include Chef::Mixin::ParamsValidate
|
39
|
+
include Chef::Mixin::ApiVersionRequestHandling
|
40
|
+
|
41
|
+
SUPPORTED_API_VERSIONS = [0,1]
|
30
42
|
|
31
43
|
def initialize
|
32
|
-
@
|
44
|
+
@username = nil
|
45
|
+
@display_name = nil
|
46
|
+
@first_name = nil
|
47
|
+
@middle_name = nil
|
48
|
+
@last_name = nil
|
49
|
+
@email = nil
|
50
|
+
@password = nil
|
33
51
|
@public_key = nil
|
34
52
|
@private_key = nil
|
53
|
+
@create_key = nil
|
35
54
|
@password = nil
|
36
|
-
@admin = false
|
37
55
|
end
|
38
56
|
|
39
|
-
def
|
40
|
-
|
57
|
+
def chef_root_rest_v0
|
58
|
+
@chef_root_rest_v0 ||= Chef::ServerAPI.new(Chef::Config[:chef_server_root], {:api_version => "0"})
|
59
|
+
end
|
60
|
+
|
61
|
+
def chef_root_rest_v1
|
62
|
+
@chef_root_rest_v1 ||= Chef::ServerAPI.new(Chef::Config[:chef_server_root], {:api_version => "1"})
|
63
|
+
end
|
64
|
+
|
65
|
+
def username(arg=nil)
|
66
|
+
set_or_return(:username, arg,
|
41
67
|
:regex => /^[a-z0-9\-_]+$/)
|
42
68
|
end
|
43
69
|
|
44
|
-
def
|
45
|
-
set_or_return(:
|
46
|
-
arg, :kind_of =>
|
70
|
+
def display_name(arg=nil)
|
71
|
+
set_or_return(:display_name,
|
72
|
+
arg, :kind_of => String)
|
73
|
+
end
|
74
|
+
|
75
|
+
def first_name(arg=nil)
|
76
|
+
set_or_return(:first_name,
|
77
|
+
arg, :kind_of => String)
|
78
|
+
end
|
79
|
+
|
80
|
+
def middle_name(arg=nil)
|
81
|
+
set_or_return(:middle_name,
|
82
|
+
arg, :kind_of => String)
|
83
|
+
end
|
84
|
+
|
85
|
+
def last_name(arg=nil)
|
86
|
+
set_or_return(:last_name,
|
87
|
+
arg, :kind_of => String)
|
88
|
+
end
|
89
|
+
|
90
|
+
def email(arg=nil)
|
91
|
+
set_or_return(:email,
|
92
|
+
arg, :kind_of => String)
|
93
|
+
end
|
94
|
+
|
95
|
+
def password(arg=nil)
|
96
|
+
set_or_return(:password,
|
97
|
+
arg, :kind_of => String)
|
98
|
+
end
|
99
|
+
|
100
|
+
def create_key(arg=nil)
|
101
|
+
set_or_return(:create_key, arg,
|
102
|
+
:kind_of => [TrueClass, FalseClass])
|
47
103
|
end
|
48
104
|
|
49
105
|
def public_key(arg=nil)
|
@@ -63,12 +119,17 @@ class Chef
|
|
63
119
|
|
64
120
|
def to_hash
|
65
121
|
result = {
|
66
|
-
"
|
67
|
-
"public_key" => @public_key,
|
68
|
-
"admin" => @admin
|
122
|
+
"username" => @username
|
69
123
|
}
|
70
|
-
result["
|
71
|
-
result["
|
124
|
+
result["display_name"] = @display_name unless @display_name.nil?
|
125
|
+
result["first_name"] = @first_name unless @first_name.nil?
|
126
|
+
result["middle_name"] = @middle_name unless @middle_name.nil?
|
127
|
+
result["last_name"] = @last_name unless @last_name.nil?
|
128
|
+
result["email"] = @email unless @email.nil?
|
129
|
+
result["password"] = @password unless @password.nil?
|
130
|
+
result["public_key"] = @public_key unless @public_key.nil?
|
131
|
+
result["private_key"] = @private_key unless @private_key.nil?
|
132
|
+
result["create_key"] = @create_key unless @create_key.nil?
|
72
133
|
result
|
73
134
|
end
|
74
135
|
|
@@ -77,21 +138,86 @@ class Chef
|
|
77
138
|
end
|
78
139
|
|
79
140
|
def destroy
|
80
|
-
|
141
|
+
# will default to the current API version (Chef::Authenticator::DEFAULT_SERVER_API_VERSION)
|
142
|
+
Chef::REST.new(Chef::Config[:chef_server_url]).delete("users/#{@username}")
|
81
143
|
end
|
82
144
|
|
83
145
|
def create
|
84
|
-
|
85
|
-
|
86
|
-
|
146
|
+
# try v1, fail back to v0 if v1 not supported
|
147
|
+
begin
|
148
|
+
payload = {
|
149
|
+
:username => @username,
|
150
|
+
:display_name => @display_name,
|
151
|
+
:first_name => @first_name,
|
152
|
+
:last_name => @last_name,
|
153
|
+
:email => @email,
|
154
|
+
:password => @password
|
155
|
+
}
|
156
|
+
payload[:public_key] = @public_key unless @public_key.nil?
|
157
|
+
payload[:create_key] = @create_key unless @create_key.nil?
|
158
|
+
payload[:middle_name] = @middle_name unless @middle_name.nil?
|
159
|
+
raise Chef::Exceptions::InvalidUserAttribute, "You cannot set both public_key and create_key for create." if !@create_key.nil? && !@public_key.nil?
|
160
|
+
new_user = chef_root_rest_v1.post("users", payload)
|
161
|
+
|
162
|
+
# get the private_key out of the chef_key hash if it exists
|
163
|
+
if new_user['chef_key']
|
164
|
+
if new_user['chef_key']['private_key']
|
165
|
+
new_user['private_key'] = new_user['chef_key']['private_key']
|
166
|
+
end
|
167
|
+
new_user['public_key'] = new_user['chef_key']['public_key']
|
168
|
+
new_user.delete('chef_key')
|
169
|
+
end
|
170
|
+
rescue Net::HTTPServerException => e
|
171
|
+
# rescue API V0 if 406 and the server supports V0
|
172
|
+
supported_versions = server_client_api_version_intersection(e, SUPPORTED_API_VERSIONS)
|
173
|
+
raise e unless supported_versions && supported_versions.include?(0)
|
174
|
+
payload = {
|
175
|
+
:username => @username,
|
176
|
+
:display_name => @display_name,
|
177
|
+
:first_name => @first_name,
|
178
|
+
:last_name => @last_name,
|
179
|
+
:email => @email,
|
180
|
+
:password => @password
|
181
|
+
}
|
182
|
+
payload[:middle_name] = @middle_name unless @middle_name.nil?
|
183
|
+
payload[:public_key] = @public_key unless @public_key.nil?
|
184
|
+
# under API V0, the server will create a key pair if public_key isn't passed
|
185
|
+
new_user = chef_root_rest_v0.post("users", payload)
|
186
|
+
end
|
187
|
+
|
87
188
|
Chef::User.from_hash(self.to_hash.merge(new_user))
|
88
189
|
end
|
89
190
|
|
90
191
|
def update(new_key=false)
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
192
|
+
begin
|
193
|
+
payload = {:username => username}
|
194
|
+
payload[:display_name] = display_name unless display_name.nil?
|
195
|
+
payload[:first_name] = first_name unless first_name.nil?
|
196
|
+
payload[:middle_name] = middle_name unless middle_name.nil?
|
197
|
+
payload[:last_name] = last_name unless last_name.nil?
|
198
|
+
payload[:email] = email unless email.nil?
|
199
|
+
payload[:password] = password unless password.nil?
|
200
|
+
|
201
|
+
# API V1 will fail if these key fields are defined, and try V0 below if relevant 400 is returned
|
202
|
+
payload[:public_key] = public_key unless public_key.nil?
|
203
|
+
payload[:private_key] = new_key if new_key
|
204
|
+
|
205
|
+
updated_user = chef_root_rest_v1.put("users/#{username}", payload)
|
206
|
+
rescue Net::HTTPServerException => e
|
207
|
+
if e.response.code == "400"
|
208
|
+
# if a 400 is returned but the error message matches the error related to private / public key fields, try V0
|
209
|
+
# else, raise the 400
|
210
|
+
error = Chef::JSONCompat.from_json(e.response.body)["error"].first
|
211
|
+
error_match = /Since Server API v1, all keys must be updated via the keys endpoint/.match(error)
|
212
|
+
if error_match.nil?
|
213
|
+
raise e
|
214
|
+
end
|
215
|
+
else # for other types of errors, test for API versioning errors right away
|
216
|
+
supported_versions = server_client_api_version_intersection(e, SUPPORTED_API_VERSIONS)
|
217
|
+
raise e unless supported_versions && supported_versions.include?(0)
|
218
|
+
end
|
219
|
+
updated_user = chef_root_rest_v0.put("users/#{username}", payload)
|
220
|
+
end
|
95
221
|
Chef::User.from_hash(self.to_hash.merge(updated_user))
|
96
222
|
end
|
97
223
|
|
@@ -107,31 +233,47 @@ class Chef
|
|
107
233
|
end
|
108
234
|
end
|
109
235
|
|
236
|
+
# Note: remove after API v0 no longer supported by client (and knife command).
|
110
237
|
def reregister
|
111
|
-
|
112
|
-
|
113
|
-
|
238
|
+
begin
|
239
|
+
payload = self.to_hash.merge({"private_key" => true})
|
240
|
+
reregistered_self = chef_root_rest_v0.put("users/#{username}", payload)
|
241
|
+
private_key(reregistered_self["private_key"])
|
242
|
+
# only V0 supported for reregister
|
243
|
+
rescue Net::HTTPServerException => e
|
244
|
+
# if there was a 406 related to versioning, give error explaining that
|
245
|
+
# only API version 0 is supported for reregister command
|
246
|
+
if e.response.code == "406" && e.response["x-ops-server-api-version"]
|
247
|
+
version_header = Chef::JSONCompat.from_json(e.response["x-ops-server-api-version"])
|
248
|
+
min_version = version_header["min_version"]
|
249
|
+
max_version = version_header["max_version"]
|
250
|
+
error_msg = reregister_only_v0_supported_error_msg(max_version, min_version)
|
251
|
+
raise Chef::Exceptions::OnlyApiVersion0SupportedForAction.new(error_msg)
|
252
|
+
else
|
253
|
+
raise e
|
254
|
+
end
|
255
|
+
end
|
114
256
|
self
|
115
257
|
end
|
116
258
|
|
117
259
|
def to_s
|
118
|
-
"user[#{@
|
119
|
-
end
|
120
|
-
|
121
|
-
def inspect
|
122
|
-
"Chef::User name:'#{name}' admin:'#{admin.inspect}'" +
|
123
|
-
"public_key:'#{public_key}' private_key:#{private_key}"
|
260
|
+
"user[#{@username}]"
|
124
261
|
end
|
125
262
|
|
126
263
|
# Class Methods
|
127
264
|
|
128
265
|
def self.from_hash(user_hash)
|
129
266
|
user = Chef::User.new
|
130
|
-
user.
|
131
|
-
user.
|
267
|
+
user.username user_hash['username']
|
268
|
+
user.display_name user_hash['display_name'] if user_hash.key?('display_name')
|
269
|
+
user.first_name user_hash['first_name'] if user_hash.key?('first_name')
|
270
|
+
user.middle_name user_hash['middle_name'] if user_hash.key?('middle_name')
|
271
|
+
user.last_name user_hash['last_name'] if user_hash.key?('last_name')
|
272
|
+
user.email user_hash['email'] if user_hash.key?('email')
|
132
273
|
user.password user_hash['password'] if user_hash.key?('password')
|
133
|
-
user.public_key user_hash['public_key']
|
134
|
-
user.
|
274
|
+
user.public_key user_hash['public_key'] if user_hash.key?('public_key')
|
275
|
+
user.private_key user_hash['private_key'] if user_hash.key?('private_key')
|
276
|
+
user.create_key user_hash['create_key'] if user_hash.key?('create_key')
|
135
277
|
user
|
136
278
|
end
|
137
279
|
|
@@ -144,12 +286,19 @@ class Chef
|
|
144
286
|
end
|
145
287
|
|
146
288
|
def self.list(inflate=false)
|
147
|
-
response = Chef::REST.new(Chef::Config[:chef_server_url]).
|
289
|
+
response = Chef::REST.new(Chef::Config[:chef_server_url]).get('users')
|
148
290
|
users = if response.is_a?(Array)
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
291
|
+
# EC 11 / CS 12 V0, V1
|
292
|
+
# GET /organizations/<org>/users
|
293
|
+
transform_list_response(response)
|
294
|
+
else
|
295
|
+
# OSC 11
|
296
|
+
# GET /users
|
297
|
+
# EC 11 / CS 12 V0, V1
|
298
|
+
# GET /users
|
299
|
+
response # OSC
|
300
|
+
end
|
301
|
+
|
153
302
|
if inflate
|
154
303
|
users.inject({}) do |user_map, (name, _url)|
|
155
304
|
user_map[name] = Chef::User.load(name)
|
@@ -160,8 +309,9 @@ class Chef
|
|
160
309
|
end
|
161
310
|
end
|
162
311
|
|
163
|
-
def self.load(
|
164
|
-
|
312
|
+
def self.load(username)
|
313
|
+
# will default to the current API version (Chef::Authenticator::DEFAULT_SERVER_API_VERSION)
|
314
|
+
response = Chef::REST.new(Chef::Config[:chef_server_url]).get("users/#{username}")
|
165
315
|
Chef::User.from_hash(response)
|
166
316
|
end
|
167
317
|
|
@@ -169,7 +319,7 @@ class Chef
|
|
169
319
|
# [ { "user" => { "username" => USERNAME }}, ...]
|
170
320
|
# into the form
|
171
321
|
# { "USERNAME" => "URI" }
|
172
|
-
def self.
|
322
|
+
def self.transform_list_response(response)
|
173
323
|
new_response = Hash.new
|
174
324
|
response.each do |u|
|
175
325
|
name = u['user']['username']
|
@@ -178,6 +328,7 @@ class Chef
|
|
178
328
|
new_response
|
179
329
|
end
|
180
330
|
|
181
|
-
private_class_method :
|
331
|
+
private_class_method :transform_list_response
|
332
|
+
|
182
333
|
end
|
183
334
|
end
|