diff options
author | John Keiser <jkeiser@opscode.com> | 2014-07-16 15:52:10 -0700 |
---|---|---|
committer | John Keiser <jkeiser@opscode.com> | 2014-07-23 19:21:23 -0600 |
commit | fa62b97a687a37df2fdcca317eeca91ebd7949cb (patch) | |
tree | c455b7ca54125adc7c8a0baed4f0f0d9f4489ff1 | |
parent | b52e96e28b46fd549dede51055205ea2b329f4ad (diff) | |
download | chef-zero-fa62b97a687a37df2fdcca317eeca91ebd7949cb.tar.gz |
Add /organizations/ORG/association_requests/... endpoints
-rw-r--r-- | lib/chef_zero/data_normalizer.rb | 8 | ||||
-rw-r--r-- | lib/chef_zero/data_store/default_facade.rb | 3 | ||||
-rw-r--r-- | lib/chef_zero/endpoints/groups_endpoint.rb | 2 | ||||
-rw-r--r-- | lib/chef_zero/endpoints/organization_association_request_endpoint.rb | 17 | ||||
-rw-r--r-- | lib/chef_zero/endpoints/organization_association_requests_endpoint.rb | 27 | ||||
-rw-r--r-- | lib/chef_zero/endpoints/organizations_endpoint.rb | 2 | ||||
-rw-r--r-- | lib/chef_zero/rest_request.rb | 2 | ||||
-rw-r--r-- | lib/chef_zero/server.rb | 17 |
8 files changed, 67 insertions, 11 deletions
diff --git a/lib/chef_zero/data_normalizer.rb b/lib/chef_zero/data_normalizer.rb index a8a0381..7c87d7a 100644 --- a/lib/chef_zero/data_normalizer.rb +++ b/lib/chef_zero/data_normalizer.rb @@ -39,6 +39,14 @@ module ChefZero container end + def self.normalize_association_request(request, id, username, orgname) + request['id'] ||= id || "#{username}-#{orgname}" + request['name'] ||= username || if id =~ /(.+)-#{orgname}$/ + $1 + end + request + end + def self.normalize_user(user, name) user['name'] ||= name user['admin'] ||= false diff --git a/lib/chef_zero/data_store/default_facade.rb b/lib/chef_zero/data_store/default_facade.rb index f2cc1c3..4ef19ae 100644 --- a/lib/chef_zero/data_store/default_facade.rb +++ b/lib/chef_zero/data_store/default_facade.rb @@ -297,7 +297,8 @@ module ChefZero 'nodes' => {}, 'roles' => {}, 'sandboxes' => {} - } + }, + 'association_requests' => {} } if single_org diff --git a/lib/chef_zero/endpoints/groups_endpoint.rb b/lib/chef_zero/endpoints/groups_endpoint.rb index a42098d..b35701f 100644 --- a/lib/chef_zero/endpoints/groups_endpoint.rb +++ b/lib/chef_zero/endpoints/groups_endpoint.rb @@ -3,7 +3,7 @@ require 'chef_zero/endpoints/rest_list_endpoint' module ChefZero module Endpoints - # /organizations/ORG/groups + # /organizations/ORG/groups/NAME class GroupsEndpoint < RestListEndpoint def initialize(server) super(server, 'groupname') diff --git a/lib/chef_zero/endpoints/organization_association_request_endpoint.rb b/lib/chef_zero/endpoints/organization_association_request_endpoint.rb new file mode 100644 index 0000000..be92c84 --- /dev/null +++ b/lib/chef_zero/endpoints/organization_association_request_endpoint.rb @@ -0,0 +1,17 @@ +require 'json' +require 'chef_zero/endpoints/rest_list_endpoint' + +module ChefZero + module Endpoints + # /organizations/ORG/association_requests/ID + class OrganizationAssociationRequestEndpoint < RestBase + def delete(request) + data = JSON.parse(get_data(request), :create_additions => false) + delete_data(request) + orgname = request.rest_path[1] + id = request.rest_path[3] + json_response(200, DataNormalizer.normalize_association_request(data, id, nil, orgname)) + end + end + end +end diff --git a/lib/chef_zero/endpoints/organization_association_requests_endpoint.rb b/lib/chef_zero/endpoints/organization_association_requests_endpoint.rb new file mode 100644 index 0000000..c4bb09d --- /dev/null +++ b/lib/chef_zero/endpoints/organization_association_requests_endpoint.rb @@ -0,0 +1,27 @@ +require 'json' +require 'chef_zero/endpoints/rest_list_endpoint' + +module ChefZero + module Endpoints + # /organizations/ORG/association_requests + class OrganizationAssociationRequestsEndpoint < RestBase + def post(request) + json = JSON.parse(request.body, :create_additions => false) + username = json['user'] + orgname = request.rest_path[1] + id = "#{username}-#{orgname}" + create_data(request, request.rest_path, id, '{}') + json_response(201, { "uri" => build_uri(request.base_uri, request.rest_path + [ id ]) }) + end + + def get(request) + requests = list_data(request) + result = list_data(request).map do |id| + json = JSON.parse(get_data(request, request.rest_path + [ id ]), :create_additions => false) + DataNormalizer.normalize_association_request(json, id, nil, request.rest_path[1]) + end + json_response(200, result) + end + end + end +end diff --git a/lib/chef_zero/endpoints/organizations_endpoint.rb b/lib/chef_zero/endpoints/organizations_endpoint.rb index 76cbfad..854f528 100644 --- a/lib/chef_zero/endpoints/organizations_endpoint.rb +++ b/lib/chef_zero/endpoints/organizations_endpoint.rb @@ -29,7 +29,7 @@ module ChefZero "assigned_at" => Time.now.to_s } org_path = request.rest_path + [ name ] - create_data(request, org_path, 'org', JSON.pretty_generate(org)) + set_data(request, org_path + [ 'org' ], JSON.pretty_generate(org)) if server.generate_real_keys? # Create the validator client diff --git a/lib/chef_zero/rest_request.rb b/lib/chef_zero/rest_request.rb index a9115da..3205166 100644 --- a/lib/chef_zero/rest_request.rb +++ b/lib/chef_zero/rest_request.rb @@ -15,7 +15,7 @@ module ChefZero end def requestor - @env['HTTP_X_OPS_USERID'] || 'mr_nobody' + @env['HTTP_X_OPS_USERID'] end def method diff --git a/lib/chef_zero/server.rb b/lib/chef_zero/server.rb index db8cb36..a9adbff 100644 --- a/lib/chef_zero/server.rb +++ b/lib/chef_zero/server.rb @@ -60,6 +60,8 @@ require 'chef_zero/endpoints/node_endpoint' require 'chef_zero/endpoints/organizations_endpoint' require 'chef_zero/endpoints/organization_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' require 'chef_zero/endpoints/principal_endpoint' require 'chef_zero/endpoints/role_endpoint' require 'chef_zero/endpoints/role_environments_endpoint' @@ -404,8 +406,8 @@ module ChefZero else [ # # EC-only - # [ "/organizations/*/users", EcUsersEndpoint.new(self) ], - # [ "/organizations/*/users/*", EcUserEndpoint.new(self) ], + # [ "/organizations/*/users", EcOrgUsersEndpoint.new(self) ], + # [ "/organizations/*/users/*", EcOrgUserEndpoint.new(self) ], [ "/users", ActorsEndpoint.new(self) ], [ "/users/*", ActorEndpoint.new(self) ], [ "/users/_acl", AclsEndpoint.new(self) ], @@ -422,16 +424,17 @@ module ChefZero [ "/organizations/*", OrganizationEndpoint.new(self) ], [ "/organizations/*/_validator_key", OrganizationValidatorKeyEndpoint.new(self) ], # [ "/organizations/*/members", RestObjectEndpoint.new(self) ], - # [ "/organizations/*/association_requests", AssociationRequestsEndpoint.new(self) ], - # [ "/organizations/*/association_requests/count", AssociationRequestsCountEndpoint.new(self) ], - # [ "/organizations/*/association_requests/*", AssociationRequestEndpoint.new(self) ], + [ "/organizations/*/association_requests", OrganizationAssociationRequestsEndpoint.new(self) ], + [ "/organizations/*/association_requests/*", OrganizationAssociationRequestEndpoint.new(self) ], + # [ "/users/*/association_requests", UserAssocationRequestsEndpoint.new(self) ], + # [ "/users/*/association_requests/count", UserAssocationRequestsCountEndpoint.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) ], - # [ "/users/*/association_requests", UserAssocationRequestsEndpoint.new(self) ], - # [ "/users/*/association_requests/*", UserAssociationRequestEndpoint.new(self) ], [ "/organizations/*/organization/_acl", AclsEndpoint.new(self) ], [ "/organizations/*/*/*/_acl", AclsEndpoint.new(self) ], [ "/organizations/*/organization/_acl/*", AclEndpoint.new(self) ], |