Skip to content

Commit

Permalink
added some more typed dicts w/ burnettk
Browse files Browse the repository at this point in the history
  • Loading branch information
jasquat committed Oct 13, 2023
1 parent 54e9685 commit 9ccf99e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 13 deletions.
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ packages = [{include = "spiffworkflow_connector_command", from = "src" }]
[tool.poetry.dependencies]
python = "^3.9"
requests = "^2.28.2"
typing-extensions = "^4.8.0"


[tool.poetry.group.dev.dependencies]
Expand Down
50 changes: 38 additions & 12 deletions src/spiffworkflow_connector_command/command_interface.py
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")

0 comments on commit 9ccf99e

Please sign in to comment.