Class: ChefZero::Endpoints::PolicyRevisionEndpoint
- Defined in:
- lib/chef_zero/endpoints/policy_revision_endpoint.rb
Overview
/organizations/ORG/policies/NAME/revisions/REVISION
Constant Summary
Constants inherited from RestBase
RestBase::DEFAULT_REQUEST_VERSION, RestBase::DEFAULT_RESPONSE_VERSION
Instance Attribute Summary
Attributes inherited from RestBase
Instance Method Summary collapse
-
#delete(request) ⇒ Object
DELETE /organizations/ORG/policies/NAME/revisions/REVISION.
-
#get(request) ⇒ Object
GET /organizations/ORG/policies/NAME/revisions/REVISION.
Methods inherited from RestBase
#accepts?, #already_json_response, #build_uri, build_uri, #call, #check_api_version, #create_data, #create_data_dir, #data_store, #delete_data, #delete_data_dir, #error, #exists_data?, #exists_data_dir?, #get_data, #get_data_or_else, #hashify_list, #head_request, #initialize, #json_only, #json_response, #list_data, #list_data_or_else, #parse_json, #policy_name_invalid?, #populate_defaults, rfc2396_parser, #set_data, #text_response, #to_json
Constructor Details
This class inherits a constructor from ChefZero::RestBase
Instance Method Details
#delete(request) ⇒ Object
DELETE /organizations/ORG/policies/NAME/revisions/REVISION
58 59 60 61 62 63 |
# File 'lib/chef_zero/endpoints/policy_revision_endpoint.rb', line 58 def delete(request) policyfile_data = parse_json(get_data(request)) policyfile_data = ChefData::DataNormalizer.normalize_policy(policyfile_data, request.rest_path[3], request.rest_path[5]) delete_data(request) json_response(200, policyfile_data) end |
#get(request) ⇒ Object
GET /organizations/ORG/policies/NAME/revisions/REVISION
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/chef_zero/endpoints/policy_revision_endpoint.rb', line 8 def get(request) data = parse_json(get_data(request)) # 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] = [] # 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 |