summaryrefslogtreecommitdiff
path: root/lib/chef_zero/endpoints/user_key_endpoint.rb
blob: 4e4872bf35100098fd357c01fc3641c9343556c9 (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
27
28
29
30
31
32
require 'ffi_yajl'
require 'chef_zero/rest_base'

module ChefZero
  module Endpoints
    # /users/USER/keys/NAME
    class UserKeyEndpoint < RestBase
      def get(request)
        path = [ "user_keys", *request.rest_path[1..-1] ]
        already_json_response(200, get_data(request, path))
      end

      def delete(request)
        path = [ "user_keys", *request.rest_path[1..-1] ]

        data = get_data(request, path)
        delete_data(request, path)

        already_json_response(200, data)
      end

      def put(request)
        path = [ "user_keys", *request.rest_path[1..-1] ]

        # We grab the old data to trigger a 404 if it doesn't exist
        get_data(request, path)

        set_data(request, path, request.body)
      end
    end
  end
end