summaryrefslogtreecommitdiff
path: root/apifw/bottleapp.py
diff options
context:
space:
mode:
Diffstat (limited to 'apifw/bottleapp.py')
-rw-r--r--apifw/bottleapp.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/apifw/bottleapp.py b/apifw/bottleapp.py
index 0d61e09..774e1c2 100644
--- a/apifw/bottleapp.py
+++ b/apifw/bottleapp.py
@@ -235,6 +235,18 @@ class BottleApplication:
else:
raise
+ def add_routes_for_resource_type(self, rt):
+ routes = self._api.find_missing_route(rt.get_path())
+ for route in routes:
+ callback = self._callback_with_body(route['callback'])
+ route_dict = {
+ 'method': route.get('method', 'GET'),
+ 'path': route['path'],
+ 'callback': callback,
+ }
+ self._bottleapp.route(**route_dict)
+ self._authz.set_route_authorization(route)
+
def _callback_with_body(self, callback):
def wrapper(*args, **kwargs):
kwargs['raw_uri_path'] = bottle.request.environ['RAW_URI']
@@ -260,7 +272,7 @@ class BottleApplication:
raise bottle.HTTPError(status=apifw.HTTP_BAD_REQUEST, body=str(e))
-def create_bottle_application(api, counter, logger, config):
+def create_bottle_application(api, counter, logger, config, resource_types=None):
# Create a new bottle.Bottle application, set it up, and return it
# so that gunicorn can execute it from the main program.
@@ -280,4 +292,7 @@ def create_bottle_application(api, counter, logger, config):
app.add_plugin(authz)
app.set_authorization_plugin(authz)
+ for rt in resource_types or []:
+ app.add_routes_for_resource_type(rt)
+
return bottleapp