summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJohn Keiser <jkeiser@opscode.com>2014-07-16 18:40:00 -0700
committerJohn Keiser <jkeiser@opscode.com>2014-07-23 19:21:23 -0600
commit2ced823a1f634e9afb5f20875ea35b741c66d075 (patch)
treedb34ebd48ca5104bca88a1508bd36525b63c3c48 /lib
parent16dfd6a8016eed76834b24b5c0cb1d0926ebf109 (diff)
downloadchef-zero-2ced823a1f634e9afb5f20875ea35b741c66d075.tar.gz
Implement /organizations/ORG/users/... endpoints
Diffstat (limited to 'lib')
-rw-r--r--lib/chef_zero/data_store/default_facade.rb6
-rw-r--r--lib/chef_zero/endpoints/organization_association_requests_endpoint.rb3
-rw-r--r--lib/chef_zero/endpoints/organization_user_endpoint.rb24
-rw-r--r--lib/chef_zero/endpoints/organization_users_endpoint.rb14
-rw-r--r--lib/chef_zero/endpoints/user_association_request_endpoint.rb2
-rw-r--r--lib/chef_zero/server.rb7
6 files changed, 46 insertions, 10 deletions
diff --git a/lib/chef_zero/data_store/default_facade.rb b/lib/chef_zero/data_store/default_facade.rb
index 2454df6..2285576 100644
--- a/lib/chef_zero/data_store/default_facade.rb
+++ b/lib/chef_zero/data_store/default_facade.rb
@@ -219,6 +219,7 @@ module ChefZero
'nodes' => {},
'roles' => {},
'sandboxes' => {},
+ 'users' => {},
'org' => '{}',
'containers' => {
@@ -299,13 +300,10 @@ module ChefZero
'sandboxes' => {}
},
'association_requests' => {},
- 'members' => {}
}
if single_org
- result['users'] = {
- 'admin' => '{ "admin": "true" }'
- }
+ result['users']['admin'] = '{ "admin": "true" }'
end
result
diff --git a/lib/chef_zero/endpoints/organization_association_requests_endpoint.rb b/lib/chef_zero/endpoints/organization_association_requests_endpoint.rb
index a048796..4367e6b 100644
--- a/lib/chef_zero/endpoints/organization_association_requests_endpoint.rb
+++ b/lib/chef_zero/endpoints/organization_association_requests_endpoint.rb
@@ -11,7 +11,7 @@ module ChefZero
orgname = request.rest_path[1]
id = "#{username}-#{orgname}"
- if !exists_data?(request, [ 'organizations', orgname, 'members', username ])
+ if !exists_data?(request, [ 'organizations', orgname, 'users', username ])
RestErrorResponse.new(409, "User #{username} is already in organization #{orgname}")
end
@@ -20,7 +20,6 @@ module ChefZero
end
def get(request)
- requests = list_data(request)
orgname = request.rest_path[1]
result = list_data(request).map { |username| { "id" => "#{username}-#{orgname}", 'username' => username } }
json_response(200, result)
diff --git a/lib/chef_zero/endpoints/organization_user_endpoint.rb b/lib/chef_zero/endpoints/organization_user_endpoint.rb
new file mode 100644
index 0000000..9cb37cf
--- /dev/null
+++ b/lib/chef_zero/endpoints/organization_user_endpoint.rb
@@ -0,0 +1,24 @@
+require 'json'
+require 'chef_zero/rest_base'
+
+module ChefZero
+ module Endpoints
+ # /organizations/ORG/users/NAME
+ class OrganizationUserEndpoint < RestBase
+ def get(request)
+ username = request.rest_path[3]
+ get_data(request) # 404 if user is not in org
+ user = get_data(request, [ 'users', username ])
+ user = JSON.parse(user, :create_additions => false)
+ json_response(200, DataNormalizer.normalize_user(user, username))
+ end
+
+ def delete(request)
+ user = get_data(request)
+ delete_data(request)
+ user = JSON.parse(user, :create_additions => false)
+ json_response(200, DataNormalizer.normalize_user(user, request.rest_path[3]))
+ end
+ end
+ end
+end
diff --git a/lib/chef_zero/endpoints/organization_users_endpoint.rb b/lib/chef_zero/endpoints/organization_users_endpoint.rb
new file mode 100644
index 0000000..810fbad
--- /dev/null
+++ b/lib/chef_zero/endpoints/organization_users_endpoint.rb
@@ -0,0 +1,14 @@
+require 'json'
+require 'chef_zero/rest_base'
+
+module ChefZero
+ module Endpoints
+ # /organizations/ORG/users
+ class OrganizationUsersEndpoint < RestBase
+ def get(request)
+ result = list_data(request).map { |username| { "user" => { "username" => username } } }
+ json_response(200, result)
+ end
+ end
+ end
+end
diff --git a/lib/chef_zero/endpoints/user_association_request_endpoint.rb b/lib/chef_zero/endpoints/user_association_request_endpoint.rb
index 2cce39c..edcbd72 100644
--- a/lib/chef_zero/endpoints/user_association_request_endpoint.rb
+++ b/lib/chef_zero/endpoints/user_association_request_endpoint.rb
@@ -15,7 +15,7 @@ module ChefZero
json = JSON.parse(request.body, :create_additions => false)
if json['response'] == 'accept'
- create_data(request, [ 'organizations', orgname, 'members' ], username, '{}')
+ create_data(request, [ 'organizations', orgname, 'users' ], username, '{}')
delete_data(request, [ 'organizations', orgname, 'association_requests', username ])
elsif json['response'] == 'reject'
delete_data(request, [ 'organizations', orgname, 'association_requests', username ])
diff --git a/lib/chef_zero/server.rb b/lib/chef_zero/server.rb
index 1ae50c2..3ad4f94 100644
--- a/lib/chef_zero/server.rb
+++ b/lib/chef_zero/server.rb
@@ -59,6 +59,8 @@ require 'chef_zero/endpoints/environment_role_endpoint'
require 'chef_zero/endpoints/node_endpoint'
require 'chef_zero/endpoints/organizations_endpoint'
require 'chef_zero/endpoints/organization_endpoint'
+require 'chef_zero/endpoints/organization_users_endpoint'
+require 'chef_zero/endpoints/organization_user_endpoint'
require 'chef_zero/endpoints/organization_validator_key_endpoint'
require 'chef_zero/endpoints/organization_association_requests_endpoint'
require 'chef_zero/endpoints/organization_association_request_endpoint'
@@ -409,8 +411,8 @@ module ChefZero
else
[
# # EC-only
- # [ "/organizations/*/users", EcOrgUsersEndpoint.new(self) ],
- # [ "/organizations/*/users/*", EcOrgUserEndpoint.new(self) ],
+ [ "/organizations/*/users", OrganizationUsersEndpoint.new(self) ],
+ [ "/organizations/*/users/*", OrganizationUserEndpoint.new(self) ],
[ "/users", ActorsEndpoint.new(self) ],
[ "/users/*", ActorEndpoint.new(self) ],
[ "/users/_acl", AclsEndpoint.new(self) ],
@@ -426,7 +428,6 @@ module ChefZero
[ "/organizations", OrganizationsEndpoint.new(self) ],
[ "/organizations/*", OrganizationEndpoint.new(self) ],
[ "/organizations/*/_validator_key", OrganizationValidatorKeyEndpoint.new(self) ],
- # [ "/organizations/*/members", RestObjectEndpoint.new(self) ],
[ "/organizations/*/association_requests", OrganizationAssociationRequestsEndpoint.new(self) ],
[ "/organizations/*/association_requests/*", OrganizationAssociationRequestEndpoint.new(self) ],
[ "/users/*/association_requests", UserAssociationRequestsEndpoint.new(self) ],