Skip to content
Snippets Groups Projects
Commit 182af5b8 authored by Shane Hutchins's avatar Shane Hutchins
Browse files

Merge branch 'eval_compile_bugfix' into 'master'

bugfix for eval and compile api based upon spec-based API tests

See merge request !383
parents 1da0ff5e 89e1c66f
No related branches found
No related tags found
2 merge requests!387Httpfix,!383bugfix for eval and compile api based upon spec-based API tests
Pipeline #193717 failed
......@@ -225,6 +225,7 @@ aws_local: CLOUD_PROVIDER := aws
aws_local: ENABLE_DEV_DIAGNOSTICS := 1
aws_local: ENABLE_ADMIN_UI := 1
aws_local: LOG_LEVEL := DEBUG
aws_local: ENTITLEMENTS_BASE_URL := ${BASE_URL}
aws_local: echoenv
uvicorn main:app --port $(PORT) --reload
......
......@@ -13,6 +13,9 @@ import _buildinfo as b
import opa
import correlation
from starlette.status import (
HTTP_422_UNPROCESSABLE_ENTITY,
)
_logger = logging.getLogger(__name__)
logger = correlation.DefaultExtrasAdapter(_logger, {"correlation_id": "None"})
......@@ -44,9 +47,15 @@ async def compile_partially_evaluate_a_query(file: UploadFile,
"""
logger = correlation.DefaultExtrasAdapter(_logger, {"correlation_id": context["correlation_id"]})
contents = await file.read()
data = contents.decode('utf-8')
try:
data = contents.decode('utf-8')
except UnicodeDecodeError as err:
raise HTTPException(status_code=HTTP_422_UNPROCESSABLE_ENTITY, detail=f"decode error {err}")
opa_response = opa.compile(query=data, metrics=metrics, instrument=instrument)
logger.info(f"OPA compile return {opa_response.json}")
if opa_response.ok:
return opa_response.json
else:
......
......@@ -96,10 +96,17 @@ async def evaluate_policy(policy_id: str,
policy_id = 'osdu/partition/' + auth_data.data_partition_id + '/' + policy_id
contents = await file.read()
posted_data = json.loads(contents.decode('utf-8'))
if not 'input' in posted_data:
raise HTTPException(status_code=HTTP_422_UNPROCESSABLE_ENTITY, detail=f"Input not found in file data")
try:
posted_data = json.loads(contents.decode('utf-8'))
if not 'input' in posted_data:
raise HTTPException(status_code=HTTP_422_UNPROCESSABLE_ENTITY, detail=f"Input not found in file data")
except json.decoder.JSONDecodeError as err:
raise HTTPException(status_code=HTTP_422_UNPROCESSABLE_ENTITY, detail=f"JSON error {err}")
except UnicodeDecodeError as err:
raise HTTPException(status_code=HTTP_422_UNPROCESSABLE_ENTITY, detail=f"JSON error {err}")
except TypeError as err:
raise HTTPException(status_code=HTTP_422_UNPROCESSABLE_ENTITY, detail=f"Input error {err}")
if include_auth:
# add/update token, xuserid and data partition id to input
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment