From d1f574f9dcd5b4546ca48cc87f553aacb1876a1c Mon Sep 17 00:00:00 2001 From: lvdongbing Date: Wed, 11 May 2016 21:32:49 -0400 Subject: [PATCH] Modify api and remove project_id Change-Id: If87115db29f6f1bf80963be2b3af5d6d8a5f1caf --- bilean/api/middleware/fault.py | 1 + bilean/api/openstack/v1/__init__.py | 10 +++++----- bilean/api/openstack/v1/util.py | 5 +---- tools/setup-service | 6 +++--- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/bilean/api/middleware/fault.py b/bilean/api/middleware/fault.py index 3479ca2..16f3e56 100644 --- a/bilean/api/middleware/fault.py +++ b/bilean/api/middleware/fault.py @@ -51,6 +51,7 @@ class FaultWrapper(wsgi.Middleware): 'InvalidParameter': webob.exc.HTTPBadRequest, 'InvalidSchemaError': webob.exc.HTTPBadRequest, 'MultipleChoices': webob.exc.HTTPBadRequest, + 'UserNotFound': webob.exc.HTTPNotFound, 'RuleNotFound': webob.exc.HTTPNotFound, 'RuleTypeNotFound': webob.exc.HTTPNotFound, 'RuleTypeNotMatch': webob.exc.HTTPBadRequest, diff --git a/bilean/api/openstack/v1/__init__.py b/bilean/api/openstack/v1/__init__.py index 11e1a01..e027918 100644 --- a/bilean/api/openstack/v1/__init__.py +++ b/bilean/api/openstack/v1/__init__.py @@ -30,7 +30,7 @@ class API(wsgi.Router): # Users users_resource = users.create_resource(conf) - users_path = "/{project_id}/users" + users_path = "/users" with mapper.submapper(controller=users_resource, path_prefix=users_path) as user_mapper: @@ -60,7 +60,7 @@ class API(wsgi.Router): # Resources res_resource = resources.create_resource(conf) - res_path = "/{project_id}/resources" + res_path = "/resources" with mapper.submapper(controller=res_resource, path_prefix=res_path) as res_mapper: @@ -84,7 +84,7 @@ class API(wsgi.Router): # Rules rule_resource = rules.create_resource(conf) - rule_path = "/{project_id}/rules" + rule_path = "/rules" with mapper.submapper(controller=rule_resource, path_prefix=rule_path) as rule_mapper: @@ -120,7 +120,7 @@ class API(wsgi.Router): # Policies policy_resource = policies.create_resource(conf) - policy_path = "/{project_id}/policies" + policy_path = "/policies" with mapper.submapper(controller=policy_resource, path_prefix=policy_path) as policy_mapper: @@ -162,7 +162,7 @@ class API(wsgi.Router): # Events event_resource = events.create_resource(conf) - event_path = "/{project_id}/events" + event_path = "/events" with mapper.submapper(controller=event_resource, path_prefix=event_path) as event_mapper: diff --git a/bilean/api/openstack/v1/util.py b/bilean/api/openstack/v1/util.py index 30db26e..97437e9 100644 --- a/bilean/api/openstack/v1/util.py +++ b/bilean/api/openstack/v1/util.py @@ -28,10 +28,7 @@ def policy_enforce(handler): This is a handler method decorator. """ @functools.wraps(handler) - def handle_bilean_method(controller, req, project_id, **kwargs): - if req.context.project != project_id: - raise exc.HTTPForbidden() - + def handle_bilean_method(controller, req, **kwargs): rule = "%s:%s" % (controller.REQUEST_SCOPE, handler.__name__) allowed = policy.enforce(context=req.context, rule=rule, target={}) diff --git a/tools/setup-service b/tools/setup-service index 5ad1c97..2484b28 100755 --- a/tools/setup-service +++ b/tools/setup-service @@ -36,9 +36,9 @@ if [[ -z $SERVICE_ID ]]; then fi openstack endpoint create \ - --adminurl "http://$HOST:$PORT/v1/\$(project_id)s" \ - --publicurl "http://$HOST:$PORT/v1/\$(project_id)s" \ - --internalurl "http://$HOST:$PORT/v1/\$(project_id)s" \ + --adminurl "http://$HOST:$PORT/v1" \ + --publicurl "http://$HOST:$PORT/v1" \ + --internalurl "http://$HOST:$PORT/v1" \ --region RegionOne \ bilean