-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adding IOClient and jobs results and payload endpoints * Adding write object methods for IOClient * Adding delete bucket methods for IOClient * post processes endpoint * use discriminant union for workflow configs * addressing PR comments * update status code * fixup all the __root__ nonsense * clean up process execute insert queries * empty string not none for create/drop db name * workflow name doesn't match process id check * addressing PR comments * remove id in payload/update tests * dont use relative path in bad workflow config --------- Co-authored-by: Hector Machin <hector.machin@ursaspace.com> Co-authored-by: jkeifer <jkeifer@element84.com>
- Loading branch information
1 parent
a0504af
commit 14c48ee
Showing
16 changed files
with
385 additions
and
109 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
|
@@ -62,3 +62,6 @@ readme = {file = "README.md"} | |
|
||
[tool.isort] | ||
profile = "black" | ||
|
||
[tool.pytest.ini_options] | ||
minversion = "6.0" |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class SwoopApiException(Exception): | ||
pass | ||
|
||
|
||
class WorkflowConfigError(SwoopApiException, ValueError): | ||
pass |
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 |
---|---|---|
@@ -0,0 +1,100 @@ | ||
from __future__ import annotations | ||
|
||
from abc import ABC | ||
from enum import Enum | ||
from pathlib import Path | ||
from typing import Annotated, Literal, Union | ||
|
||
import yaml | ||
from pydantic import BaseModel, Field, StrictBool, StrictInt, StrictStr | ||
|
||
from swoop.api.exceptions import WorkflowConfigError | ||
|
||
|
||
class Response(Enum): | ||
# raw = "raw" | ||
document = "document" | ||
|
||
|
||
class BaseWorkflow(BaseModel, ABC): | ||
name: StrictStr | ||
description: StrictStr | ||
version: StrictInt | ||
cache_key_hash_includes: list[StrictStr] = [] | ||
cache_key_hash_excludes: list[StrictStr] = [] | ||
|
||
|
||
class ArgoWorkflow(BaseWorkflow): | ||
handler: Literal["argo-workflow"] | ||
argo_template: StrictStr | ||
|
||
|
||
class CirrusWorkflow(BaseWorkflow): | ||
handler: Literal["cirrus-workflow"] | ||
sfn_arn: StrictStr | ||
|
||
|
||
Workflow = Annotated[ | ||
Union[ | ||
ArgoWorkflow, | ||
CirrusWorkflow, | ||
], | ||
Field(discriminator="handler"), | ||
] | ||
|
||
|
||
class Feature(BaseModel): | ||
id: StrictStr | ||
collection: StrictStr | ||
|
||
|
||
class UploadOptions(BaseModel): | ||
path_template: StrictStr | ||
collections: dict | ||
public_assets: list[StrictStr] = [] | ||
headers: dict | ||
s3_urls: StrictBool | ||
|
||
|
||
class Process(BaseModel): | ||
description: StrictStr | None = None | ||
tasks: dict | ||
# input_collections: Optional[list[StrictStr]] = None | ||
upload_options: UploadOptions | ||
workflow: StrictStr | ||
|
||
|
||
class Payload(BaseModel): | ||
type: StrictStr = "FeatureCollection" | ||
features: list[Feature] | ||
process: list[Process] | ||
|
||
|
||
class InputPayload(BaseModel): | ||
payload: Payload | ||
|
||
|
||
class Execute(BaseModel): | ||
# TODO: I believe this is where we need to specify the input payload schema | ||
# inputs: dict[str, InlineOrRefData | list[InlineOrRefData]] | None = None | ||
inputs: InputPayload | ||
# TODO: We should likely omit the ability to specify outputs | ||
# outputs: dict[str, Output] | None = None | ||
# TODO: Response isn't really to be supported, all results are json | ||
response: Literal["document"] = "document" | ||
# subscriber: Subscriber | None = None | ||
|
||
|
||
class Workflows(dict[str, Workflow]): | ||
class _type(BaseModel): | ||
__root__: dict[str, Workflow] | ||
|
||
@classmethod | ||
def from_yaml(cls, path: Path) -> Workflows: | ||
try: | ||
workflows = yaml.safe_load(path.read_text())["workflows"] | ||
for name, workflow in workflows.items(): | ||
workflow["name"] = name | ||
return cls(cls._type.parse_obj(workflows).__root__) | ||
except Exception as e: | ||
raise WorkflowConfigError("Could not load workflow configuration") from e |
Oops, something went wrong.