summaryrefslogtreecommitdiff
path: root/lib/chef_zero/endpoints/user_key_endpoint.rb
diff options
context:
space:
mode:
authorJordan Running <jr@getchef.com>2016-01-14 16:56:12 -0600
committerJordan Running <jr@getchef.com>2016-01-29 15:30:21 -0600
commit6307a675f0b84f47b65b76ca76ab8bcdf3e4d543 (patch)
treeacba667fe490e410482a00b2cf8cf37e21d17b6a /lib/chef_zero/endpoints/user_key_endpoint.rb
parent2c71be878c318116adbf406717bf99ecaebe05d7 (diff)
downloadchef-zero-6307a675f0b84f47b65b76ca76ab8bcdf3e4d543.tar.gz
Make user keys endpoint specs passjr/pedant-keys
- Add UserKeyEndpoint; handles GET/DELETE/PUT `/user_keys/USERNAME/keys/KEY_NAME`. - Add UserKeysEndpoint; handles GET, POST `/user_keys/USERNAME`. - RestBase - Add some docs. - #json_response - Move `request_version` and `response_version` params into options hash. - Accept `:headers` option for additional headers to be set on response. - #already_json_response: #json_response - RestObjectEndpoint - Add some docs. - Move some repeated logic into methods (`identity_key_value`, `is_rename?`). - #patch_request_body: Add `:except` option to allow skipping keys not wanted in output. - ActorsEndpoint - #post: Store `public_key` in store under `user_keys/USERNAME/keys/default` instead of with user. - ActorEndpoint - #delete: Delete user keys when user is deleted. - #put: Store `public_key` in store under `user_keys` as above. - #populate_defaults: Retrieve user's default `public_key` from store and merge with user response. - OrganizationUserEndpoint - #get: Retrieve user's default `public_key` from store and merge with user response. - PrincipalEndpont - #get - Retrieve user's default `public_key` from store and merge with user response. - Refactor complex nested `if`s.
Diffstat (limited to 'lib/chef_zero/endpoints/user_key_endpoint.rb')
-rw-r--r--lib/chef_zero/endpoints/user_key_endpoint.rb32
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/chef_zero/endpoints/user_key_endpoint.rb b/lib/chef_zero/endpoints/user_key_endpoint.rb
new file mode 100644
index 0000000..4e4872b
--- /dev/null
+++ b/lib/chef_zero/endpoints/user_key_endpoint.rb
@@ -0,0 +1,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