diff options
author | tylercloke <tylercloke@gmail.com> | 2015-06-01 15:09:40 -0700 |
---|---|---|
committer | tylercloke <tylercloke@gmail.com> | 2015-06-05 10:38:49 -0700 |
commit | fb73d4ae3a0c20a3c0dfa5a85b652b8f0cba5a32 (patch) | |
tree | 55c4821657ad8a8ab106e767e3c52b543dc0b6c4 /lib | |
parent | aa569ebb6fe0c6263bcb93fae80cc65ddfaff481 (diff) | |
download | chef-fb73d4ae3a0c20a3c0dfa5a85b652b8f0cba5a32.tar.gz |
Fixed bug where boolean fields would not be populated in Chef::User/ApiClient.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/chef/api_client.rb | 8 | ||||
-rw-r--r-- | lib/chef/user.rb | 43 |
2 files changed, 26 insertions, 25 deletions
diff --git a/lib/chef/api_client.rb b/lib/chef/api_client.rb index f3a83d7bcb..9e964081ec 100644 --- a/lib/chef/api_client.rb +++ b/lib/chef/api_client.rb @@ -141,9 +141,9 @@ class Chef 'json_class' => self.class.name, "chef_type" => "client" } - result["private_key"] = @private_key if @private_key - result["public_key"] = @public_key if @public_key - result["create_key"] = @create_key if @create_key + result["private_key"] = @private_key unless @private_key.nil? + result["public_key"] = @public_key unless @public_key.nil? + result["create_key"] = @create_key unless @create_key.nil? result end @@ -269,7 +269,7 @@ class Chef } begin # try API V1 - raise Chef::Exceptions::InvalidClientAttribute, "You cannot set both public_key and create_key for create." if create_key && public_key + raise Chef::Exceptions::InvalidClientAttribute, "You cannot set both public_key and create_key for create." if !create_key.nil? && !public_key.nil? payload[:public_key] = public_key unless public_key.nil? payload[:create_key] = create_key unless create_key.nil? diff --git a/lib/chef/user.rb b/lib/chef/user.rb index 9159d162f4..6758ed671d 100644 --- a/lib/chef/user.rb +++ b/lib/chef/user.rb @@ -116,14 +116,15 @@ class Chef result = { "username" => @username } - result["display_name"] = @display_name if @display_name - result["first_name"] = @first_name if @first_name - result["middle_name"] = @middle_name if @middle_name - result["last_name"] = @last_name if @last_name - result["email"] = @email if @email - result["password"] = @password if @password - result["public_key"] = @public_key if @public_key - result["private_key"] = @private_key if @private_key + result["display_name"] = @display_name unless @display_name.nil? + result["first_name"] = @first_name unless @first_name.nil? + result["middle_name"] = @middle_name unless @middle_name.nil? + result["last_name"] = @last_name unless @last_name.nil? + result["email"] = @email unless @email.nil? + result["password"] = @password unless @password.nil? + result["public_key"] = @public_key unless @public_key.nil? + result["private_key"] = @private_key unless @private_key.nil? + result["create_key"] = @create_key unless @create_key.nil? result end @@ -146,10 +147,10 @@ class Chef :email => @email, :password => @password } - payload[:public_key] = @public_key if @public_key - payload[:create_key] = @create_key if @create_key - payload[:middle_name] = @middle_name if @middle_name - raise Chef::Exceptions::InvalidUserAttribute, "You cannot set both public_key and create_key for create." if @create_key && @public_key + payload[:public_key] = @public_key unless @public_key.nil? + payload[:create_key] = @create_key unless @create_key.nil? + payload[:middle_name] = @middle_name unless @middle_name.nil? + raise Chef::Exceptions::InvalidUserAttribute, "You cannot set both public_key and create_key for create." if !@create_key.nil? && !@public_key.nil? new_user = chef_root_rest_v1.post("users", payload) # get the private_key out of the chef_key hash if it exists @@ -171,8 +172,8 @@ class Chef :email => @email, :password => @password } - payload[:middle_name] = @middle_name if @middle_name - payload[:public_key] = @public_key if @public_key + payload[:middle_name] = @middle_name unless @middle_name.nil? + payload[:public_key] = @public_key unless @public_key.nil? # under API V0, the server will create a key pair if public_key isn't passed new_user = chef_root_rest_v0.post("users", payload) end @@ -183,15 +184,15 @@ class Chef def update(new_key=false) begin payload = {:username => username} - payload[:display_name] = display_name if display_name - payload[:first_name] = first_name if first_name - payload[:middle_name] = middle_name if middle_name - payload[:last_name] = last_name if last_name - payload[:email] = email if email - payload[:password] = password if password + payload[:display_name] = display_name unless display_name.nil? + payload[:first_name] = first_name unless first_name.nil? + payload[:middle_name] = middle_name unless middle_name.nil? + payload[:last_name] = last_name unless last_name.nil? + payload[:email] = email unless email.nil? + payload[:password] = password unless password.nil? # API V1 will fail if these key fields are defined, and try V0 below if relevant 400 is returned - payload[:public_key] = public_key if public_key + payload[:public_key] = public_key unless public_key.nil? payload[:private_key] = new_key if new_key updated_user = chef_root_rest_v1.put("users/#{username}", payload) |