summaryrefslogtreecommitdiff
path: root/lib/chef_zero/endpoints/organization_validator_key_endpoint.rb
blob: 49fcd54780c0dc0cb74a9c39b028451e52f45b18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
require "ffi_yajl" unless defined?(FFI_Yajl)
require_relative "../rest_base"
require "uuidtools"

module ChefZero
  module Endpoints
    # /organizations/NAME/_validator_key
    class OrganizationValidatorKeyEndpoint < RestBase
      def post(request)
        org_name = request.rest_path[-2]
        validator_path = [ "organizations", org_name, "clients", "#{org_name}-validator"]
        validator = FFI_Yajl::Parser.parse(get_data(request, validator_path))
        private_key, public_key = server.gen_key_pair
        validator["public_key"] = public_key
        set_data(request, validator_path, FFI_Yajl::Encoder.encode(validator, pretty: true))
        json_response(200, { "private_key" => private_key })
      end
    end
  end
end