Class: ChefZero::Endpoints::PolicyGroupsEndpoint
- Defined in:
- lib/chef_zero/endpoints/policy_groups_endpoint.rb
Overview
/organizations/ORG/policy_groups
in the data store, this REST path actually stores the revision ID of $policy_name that’s currently associated with $policy_group.
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
-
#get(request) ⇒ Object
GET /organizations/ORG/policy_groups.
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
#get(request) ⇒ Object
GET /organizations/ORG/policy_groups
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/chef_zero/endpoints/policy_groups_endpoint.rb', line 13 def get(request) # each policy group has policies and associated revisions under # /policy_groups/{group name}/policies/{policy name}. response_data = {} list_data(request).each do |group_name| group_path = request.rest_path + [group_name] policy_list = list_data(request, group_path + ["policies"]) # build the list of policies with their revision ID associated with this policy group. policies = {} policy_list.each do |policy_name| revision_id = parse_json(get_data(request, group_path + ["policies", policy_name])) policies[policy_name] = { revision_id: revision_id } end response_data[group_name] = { uri: build_uri(request.base_uri, group_path), } response_data[group_name][:policies] = policies unless policies.empty? end json_response(200, response_data) end |