summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-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
-rw-r--r--lib/chef_zero/rest_request.rb4
-rw-r--r--lib/chef_zero/server.rb9
6 files changed, 68 insertions, 8 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
diff --git a/lib/chef_zero/rest_request.rb b/lib/chef_zero/rest_request.rb
index 60738cf..f18ce4d 100644
--- a/lib/chef_zero/rest_request.rb
+++ b/lib/chef_zero/rest_request.rb
@@ -41,6 +41,10 @@ module ChefZero
@rest_path ||= rest_base_prefix + env['PATH_INFO'].split('/').select { |part| part != "" }
end
+ def rest_path=(rest_path)
+ @rest_path = rest_path
+ end
+
def body=(body)
@body = body
end
diff --git a/lib/chef_zero/server.rb b/lib/chef_zero/server.rb
index 7d508ca..9378afb 100644
--- a/lib/chef_zero/server.rb
+++ b/lib/chef_zero/server.rb
@@ -43,6 +43,9 @@ require 'chef_zero/endpoints/acl_endpoint'
require 'chef_zero/endpoints/actor_endpoint'
require 'chef_zero/endpoints/actors_endpoint'
require 'chef_zero/endpoints/actor_key_endpoint'
+require 'chef_zero/endpoints/organization_user_key_endpoint'
+require 'chef_zero/endpoints/organization_user_default_key_endpoint'
+require 'chef_zero/endpoints/organization_user_keys_endpoint'
require 'chef_zero/endpoints/actor_default_key_endpoint'
require 'chef_zero/endpoints/actor_keys_endpoint'
require 'chef_zero/endpoints/cookbooks_endpoint'
@@ -526,7 +529,7 @@ module ChefZero
[
[ "/organizations/*/users", ActorsEndpoint.new(self) ],
[ "/organizations/*/users/*", ActorEndpoint.new(self) ],
- [ "/organizations/*/authenticate_user", OrganizationAuthenticateUserEndpoint.new(self) ],
+ [ "/organizations/*/authenticate_user", OrganizationAuthenticateUserEndpoint.new(self) ]
]
else
# EC-only
@@ -547,7 +550,6 @@ module ChefZero
[ "/authenticate_user", AuthenticateUserEndpoint.new(self) ],
[ "/system_recovery", SystemRecoveryEndpoint.new(self) ],
[ "/license", LicenseEndpoint.new(self) ],
-
[ "/organizations", OrganizationsEndpoint.new(self) ],
[ "/organizations/*", OrganizationEndpoint.new(self) ],
[ "/organizations/*/_validator_key", OrganizationValidatorKeyEndpoint.new(self) ],
@@ -573,6 +575,9 @@ module ChefZero
[ "/organizations/*/clients/*/keys", ActorKeysEndpoint.new(self) ],
[ "/organizations/*/clients/*/keys/default", ActorDefaultKeyEndpoint.new(self) ],
[ "/organizations/*/clients/*/keys/*", ActorKeyEndpoint.new(self) ],
+ [ "/organizations/*/users/*/keys", OrganizationUserKeysEndpoint.new(self) ],
+ [ "/organizations/*/users/*/keys/default", OrganizationUserDefaultKeyEndpoint.new(self) ],
+ [ "/organizations/*/users/*/keys/*", OrganizationUserKeyEndpoint.new(self) ],
[ "/organizations/*/controls", ControlsEndpoint.new(self) ],
[ "/organizations/*/cookbooks", CookbooksEndpoint.new(self) ],
[ "/organizations/*/cookbooks/*", CookbookEndpoint.new(self) ],