diff options
author | PrajaktaPurohit <PrajaktaPurohit@users.noreply.github.com> | 2021-10-17 08:23:28 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-17 08:23:28 -0700 |
commit | 019107ea2deac1070a098fb370c721b2ed11cb3f (patch) | |
tree | 6735afd6e083d4b0c81702bab2e381561557c004 /lib/chef_zero/endpoints/policy_revision_endpoint.rb | |
parent | acb62bfdd88e236bd9ea8af1f07e959f55824392 (diff) | |
parent | 5a47c3218671a5bc9588786fd604909584222586 (diff) | |
download | chef-zero-019107ea2deac1070a098fb370c721b2ed11cb3f.tar.gz |
Merge pull request #320 from vinay-satish/zei/update_policy_revision_API
Updating the policy_revision_endpoint to add policy_group_list
Diffstat (limited to 'lib/chef_zero/endpoints/policy_revision_endpoint.rb')
-rw-r--r-- | lib/chef_zero/endpoints/policy_revision_endpoint.rb | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/lib/chef_zero/endpoints/policy_revision_endpoint.rb b/lib/chef_zero/endpoints/policy_revision_endpoint.rb index be19fdc..ee2c6df 100644 --- a/lib/chef_zero/endpoints/policy_revision_endpoint.rb +++ b/lib/chef_zero/endpoints/policy_revision_endpoint.rb @@ -7,7 +7,50 @@ 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]) + + # need to add another field in the response called 'policy_group_list' + # example response + # { + # "revision_id": "909c26701e291510eacdc6c06d626b9fa5350d25", + # "name": "some_policy_name", + # "run_list": [ + # "recipe[policyfile_demo::default]" + # ], + # "cookbook_locks": { + # "policyfile_demo": { + # "identifier": "f04cc40faf628253fe7d9566d66a1733fb1afbe9", + # "version": "1.2.3" + # } + # }, + # "policy_group_list": ["some_policy_group"] + # } + 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 |