Example #1
0
def config_routes(global_config, settings):
    """
    """
    config = Configurator(settings=settings)

    # Configure graphite metrics pusher:
    from pp.metrics import stats

    stats.init(settings)

    not_found = restfulhelpers.xyz_handler(httplib.NOT_FOUND)
    config.add_view(not_found, context="pyramid.exceptions.NotFound")

    bad_request = restfulhelpers.xyz_handler(httplib.BAD_REQUEST)
    config.add_view(bad_request, context="pyramid.httpexceptions.HTTPBadRequest")

    # Attach the configured Gymkhana instance to requests. This will save the
    # views having to create it. I can set up the redis configuration from
    # here.
    config.set_request_property("pp.latchpony.service.gymkhana:PyramidGymkhana", name="gymkhana", reify=True)

    # Maps to the status page:
    config.add_route("home", "/")

    # Gymkhana management of competitions
    config.add_route("listing", "/gymkhana/")
    config.add_route("competition", "/gymkhana/{org_id}/")
    config.add_route("can_perform", "/gymkhana/can_perform/{org_id}/{user_uuid}/{action}/{resource}/")
    config.add_route("slot_types_for", "/gymkhana/slot_types_for/{org_id}/{user_uuid}/")
    config.add_route("raw_competition", "/gymkhana/competition/{org_id}/")

    # sysadmin actions
    config.add_route("dump", "/poniverse/dump/")
    config.add_route("load", "/poniverse/load/")

    config.add_route("get_tags_for_items", "/latchpony/{org_id}/tags")
    config.add_route("create_competition", "/latchpony/competition/{org_id}")

    # Pick up the views which set up the views automatically:
    #
    config.scan("pp.latchpony.service", ignore="pp.latchpony.service.tests")

    return config
Example #2
0
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    log = logging.getLogger("{}.main".format(__name__))

    config = Configurator(settings=settings)

    cfg = dict(
        dbname=settings.get("mongodb.dbname", "ppusertestdb"),
        port=int(settings.get("mongodb.port", 27017)),
        host=settings.get("mongodb.host", "127.0.0.1"),
    )
    log.info("MongoDB config<{:s}>".format(cfg))
    db.init(cfg)

    # Custom 404 json response handler. This returns a useful JSON
    # response in the body of the 404.
    # XXX this is conflicting
    #config.add_view(restfulhelpers.notfound_404_view, context=HTTPNotFound)

    not_found = restfulhelpers.xyz_handler(httplib.NOT_FOUND)
    config.add_view(not_found, context='pyramid.exceptions.NotFound')

    bad_request = restfulhelpers.xyz_handler(httplib.BAD_REQUEST)
    config.add_view(
        bad_request, context='pyramid.httpexceptions.HTTPBadRequest'
    )

    # Maps to the status page:
    config.add_route('home', '/')

    # sysadmin actions
    config.add_route('dump', '/usiverse/dump/')
    config.add_route('load', '/usiverse/load/')

    # User management

    config.add_route('the_users', '/users')
    config.add_route('the_users-1', '/users/')

    config.add_route('user-auth', '/access/auth/{username}/')
    config.add_route('user-auth-1', '/access/auth/{username}')

    # recover an access secret token for the given access token:
    config.add_route('user-secret', '/access/secret/{access_token}/')
    config.add_route('user-secret-1', '/access/secret/{access_token}/')

    config.add_route('user', '/user/{username}')
    config.add_route('user-1', '/user/{username}/')

    # Pick up the views which set up the views automatically:
    #
    config.scan("pp.user.service", ignore="pp.user.service.tests")

    # Make the pyramid app I'll then wrap in other middleware:
    app = config.make_wsgi_app()

    # Add in the configured pp_auth magic.
    app = pp_auth_middleware(settings, app)

    # RESTful helper class to handle PUT, DELETE over POST requests:
    app = restfulhelpers.HttpMethodOverrideMiddleware(app)

    # Should be last to catch all errors of below wsgi apps. This
    # returns useful JSON response in the body of the 500:
    app = restfulhelpers.JSONErrorHandler(app)

    return app