Class: ChefZero::Endpoints::ActorDefaultKeyEndpoint
- Defined in:
- lib/chef_zero/endpoints/actor_default_key_endpoint.rb
Overview
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
Constant Summary collapse
- DEFAULT_PUBLIC_KEY_NAME =
"default".freeze
Constants inherited from RestBase
RestBase::DEFAULT_REQUEST_VERSION, RestBase::DEFAULT_RESPONSE_VERSION
Instance Attribute Summary
Attributes inherited from RestBase
Instance Method Summary collapse
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
#delete(request) ⇒ Object
34 35 36 37 38 39 40 |
# 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) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# 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) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# 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 |