Exemple #1
0
def application_factory(name='public'):
    if name not in ('admin', 'public'):
        raise RuntimeError('Application name (for base_url lookup) must be '
                           'either `admin` or `public`.')

    # NOTE(morgan): The Flask App actually dispatches nothing until we migrate
    # some routers to Flask-Blueprints, it is simply a placeholder.
    app = flask.Flask(name)

    # TODO(morgan): Convert Subsystems over to Flask-Native, for now, we simply
    # dispatch to another "application" [e.g "keystone"]
    # NOTE(morgan): as each router is converted to flask-native blueprint,
    # remove from this list. WARNING ORDER MATTERS; ordered dict used to
    # ensure sane ordering of the routers in the legacy-dispatch model.
    dispatch_map = collections.OrderedDict()

    # Load in Healthcheck and map it to /healthcheck
    hc_app = healthcheck.Healthcheck.app_factory(
        {}, oslo_config_project='keystone')
    dispatch_map['/healthcheck'] = hc_app

    # More legacy code to instantiate all the magic for the dispatchers.
    # The move to blueprints (FLASK) will allow this to be eliminated.
    _routers = []
    sub_routers = []
    mapper = routes.Mapper()
    for api_routers in ALL_API_ROUTERS:
        routers_instance = api_routers.Routers()
        _routers.append(routers_instance)
        routers_instance.append_v3_routers(mapper, sub_routers)

    # Add in the v3 version api
    sub_routers.append(version_routers.VersionV3('public', _routers))
    version_controllers.register_version('v3')
    legacy_dispatcher = keystone_wsgi.ComposingRouter(mapper, sub_routers)

    for pfx in itertools.chain(
            *[rtr.Routers._path_prefixes for rtr in ALL_API_ROUTERS]):
        dispatch_map['/v3/%s' % pfx] = legacy_dispatcher

    # NOTE(morgan) Move the version routers to Flask Native First! It will
    # not work well due to how the dispatcher works unless this is first,
    # otherwise nothing falls through to the native flask app.
    dispatch_map['/v3'] = legacy_dispatcher

    # NOTE(morgan): The Root Version Discovery Document is special and needs
    # it's own mapper/router since the v3 one assumes it owns the root due
    # to legacy paste-isms where /v3 would be routed to APP=/v3, PATH=/
    root_version_disc_mapper = routes.Mapper()
    root_version_disc_router = version_routers.Versions(name)
    root_dispatcher = keystone_wsgi.ComposingRouter(root_version_disc_mapper,
                                                    [root_version_disc_router])
    dispatch_map['/'] = root_dispatcher

    application = KeystoneDispatcherMiddleware(app, dispatch_map)
    return application
Exemple #2
0
def admin_version_app_factory(global_conf, **local_conf):
    return wsgi.ComposingRouter(routes.Mapper(), [routers.Versions('admin')])