Change config model
This commit is contained in:
@@ -20,10 +20,9 @@ from .reqs_graphql import get_catalog, get_object
|
||||
import xml.etree.ElementTree as ET
|
||||
from .reqs.request_xml_service import RequestXmlService
|
||||
import zipfile
|
||||
from .config import Config
|
||||
from .config import config
|
||||
from .zip import Zip
|
||||
import boto3
|
||||
import request_itv.db as db
|
||||
from sqlalchemy.orm import Session
|
||||
from fastapi import FastAPI, Response, Form, UploadFile, File, Request
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
@@ -45,9 +44,9 @@ logger = logging.getLogger('xmlrpcserver')
|
||||
|
||||
|
||||
def s3_connection():
|
||||
return boto3.client('s3', endpoint_url=Config.s3_endpoint,
|
||||
aws_access_key_id=Config.s3_key_id,
|
||||
aws_secret_access_key=Config.s3_access_key)
|
||||
return boto3.client('s3', endpoint_url=config.default.REQUEST_ITV.s3.endpoint,
|
||||
aws_access_key_id=config.default.REQUEST_ITV.s3.key_id,
|
||||
aws_secret_access_key=config.default.REQUEST_ITV.s3.access_key)
|
||||
|
||||
|
||||
def download_file(key: str, bucket: str, filename: str):
|
||||
@@ -92,22 +91,22 @@ def send_response(params, files, url):
|
||||
files_s3 = []
|
||||
for file in files:
|
||||
fn = uuid4().hex
|
||||
upload_file(file['url'], fn, Config.s3_bucket_itv)
|
||||
file['url'] = {'name': fn, 'bucket': Config.s3_bucket_itv}
|
||||
upload_file(file['url'], fn, config.default.REQUEST_ITV.s3.bucket_itv)
|
||||
file['url'] = {'name': fn, 'bucket': config.default.REQUEST_ITV.s3.bucket_itv}
|
||||
files_s3.append(file)
|
||||
data = {
|
||||
'params': params,
|
||||
'files': files_s3,
|
||||
'url': url,
|
||||
}
|
||||
channel_send.basic_publish(exchange=Config.rabbit_out_exchange, body=json.dumps(data), routing_key='')
|
||||
channel_send.basic_publish(exchange=config.default.REQUEST_ITV.amqp.out_exchange, body=json.dumps(data), routing_key='')
|
||||
|
||||
|
||||
def pika_task():
|
||||
global connection
|
||||
global channel_receive
|
||||
channel_receive = connection.channel()
|
||||
channel_receive.basic_consume(queue=Config.rabbit_incoming_queue, on_message_callback=pika_callback)
|
||||
channel_receive.basic_consume(queue=config.default.REQUEST_ITV.amqp.incoming_queue, on_message_callback=pika_callback)
|
||||
channel_receive.start_consuming()
|
||||
|
||||
|
||||
@@ -170,7 +169,7 @@ def get_objects(params, files, url):
|
||||
for file in obj['properties'].get('c1000', []):
|
||||
if not main_filename:
|
||||
main_filename = file['fileName']
|
||||
res = requests.get(Config.gql_download, params={'item_id': file["key"]})
|
||||
res = requests.get(config.default.REQUEST_ITV.gql.download, params={'item_id': file["key"]})
|
||||
zipf.writestr(f'{main_filename}/{file["fileName"]}', res.content)
|
||||
zipf.close()
|
||||
response_files = [{'name': filename, 'url': filepath, 'size': os.path.getsize(filepath)}]
|
||||
@@ -232,9 +231,11 @@ def put_object(params, files, url):
|
||||
req = ET.fromstring(params['query_data'])
|
||||
obj = req.find('chart')
|
||||
class_id = obj.get('Class')
|
||||
con = OOConnectionParams(Config.oodb_schema, Config.oodb_host, Config.oodb_port, Config.oodb_dbname,
|
||||
Config.oodb_username, Config.oodb_passwd, Config.oodb_schema)
|
||||
ws = OODBWorkspace.ws(Config.oodb_schema)
|
||||
con = OOConnectionParams(config.default.REQUEST_ITV.oodb.schema, config.default.REQUEST_ITV.oodb.host,
|
||||
config.default.REQUEST_ITV.oodb.port, config.default.REQUEST_ITV.oodb.dbname,
|
||||
config.default.REQUEST_ITV.oodb.username, config.default.REQUEST_ITV.oodb.passwd,
|
||||
config.default.REQUEST_ITV.oodb.schema)
|
||||
ws = OODBWorkspace.ws(config.default.REQUEST_ITV.oodb.schema)
|
||||
if not ws.isInit():
|
||||
res = ws.init(con)
|
||||
logger.warning(res)
|
||||
@@ -262,9 +263,9 @@ def put_object(params, files, url):
|
||||
key = uuid4().hex
|
||||
fileVal.fileName = variantToString(item.relative_to(dir.name))
|
||||
fileVal.key = variantToString(key)
|
||||
fileVal.bucket = variantToString(Config.s3_bucket)
|
||||
fileVal.bucket = variantToString(config.default.REQUEST_ITV.s3.bucket)
|
||||
res &= feature.addAttribute('c1000', variantFromFileValue(fileVal))
|
||||
upload_file(str(item), key, Config.s3_bucket)
|
||||
upload_file(str(item), key, config.default.REQUEST_ITV.s3.bucket)
|
||||
|
||||
ws.transaction()
|
||||
res = ws.save()
|
||||
@@ -288,7 +289,7 @@ def main():
|
||||
global server
|
||||
global channel_send
|
||||
|
||||
connection = pika.BlockingConnection(pika.URLParameters(Config.rabbit_conn))
|
||||
connection = pika.BlockingConnection(pika.URLParameters(config.default.REQUEST_ITV.amqp.conn))
|
||||
channel_send = connection.channel()
|
||||
|
||||
logger.setLevel(logging.INFO)
|
||||
|
||||
Reference in New Issue
Block a user