From ccc1dc3aba32d3726ff94410acf06bedda9a4d01 Mon Sep 17 00:00:00 2001 From: Luke Swanson Date: Wed, 9 Sep 2026 12:30:07 -0500 Subject: [PATCH 1/4] Change RESTType to use StrEnum as base class, no longer need a custom __str__ function either. --- src/ogd/apis/models/enums/RESTType.py | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/src/ogd/apis/models/enums/RESTType.py b/src/ogd/apis/models/enums/RESTType.py index 0a9b539..2d9e48c 100644 --- a/src/ogd/apis/models/enums/RESTType.py +++ b/src/ogd/apis/models/enums/RESTType.py @@ -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" \ No newline at end of file + GET = "GET" + POST = "POST" + PUT = "PUT" From fb4ad38aaa8775f57f0af2abeed3f1fb4e00671f Mon Sep 17 00:00:00 2001 From: Luke Swanson Date: Wed, 9 Sep 2026 12:37:42 -0500 Subject: [PATCH 2/4] With RESTType base class changing, slightly clarify logic for handling it in APIRequest. --- src/ogd/apis/models/APIRequest.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/ogd/apis/models/APIRequest.py b/src/ogd/apis/models/APIRequest.py index ce1ceed..4010053 100644 --- a/src/ogd/apis/models/APIRequest.py +++ b/src/ogd/apis/models/APIRequest.py @@ -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 From f58dd1d7696e729b1df731d38dfdc3b4b57daaee Mon Sep 17 00:00:00 2001 From: Luke Swanson Date: Wed, 9 Sep 2026 12:39:43 -0500 Subject: [PATCH 3/4] Similar for APIResponse, clarify a couple blocks by using match-case clauses. --- src/ogd/apis/models/APIResponse.py | 34 ++++++++++++++++-------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/ogd/apis/models/APIResponse.py b/src/ogd/apis/models/APIResponse.py index 42a3734..70e8ffa 100644 --- a/src/ogd/apis/models/APIResponse.py +++ b/src/ogd/apis/models/APIResponse.py @@ -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 From 47f83d1de1637c2224a139582da49d348da15931 Mon Sep 17 00:00:00 2001 From: Luke Swanson Date: Wed, 9 Sep 2026 12:55:58 -0500 Subject: [PATCH 4/4] Ok, guess we need to bookend our branch tag, on off chance our character limit cuts us off with a trailing -. Because tags can't end in -, only *contain* them. Fuck's sake. --- .github/workflows/CI_APIUtils.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CI_APIUtils.yml b/.github/workflows/CI_APIUtils.yml index 812321c..7ac4201 100644 --- a/.github/workflows/CI_APIUtils.yml +++ b/.github/workflows/CI_APIUtils.yml @@ -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