Skip to content

Commit

Permalink
Add external_authentication_uid to actors endpoint for querying
Browse files Browse the repository at this point in the history
  • Loading branch information
kmacgugan authored and srenatus committed Jun 9, 2016
1 parent f6f92e1 commit 1b950b2
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions lib/chef_zero/endpoints/actors_endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,12 @@ class ActorsEndpoint < RestListEndpoint
def get(request)
response = super(request)

if request.query_params['email']
results = parse_json(response[2])
new_results = {}
results.each do |name, url|
record = get_data(request, request.rest_path + [ name ], :nil)
if record
record = parse_json(record)
new_results[name] = url if record['email'] == request.query_params['email']
end
end
response[2] = to_json(new_results)
# apply query filters: if one applies, stop processing rest
# (precendence matches chef-server: https://github.com/chef/chef-server/blob/268a0c9/src/oc_erchef/apps/chef_objects/src/chef_user.erl#L554-L559)
if value = request.query_params['external_authentication_uid']
response[2] = filter('external_authentication_uid', value, request, response[2])
elsif value = request.query_params['email']
response[2] = filter('email', value, request, response[2])
end

if request.query_params['verbose']
Expand Down Expand Up @@ -85,6 +80,21 @@ def post(request)
result
end
end

private

def filter(key, value, request, resp)
results = parse_json(resp)
new_results = {}
results.each do |name, url|
record = get_data(request, request.rest_path + [ name ], :nil)
if record
record = parse_json(record)
new_results[name] = url if record[key] == value
end
end
to_json(new_results)
end
end
end
end

0 comments on commit 1b950b2

Please sign in to comment.