Skip to content

Commit

Permalink
Merge pull request #130 from bento-platform/fix/misc-v9-fixes
Browse files Browse the repository at this point in the history
fix: auth type hinting and workflow input model field defaults
  • Loading branch information
davidlougheed authored Oct 19, 2023
2 parents 1e46abb + da6f2e1 commit b816a5e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
13 changes: 8 additions & 5 deletions bento_lib/auth/middleware/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@

from ..exceptions import BentoAuthException

__all__ = ["BaseAuthMiddleware"]
__all__ = ["EvaluationResultMatrix", "BaseAuthMiddleware"]


EvaluationResultMatrix = tuple[tuple[bool, ...], ...]


class BaseAuthMiddleware(ABC):
Expand Down Expand Up @@ -96,7 +99,7 @@ def _evaluate_body(resources: Iterable[dict], permissions: Iterable[str]) -> dic
return {"resources": tuple(resources), "permissions": tuple(permissions)}

@staticmethod
def _matrix_tuple_cast(authz_result: list[list[bool]]) -> tuple[tuple[bool, ...]]:
def _matrix_tuple_cast(authz_result: list[list[bool]]) -> tuple[tuple[bool, ...], ...]:
return tuple(tuple(x) for x in authz_result)

def evaluate(
Expand All @@ -107,7 +110,7 @@ def evaluate(
require_token: bool = False,
headers_getter: Callable[[Any], dict[str, str]] | None = None,
mark_authz_done: bool = False,
) -> tuple[tuple[bool, ...]]:
) -> EvaluationResultMatrix:
if mark_authz_done:
self.mark_authz_done(request)
return self._matrix_tuple_cast(
Expand Down Expand Up @@ -159,7 +162,7 @@ async def async_evaluate(
require_token: bool = False,
headers_getter: Callable[[Any], dict[str, str]] | None = None,
mark_authz_done: bool = False,
) -> tuple[tuple[bool, ...]]:
) -> EvaluationResultMatrix:
if mark_authz_done:
self.mark_authz_done(request)
return self._matrix_tuple_cast(
Expand Down Expand Up @@ -228,7 +231,7 @@ async def async_check_authz_evaluate(
require_token: bool = True,
set_authz_flag: bool = False,
headers_getter: Callable[[Any], dict[str, str]] | None = None,
):
) -> None:
if not self.enabled:
return

Expand Down
2 changes: 1 addition & 1 deletion bento_lib/package.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = bento_lib
version = 9.0.0a1
version = 9.0.0a2
authors = David Lougheed, Paul Pillot
author_emails = [email protected], [email protected]
26 changes: 13 additions & 13 deletions bento_lib/workflows/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,36 +37,36 @@ class WorkflowBaseInput(FrozenBaseModel):


class WorkflowInjectedInput(WorkflowBaseInput):
injected: Literal[True]
injected: Literal[True] = True


class WorkflowStringInput(WorkflowBaseInput):
type: Literal["string"]
type: Literal["string"] = "string"


class WorkflowStringArrayInput(WorkflowBaseInput):
type: Literal["string[]"]
type: Literal["string[]"] = "string[]"


class WorkflowNumberInput(WorkflowBaseInput):
type: Literal["number"]
type: Literal["number"] = "number"


class WorkflowNumberArrayInput(WorkflowBaseInput):
type: Literal["number[]"]
type: Literal["number[]"] = "number[]"


class WorkflowBooleanInput(WorkflowBaseInput):
type: Literal["boolean"]
type: Literal["boolean"] = "boolean"


class WorkflowEnumInput(WorkflowBaseInput):
type: Literal["enum"]
type: Literal["enum"] = "enum"
values: list[str] | HttpUrl # list of values, or a URL returning an array of enum values


class WorkflowEnumArrayInput(WorkflowBaseInput):
type: Literal["enum[]"]
type: Literal["enum[]"] = "enum[]"
values: list[str] | HttpUrl # list of values, or a URL returning an array of enum values
repeatable: bool = True

Expand All @@ -77,28 +77,28 @@ class WorkflowProjectDatasetInput(WorkflowBaseInput):

class WorkflowFileInput(WorkflowBaseInput):
# can be sourced from drop box / DRS / workflow outputs, whatever the UI decides works
type: Literal["file"]
type: Literal["file"] = "file"
pattern: str = "*" # file name regular expression pattern


class WorkflowFileArrayInput(WorkflowBaseInput):
# can be sourced from drop box / DRS / workflow outputs, whatever the UI decides works
type: Literal["file[]"]
type: Literal["file[]"] = "file[]"
pattern: str = "*" # file name regular expression pattern


class WorkflowDirectoryInput(WorkflowBaseInput):
# can be sourced from drop box / DRS / workflow outputs, whatever the UI decides works
type: Literal["directory"]
type: Literal["directory"] = "directory"


class WorkflowDirectoryArrayInput(WorkflowBaseInput):
# can be sourced from drop box / DRS / workflow outputs, whatever the UI decides works
type: Literal["directory[]"]
type: Literal["directory[]"] = "directory[]"


class WorkflowServiceUrlInput(WorkflowInjectedInput):
type: Literal["service-url"]
type: Literal["service-url"] = "service-url"
service_kind: str


Expand Down

0 comments on commit b816a5e

Please sign in to comment.