diff options
author | Steven Danna <steve@opscode.com> | 2012-12-22 09:22:51 -0800 |
---|---|---|
committer | Bryan McLellan <btm@opscode.com> | 2013-02-06 09:51:02 -0800 |
commit | 42d5ab44d53c02a731a7cc5ca987d728f6dc2f59 (patch) | |
tree | ea1d04b98dd8a3f7e661bf40dd38748ead837c8b /lib/chef/user.rb | |
parent | 4d45c9fb1bb4ec70c342fee963c3ac9b1134fdba (diff) | |
download | chef-42d5ab44d53c02a731a7cc5ca987d728f6dc2f59.tar.gz |
Chef::User.list should handle responses from Hosted/Private Chef
The API responses from a GET to the "users" endpoint currently returns
a different response on Hosted and Private Chef. Chef::User.list
transforms this response into form returned by the open source server.
Diffstat (limited to 'lib/chef/user.rb')
-rw-r--r-- | lib/chef/user.rb | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/lib/chef/user.rb b/lib/chef/user.rb index b97cc3cfd2..994cbb5773 100644 --- a/lib/chef/user.rb +++ b/lib/chef/user.rb @@ -143,13 +143,18 @@ class Chef end def self.list(inflate=false) - if inflate - users = Chef::REST.new(Chef::Config[:chef_server_url]).get_rest('users') - users.map do |name| - Chef::User.load(name) - end + response = if inflate + users = Chef::REST.new(Chef::Config[:chef_server_url]).get_rest('users') + users.map do |name| + Chef::User.load(name) + end + else + Chef::REST.new(Chef::Config[:chef_server_url]).get_rest('users') + end + if response.is_a? Array + transform_ohc_list_response(response) else - Chef::REST.new(Chef::Config[:chef_server_url]).get_rest('users') + response end end @@ -157,5 +162,20 @@ class Chef response = Chef::REST.new(Chef::Config[:chef_server_url]).get_rest("users/#{name}") Chef::User.from_hash(response) end + + private + + # Gross. Transforms an API response in the form of: + # [ { "user" => { "username" => USERNAME }}, ...] + # into the form + # { "USERNAME" => "URI" } + def self.transform_ohc_list_response(response) + new_response = Hash.new + response.each do |u| + name = u['user']['username'] + new_response[name] = Chef::Config[:chef_server_url] + "/users/#{name}" + end + new_response + end end end |