summaryrefslogtreecommitdiff
path: root/lib/chef_zero/endpoints/policies_endpoint.rb
blob: 1b6f7ce01fea0eea0109ae4d3e800f1cdf5254bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
require_relative "../chef_data/data_normalizer"

module ChefZero
  module Endpoints
    # /organizations/ORG/policies
    class PoliciesEndpoint < RestBase
      # GET /organizations/ORG/policies
      def get(request)
        response_data = {}
        policy_names = list_data(request)
        policy_names.each do |policy_name|
          policy_path = request.rest_path + [policy_name]
          policy_uri = build_uri(request.base_uri, policy_path)
          revisions = list_data(request, policy_path + ["revisions"])

          response_data[policy_name] = {
            uri: policy_uri,
            revisions: hashify_list(revisions),
          }
        end

        json_response(200, response_data)
      end
    end
  end
end