def main(global_config, **settings): config = Configurator( autocommit=True, settings=settings, authentication_policy=AuthenticationPolicy(settings['auth.file'], __name__), authorization_policy=AuthorizationPolicy(), route_prefix=route_prefix(settings), ) config.include('pyramid_exclog') config.include("cornice") config.add_forbidden_view(forbidden) config.add_request_method(request_params, 'params', reify=True) config.add_request_method(authenticated_role, reify=True) config.add_request_method(check_accreditation) config.add_renderer('json', JSON(serializer=simplejson.dumps)) config.add_renderer('prettyjson', JSON(indent=4, serializer=simplejson.dumps)) config.add_renderer( 'jsonp', JSONP(param_name='opt_jsonp', serializer=simplejson.dumps)) config.add_renderer( 'prettyjsonp', JSONP(indent=4, param_name='opt_jsonp', serializer=simplejson.dumps)) # search for plugins plugins = settings.get('plugins') and settings['plugins'].split(',') for entry_point in iter_entry_points('openprocurement.api.plugins'): if not plugins or entry_point.name in plugins: plugin = entry_point.load() plugin(config) # CouchDB connection aserver, server, db = set_api_security(settings) config.registry.couchdb_server = server if aserver: config.registry.admin_couchdb_server = aserver config.registry.db = db # readjust couchdb json decoder couchdb_json_decode() # Document Service key config.registry.docservice_url = settings.get('docservice_url') config.registry.docservice_username = settings.get('docservice_username') config.registry.docservice_password = settings.get('docservice_password') config.registry.docservice_upload_url = settings.get( 'docservice_upload_url') config.registry.docservice_key = dockey = Signer( settings.get('dockey', '').decode('hex')) config.registry.keyring = keyring = {} dockeys = settings.get( 'dockeys') if 'dockeys' in settings else dockey.hex_vk() for key in dockeys.split('\0'): keyring[key[:8]] = Verifier(key) # Archive keys arch_pubkey = settings.get('arch_pubkey', None) config.registry.arch_pubkey = PublicKey( arch_pubkey.decode('hex') if arch_pubkey else SecretKey().pk) # migrate data if not os.environ.get('MIGRATION_SKIP'): for entry_point in iter_entry_points('openprocurement.api.migrations'): plugin = entry_point.load() plugin(config.registry) config.registry.server_id = settings.get('id', '') # search subscribers subscribers_keys = [k for k in settings if k.startswith('subscribers.')] for k in subscribers_keys: subscribers = settings[k].split(',') for subscriber in subscribers: for entry_point in iter_entry_points( 'openprocurement.{}'.format(k), subscriber): if entry_point: plugin = entry_point.load() plugin(config) config.registry.health_threshold = float( settings.get('health_threshold', 512)) config.registry.health_threshold_func = settings.get( 'health_threshold_func', 'all') config.registry.update_after = asbool(settings.get('update_after', True)) return config.make_wsgi_app()
def main(global_config, **settings): config = Configurator( autocommit=True, settings=settings, authentication_policy=AuthenticationPolicy(settings['auth.file'], __name__), authorization_policy=AuthorizationPolicy(), route_prefix=route_prefix(settings), ) config.include('pyramid_exclog') config.include("cornice") config.add_forbidden_view(forbidden) config.add_request_method(request_params, 'params', reify=True) config.add_request_method(authenticated_role, reify=True) config.add_request_method(check_accreditation) config.add_renderer('json', JSON(serializer=simplejson.dumps)) config.add_renderer('prettyjson', JSON(indent=4, serializer=simplejson.dumps)) config.add_renderer('jsonp', JSONP(param_name='opt_jsonp', serializer=simplejson.dumps)) config.add_renderer('prettyjsonp', JSONP(indent=4, param_name='opt_jsonp', serializer=simplejson.dumps)) # search for plugins plugins = settings.get('plugins') and settings['plugins'].split(',') for entry_point in iter_entry_points('openprocurement.api.plugins'): if not plugins or entry_point.name in plugins: plugin = entry_point.load() plugin(config) # CouchDB connection aserver, server, db = set_api_security(settings) config.registry.couchdb_server = server if aserver: config.registry.admin_couchdb_server = aserver config.registry.db = db # readjust couchdb json decoder couchdb_json_decode() # Document Service key config.registry.docservice_url = settings.get('docservice_url') config.registry.docservice_username = settings.get('docservice_username') config.registry.docservice_password = settings.get('docservice_password') config.registry.docservice_upload_url = settings.get('docservice_upload_url') config.registry.docservice_key = dockey = Signer(settings.get('dockey', '').decode('hex')) config.registry.keyring = keyring = {} dockeys = settings.get('dockeys') if 'dockeys' in settings else dockey.hex_vk() for key in dockeys.split('\0'): keyring[key[:8]] = Verifier(key) # Archive keys arch_pubkey = settings.get('arch_pubkey', None) config.registry.arch_pubkey = PublicKey(arch_pubkey.decode('hex') if arch_pubkey else SecretKey().pk) # migrate data if not os.environ.get('MIGRATION_SKIP'): for entry_point in iter_entry_points('openprocurement.api.migrations'): plugin = entry_point.load() plugin(config.registry) config.registry.server_id = settings.get('id', '') # search subscribers subscribers_keys = [k for k in settings if k.startswith('subscribers.')] for k in subscribers_keys: subscribers = settings[k].split(',') for subscriber in subscribers: for entry_point in iter_entry_points('openprocurement.{}'.format(k), subscriber): if entry_point: plugin = entry_point.load() plugin(config) config.registry.health_threshold = float(settings.get('health_threshold', 512)) config.registry.health_threshold_func = settings.get('health_threshold_func', 'all') config.registry.update_after = asbool(settings.get('update_after', True)) return config.make_wsgi_app()
def main(global_config, **settings): dsn = settings.get("sentry.dsn", None) if dsn: LOGGER.info("Init sentry sdk for {}".format(dsn)) sentry_sdk.init( dsn=dsn, integrations=[ LoggingIntegration(level=None, event_level=None), PyramidIntegration() ], send_default_pii=True, request_bodies="always", environment=settings.get("sentry.environment", None), debug=settings.get("sentry.debug", False), ) config = Configurator( autocommit=True, settings=settings, authentication_policy=AuthenticationPolicy(settings["auth.file"], __name__), authorization_policy=AuthorizationPolicy(), route_prefix=ROUTE_PREFIX, ) config.include("pyramid_exclog") config.include("cornice") config.add_forbidden_view(forbidden) config.add_view(precondition, context=HTTPPreconditionFailed) config.add_request_method(request_params, "params", reify=True) config.add_request_method(authenticated_role, reify=True) config.add_request_method(check_accreditations) config.add_request_method(get_currency_rates, name="currency_rates", reify=True) config.add_renderer("json", JSON(serializer=simplejson.dumps)) config.add_renderer("prettyjson", JSON(indent=4, serializer=simplejson.dumps)) config.add_renderer( "jsonp", JSONP(param_name="opt_jsonp", serializer=simplejson.dumps)) config.add_renderer( "prettyjsonp", JSONP(indent=4, param_name="opt_jsonp", serializer=simplejson.dumps)) # search for plugins plugins = settings.get("plugins") and [ plugin.strip() for plugin in settings["plugins"].split(",") ] for entry_point in iter_entry_points("openprocurement.api.plugins"): if not plugins or entry_point.name in plugins: plugin = entry_point.load() plugin(config) # CouchDB connection aserver, server, db = set_api_security(settings) config.registry.couchdb_server = server if aserver: config.registry.admin_couchdb_server = aserver config.registry.db = db # CouchDB specific databases connections config.registry.databases = Databases( admin_connection=aserver or server, connection=server, migrations=settings.get("couchdb.migrations_db_name"), frameworks=settings.get("couchdb.frameworks_db_name"), submissions=settings.get("couchdb.submissions_db_name"), qualifications=settings.get("couchdb.qualifications_db_name"), agreements=settings.get("couchdb.agreements_db_name"), transfers=settings.get("couchdb.transfers_db_name"), plans=settings.get("couchdb.plans_db_name"), contracts=settings.get("couchdb.contracts_db_name"), ) # readjust couchdb json decoder couchdb_json_decode() # Document Service key config.registry.docservice_url = settings.get("docservice_url") config.registry.docservice_username = settings.get("docservice_username") config.registry.docservice_password = settings.get("docservice_password") config.registry.docservice_upload_url = settings.get( "docservice_upload_url") signing_key = settings.get('dockey', '') signer = SigningKey( signing_key, encoder=HexEncoder) if signing_key else SigningKey.generate() config.registry.docservice_key = signer verifier = signer.verify_key config.registry.keyring = { verifier.encode(encoder=HexEncoder)[:8].decode(): verifier } dockeys = settings.get('dockeys', '') for key in dockeys.split('\0'): if key: config.registry.keyring[key[:8]] = VerifyKey(key, encoder=HexEncoder) # migrate data if not os.environ.get("MIGRATION_SKIP"): for entry_point in iter_entry_points("openprocurement.api.migrations"): plugin = entry_point.load() plugin(config.registry) config.registry.server_id = settings.get("id", "") # search subscribers subscribers_keys = [k for k in settings if k.startswith("subscribers.")] for k in subscribers_keys: subscribers = settings[k].split(",") for subscriber in subscribers: for entry_point in iter_entry_points( "openprocurement.{}".format(k), subscriber): if entry_point: plugin = entry_point.load() plugin(config) config.registry.health_threshold = float( settings.get("health_threshold", 512)) config.registry.health_threshold_func = settings.get( "health_threshold_func", "all") config.registry.update_after = asbool(settings.get("update_after", True)) return config.make_wsgi_app()
def main(global_config, **settings): def strip_sensitive_data(event, hint): return event if settings.has_key("sentry.dsn"): dsn = settings.get("sentry.dsn") LOGGER.info("Init sentry sdk for {}".format(dsn)) sentry_sdk.init( dsn=dsn, integrations=[ LoggingIntegration(level=None, event_level=None), PyramidIntegration() ], send_default_pii=True, request_bodies="always", environment=settings.get("sentry.environment", None), ) config = Configurator( autocommit=True, settings=settings, authentication_policy=AuthenticationPolicy(settings["auth.file"], __name__), authorization_policy=AuthorizationPolicy(), route_prefix=ROUTE_PREFIX, ) config.include("pyramid_exclog") config.include("cornice") config.add_forbidden_view(forbidden) config.add_view(precondition, context=HTTPPreconditionFailed) config.add_request_method(request_params, "params", reify=True) config.add_request_method(authenticated_role, reify=True) config.add_request_method(check_accreditations) config.add_renderer("json", JSON(serializer=simplejson.dumps)) config.add_renderer("prettyjson", JSON(indent=4, serializer=simplejson.dumps)) config.add_renderer( "jsonp", JSONP(param_name="opt_jsonp", serializer=simplejson.dumps)) config.add_renderer( "prettyjsonp", JSONP(indent=4, param_name="opt_jsonp", serializer=simplejson.dumps)) # search for plugins plugins = settings.get("plugins") and settings["plugins"].split(",") for entry_point in iter_entry_points("openprocurement.api.plugins"): if not plugins or entry_point.name in plugins: plugin = entry_point.load() plugin(config) # CouchDB connection aserver, server, db = set_api_security(settings) config.registry.couchdb_server = server if aserver: config.registry.admin_couchdb_server = aserver config.registry.db = db # readjust couchdb json decoder couchdb_json_decode() # Document Service key config.registry.docservice_url = settings.get("docservice_url") config.registry.docservice_username = settings.get("docservice_username") config.registry.docservice_password = settings.get("docservice_password") config.registry.docservice_upload_url = settings.get( "docservice_upload_url") config.registry.docservice_key = dockey = Signer( settings.get("dockey", "").decode("hex")) config.registry.keyring = keyring = {} dockeys = settings.get( "dockeys") if "dockeys" in settings else dockey.hex_vk() for key in dockeys.split("\0"): keyring[key[:8]] = Verifier(key) # Archive keys arch_pubkey = settings.get("arch_pubkey", None) config.registry.arch_pubkey = PublicKey( arch_pubkey.decode("hex") if arch_pubkey else SecretKey().pk) # migrate data if not os.environ.get("MIGRATION_SKIP"): for entry_point in iter_entry_points("openprocurement.api.migrations"): plugin = entry_point.load() plugin(config.registry) config.registry.server_id = settings.get("id", "") # search subscribers subscribers_keys = [k for k in settings if k.startswith("subscribers.")] for k in subscribers_keys: subscribers = settings[k].split(",") for subscriber in subscribers: for entry_point in iter_entry_points( "openprocurement.{}".format(k), subscriber): if entry_point: plugin = entry_point.load() plugin(config) config.registry.health_threshold = float( settings.get("health_threshold", 512)) config.registry.health_threshold_func = settings.get( "health_threshold_func", "all") config.registry.update_after = asbool(settings.get("update_after", True)) return config.make_wsgi_app()