Skip to content

Commit 92ab0d6

Browse files
d-linkoDavidEdellDavid LinkoBrianSipos
authored
fixed handling bad inputs for ADMs routes (#256)
* Added workflow to test publishing of built containers to ghcr.io * Second take (GPT-assisted refinements) * Back to a simpler approach * Simplest form * Fix capitalization * Adjusting registry name * Removed bad env var * Missing recursive clone flag * Add testenv build, added test echo as precursor to fixing push path. * Fix healthcheck for ion-manager and ion-agent * updated to lastest tool and new SQL schema * Fixed GHCR container naming. * Fixed default .env path * Updating quickstart to pull prebuilt containers by default * Pin puppet-lint to compatible version * fixed handling bad inputs for ADMs routes * Updated README. * Removing test branch reference from workflow. * fixed typo know to known --------- Co-authored-by: David Edell <david.edell@jhuapl.edu> Co-authored-by: David Linko <david.linko@jhuapl.edu> Co-authored-by: Brian Sipos <brian.sipos@jhuapl.edu>
1 parent 5ba1186 commit 92ab0d6

File tree

1 file changed

+14
-7
lines changed
  • anms-core/anms/routes/adms

1 file changed

+14
-7
lines changed

anms-core/anms/routes/adms/adm.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#
2424

2525
# External modules
26-
from fastapi import APIRouter, status, Request
26+
from fastapi import APIRouter, status, Request, HTTPException
2727
from fastapi.responses import JSONResponse
2828
from fastapi import UploadFile
2929
from pydantic import BaseModel
@@ -88,9 +88,16 @@ async def getall():
8888
async def get_adm(enumeration: int,namespace: str):
8989
async with get_async_session() as session:
9090
result_dm = await DataModel.get(enumeration, namespace, session)
91-
result, _ = await AdmData.get(result_dm.data_model_id, session)
92-
if result:
93-
return result.data
91+
if result_dm:
92+
result, _ = await AdmData.get(result_dm.data_model_id, session)
93+
if result:
94+
return result.data
95+
else:
96+
logger.error(f"ADM ENUM:{enumeration} in NAMESPACE {namespace} not a known ADM")
97+
raise HTTPException(status_code = status.HTTP_400_BAD_REQUEST, detail = f"ADM ENUM:{enumeration} in NAMESPACE {namespace} not a known ADM")
98+
else:
99+
logger.error(f"ADM ENUM:{enumeration} in NAMESPACE {namespace} not a known DataModel")
100+
raise HTTPException(status_code = status.HTTP_400_BAD_REQUEST, detail = f"ADM ENUM:{enumeration} in NAMESPACE {namespace} not a known DataModel")
94101

95102

96103

@@ -112,15 +119,15 @@ async def remove_adm(enumeration: int, namespace:str):
112119
async with get_async_session() as session:
113120
nm_row = await DataModel.get(enumeration, namespace, session)
114121
if nm_row:
115-
logger.info(f"Removing {nm_row.data_model_name} ADM")
122+
logger.info(f"Removing {nm_row.name} ADM")
116123
stmt_2 = delete(AdmData).where(AdmData.enumeration == nm_row.data_model_id)
117124
await session.execute(stmt_1)
118125
await session.execute(stmt_2)
119126
await session.commit()
120127
return status.HTTP_200_OK
121128
else:
122-
logger.debug(f"ADM ENUM:{enumeration} not a know ADM")
123-
return status.HTTP_400_BAD_REQUEST
129+
logger.debug(f"ADM ENUM:{enumeration} in NAMESPACE {namespace} not a known ADM")
130+
raise HTTPException(status_code = status.HTTP_400_BAD_REQUEST, detail = f"ADM ENUM:{enumeration} in NAMESPACE {namespace} not a known ADM")
124131

125132

126133

0 commit comments

Comments
 (0)