Reclassify get_project_by_name() controller method

The v2 controller's public methods are supposed to be the functions
called for the REST APIs, for example,

 /v2.0/projects/{id} -> get_project().

There's no v2 route for get_project_by_name, so this method should
not be public, should not be marked as a deprecated v2 API, and
should not have to assert admin itself.

Change-Id: I02edacccd96fde9a93fc1a700248cc5dfea04227
This commit is contained in:
Brant Knudson 2015-10-05 17:03:32 -05:00
parent 64c28885dd
commit 13fb3edad2
2 changed files with 19 additions and 16 deletions

View File

@ -40,11 +40,11 @@ class Tenant(controller.V2Controller):
@controller.v2_deprecated
def get_all_projects(self, context, **kw):
"""Gets a list of all tenants for an admin user."""
if 'name' in context['query_string']:
return self.get_project_by_name(
context, context['query_string'].get('name'))
self.assert_admin(context)
if 'name' in context['query_string']:
return self._get_project_by_name(context['query_string']['name'])
tenant_refs = self.resource_api.list_projects_in_domain(
CONF.identity.default_domain_id)
tenant_refs = [self.v3_to_v2_project(tenant_ref)
@ -71,9 +71,7 @@ class Tenant(controller.V2Controller):
self._assert_not_is_domain_project(tenant_id, ref)
return {'tenant': self.v3_to_v2_project(ref)}
@controller.v2_deprecated
def get_project_by_name(self, context, tenant_name):
self.assert_admin(context)
def _get_project_by_name(self, tenant_name):
# Projects acting as a domain should not be visible via v2
ref = self.resource_api.get_project_by_name(
tenant_name, CONF.identity.default_domain_id)

View File

@ -13,6 +13,7 @@
# under the License.
import copy
import uuid
from keystone.assignment import controllers as assignment_controllers
@ -107,18 +108,22 @@ class TenantTestCase(unit.TestCase):
"""Test that get project does not return is_domain projects."""
project = self._create_is_domain_project()
self.assertRaises(
exception.ProjectNotFound,
self.tenant_controller.get_project_by_name,
_ADMIN_CONTEXT,
project['name']
)
context = copy.deepcopy(_ADMIN_CONTEXT)
context['query_string']['name'] = project['name']
self.assertRaises(
exception.ProjectNotFound,
self.tenant_controller.get_project,
_ADMIN_CONTEXT,
project['id']
self.tenant_controller.get_all_projects,
context
)
context = copy.deepcopy(_ADMIN_CONTEXT)
context['query_string']['name'] = project['id']
self.assertRaises(
exception.ProjectNotFound,
self.tenant_controller.get_all_projects,
context
)
def test_update_is_domain_project_not_found(self):