summaryrefslogtreecommitdiff
path: root/lib/chef_zero/endpoints
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chef_zero/endpoints')
-rw-r--r--lib/chef_zero/endpoints/actor_keys_endpoint.rb13
-rw-r--r--lib/chef_zero/endpoints/organization_user_default_key_endpoint.rb16
-rw-r--r--lib/chef_zero/endpoints/organization_user_key_endpoint.rb17
-rw-r--r--lib/chef_zero/endpoints/organization_user_keys_endpoint.rb17
4 files changed, 57 insertions, 6 deletions
diff --git a/lib/chef_zero/endpoints/actor_keys_endpoint.rb b/lib/chef_zero/endpoints/actor_keys_endpoint.rb
index ba91a6b..f3624d6 100644
--- a/lib/chef_zero/endpoints/actor_keys_endpoint.rb
+++ b/lib/chef_zero/endpoints/actor_keys_endpoint.rb
@@ -8,7 +8,7 @@ module ChefZero
DEFAULT_PUBLIC_KEY_NAME = "default"
DATE_FORMAT = "%FT%TZ" # e.g. 2015-12-24T21:00:00Z
- def get(request)
+ def get(request, alt_uri_root=nil)
path = data_path(request)
# Get actor or 404 if it doesn't exist
@@ -18,7 +18,7 @@ module ChefZero
key_names.unshift(DEFAULT_PUBLIC_KEY_NAME) if actor_has_default_public_key?(actor_json)
result = key_names.map do |key_name|
- list_key(request, [ *path, key_name ])
+ list_key(request, [ *path, key_name ], alt_uri_root)
end
json_response(200, result)
@@ -90,7 +90,7 @@ module ChefZero
end
end
- def list_key(request, data_path)
+ def list_key(request, data_path, alt_uri_root=nil)
key_name, expiration_date =
if data_path[-1] == DEFAULT_PUBLIC_KEY_NAME
[ DEFAULT_PUBLIC_KEY_NAME, "infinity" ]
@@ -103,7 +103,7 @@ module ChefZero
DateTime.now > DateTime.strptime(expiration_date, DATE_FORMAT)
{ "name" => key_name,
- "uri" => key_uri(request, key_name),
+ "uri" => key_uri(request, key_name, alt_uri_root),
"expired" => expired }
end
@@ -111,8 +111,9 @@ module ChefZero
request.rest_path[2] == "clients"
end
- def key_uri(request, key_name)
- build_uri(request.base_uri, [ *request.rest_path, key_name ])
+ def key_uri(request, key_name, alt_uri_root=nil)
+ uri_root = alt_uri_root.nil? ? request.rest_path : alt_uri_root
+ build_uri(request.base_uri, [ *uri_root, key_name ])
end
def actor_path(request)
diff --git a/lib/chef_zero/endpoints/organization_user_default_key_endpoint.rb b/lib/chef_zero/endpoints/organization_user_default_key_endpoint.rb
new file mode 100644
index 0000000..953edc1
--- /dev/null
+++ b/lib/chef_zero/endpoints/organization_user_default_key_endpoint.rb
@@ -0,0 +1,16 @@
+require 'chef_zero/rest_base'
+
+module ChefZero
+ module Endpoints
+ # GET /organizations/ORG/users/USER/keys/default
+ class OrganizationUserDefaultKeyEndpoint < RestBase
+ def get(request)
+ # 404 if it doesn't exist
+ get_data(request, request.rest_path[0..3])
+ # Just use the /users/USER/keys/default endpoint
+ request.rest_path = request.rest_path[2..-1]
+ ActorDefaultKeyEndpoint.new(server).get(request)
+ end
+ end
+ end
+end
diff --git a/lib/chef_zero/endpoints/organization_user_key_endpoint.rb b/lib/chef_zero/endpoints/organization_user_key_endpoint.rb
new file mode 100644
index 0000000..e0c114c
--- /dev/null
+++ b/lib/chef_zero/endpoints/organization_user_key_endpoint.rb
@@ -0,0 +1,17 @@
+require 'chef_zero/rest_base'
+require 'chef_zero/endpoints/actor_keys_endpoint'
+
+module ChefZero
+ module Endpoints
+ # GET /organizations/ORG/users/USER/keys/NAME
+ class OrganizationUserKeyEndpoint < RestBase
+ def get(request)
+ # 404 if not a member of the org
+ get_data(request, request.rest_path[0..3])
+ # Just use the /users/USER/keys endpoint
+ request.rest_path = request.rest_path[2..-1]
+ ActorKeyEndpoint.new(server).get(request)
+ end
+ end
+ end
+end
diff --git a/lib/chef_zero/endpoints/organization_user_keys_endpoint.rb b/lib/chef_zero/endpoints/organization_user_keys_endpoint.rb
new file mode 100644
index 0000000..96a84fe
--- /dev/null
+++ b/lib/chef_zero/endpoints/organization_user_keys_endpoint.rb
@@ -0,0 +1,17 @@
+require 'chef_zero/rest_base'
+
+module ChefZero
+ module Endpoints
+ # GET /organizations/ORG/users/USER/keys
+ class OrganizationUserKeysEndpoint < RestBase
+ def get(request)
+ # 404 if it doesn't exist
+ get_data(request, request.rest_path[0..3])
+ # Just use the /users/USER/keys/key endpoint
+ original_path = request.rest_path
+ request.rest_path = request.rest_path[2..-1]
+ ActorKeysEndpoint.new(server).get(request, original_path)
+ end
+ end
+ end
+end