summaryrefslogtreecommitdiff
path: root/lib/chef_zero
diff options
context:
space:
mode:
authorkmacgugan <kmacgugan@chef.io>2016-06-08 17:08:12 -0700
committerStephan Renatus <srenatus@chef.io>2016-06-09 13:17:42 +0200
commit1b950b246c3d385e52fde619538f03763bcb3c11 (patch)
treebf79415ac655957f138ff7fbfa1aaa50fba71efc /lib/chef_zero
parentf6f92e14d17ec7ad6858aea98ef8a5a05f92b6fc (diff)
downloadchef-zero-1b950b246c3d385e52fde619538f03763bcb3c11.tar.gz
Add external_authentication_uid to actors endpoint for queryingsaml/et-205
Diffstat (limited to 'lib/chef_zero')
-rw-r--r--lib/chef_zero/endpoints/actors_endpoint.rb32
1 files changed, 21 insertions, 11 deletions
diff --git a/lib/chef_zero/endpoints/actors_endpoint.rb b/lib/chef_zero/endpoints/actors_endpoint.rb
index d1e4714..6297aed 100644
--- a/lib/chef_zero/endpoints/actors_endpoint.rb
+++ b/lib/chef_zero/endpoints/actors_endpoint.rb
@@ -8,17 +8,12 @@ module ChefZero
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']
@@ -85,6 +80,21 @@ module ChefZero
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