summaryrefslogtreecommitdiff
path: root/lib/chef/knife/user_edit.rb
diff options
context:
space:
mode:
authortylercloke <tylercloke@gmail.com>2015-06-02 16:54:21 -0700
committertylercloke <tylercloke@gmail.com>2015-06-05 10:38:49 -0700
commit4f2400c8cce57e68f14cb9d4b756ab82b23dd69d (patch)
tree836ac3d3f71ec2ab234f975d2ed2f4fad93e94a5 /lib/chef/knife/user_edit.rb
parenteb49eedb6333bc1c6b82d0c7befffb9188c5b523 (diff)
downloadchef-4f2400c8cce57e68f14cb9d4b756ab82b23dd69d.tar.gz
Backwards compatible support for OSC 11 in knife user commands.
All knife user commands can detect when they have failed for OSC 11 reasons and forward the request to backwards compatible knife osc_user commands.
Diffstat (limited to 'lib/chef/knife/user_edit.rb')
-rw-r--r--lib/chef/knife/user_edit.rb46
1 files changed, 39 insertions, 7 deletions
diff --git a/lib/chef/knife/user_edit.rb b/lib/chef/knife/user_edit.rb
index ae319c8872..5bed51a1cc 100644
--- a/lib/chef/knife/user_edit.rb
+++ b/lib/chef/knife/user_edit.rb
@@ -29,6 +29,21 @@ 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
+ Chef::Knife.run(ARGV, Chef::Application::Knife.options)
+ end
+
def run
@user_name = @name_args[0]
@@ -39,14 +54,31 @@ 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_user_create with our input
+ ARGV.delete("user")
+ ARGV.unshift("osc_user")
+ 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