Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/CI_APIUtils.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
uses: ./.github/workflows/DEPLOY_APIUtils.yml
with:
image_name: ${{ needs.build.outputs.image_name }}
revision_tag: "t-${{ needs.setup.outputs.branch_tag }}"
revision_tag: "t-${{ needs.setup.outputs.branch_tag }}-t"
remove: false
secrets: inherit

Expand Down
19 changes: 11 additions & 8 deletions src/ogd/apis/models/APIRequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,17 @@ def __init__(self, url:str, request_type:str | RESTType, params:Optional[Dict[st

if not (url.startswith("http://") or url.startswith("https://")):
url = f"https://{url}"
if isinstance(request_type, RESTType):
self._request_type = request_type
else:
try:
self._request_type = RESTType[request_type]
except KeyError:
current_app.logger.warning(f"Bad request type {request_type}, defaulting to GET")
self._request_type = RESTType.GET
match request_type:
case RESTType():
self._request_type = request_type
case str():
try:
self._request_type = RESTType[request_type.upper()]
except KeyError:
current_app.logger.warning(f"Bad request type {request_type}, defaulting to GET")
self._request_type = RESTType.GET
case _:
raise TypeError(f"request_type for APIRequest was invalid type {type(request_type)}")

self._url = url
self._params = params
Expand Down
34 changes: 18 additions & 16 deletions src/ogd/apis/models/APIResponse.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,24 @@ def __init__(self, req_type:Optional[RESTType | str], val:Optional[Map], msg:str
self._type : Optional[RESTType]
self._val : Optional[Map]

if isinstance(req_type, RESTType):
self._type = req_type
elif isinstance(req_type, str):
self._type = RESTType[req_type]
else:
self._type = None
if isinstance(val, dict) or val is None:
self._val = val
else:
try:
self._val = json.loads(str(val))
except json.decoder.JSONDecodeError as err:
abbreviated_val = f"{str(val)[:20]}..." if len(str(val)) > 20 else str(val)
_msg = f"API response 'value' field contained value '{abbreviated_val}' with invalid type {type(val)}, which could not be converted to a dictionary. Attempting to do so resulted in error:\n{err}\nThe value field will be left blank."
Logger.Log(_msg, logging.ERROR)
self._val = None
match req_type:
case RESTType():
self._type = req_type
case str():
self._type = RESTType[req_type]
case _:
self._type = None
match val:
case dict() | None:
self._val = val
case _:
try:
self._val = json.loads(str(val))
except json.decoder.JSONDecodeError as err:
abbreviated_val = f"{str(val)[:20]}..." if len(str(val)) > 20 else str(val)
_msg = f"API response 'value' field contained value '{abbreviated_val}' with invalid type {type(val)}, which could not be converted to a dictionary. Attempting to do so resulted in error:\n{err}\nThe value field will be left blank."
Logger.Log(_msg, logging.ERROR)
self._val = None
self._msg : str = msg
self._status : ResponseStatus = status

Expand Down
27 changes: 5 additions & 22 deletions src/ogd/apis/models/enums/RESTType.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,8 @@
from enum import IntEnum
from typing import Set
from enum import StrEnum

class RESTType(IntEnum):
class RESTType(StrEnum):
"""Simple enumerated type to track type of a REST request.
"""
GET = 1
POST = 2
PUT = 3

def __str__(self):
"""Stringify function for RESTTypes.

:return: Simple string version of the name of a RESTType
:rtype: _type_
"""
match self.value:
case RESTType.GET:
return "GET"
case RESTType.POST:
return "POST"
case RESTType.PUT:
return "PUT"
case _:
return "INVALID REST TYPE"
GET = "GET"
POST = "POST"
PUT = "PUT"
Loading