From 61773ed71ac6cd7c01718e70ed8b59fcb581ecf1 Mon Sep 17 00:00:00 2001 From: Vinay Satish Date: Mon, 11 Oct 2021 17:08:13 +0530 Subject: updating the policy_revision_endpoint to add policy_group_list Signed-off-by: Vinay Satish --- .../endpoints/policy_revision_endpoint.rb | 28 +++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/chef_zero/endpoints/policy_revision_endpoint.rb b/lib/chef_zero/endpoints/policy_revision_endpoint.rb index be19fdc..479a233 100644 --- a/lib/chef_zero/endpoints/policy_revision_endpoint.rb +++ b/lib/chef_zero/endpoints/policy_revision_endpoint.rb @@ -7,7 +7,33 @@ module ChefZero # GET /organizations/ORG/policies/NAME/revisions/REVISION def get(request) data = parse_json(get_data(request)) - data = ChefData::DataNormalizer.normalize_policy(data, request.rest_path[3], request.rest_path[5]) + data[:policy_group_list] = Array.new + + # extracting policy name and revision + request_policy_name = request.rest_path[3] + request_policy_revision = request.rest_path[5] + + # updating the request to fetch the policy group list + request.rest_path[2] = "policy_groups" + request.rest_path = request.rest_path.slice(0,3) + + list_data(request).each do |group_name| + group_path = request.rest_path + [group_name] + + # fetching all the policies associated with each group + policy_list = list_data(request, group_path + ["policies"]) + policy_list.each do |policy_name| + revision_id = parse_json(get_data(request, group_path + ["policies", policy_name])) + + # if the name and revision matchs, we add the group to the response + if (policy_name == request_policy_name) && (revision_id == request_policy_revision) + policy_group_list = data[:policy_group_list] + data[:policy_group_list] = [group_name] + policy_group_list + end + end + end + + data = ChefData::DataNormalizer.normalize_policy(data, request_policy_name, request_policy_revision) json_response(200, data) end -- cgit v1.2.1