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()
def configure_routes(config): cache_max_age = 86400 * 365 config.add_static_view('static', 'static', cache_max_age=cache_max_age) config.add_static_view('css', 'static/css', cache_max_age=cache_max_age) config.add_static_view('img', 'static/img', cache_max_age=cache_max_age) config.add_static_view('js', 'static/js', cache_max_age=cache_max_age) config.add_route('home', '/')
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()
def includeme(config): """ Configure the app """ settings = config.get_settings() init_celery(settings) config.add_route('tasks_active', '/tasks/active') config.add_route('tasks_registered', '/tasks/registered') config.add_route('tasks_reserved', '/tasks/reserved') config.add_route('tasks_scheduled', '/tasks/scheduled') config.scan(__package__ + '.views')
def include_routes(config): config.add_route('login', '/login') config.add_route('logout', '/logout') config.add_route('forbidden', '/forbidden') config.add_route('home', 'cot/chart') config.include(commodity_routes, route_prefix='commodities') config.include(financial_routes, route_prefix='financials')
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()
def includeme(config): config.include('pyramid_jinja2') config.add_jinja2_search_path("dashboard:templates") config.commit() # commit to allow access to jinja environment # request methods config.add_request_method(get_request_user, 'user', reify=True) config.get_jinja2_environment().filters['format_date'] = format_date config.get_jinja2_environment().filters['format_time'] = format_time config.get_jinja2_environment().filters['format_decimal'] = format_decimal config.get_jinja2_environment().filters['format_percent'] = format_percent config.get_jinja2_environment().filters['format_number'] = format_number config.get_jinja2_environment().filters['datetime'] = ( date_string_to_datetime) config.add_static_view('static', 'dashboard:static', cache_max_age=3600) config.add_route('default', '/') config.add_route('submissions', '/submissions/*traverse') config.scan()
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()
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): 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()
def includeme(config): config.include('dashboard') config.commit() config.get_jinja2_environment().filters['friendly_group_name'] =\ friendly_group_name # hook up our submission handlers hook_submission_handlers() # request methods config.add_request_method(get_request_user, 'user', reify=True) config.add_request_method(is_current_path) # pyramid_jinja2 is already included by Dashboard config.add_jinja2_search_path("composting:templates") config.add_renderer('xlsx', 'composting.views.renderers.TablibXLSXRenderer') config.add_static_view('static', 'composting:static', cache_max_age=3600) config.add_static_view('docs', '../docs/_build/html', cache_max_age=3600) config.add_route('default', '/') config.add_route('auth', '/auth/{action}') config.add_route('oauth', '/oauth/{action}') config.add_route('municipalities', '/municipalities/*traverse', factory=MunicipalityFactory) config.add_route('submissions', '/submissions/*traverse', factory=SubmissionFactory) config.add_route('skips', '/skips/*traverse', factory=SkipFactory) config.add_route('users', '/users/*traverse', factory=UserFactory) config.scan()
def financial_routes(config): config.add_route('fin_chart', '/chart') config.add_route('fin_chart_data', '/chart/{code}') config.add_route('fin_prices', '/prices')
def commodity_routes(config): config.add_route('comm_chart', '/chart') config.add_route('comm_chart_data', '/chart/{code}') config.add_route('comm_prices', '/prices')
def includeme(config): config.include('pyramid_jinja2') config.commit() config.add_jinja2_search_path("whoahqa:templates") config.get_jinja2_environment().filters['format_date'] = \ format_date_for_locale config.get_jinja2_environment().filters['format_location_name'] = \ format_location_name config.get_jinja2_environment().filters['round_or_none'] = round_or_none config.add_static_view('static', 'static', cache_max_age=3600) config.add_route('default', '/') config.add_route('logout', '/logout/') config.add_route('push', '/push/{action}') config.add_route('locale', '/locale/') config.add_route('admin', '/admin/*traverse', factory=UserFactory) config.add_route('auth', '/auth/{action}') config.add_route('users', '/users/*traverse', factory=UserFactory) config.add_route('clinics', '/clinics/*traverse', factory=ClinicFactory) config.add_route('submissions', '/submissions/*traverse', factory=SubmissionFactory) config.add_route('periods', '/reporting-periods/*traverse', factory=ReportingPeriodFactory) config.add_route('municipalities', '/municipalities/*traverse', factory=LocationFactory) config.add_route('states', '/states/*traverse', factory=LocationFactory) config.add_route('locations', '/locations/*traverse', factory=LocationFactory) config.scan()
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()