Ejemplo n.º 1
0
def main(global_config, **local_config):
    """ This function returns a WSGI application.
    
    It is usually called by the PasteDeploy framework during 
    ``paster serve``.
    """

    the_settings = settings.load_settings(global_config, local_config)

    request_factory = None
    if os.environ.get('mock_request'):
        request_factory = GizaRequest
    config = Configurator(settings=the_settings, root_factory=Root, request_factory=request_factory)

    # NOTE: configure_jinja should come last because pyramid_webassets 
    # registers a static view with default settings. Since we register our own
    # static views with custom cache_max_age, we want those views to come first
    # (since the router goes in the order in which views are added).
    configure_logging(config)
    configure_version(config)
    configure_file_watcher(config)
    configure_db(config)
    configure_auth(config)
    configure_redirects(config)
    configure_routes(config)
    configure_jinja(config)
    configure_helpers(config)

    config.scan('.views')

    return config.make_wsgi_app()
Ejemplo n.º 2
0
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.bind = engine
    session_factory = UnencryptedCookieSessionFactoryConfig(
        settings['secret_key'])
    config = Configurator(settings=settings,
                          root_factory='composting.models.base.RootFactory',
                          session_factory=session_factory)
    config.set_authentication_policy(
        AuthTktAuthenticationPolicy(settings['secret_key'],
                                    callback=group_finder,
                                    hashalg='sha512'))

    config.set_authorization_policy(ACLAuthorizationPolicy())
    config.set_default_permission('authenticated')

    logging.config.fileConfig(global_config['__file__'],
                              disable_existing_loggers=False)

    # configure password context
    pwd_context.load_path(global_config['__file__'])

    # include ourselves
    includeme(config)
    return config.make_wsgi_app()
Ejemplo n.º 3
0
def main(*args, **settings):
    from pyramid.config import Configurator
    from pyramid.events import NewRequest, ContextFound
    from pyramid.authentication import BasicAuthAuthenticationPolicy
    from pyramid.authorization import ACLAuthorizationPolicy
    from pyramid.renderers import JSON, JSONP

    logger.info('Start registry api...')
    read_users(settings['auth.file'])
    config = Configurator(autocommit=True,
                          settings=settings,
                          authentication_policy=BasicAuthAuthenticationPolicy(
                              auth_check, __name__),
                          authorization_policy=ACLAuthorizationPolicy(),
                          root_factory=Root,
                          route_prefix=ROUTE_PREFIX)

    config.include('pyramid_exclog')
    config.add_forbidden_view(forbidden)
    config.add_request_method(request_params, 'params', reify=True)
    config.add_request_method(authenticated_role, reify=True)
    config.add_renderer('prettyjson', JSON(indent=4))
    config.add_renderer('jsonp', JSONP(param_name='opt_jsonp'))
    config.add_renderer('prettyjsonp', JSONP(indent=4, param_name='opt_jsonp'))
    config.add_subscriber(add_logging_context, NewRequest)
    config.add_subscriber(set_logging_context, ContextFound)
    config.add_subscriber(set_renderer, NewRequest)
    config.add_route('health', '/health')
    config.add_route('registry', '/registry/{param}.json')
    config.scan('openprocurement.medicines.registry.api.views')
    return config.make_wsgi_app()
Ejemplo n.º 4
0
def main(global_config, **settings):

    # support logging in python3
    logging.config.fileConfig(settings["logging.config"],
                              disable_existing_loggers=False)
    config = Configurator(settings=settings)
    config.include(".routes")
    config.scan()
    app = config.make_wsgi_app()
    return ignore_websocket_closed(app)
Ejemplo n.º 5
0
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """

    # support logging in python3
    logging.config.fileConfig(
        settings['logging.config'],
        disable_existing_loggers=False
    )

    config = Configurator(settings=settings)

    config.include('pyramid_raven')

    return config.make_wsgi_app()
Ejemplo n.º 6
0
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.bind = engine
    session_factory = SignedCookieSessionFactory(
        settings['secret_key'])
    config = Configurator(settings=settings,
                          root_factory='whoahqa.models.RootFactory',
                          session_factory=session_factory)
    config.set_authentication_policy(
        AuthTktAuthenticationPolicy(settings['secret_key'],
                                    callback=group_finder,
                                    hashalg='sha512'))

    config.set_authorization_policy(ACLAuthorizationPolicy())
    config.set_default_permission(perms.AUTHENTICATED)

    # Add custom renderers
    config.add_renderer('csv', 'whoahqa.renderers.CSVRenderer')

    # Add request object helpers
    add_request_helpers(config)

    # setup the hashid salt
    hashid._salt = settings['hashid_salt']

    # add locale directory to project configuration
    config.add_translation_dirs('whoahqa:locale')

    # configure enketo
    enketo.configure(
        settings['enketo_url'],
        settings['enketo_api_token'])

    logging.config.fileConfig(
        global_config['__file__'], disable_existing_loggers=False)

    # configure password context
    pwd_context.load_path(global_config['__file__'])

    includeme(config)

    if settings.get("environment", "") == DEVELOPMENT_ENV:
        setup_development_data()

    return config.make_wsgi_app()
Ejemplo n.º 7
0
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """

    # support logging in python3
    logging.config.fileConfig(settings['logging.config'],
                              disable_existing_loggers=False)

    config = Configurator(settings=settings)
    config.set_root_factory(RootFactory)

    config.add_route('index', '/')
    config.add_route('secure', '/secure')
    config.scan()

    return config.make_wsgi_app()
Ejemplo n.º 8
0
def main(global_config, **settings):
    logging.config.fileConfig(settings['logging.config'], disable_existing_loggers=False)
    """ This function returns a Pyramid WSGI application.
    """
    config = Configurator(settings=settings, root_factory='jungo.model.RootFactory')
    config.include('pyramid_chameleon')
    config.add_static_view('static', 'static', cache_max_age=3600)
    config.add_route('home', '/old-home')
    config.add_route('search', '/')
    config.add_route('common_interests', '/common-interests')
    config.add_route('profile', '/me')
    config.add_route('user', '/user/{username}')

    config.add_route('login', '/login')
    config.add_route('logout', '/logout')

    config.add_route('interest_match', '/interest-match/{username}/{interest_id}')
    config.add_route('api_add_user', '/api/user', request_method='POST')
    config.add_route('api_user', '/api/user/{username}', request_method='GET')
    config.add_route('api_add_interests', '/api/user/{username}/interests', request_method='POST')
    config.add_route('api_common_interests', '/api/common-interests', request_method='GET')

    authn_policy = AuthTktAuthenticationPolicy('super secret magic', callback=groupfinder, hashalg='sha512')
    authz_policy = ACLAuthorizationPolicy()
    config.set_authentication_policy(authn_policy)
    config.set_authorization_policy(authz_policy)

    config.set_session_factory(session_factory)

    db_url = settings['mongo_uri']

    config.registry.client = pymongo.MongoClient(db_url)

    def add_db(request):
        uri = urlparse.urlparse(db_url)
        db = config.registry.client[uri.path[1:]]
        if uri.username and uri.password:
            db.authenticate(uri.username, uri.password)
        return DataStore(db)

    add_db(None).create_indices()

    config.add_request_method(add_db, 'db', reify=True)

    config.scan()

    return config.make_wsgi_app()
Ejemplo n.º 9
0
def make_wsgi_app(settings):
    config = Configurator(
        settings=settings,
        root_factory=RootFactory,
        session_factory=pyramid.session.UnencryptedCookieSessionFactoryConfig(
            'secret_shit',
            cookie_name='s',
            timeout=60 * 60 * 24 * 3,
            cookie_max_age=60 * 60 * 24 * 3,
        ),
        authentication_policy=pyramid.authentication.
        SessionAuthenticationPolicy(prefix='auth.',
                                    callback=group_finder,
                                    debug=False),
        authorization_policy=pyramid.authorization.ACLAuthorizationPolicy(),
    )

    config.set_request_property(
        lambda request: lambda permission: pyramid.security.has_permission(
            permission, request.root, request), 'has_permission')

    config.add_tween('mistress_stat.stat_server.autocommit_tween_factory',
                     under=pyramid.tweens.EXCVIEW)
    config.add_tween('sapyens.db.notfound_tween_factory',
                     under=pyramid.tweens.EXCVIEW)

    config.add_subscriber(_add_renderer_globals, pyramid.events.BeforeRender)

    config.add_static_view('static',
                           'mistress_stat:static',
                           cache_max_age=3600)

    config.add_route('login', '/login')
    login_view = LoginView(
        lambda _, request: request.registry.settings['password'])
    config.add_view(login_view,
                    route_name='login',
                    renderer='sapyens.views:templates/login.mako')
    config.add_forbidden_view(login_view,
                              renderer='sapyens.views:templates/login.mako')
    config.add_route('logout', '/logout')
    config.add_view(sapyens.views.LogoutView('root'), route_name='logout')

    config.scan(package='mistress_stat')

    return config.make_wsgi_app()
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """

    # support logging in python3
    logging.config.fileConfig(
        settings['logging.config'],
        disable_existing_loggers=False
    )

    config = Configurator(settings=settings)
    config.set_root_factory(RootFactory)

    config.add_route('index', '/')
    config.add_route('secure', '/secure')
    config.scan()

    return config.make_wsgi_app()
Ejemplo n.º 11
0
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application."""

    session_factory = SignedCookieSessionFactory('itsaseekreet',
                                                 max_age=31536000,
                                                 timeout=31536000)  # TODO:

    # support logging in python3
    logging.config.fileConfig(settings['logging.config'],
                              disable_existing_loggers=False)

    config = Configurator(settings=settings,
                          session_factory=session_factory,
                          root_factory=Root)

    # Addons
    config.include('pyramid_chameleon')

    # Security policies
    authn_policy = AuthTktAuthenticationPolicy(
        'qwerty',
        callback=groupfinder,  # TODO:
        hashalg='sha512')
    authz_policy = ACLAuthorizationPolicy()
    config.set_authentication_policy(authn_policy)
    config.set_authorization_policy(authz_policy)

    # Routing
    config.add_route('home', '/')
    config.add_route('second', '/second')
    config.add_route('login', '/login')
    config.add_route('auth', '/auth')
    config.add_route('logout', '/logout')
    config.add_static_view('deform_static', 'deform:static/')
    config.scan()

    return config.make_wsgi_app()
Ejemplo n.º 12
0
def make_wsgi_app (settings):
	config = Configurator(
		settings = settings,
		root_factory = RootFactory,
		session_factory = pyramid.session.UnencryptedCookieSessionFactoryConfig(
			'secret_shit', cookie_name = 's', timeout = 60*60*24*3, cookie_max_age = 60*60*24*3,
		),
		authentication_policy = pyramid.authentication.SessionAuthenticationPolicy(
			prefix = 'auth.',
			callback = group_finder,
			debug = False
		),
		authorization_policy = pyramid.authorization.ACLAuthorizationPolicy(),
	)

	config.set_request_property(
		lambda request: lambda permission: pyramid.security.has_permission(permission, request.root, request),
		'has_permission'
	)

	config.add_tween('mistress_stat.stat_server.autocommit_tween_factory', under = pyramid.tweens.EXCVIEW)
	config.add_tween('sapyens.db.notfound_tween_factory', under = pyramid.tweens.EXCVIEW)

	config.add_subscriber(_add_renderer_globals, pyramid.events.BeforeRender)

	config.add_static_view('static', 'mistress_stat:static', cache_max_age=3600)

	config.add_route('login', '/login')
	login_view = LoginView(lambda _, request: request.registry.settings['password'])
	config.add_view(login_view, route_name = 'login', renderer = 'sapyens.views:templates/login.mako')
	config.add_forbidden_view(login_view, renderer = 'sapyens.views:templates/login.mako')
	config.add_route('logout', '/logout')
	config.add_view(sapyens.views.LogoutView('root'), route_name = 'logout')

	config.scan(package = 'mistress_stat')

	return config.make_wsgi_app()
Ejemplo n.º 13
0
import logging.config

from pyramid.config import Configurator
from pyramid.renderers import JSON

from {{ cookiecutter.repo_name }} import settings


# Set up logging
logging.config.dictConfig(settings.LOGGING)

config = Configurator(settings=settings.PYRAMID_APP_SETTINGS)
json_render = JSON()

config.add_renderer(None, json_render)
config.include('.models')
config.include('.routes')
config.scan()

application = config.make_wsgi_app()
Ejemplo n.º 14
0
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    config = Configurator(settings=settings)
    config.include('pyramid_chameleon')
    config.add_subscriber(add_cors_headers_response_callback, NewRequest)
    social_providers = config.registry.settings['allow_auth'].split(',')
    if 'google' in social_providers:
        config.include('velruse.providers.google_oauth2')
        config.add_google_oauth2_login_from_settings()
    if 'github' in social_providers:
        config.include('velruse.providers.github')
        config.add_github_login_from_settings()
    config.add_subscriber(before_render, BeforeRender)

    my_session_factory = session_factory_from_settings(settings)
    config.set_session_factory(my_session_factory)

    yaml_config = None
    try:
        with open(config.registry.settings['config'], 'r') as ymlfile:
            yaml_config = yaml.load(ymlfile)
            if yaml_config['log_config'] is not None:
                for handler in list(
                        yaml_config['log_config']['handlers'].keys()):
                    yaml_config['log_config']['handlers'][handler] = dict(
                        yaml_config['log_config']['handlers'][handler])
                logging.config.dictConfig(yaml_config['log_config'])
    except Exception as e:
        logging.error('No config file found or declared: ' + str(e))

    logging.warn('Start bioshadock web server')

    config.registry.config = yaml_config

    mongo = MongoClient(yaml_config['services']['mongo']['url'])
    dbmongo = mongo[yaml_config['services']['mongo']['db']]
    config.registry.db_mongo = dbmongo

    r = redis.StrictRedis(host=yaml_config['services']['redis']['host'],
                          port=yaml_config['services']['redis']['port'],
                          db=yaml_config['services']['redis']['db'])
    config.registry.db_redis = r

    config.registry.admin = yaml_config['general']['admin'].split(',')

    config.registry.es = Elasticsearch(
        yaml_config['services']['elastic']['host'].split(','))

    config.registry.ldap_server = None
    config.registry.con = None
    if yaml_config['ldap']['use'] == 1:
        # Check if in ldap
        #import ldap
        from ldap3 import Server, Connection, AUTH_SIMPLE, STRATEGY_SYNC, STRATEGY_ASYNC_THREADED, SEARCH_SCOPE_WHOLE_SUBTREE, GET_ALL_INFO
        try:
            ldap_host = yaml_config['ldap']['host']
            ldap_port = yaml_config['ldap']['port']
            config.registry.ldap_server = Server(ldap_host,
                                                 port=ldap_port,
                                                 get_info=GET_ALL_INFO)
        except Exception as err:
            logging.error(str(err))
            sys.exit(1)

    config.add_static_view('static', 'static', cache_max_age=3600)

    runenv = "dist"
    if "BIOSHADOCK_ENV" in os.environ and os.environ["BIOSHADOCK_ENV"] == "dev":
        runenv = "app"
    config.registry.runenv = runenv

    config.add_static_view('app', 'shadock:webapp/' + runenv + '/')
    config.add_route('home', '/')
    config.add_route('config', '/config')
    config.add_route('search', '/search')
    config.add_route('user_is_logged', '/user/logged')
    config.add_route('users', '/user')
    config.add_route('user_logout', '/user/logout')
    config.add_route('user_bind', '/user/bind')
    config.add_route('user', '/user/{id}')
    config.add_route('containers', '/container')
    config.add_route('containers_all', '/container/all')
    config.add_route('containers_latest', '/container/latest')
    config.add_route('containers_search', '/container/search')
    config.add_route('containers_new', '/container/new')
    config.add_route('container_manifest', '/container/manifest/*id')
    config.add_route('container_tags', '/container/tags/*id')
    config.add_route('container_dockerfile', '/container/dockerfile/*id')
    config.add_route('container_git', '/container/git/*id')
    config.add_route('container_tag', '/container/tag/*id')
    config.add_route('container_elixir', '/container/elixir/*id')
    config.add_route('container_metaelixir', '/container/metaelixir/*id')
    config.add_route('container_vulnerabilities',
                     '/container/vulnerabilities/*id')
    config.add_route('container', '/container/*id')
    config.add_route('clair_notification', '/clair/notify')
    config.add_route('builds', '/builds/*id')
    config.add_route('build', '/build/{id}')
    config.add_route('api_users', '/v1/users/')
    config.add_route('api_library', '/v1/repositories/{image}/')
    config.add_route('api_library_auth', '/v1/repositories/{image}/auth')
    config.add_route('api_library_images', '/v1/repositories/{image}/images')
    config.add_route('api_repositories_images_get',
                     '/v1/repositories/{namespace}/{image}/images')
    config.add_route('api_repositories_images_put',
                     '/v1/repositories/{namespace}/{image}/images')
    config.add_route('api_repositories_images_layer_access',
                     '/v1/repositories/{namespace}/{image}/layer/{id}/access')
    config.add_route('api_repositories',
                     '/v1/repositories/{namespace}/{image}/')
    config.add_route('api_repositories_auth',
                     '/v1/repositories/{namespace}/{image}/auth')
    config.add_route('api_ping', '/v1/_ping')
    config.add_route('api2_ping', '/v2/_ping')
    config.add_route('api2_token', '/v2/token/')
    config.add_route('api2_other', '/v2/*api')
    config.add_route('api_other', '/v1/*api')
    # GA4GH API
    config.add_route('ga4gh_tools', '/api/ga4gh/v1/tools')
    config.add_route('ga4gh_tools_id', '/api/ga4gh/v1/tools/{id}')
    config.add_route('ga4gh_tools_id_versions',
                     '/api/ga4gh/v1/tools/{id}/versions')
    config.add_route('ga4gh_tools_id_version',
                     '/api/ga4gh/v1/tools/{id}/versions/{versionid}')
    config.add_route(
        'ga4gh_tools_id_version_descriptor',
        '/api/ga4gh/v1/tools/{id}/versions/{versionid}/{type}/descriptor')
    config.add_route(
        'ga4gh_tools_id_version_descriptor_file_relative_path',
        '/api/ga4gh/v1/tools/{id}/versions/{versionid}/{type}/descriptor/{relativepath}'
    )
    config.add_route(
        'ga4gh_tools_id_version_dockerfile',
        '/api/ga4gh/v1/tools/{id}/versions/{versionid}/dockerfile')
    config.add_route('ga4gh_metadata', '/api/ga4gh/v1/metadata')
    config.add_route('ga4gh_tool_classes', '/api/ga4gh/v1/tool-classes')

    # Deprecated
    config.add_route('ga4gh_tools_query', '/api/ga4gh/v1/tools/query')
    config.add_route('ga4gh_tool_descriptor',
                     '/api/ga4gh/v1/tools/{id}/descriptor')
    config.add_route('ga4gh_tool_dockerfile',
                     '/api/ga4gh/v1/tools/{id}/dockerfile')
    config.scan()

    json_renderer = JSON()

    def pymongo_adapter(obj, request):
        return json_util.default(obj)

    json_renderer.add_adapter(ObjectId, pymongo_adapter)
    json_renderer.add_adapter(datetime.datetime, pymongo_adapter)

    config.add_renderer('json', json_renderer)
    return config.make_wsgi_app()