-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'a258001251842882_refactoring'
- Loading branch information
Showing
54 changed files
with
600 additions
and
19,674 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,124 +1 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Main entry point | ||
""" | ||
if 'test' not in __import__('sys').argv[0]: | ||
import gevent.monkey | ||
gevent.monkey.patch_all() | ||
import os | ||
from libnacl.sign import Signer, Verifier | ||
from libnacl.public import SecretKey, PublicKey | ||
from logging import getLogger | ||
from openprocurement.api.auth import AuthenticationPolicy, authenticated_role, check_accreditation | ||
from openprocurement.api.models import Tender | ||
from openprocurement.api.database import set_api_security | ||
from openprocurement.api.utils import ( | ||
forbidden, | ||
add_logging_context, | ||
set_logging_context, | ||
extract_tender, | ||
request_params, | ||
isTender, | ||
set_renderer, | ||
beforerender, | ||
register_tender_procurementMethodType, | ||
tender_from_data, | ||
route_prefix, | ||
ROUTE_PREFIX | ||
) | ||
from pkg_resources import iter_entry_points | ||
from pyramid.authorization import ACLAuthorizationPolicy as AuthorizationPolicy | ||
from pyramid.config import Configurator | ||
from pyramid.events import NewRequest, BeforeRender, ContextFound | ||
from pyramid.renderers import JSON, JSONP | ||
from pyramid.settings import asbool | ||
|
||
LOGGER = getLogger("{}.init".format(__name__)) | ||
|
||
|
||
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(extract_tender, 'tender', reify=True) | ||
config.add_request_method(check_accreditation) | ||
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_subscriber(beforerender, BeforeRender) | ||
config.scan("openprocurement.api.views.spore") | ||
config.scan("openprocurement.api.views.health") | ||
|
||
# tender procurementMethodType plugins support | ||
config.add_route_predicate('procurementMethodType', isTender) | ||
config.registry.tender_procurementMethodTypes = {} | ||
config.add_request_method(tender_from_data) | ||
config.add_directive('add_tender_procurementMethodType', register_tender_procurementMethodType) | ||
|
||
# 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 | ||
|
||
# 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 includeme(config): | ||
config.add_tender_procurementMethodType(Tender) | ||
config.scan("openprocurement.api.views") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# -*- coding: utf-8 -*- | ||
class ContentConfigurator(object): | ||
""" Base OP Content Configuration adapter """ | ||
|
||
name = "Base Openprocurement Content Configurator" | ||
|
||
def __init__(self, context, request): | ||
self.context = context | ||
self.request = request | ||
|
||
def __repr__(self): | ||
return "<Configuration adapter for %s>" % type(self.context) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Main entry point | ||
""" | ||
if 'test' not in __import__('sys').argv[0]: | ||
import gevent.monkey | ||
gevent.monkey.patch_all() | ||
import os | ||
from couchdb import Server as CouchdbServer, Session | ||
from couchdb.http import Unauthorized, extract_credentials | ||
from libnacl.sign import Signer, Verifier | ||
from libnacl.public import SecretKey, PublicKey | ||
from logging import getLogger | ||
from openprocurement.api.auth import AuthenticationPolicy, authenticated_role, check_accreditation | ||
from openprocurement.api.database import set_api_security | ||
from openprocurement.api.utils import forbidden, request_params | ||
from openprocurement.api.constants import ROUTE_PREFIX | ||
from pkg_resources import iter_entry_points | ||
from pyramid.authorization import ACLAuthorizationPolicy as AuthorizationPolicy | ||
from pyramid.config import Configurator | ||
from pyramid.events import NewRequest, BeforeRender, ContextFound | ||
from pyramid.renderers import JSON, JSONP | ||
from pyramid.settings import asbool | ||
|
||
LOGGER = getLogger("{}.init".format(__name__)) | ||
|
||
|
||
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, | ||
) | ||
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('prettyjson', JSON(indent=4)) | ||
config.add_renderer('jsonp', JSONP(param_name='opt_jsonp')) | ||
config.add_renderer('prettyjsonp', JSONP(indent=4, param_name='opt_jsonp')) | ||
|
||
# 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 | ||
|
||
# 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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# -*- coding: utf-8 -*- | ||
import os | ||
import re | ||
from pytz import timezone | ||
from datetime import datetime | ||
from pkg_resources import get_distribution | ||
from logging import getLogger | ||
from requests import Session | ||
|
||
PKG = get_distribution(__package__) | ||
LOGGER = getLogger(PKG.project_name) | ||
VERSION = '{}.{}'.format(int(PKG.parsed_version[0]), int(PKG.parsed_version[1]) if PKG.parsed_version[1].isdigit() else 0) | ||
ROUTE_PREFIX = '/api/{}'.format(VERSION) | ||
SESSION = Session() | ||
SCHEMA_VERSION = 24 | ||
SCHEMA_DOC = 'openprocurement_schema' | ||
|
||
TZ = timezone(os.environ['TZ'] if 'TZ' in os.environ else 'Europe/Kiev') | ||
SANDBOX_MODE = os.environ.get('SANDBOX_MODE', False) | ||
|
||
DOCUMENT_BLACKLISTED_FIELDS = ('title', 'format', 'url', 'dateModified', 'hash') | ||
DOCUMENT_WHITELISTED_FIELDS = ('id', 'datePublished', 'author', '__parent__') | ||
|
||
def read_json(name): | ||
import os.path | ||
from json import loads | ||
curr_dir = os.path.dirname(os.path.realpath(__file__)) | ||
file_path = os.path.join(curr_dir, name) | ||
with open(file_path) as lang_file: | ||
data = lang_file.read() | ||
return loads(data) | ||
|
||
CPV_CODES = read_json('cpv.json') | ||
CPV_CODES.append('99999999-9') | ||
DK_CODES = read_json('dk021.json') | ||
#DKPP_CODES = read_json('dkpp.json') | ||
ORA_CODES = [i['code'] for i in read_json('OrganisationRegistrationAgency.json')['data']] | ||
WORKING_DAYS = read_json('working_days.json') | ||
|
||
ADDITIONAL_CLASSIFICATIONS_SCHEMES = [u'ДКПП', u'NONE', u'ДК003', u'ДК015', u'ДК018'] | ||
ADDITIONAL_CLASSIFICATIONS_SCHEMES_2017 = [u'ДК003', u'ДК015', u'ДК018', u'specialNorms'] | ||
COORDINATES_REG_EXP = re.compile(r'-?\d{1,3}\.\d+|-?\d{1,3}') | ||
|
||
CPV_ITEMS_CLASS_FROM = datetime(2017, 1, 1, tzinfo=TZ) | ||
CPV_BLOCK_FROM = datetime(2017, 6, 2, tzinfo=TZ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.