-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added some more typed dicts w/ burnettk
- Loading branch information
Showing
3 changed files
with
40 additions
and
13 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,52 @@ | ||
from __future__ import annotations | ||
|
||
import abc | ||
import sys | ||
from typing import Any | ||
from typing import TypedDict | ||
|
||
if sys.version_info < (3, 11): | ||
from typing_extensions import NotRequired | ||
from typing_extensions import TypedDict | ||
else: | ||
from typing import NotRequired | ||
from typing import TypedDict | ||
|
||
|
||
class CommandErrorDict(TypedDict): | ||
error_name: str | ||
message: str | ||
|
||
|
||
class CommandResponseDict(TypedDict): | ||
response: dict | ||
"""This is passed back to spiffworkflow-backend as the response body.""" | ||
|
||
# this is given to the service task as task data | ||
command_response: dict | ||
error: CommandErrorDict | None | ||
|
||
# these are printed to spiffworkflow-backend logs | ||
spiff__logs: NotRequired[list[str]| None] | ||
|
||
# added by spiffworkflow-proxy if not set | ||
# example: http/GetRequestV2 | ||
operator_id: NotRequired[str] | ||
|
||
|
||
class CommandResultDict(TypedDict): | ||
"""spiffworkflow-proxy parses this result to determine what happended.""" | ||
response: CommandResponseDict | ||
status: int | ||
mimetype: str | ||
|
||
|
||
class CommandInterface(metaclass=abc.ABCMeta): | ||
class ConnectorCommand(metaclass=abc.ABCMeta): | ||
"""Abstract class to describe how to make a command.""" | ||
|
||
@classmethod | ||
def __subclasshook__(cls, subclass: Any) -> bool: | ||
return ( | ||
hasattr(subclass, "execute") | ||
and callable(subclass.run) | ||
and NotImplemented | ||
) | ||
|
||
@abc.abstractmethod | ||
def execute(self, config: Any, task_data: dict) -> CommandResponseDict: | ||
def execute(self, config: Any, task_data: dict) -> CommandResultDict: | ||
raise NotImplementedError("method must be implemented on subclass: execute") | ||
|
||
# this is not a required method but if it gets used then it must be overridden | ||
def app_description(self, *args: Any, **kwargs: Any) -> dict: | ||
"""Return a dict to describe the connector. This is used only for authentication commands at the moment.""" | ||
raise NotImplementedError("method must be implemented on subclass: app_description") |