diff --git a/routes/routesEspo.py b/routes/routesEspo.py index e1d167e..39c958e 100644 --- a/routes/routesEspo.py +++ b/routes/routesEspo.py @@ -1,17 +1,22 @@ -from fastapi import APIRouter, Request, Depends, HTTPException +from fastapi import APIRouter, Request, Depends from fastapi.responses import JSONResponse from utils.utilsKobo import ( add_submission, clean_kobo_data, get_attachment_dict, - update_submission_status + get_kobo_attachment, + update_submission_status, ) from utils.utilsEspo import espo_request, required_headers_espocrm -import logging +from utils.logger import logger +from clients.espo_api_client import EspoAPI import os +import re +import base64 router = APIRouter() + @router.post("/kobo-to-espocrm") async def kobo_to_espocrm( request: Request, dependencies=Depends(required_headers_espocrm) @@ -214,4 +219,3 @@ async def kobo_to_espocrm( logger.info("Success", extra=extra_logs) update_submission_status(submission, "success") return JSONResponse(status_code=200, content=target_response) - diff --git a/utils/utilsKobo.py b/utils/utilsKobo.py index e86d1cf..c03e339 100644 --- a/utils/utilsKobo.py +++ b/utils/utilsKobo.py @@ -3,15 +3,23 @@ from fastapi import HTTPException, Header from azure.cosmos.exceptions import CosmosResourceExistsError from utils.cosmos import cosmos_container_client +import sys + def required_headers_kobo(kobotoken: str = Header(), koboasset: str = Header()): return kobotoken, koboasset + def required_headers_121_kobo( - url121: str = Header(), username121: str = Header(), password121: str = Header(), kobotoken: str = Header(), koboasset: str = Header() + url121: str = Header(), + username121: str = Header(), + password121: str = Header(), + kobotoken: str = Header(), + koboasset: str = Header(), ): return url121, username121, password121, kobotoken, koboasset + def add_submission(kobo_data): """Add submission to CosmosDB. If submission already exists and status is pending, raise HTTPException.""" submission = { @@ -94,4 +102,3 @@ def clean_kobo_data(kobo_data): new_key = key.split("/")[-1] kobo_data_clean[new_key] = kobo_data_clean.pop(key) return kobo_data_clean -