2021-02-18 06:04:30 +01:00
|
|
|
# standard imports
|
|
|
|
import os
|
|
|
|
import logging
|
|
|
|
import argparse
|
|
|
|
import base64
|
|
|
|
|
2021-05-18 19:13:57 +02:00
|
|
|
# external imports
|
2021-02-18 06:04:30 +01:00
|
|
|
import confini
|
|
|
|
|
|
|
|
# local imports
|
2021-10-20 17:02:36 +02:00
|
|
|
import cic_cache.cli
|
2021-02-18 06:04:30 +01:00
|
|
|
from cic_cache.db import dsn_from_config
|
|
|
|
from cic_cache.db.models.base import SessionBase
|
2021-05-18 19:13:57 +02:00
|
|
|
from cic_cache.runnable.daemons.query import (
|
2021-11-04 07:59:38 +01:00
|
|
|
process_default_limit,
|
2021-05-18 19:13:57 +02:00
|
|
|
process_transactions_account_bloom,
|
2021-10-08 11:19:21 +02:00
|
|
|
process_transactions_account_data,
|
2021-05-18 19:13:57 +02:00
|
|
|
process_transactions_all_bloom,
|
|
|
|
process_transactions_all_data,
|
|
|
|
)
|
2021-10-08 11:19:21 +02:00
|
|
|
import cic_cache.cli
|
2021-02-18 06:04:30 +01:00
|
|
|
|
|
|
|
logging.basicConfig(level=logging.WARNING)
|
|
|
|
logg = logging.getLogger()
|
|
|
|
|
|
|
|
|
2021-10-08 11:19:21 +02:00
|
|
|
arg_flags = cic_cache.cli.argflag_std_read
|
2021-10-25 20:20:40 +02:00
|
|
|
local_arg_flags = cic_cache.cli.argflag_local_sync | cic_cache.cli.argflag_local_task
|
2021-10-08 11:19:21 +02:00
|
|
|
argparser = cic_cache.cli.ArgumentParser(arg_flags)
|
|
|
|
argparser.process_local_flags(local_arg_flags)
|
2021-02-18 06:04:30 +01:00
|
|
|
args = argparser.parse_args()
|
|
|
|
|
2021-10-08 11:19:21 +02:00
|
|
|
# process config
|
|
|
|
config = cic_cache.cli.Config.from_args(args, arg_flags, local_arg_flags)
|
2021-02-18 06:04:30 +01:00
|
|
|
|
2021-10-20 17:02:36 +02:00
|
|
|
# connect to database
|
2021-02-18 06:04:30 +01:00
|
|
|
dsn = dsn_from_config(config)
|
|
|
|
SessionBase.connect(dsn, config.true('DATABASE_DEBUG'))
|
|
|
|
|
|
|
|
|
|
|
|
# uwsgi application
|
|
|
|
def application(env, start_response):
|
|
|
|
|
|
|
|
headers = []
|
|
|
|
content = b''
|
|
|
|
|
|
|
|
session = SessionBase.create_session()
|
|
|
|
for handler in [
|
2021-11-08 09:58:22 +01:00
|
|
|
process_transactions_account_data,
|
|
|
|
process_transactions_account_bloom,
|
2021-05-18 19:13:57 +02:00
|
|
|
process_transactions_all_data,
|
2021-02-18 06:04:30 +01:00
|
|
|
process_transactions_all_bloom,
|
2021-11-04 07:59:38 +01:00
|
|
|
process_default_limit,
|
2021-02-18 06:04:30 +01:00
|
|
|
]:
|
2021-05-18 19:13:57 +02:00
|
|
|
r = None
|
|
|
|
try:
|
|
|
|
r = handler(session, env)
|
|
|
|
except ValueError as e:
|
|
|
|
start_response('400 {}'.format(str(e)))
|
|
|
|
return []
|
2021-02-18 06:04:30 +01:00
|
|
|
if r != None:
|
|
|
|
(mime_type, content) = r
|
|
|
|
break
|
|
|
|
session.close()
|
|
|
|
|
|
|
|
headers.append(('Content-Length', str(len(content))),)
|
|
|
|
headers.append(('Access-Control-Allow-Origin', '*',));
|
|
|
|
|
|
|
|
if len(content) == 0:
|
|
|
|
headers.append(('Content-Type', 'text/plain, charset=UTF-8',))
|
|
|
|
start_response('404 Looked everywhere, sorry', headers)
|
|
|
|
else:
|
|
|
|
headers.append(('Content-Type', mime_type,))
|
|
|
|
start_response('200 OK', headers)
|
|
|
|
|
|
|
|
return [content]
|