summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Keiser <jkeiser@opscode.com>2014-07-16 18:52:16 -0700
committerJohn Keiser <jkeiser@opscode.com>2014-07-23 19:21:23 -0600
commitbdcfae41acd00e515e1fc2cb996a07034a61ab4c (patch)
tree9c75cfd99b5e1c09be48cc144cd77f81c940bda3
parent2ced823a1f634e9afb5f20875ea35b741c66d075 (diff)
downloadchef-zero-bdcfae41acd00e515e1fc2cb996a07034a61ab4c.tar.gz
Add /users/NAME/organizations endpoint
-rw-r--r--lib/chef_zero/endpoints/user_organizations_endpoint.rb22
-rw-r--r--lib/chef_zero/server.rb13
2 files changed, 29 insertions, 6 deletions
diff --git a/lib/chef_zero/endpoints/user_organizations_endpoint.rb b/lib/chef_zero/endpoints/user_organizations_endpoint.rb
new file mode 100644
index 0000000..aa5034c
--- /dev/null
+++ b/lib/chef_zero/endpoints/user_organizations_endpoint.rb
@@ -0,0 +1,22 @@
+require 'json'
+require 'chef_zero/rest_base'
+
+module ChefZero
+ module Endpoints
+ # /users/USER/organizations
+ class UserOrganizationsEndpoint < RestBase
+ def get(request)
+ username = request.rest_path[1]
+ result = list_data(request, [ 'organizations' ]).select do |orgname|
+ exists_data?(request, [ 'organizations', orgname, 'users', username ])
+ end
+ result = result.map do |orgname|
+ org = get_data(request, [ 'organizations', orgname, 'org' ])
+ org = JSON.parse(org, :create_additions => false)
+ DataNormalizer.normalize_organization(org, orgname)
+ end
+ json_response(200, result)
+ end
+ end
+ end
+end
diff --git a/lib/chef_zero/server.rb b/lib/chef_zero/server.rb
index 3ad4f94..25add0e 100644
--- a/lib/chef_zero/server.rb
+++ b/lib/chef_zero/server.rb
@@ -74,6 +74,7 @@ require 'chef_zero/endpoints/search_endpoint'
require 'chef_zero/endpoints/user_association_requests_endpoint'
require 'chef_zero/endpoints/user_association_requests_count_endpoint'
require 'chef_zero/endpoints/user_association_request_endpoint'
+require 'chef_zero/endpoints/user_organizations_endpoint'
require 'chef_zero/endpoints/file_store_file_endpoint'
require 'chef_zero/endpoints/not_found_endpoint'
@@ -409,14 +410,18 @@ module ChefZero
[ "/organizations/*/users/*", ActorEndpoint.new(self) ]
]
else
+ # EC-only
[
- # # EC-only
[ "/organizations/*/users", OrganizationUsersEndpoint.new(self) ],
[ "/organizations/*/users/*", OrganizationUserEndpoint.new(self) ],
[ "/users", ActorsEndpoint.new(self) ],
[ "/users/*", ActorEndpoint.new(self) ],
[ "/users/_acl", AclsEndpoint.new(self) ],
- [ "/users/_acl/*", AclEndpoint.new(self) ]
+ [ "/users/_acl/*", AclEndpoint.new(self) ],
+ [ "/users/*/association_requests", UserAssociationRequestsEndpoint.new(self) ],
+ [ "/users/*/association_requests/count", UserAssociationRequestsCountEndpoint.new(self) ],
+ [ "/users/*/association_requests/*", UserAssociationRequestEndpoint.new(self) ],
+ [ "/users/*/organizations", UserOrganizationsEndpoint.new(self) ]
# [ "/verify_password", VerifyPasswordEndpoint.new(self) ],
# [ "/authenticate_user", AuthenticateUserEndpoint.new(self) ],
# [ "/system_recovery", SystemRecoveryEndpoint.new(self) ],
@@ -430,15 +435,11 @@ module ChefZero
[ "/organizations/*/_validator_key", OrganizationValidatorKeyEndpoint.new(self) ],
[ "/organizations/*/association_requests", OrganizationAssociationRequestsEndpoint.new(self) ],
[ "/organizations/*/association_requests/*", OrganizationAssociationRequestEndpoint.new(self) ],
- [ "/users/*/association_requests", UserAssociationRequestsEndpoint.new(self) ],
- [ "/users/*/association_requests/count", UserAssociationRequestsCountEndpoint.new(self) ],
- [ "/users/*/association_requests/*", UserAssociationRequestEndpoint.new(self) ],
[ "/organizations/*/containers", ContainersEndpoint.new(self) ],
[ "/organizations/*/containers/*", ContainerEndpoint.new(self) ],
[ "/organizations/*/groups", GroupsEndpoint.new(self) ],
[ "/organizations/*/groups/*", GroupEndpoint.new(self) ],
- # [ "/users/*/organizations", UserOrganizationsEndpoint.new(self) ],
[ "/organizations/*/organization/_acl", AclsEndpoint.new(self) ],
[ "/organizations/*/*/*/_acl", AclsEndpoint.new(self) ],
[ "/organizations/*/organization/_acl/*", AclEndpoint.new(self) ],