Skip to content

Commit

Permalink
handle missing license
Browse files Browse the repository at this point in the history
Signed-off-by: Steve Taylor <steve@deployhub.com>
  • Loading branch information
sbtaylor15 committed Sep 2, 2024
1 parent 8034495 commit fcafa3f
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1395,22 +1395,6 @@ async def spdx(request: Request, response: Response, compid: int):

cookies = request.cookies

try:
result = requests.get(validateuser_url + "/msapi/validateuser", cookies=request.cookies, timeout=5)
if result is None:
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Authorization Failed")

if result.status_code != status.HTTP_200_OK:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Authorization Failed status_code=" + str(result.status_code),
)
except Exception as err:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Authorization Failed:" + str(err),
) from None

spdx_json = await request.json()
components_data = []
components = spdx_json.get("packages", [])
Expand All @@ -1436,6 +1420,10 @@ async def spdx(request: Request, response: Response, compid: int):
license_url = ""
license_name = ""
current_license = component.get("licenseDeclared")

if current_license is None:
current_license = "NOASSERTION"

if current_license != "NOASSERTION":
license_name = current_license
license_url = "https://spdx.org/licenses/" + license_name + ".html"
Expand Down

0 comments on commit fcafa3f

Please sign in to comment.