Allow class-level definition of API URL Prefix

Add the ability to define API URL Prefix at the class-level. This
will be used only if no ap_url_prefix is passed into __init__.

Flask-restful handles prefixes in the order of `BAE` as used in Keystone:
  * Blueprint
  * API
  * Endpoint (flask-endpoint)

This allows for additional prefixes such as "OS-TRUST" for
legacy/converted extension code that has not been updated to use
non-"OS" prefixed pathes.

Change-Id: I7acf2f16a25efc6a801e6c87c1aac436bb8e5453
Partial-Bug: #1776504
This commit is contained in:
Morgan Fainberg 2018-07-13 20:48:35 -04:00
parent cb130ffae8
commit c008cbcea0
1 changed files with 4 additions and 1 deletions

View File

@ -239,7 +239,10 @@ class APIBase(object):
if api_url_prefix and not api_url_prefix.startswith('/'):
self._api_url_prefix = '/%s' % api_url_prefix
else:
self._api_url_prefix = api_url_prefix
# NOTE(morgan): If the api_url_prefix is empty fall back on the
# class-level defined `_api_url_prefix` if it is set.
self._api_url_prefix = (api_url_prefix or
getattr(self, '_api_url_prefix', ''))
if blueprint_url_prefix and not blueprint_url_prefix.startswith('/'):
self._blueprint_url_prefix = self._build_bp_url_prefix(