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
@@ -29,6 +29,40 @@ class Chef
|
|
29
29
|
|
30
30
|
banner "knife user delete USER (options)"
|
31
31
|
|
32
|
+
def osc_11_warning
|
33
|
+
<<-EOF
|
34
|
+
The Chef Server you are using does not support the username field.
|
35
|
+
This means it is an Open Source 11 Server.
|
36
|
+
knife user delete for Open Source 11 Server is being deprecated.
|
37
|
+
Open Source 11 Server user commands now live under the knife osc_user namespace.
|
38
|
+
For backwards compatibility, we will forward this request to knife osc_user delete.
|
39
|
+
If you are using an Open Source 11 Server, please use that command to avoid this warning.
|
40
|
+
EOF
|
41
|
+
end
|
42
|
+
|
43
|
+
def run_osc_11_user_delete
|
44
|
+
# run osc_user_delete with our input
|
45
|
+
ARGV.delete("user")
|
46
|
+
ARGV.unshift("osc_user")
|
47
|
+
Chef::Knife.run(ARGV, Chef::Application::Knife.options)
|
48
|
+
end
|
49
|
+
|
50
|
+
# DEPRECATION NOTE
|
51
|
+
# Delete this override method after OSC 11 support is dropped
|
52
|
+
def delete_object(user_name)
|
53
|
+
confirm("Do you really want to delete #{user_name}")
|
54
|
+
|
55
|
+
if Kernel.block_given?
|
56
|
+
object = block.call
|
57
|
+
else
|
58
|
+
object = Chef::User.load(user_name)
|
59
|
+
object.destroy
|
60
|
+
end
|
61
|
+
|
62
|
+
output(format_for_display(object)) if config[:print_after]
|
63
|
+
self.msg("Deleted #{user_name}")
|
64
|
+
end
|
65
|
+
|
32
66
|
def run
|
33
67
|
@user_name = @name_args[0]
|
34
68
|
|
@@ -38,9 +72,25 @@ class Chef
|
|
38
72
|
exit 1
|
39
73
|
end
|
40
74
|
|
41
|
-
|
42
|
-
|
75
|
+
# DEPRECATION NOTE
|
76
|
+
#
|
77
|
+
# Below is modification of Chef::Knife.delete_object to detect OSC 11 server.
|
78
|
+
# When OSC 11 is deprecated, simply delete all this and go back to:
|
79
|
+
#
|
80
|
+
# delete_object(Chef::User, @user_name)
|
81
|
+
#
|
82
|
+
# Also delete our override of delete_object above
|
83
|
+
object = Chef::User.load(@user_name)
|
43
84
|
|
85
|
+
# OSC 11 case
|
86
|
+
if object.username.nil?
|
87
|
+
ui.warn(osc_11_warning)
|
88
|
+
run_osc_11_user_delete
|
89
|
+
else # proceed with EC / CS delete
|
90
|
+
delete_object(@user_name)
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
44
94
|
end
|
45
95
|
end
|
46
96
|
end
|
data/lib/chef/knife/user_edit.rb
CHANGED
@@ -29,6 +29,24 @@ class Chef
|
|
29
29
|
|
30
30
|
banner "knife user edit USER (options)"
|
31
31
|
|
32
|
+
def osc_11_warning
|
33
|
+
<<-EOF
|
34
|
+
The Chef Server you are using does not support the username field.
|
35
|
+
This means it is an Open Source 11 Server.
|
36
|
+
knife user edit for Open Source 11 Server is being deprecated.
|
37
|
+
Open Source 11 Server user commands now live under the knife oc_user namespace.
|
38
|
+
For backwards compatibility, we will forward this request to knife osc_user edit.
|
39
|
+
If you are using an Open Source 11 Server, please use that command to avoid this warning.
|
40
|
+
EOF
|
41
|
+
end
|
42
|
+
|
43
|
+
def run_osc_11_user_edit
|
44
|
+
# run osc_user_create with our input
|
45
|
+
ARGV.delete("user")
|
46
|
+
ARGV.unshift("osc_user")
|
47
|
+
Chef::Knife.run(ARGV, Chef::Application::Knife.options)
|
48
|
+
end
|
49
|
+
|
32
50
|
def run
|
33
51
|
@user_name = @name_args[0]
|
34
52
|
|
@@ -39,14 +57,26 @@ class Chef
|
|
39
57
|
end
|
40
58
|
|
41
59
|
original_user = Chef::User.load(@user_name).to_hash
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
60
|
+
|
61
|
+
# DEPRECATION NOTE
|
62
|
+
# Remove this if statement and corrosponding code post OSC 11 support.
|
63
|
+
#
|
64
|
+
# if username is nil, we are in the OSC 11 case,
|
65
|
+
# forward to deprecated command
|
66
|
+
if original_user["username"].nil?
|
67
|
+
ui.warn(osc_11_warning)
|
68
|
+
run_osc_11_user_edit
|
69
|
+
else # EC / CS 12 user create
|
70
|
+
edited_user = edit_data(original_user)
|
71
|
+
if original_user != edited_user
|
72
|
+
user = Chef::User.from_hash(edited_user)
|
73
|
+
user.update
|
74
|
+
ui.msg("Saved #{user}.")
|
75
|
+
else
|
76
|
+
ui.msg("User unchaged, not saving.")
|
77
|
+
end
|
49
78
|
end
|
79
|
+
|
50
80
|
end
|
51
81
|
end
|
52
82
|
end
|
data/lib/chef/knife/user_list.rb
CHANGED
@@ -18,6 +18,8 @@
|
|
18
18
|
|
19
19
|
require 'chef/knife'
|
20
20
|
|
21
|
+
# NOTE: only knife user command that is backwards compatible with OSC 11,
|
22
|
+
# so no deprecation warnings are necessary.
|
21
23
|
class Chef
|
22
24
|
class Knife
|
23
25
|
class UserList < Knife
|
@@ -37,6 +39,7 @@ class Chef
|
|
37
39
|
def run
|
38
40
|
output(format_list_for_display(Chef::User.list))
|
39
41
|
end
|
42
|
+
|
40
43
|
end
|
41
44
|
end
|
42
45
|
end
|
@@ -29,6 +29,24 @@ class Chef
|
|
29
29
|
|
30
30
|
banner "knife user reregister USER (options)"
|
31
31
|
|
32
|
+
def osc_11_warning
|
33
|
+
<<-EOF
|
34
|
+
The Chef Server you are using does not support the username field.
|
35
|
+
This means it is an Open Source 11 Server.
|
36
|
+
knife user reregister for Open Source 11 Server is being deprecated.
|
37
|
+
Open Source 11 Server user commands now live under the knife osc_user namespace.
|
38
|
+
For backwards compatibility, we will forward this request to knife osc_user reregister.
|
39
|
+
If you are using an Open Source 11 Server, please use that command to avoid this warning.
|
40
|
+
EOF
|
41
|
+
end
|
42
|
+
|
43
|
+
def run_osc_11_user_reregister
|
44
|
+
# run osc_user_edit with our input
|
45
|
+
ARGV.delete("user")
|
46
|
+
ARGV.unshift("osc_user")
|
47
|
+
Chef::Knife.run(ARGV, Chef::Application::Knife.options)
|
48
|
+
end
|
49
|
+
|
32
50
|
option :file,
|
33
51
|
:short => "-f FILE",
|
34
52
|
:long => "--file FILE",
|
@@ -43,16 +61,29 @@ class Chef
|
|
43
61
|
exit 1
|
44
62
|
end
|
45
63
|
|
46
|
-
user = Chef::User.load(@user_name)
|
47
|
-
|
48
|
-
|
49
|
-
if
|
50
|
-
|
51
|
-
|
64
|
+
user = Chef::User.load(@user_name)
|
65
|
+
|
66
|
+
# DEPRECATION NOTE
|
67
|
+
# Remove this if statement and corrosponding code post OSC 11 support.
|
68
|
+
#
|
69
|
+
# if username is nil, we are in the OSC 11 case,
|
70
|
+
# forward to deprecated command
|
71
|
+
if user.username.nil?
|
72
|
+
ui.warn(osc_11_warning)
|
73
|
+
run_osc_11_user_reregister
|
74
|
+
else # EC / CS 12 case
|
75
|
+
user.reregister
|
76
|
+
Chef::Log.debug("Updated user data: #{user.inspect}")
|
77
|
+
key = user.private_key
|
78
|
+
if config[:file]
|
79
|
+
File.open(config[:file], "w") do |f|
|
80
|
+
f.print(key)
|
81
|
+
end
|
82
|
+
else
|
83
|
+
ui.msg key
|
52
84
|
end
|
53
|
-
else
|
54
|
-
ui.msg key
|
55
85
|
end
|
86
|
+
|
56
87
|
end
|
57
88
|
end
|
58
89
|
end
|
data/lib/chef/knife/user_show.rb
CHANGED
@@ -31,6 +31,24 @@ class Chef
|
|
31
31
|
|
32
32
|
banner "knife user show USER (options)"
|
33
33
|
|
34
|
+
def osc_11_warning
|
35
|
+
<<-EOF
|
36
|
+
The Chef Server you are using does not support the username field.
|
37
|
+
This means it is an Open Source 11 Server.
|
38
|
+
knife user show for Open Source 11 Server is being deprecated.
|
39
|
+
Open Source 11 Server user commands now live under the knife osc_user namespace.
|
40
|
+
For backwards compatibility, we will forward this request to knife osc_user show.
|
41
|
+
If you are using an Open Source 11 Server, please use that command to avoid this warning.
|
42
|
+
EOF
|
43
|
+
end
|
44
|
+
|
45
|
+
def run_osc_11_user_show
|
46
|
+
# run osc_user_edit with our input
|
47
|
+
ARGV.delete("user")
|
48
|
+
ARGV.unshift("osc_user")
|
49
|
+
Chef::Knife.run(ARGV, Chef::Application::Knife.options)
|
50
|
+
end
|
51
|
+
|
34
52
|
def run
|
35
53
|
@user_name = @name_args[0]
|
36
54
|
|
@@ -41,7 +59,18 @@ class Chef
|
|
41
59
|
end
|
42
60
|
|
43
61
|
user = Chef::User.load(@user_name)
|
44
|
-
|
62
|
+
|
63
|
+
# DEPRECATION NOTE
|
64
|
+
# Remove this if statement and corrosponding code post OSC 11 support.
|
65
|
+
#
|
66
|
+
# if username is nil, we are in the OSC 11 case,
|
67
|
+
# forward to deprecated command
|
68
|
+
if user.username.nil?
|
69
|
+
ui.warn(osc_11_warning)
|
70
|
+
run_osc_11_user_show
|
71
|
+
else
|
72
|
+
output(format_for_display(user))
|
73
|
+
end
|
45
74
|
end
|
46
75
|
|
47
76
|
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Tyler Cloke (tyler@chef.io)
|
3
|
+
# Copyright:: Copyright 2015 Chef Software, 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
|
+
|
19
|
+
class Chef
|
20
|
+
module Mixin
|
21
|
+
module ApiVersionRequestHandling
|
22
|
+
# Input:
|
23
|
+
# exeception:
|
24
|
+
# Net::HTTPServerException that may or may not contain the x-ops-server-api-version header
|
25
|
+
# supported_client_versions:
|
26
|
+
# An array of Integers that represent the API versions the client supports.
|
27
|
+
#
|
28
|
+
# Output:
|
29
|
+
# nil:
|
30
|
+
# If the execption was not a 406 or the server does not support versioning
|
31
|
+
# Array of length zero:
|
32
|
+
# If there was no intersection between supported client versions and supported server versions
|
33
|
+
# Arrary of Integers:
|
34
|
+
# If there was an intersection of supported versions, the array returns will contain that intersection
|
35
|
+
def server_client_api_version_intersection(exception, supported_client_versions)
|
36
|
+
# return empty array unless 406 Unacceptable with proper header
|
37
|
+
return nil if exception.response.code != "406" || exception.response["x-ops-server-api-version"].nil?
|
38
|
+
|
39
|
+
# intersection of versions the server and client support, will be of length zero if no intersection
|
40
|
+
server_supported_client_versions = Array.new
|
41
|
+
|
42
|
+
header = Chef::JSONCompat.from_json(exception.response["x-ops-server-api-version"])
|
43
|
+
min_server_version = Integer(header["min_version"])
|
44
|
+
max_server_version = Integer(header["max_version"])
|
45
|
+
|
46
|
+
supported_client_versions.each do |version|
|
47
|
+
if version >= min_server_version && version <= max_server_version
|
48
|
+
server_supported_client_versions.push(version)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
server_supported_client_versions
|
52
|
+
end
|
53
|
+
|
54
|
+
def reregister_only_v0_supported_error_msg(max_version, min_version)
|
55
|
+
<<-EOH
|
56
|
+
The reregister command only supports server API version 0.
|
57
|
+
The server that received the request supports a min version of #{min_version} and a max version of #{max_version}.
|
58
|
+
User keys are now managed via the key rotation commmands.
|
59
|
+
Please refer to the documentation on how to manage your keys via the key rotation commands:
|
60
|
+
https://docs.chef.io/server_security.html#key-rotation
|
61
|
+
EOH
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -23,9 +23,7 @@ class Chef
|
|
23
23
|
extend self
|
24
24
|
|
25
25
|
def convert_to_class_name(str)
|
26
|
-
str = str
|
27
|
-
str.gsub!(/[^A-Za-z0-9_]/,'_')
|
28
|
-
str.gsub!(/^(_+)?/,'')
|
26
|
+
str = normalize_snake_case_name(str)
|
29
27
|
rname = nil
|
30
28
|
regexp = %r{^(.+?)(_(.+))?$}
|
31
29
|
|
@@ -51,6 +49,13 @@ class Chef
|
|
51
49
|
str
|
52
50
|
end
|
53
51
|
|
52
|
+
def normalize_snake_case_name(str)
|
53
|
+
str = str.dup
|
54
|
+
str.gsub!(/[^A-Za-z0-9_]/,'_')
|
55
|
+
str.gsub!(/^(_+)?/,'')
|
56
|
+
str
|
57
|
+
end
|
58
|
+
|
54
59
|
def snake_case_basename(str)
|
55
60
|
with_namespace = convert_to_snake_case(str)
|
56
61
|
with_namespace.split("::").last.sub(/^_/, '')
|
@@ -58,7 +63,8 @@ class Chef
|
|
58
63
|
|
59
64
|
def filename_to_qualified_string(base, filename)
|
60
65
|
file_base = File.basename(filename, ".rb")
|
61
|
-
base.to_s + (file_base == 'default' ? '' : "_#{file_base}")
|
66
|
+
str = base.to_s + (file_base == 'default' ? '' : "_#{file_base}")
|
67
|
+
normalize_snake_case_name(str)
|
62
68
|
end
|
63
69
|
|
64
70
|
# Copied from rails activesupport. In ruby >= 2.0 const_get will just do this, so this can
|
@@ -95,6 +95,30 @@ class Chef
|
|
95
95
|
DeprecatedInstanceVariable.new(obj, name, level)
|
96
96
|
end
|
97
97
|
|
98
|
+
def deprecated_attr(name, alternative)
|
99
|
+
deprecated_attr_reader(name, alternative)
|
100
|
+
deprecated_attr_writer(name, alternative)
|
101
|
+
end
|
102
|
+
|
103
|
+
def deprecated_attr_reader(name, alternative, level=:warn)
|
104
|
+
define_method(name) do
|
105
|
+
Chef::Log.deprecation("#{self.class}.#{name} is deprecated. Support will be removed in a future release.")
|
106
|
+
Chef::Log.deprecation(alternative)
|
107
|
+
Chef::Log.deprecation("Called from:")
|
108
|
+
caller[0..3].each {|c| Chef::Log.deprecation(c)}
|
109
|
+
instance_variable_get("@#{name}")
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def deprecated_attr_writer(name, alternative, level=:warn)
|
114
|
+
define_method("#{name}=") do |value|
|
115
|
+
Chef::Log.deprecation("Writing to #{self.class}.#{name} with #{name}= is deprecated. Support will be removed in a future release.")
|
116
|
+
Chef::Log.deprecation(alternative)
|
117
|
+
Chef::Log.deprecation("Called from:")
|
118
|
+
caller[0..3].each {|c| Chef::Log.deprecation(c)}
|
119
|
+
instance_variable_set("@#{name}", value)
|
120
|
+
end
|
121
|
+
end
|
98
122
|
end
|
99
123
|
end
|
100
124
|
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright:: Copyright (c) 2015 Chef Software, Inc.
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require 'chef/mixin/shell_out'
|
18
|
+
require 'chef/mixin/windows_architecture_helper'
|
19
|
+
|
20
|
+
class Chef
|
21
|
+
module Mixin
|
22
|
+
module PowershellOut
|
23
|
+
include Chef::Mixin::ShellOut
|
24
|
+
include Chef::Mixin::WindowsArchitectureHelper
|
25
|
+
|
26
|
+
# Run a command under powershell with the same API as shell_out. The
|
27
|
+
# options hash is extended to take an "architecture" flag which
|
28
|
+
# can be set to :i386 or :x86_64 to force the windows architecture.
|
29
|
+
#
|
30
|
+
# @param script [String] script to run
|
31
|
+
# @param options [Hash] options hash
|
32
|
+
# @return [Mixlib::Shellout] mixlib-shellout object
|
33
|
+
def powershell_out(*command_args)
|
34
|
+
script = command_args.first
|
35
|
+
options = command_args.last.is_a?(Hash) ? command_args.last : nil
|
36
|
+
|
37
|
+
run_command_with_os_architecture(script, options)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Run a command under powershell with the same API as shell_out!
|
41
|
+
# (raises exceptions on errors)
|
42
|
+
#
|
43
|
+
# @param script [String] script to run
|
44
|
+
# @param options [Hash] options hash
|
45
|
+
# @return [Mixlib::Shellout] mixlib-shellout object
|
46
|
+
def powershell_out!(*command_args)
|
47
|
+
cmd = powershell_out(*command_args)
|
48
|
+
cmd.error!
|
49
|
+
cmd
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
# Helper function to run shell_out and wrap it with the correct
|
55
|
+
# flags to possibly disable WOW64 redirection (which we often need
|
56
|
+
# because chef-client runs as a 32-bit app on 64-bit windows).
|
57
|
+
#
|
58
|
+
# @param script [String] script to run
|
59
|
+
# @param options [Hash] options hash
|
60
|
+
# @return [Mixlib::Shellout] mixlib-shellout object
|
61
|
+
def run_command_with_os_architecture(script, options)
|
62
|
+
options ||= {}
|
63
|
+
options = options.dup
|
64
|
+
arch = options.delete(:architecture)
|
65
|
+
|
66
|
+
with_os_architecture(nil, architecture: arch) do
|
67
|
+
shell_out(
|
68
|
+
build_powershell_command(script),
|
69
|
+
options
|
70
|
+
)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# Helper to build a powershell command around the script to run.
|
75
|
+
#
|
76
|
+
# @param script [String] script to run
|
77
|
+
# @retrurn [String] powershell command to execute
|
78
|
+
def build_powershell_command(script)
|
79
|
+
flags = [
|
80
|
+
# Hides the copyright banner at startup.
|
81
|
+
"-NoLogo",
|
82
|
+
# Does not present an interactive prompt to the user.
|
83
|
+
"-NonInteractive",
|
84
|
+
# Does not load the Windows PowerShell profile.
|
85
|
+
"-NoProfile",
|
86
|
+
# always set the ExecutionPolicy flag
|
87
|
+
# see http://technet.microsoft.com/en-us/library/ee176961.aspx
|
88
|
+
"-ExecutionPolicy Unrestricted",
|
89
|
+
# Powershell will hang if STDIN is redirected
|
90
|
+
# http://connect.microsoft.com/PowerShell/feedback/details/572313/powershell-exe-can-hang-if-stdin-is-redirected
|
91
|
+
"-InputFormat None"
|
92
|
+
]
|
93
|
+
|
94
|
+
"powershell.exe #{flags.join(' ')} -Command \"#{script}\""
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|