diff options
Diffstat (limited to 'lib/chef/knife/user_edit.rb')
-rw-r--r-- | lib/chef/knife/user_edit.rb | 44 |
1 files changed, 37 insertions, 7 deletions
diff --git a/lib/chef/knife/user_edit.rb b/lib/chef/knife/user_edit.rb index ae319c8872..dd2fc02743 100644 --- a/lib/chef/knife/user_edit.rb +++ b/lib/chef/knife/user_edit.rb @@ -29,6 +29,24 @@ class Chef banner "knife user edit USER (options)" + def osc_11_warning +<<-EOF +The Chef Server you are using does not support the username field. +This means it is an Open Source 11 Server. +knife user edit for Open Source 11 Server is being deprecated. +Open Source 11 Server user commands now live under the knife oc_user namespace. +For backwards compatibility, we will forward this request to knife osc_user edit. +If you are using an Open Source 11 Server, please use that command to avoid this warning. +EOF + end + + def run_osc_11_user_edit + # run osc_user_create with our input + ARGV.delete("user") + ARGV.unshift("osc_user") + Chef::Knife.run(ARGV, Chef::Application::Knife.options) + end + def run @user_name = @name_args[0] @@ -39,14 +57,26 @@ class Chef end original_user = Chef::User.load(@user_name).to_hash - edited_user = edit_data(original_user) - if original_user != edited_user - user = Chef::User.from_hash(edited_user) - user.update - ui.msg("Saved #{user}.") - else - ui.msg("User unchaged, not saving.") + + # DEPRECATION NOTE + # Remove this if statement and corrosponding code post OSC 11 support. + # + # if username is nil, we are in the OSC 11 case, + # forward to deprecated command + if original_user["username"].nil? + ui.warn(osc_11_warning) + run_osc_11_user_edit + else # EC / CS 12 user create + edited_user = edit_data(original_user) + if original_user != edited_user + user = Chef::User.from_hash(edited_user) + user.update + ui.msg("Saved #{user}.") + else + ui.msg("User unchaged, not saving.") + end end + end end end |