summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortylercloke <tylercloke@gmail.com>2015-05-29 15:34:33 -0700
committertylercloke <tylercloke@gmail.com>2015-06-05 10:38:48 -0700
commit549b093710c10e6409d101c651629df7b0bd7b67 (patch)
tree24b0b95622d8bdeb634ec74030d8c1bf23ac08d0
parent8565a36f8010760a3a65df8e521f442cc57e5934 (diff)
downloadchef-549b093710c10e6409d101c651629df7b0bd7b67.tar.gz
Small updates to Chef::User.list.
-rw-r--r--lib/chef/user.rb36
-rw-r--r--spec/unit/user_spec.rb10
2 files changed, 10 insertions, 36 deletions
diff --git a/lib/chef/user.rb b/lib/chef/user.rb
index b4f233f3f6..3620266ac2 100644
--- a/lib/chef/user.rb
+++ b/lib/chef/user.rb
@@ -49,14 +49,6 @@ class Chef
@password = nil
end
- def chef_rest_v0
- @chef_rest_v0 ||= get_versioned_rest_object(Chef::Config[:chef_server_url], "0")
- end
-
- def chef_rest_v1
- @chef_rest_v1 ||= get_versioned_rest_object(Chef::Config[:chef_server_url], "1")
- end
-
def chef_root_rest_v0
@chef_root_rest_v0 ||= get_versioned_rest_object(Chef::Config[:chef_server_root], "0")
end
@@ -242,6 +234,7 @@ Please refer to the documentation on how to manage your keys via the key rotatio
EOH
end
+ # Note: remove after API v0 no longer supported by client (and knife command).
def reregister
begin
payload = self.to_hash.merge({:private_key => true})
@@ -295,11 +288,16 @@ EOH
def self.list(inflate=false)
response = Chef::REST.new(Chef::Config[:chef_server_url]).get('users')
- users = if response.is_a?(Array)
- transform_ohc_list_response(response) # OHC/OPC
- else
- response # OSC
+ # Gross. Transforms an API response in the form of:
+ # [ { "user" => { "username" => USERNAME }}, ...]
+ # into the form
+ # { "USERNAME" => "URI" }
+ users = Hash.new
+ response.each do |u|
+ name = u['user']['username']
+ users[name] = Chef::Config[:chef_server_url] + "/users/#{name}"
end
+
if inflate
users.inject({}) do |user_map, (name, _url)|
user_map[name] = Chef::User.load(name)
@@ -315,19 +313,5 @@ EOH
Chef::User.from_hash(response)
end
- # 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
-
- private_class_method :transform_ohc_list_response
end
end
diff --git a/spec/unit/user_spec.rb b/spec/unit/user_spec.rb
index 67ad44a043..146230fa1c 100644
--- a/spec/unit/user_spec.rb
+++ b/spec/unit/user_spec.rb
@@ -584,16 +584,6 @@ describe Chef::User do
@osc_inflated_response = { "admin" => @user }
end
- it "lists all clients on an OSC server" do
- allow(@http_client).to receive(:get).with("users").and_return(@osc_response)
- expect(Chef::User.list).to eq(@osc_response)
- end
-
- it "inflate all clients on an OSC server" do
- allow(@http_client).to receive(:get).with("users").and_return(@osc_response)
- expect(Chef::User.list(true)).to eq(@osc_inflated_response)
- end
-
it "lists all clients on an OHC/OPC server" do
allow(@http_client).to receive(:get).with("users").and_return(@ohc_response)
# We expect that Chef::User.list will give a consistent response