class ChefZero::Endpoints::ActorDefaultKeyEndpoint
This class handles DELETE/GET/PUT requests for client/user default public keys, i.e. requests with identity key “default”. All others are handled by ActorKeyEndpoint.
Default public keys are stored with the actor (client or user) instead of under user/client_keys. Handling those in a separate endpoint offloads the branching logic onto the router rather than branching in every endpoint method (`if request.rest_path == “default” …`).
/users/USER/keys/default /organizations/ORG/clients/CLIENT/keys/default
Constants
- DEFAULT_PUBLIC_KEY_NAME
Public Instance Methods
delete(request)
click to toggle source
# File lib/chef_zero/endpoints/actor_default_key_endpoint.rb, line 34 def delete(request) path = actor_path(request) actor_data = get_actor_data(request) # 404 if actor doesn't exist default_public_key = delete_actor_default_public_key!(request, path, actor_data) json_response(200, default_public_key) end
get(request)
click to toggle source
# File lib/chef_zero/endpoints/actor_default_key_endpoint.rb, line 21 def get(request) # 404 if actor doesn't exist actor_data = get_actor_data(request) key_data = default_public_key_from_actor(actor_data) # 404 if the actor doesn't have a default key if key_data["public_key"].nil? raise RestErrorResponse.new(404, "Object not found: #{build_uri(request.base_uri, request.rest_path)}") end json_response(200, default_public_key_from_actor(actor_data)) end
put(request)
click to toggle source
# File lib/chef_zero/endpoints/actor_default_key_endpoint.rb, line 42 def put(request) # 404 if actor doesn't exist actor_data = get_actor_data(request) new_public_key = parse_json(request.body)["public_key"] actor_data["public_key"] = new_public_key set_data(request, actor_path(request), to_json(actor_data)) end
Private Instance Methods
actor_path(request)
click to toggle source
# File lib/chef_zero/endpoints/actor_default_key_endpoint.rb, line 54 def actor_path(request) return request.rest_path[0..3] if request.rest_path[2] == "clients" request.rest_path[0..1] end
default_public_key_from_actor(actor_data)
click to toggle source
# File lib/chef_zero/endpoints/actor_default_key_endpoint.rb, line 64 def default_public_key_from_actor(actor_data) { "name" => DEFAULT_PUBLIC_KEY_NAME, "public_key" => actor_data["public_key"], "expiration_date" => "infinity" } end
delete_actor_default_public_key!(request, path, actor_data)
click to toggle source
# File lib/chef_zero/endpoints/actor_default_key_endpoint.rb, line 70 def delete_actor_default_public_key!(request, path, actor_data) new_actor_data = actor_data.merge("public_key" => nil) set_data(request, path, to_json(new_actor_data)) default_public_key_from_actor(actor_data) end
get_actor_data(request)
click to toggle source
# File lib/chef_zero/endpoints/actor_default_key_endpoint.rb, line 59 def get_actor_data(request) path = actor_path(request) parse_json(get_data(request, path)) end