From fca177ffe3fb42e1caf59e6eadb8b7a8890acec8 Mon Sep 17 00:00:00 2001 From: Daryl Lim <5508348+daryllimyt@users.noreply.github.com> Date: Wed, 4 Dec 2024 15:00:06 -0800 Subject: [PATCH 1/3] app: Fix identifiers types --- tracecat/identifiers/resource.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tracecat/identifiers/resource.py b/tracecat/identifiers/resource.py index a7bb12934..68552a9c8 100644 --- a/tracecat/identifiers/resource.py +++ b/tracecat/identifiers/resource.py @@ -13,15 +13,13 @@ """Resource identifier pattern. e.g. 'wf-77932a0b140a4465a1a25a5c95edcfb8'""" -def generate_resource_id(prefix: ResourcePrefix, *, sep: str = "-") -> ResourceID: +def generate_resource_id(prefix: str, *, sep: str = "-") -> ResourceID: """Generate a short unique identifier with a prefix.""" return prefix + sep + uuid4().hex -def id_factory( - prefix: ResourcePrefix, *, sep: str = "-" -) -> Callable[[str], ResourceID]: +def id_factory(prefix: str, *, sep: str = "-") -> Callable[[], ResourceID]: """Factory function to generate a short unique identifier with a prefix.""" # Assert that the prefix is a valid resource class identifier. From 4ef3f24e11c099861e6e3ebdb64cdf66e267adb9 Mon Sep 17 00:00:00 2001 From: Daryl Lim <5508348+daryllimyt@users.noreply.github.com> Date: Wed, 4 Dec 2024 15:00:44 -0800 Subject: [PATCH 2/3] app: Fix TIMESTAMP type --- tracecat/db/schemas.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tracecat/db/schemas.py b/tracecat/db/schemas.py index 721adff0f..01957c401 100644 --- a/tracecat/db/schemas.py +++ b/tracecat/db/schemas.py @@ -41,14 +41,14 @@ class Resource(SQLModel): surrogate_id: int | None = Field(default=None, primary_key=True, exclude=True) owner_id: OwnerID created_at: datetime = Field( - sa_type=TIMESTAMP(timezone=True), # UTC Timestamp + sa_type=TIMESTAMP, sa_column_kwargs={ "server_default": text("(now() AT TIME ZONE 'utc'::text)"), "nullable": False, }, ) updated_at: datetime = Field( - sa_type=TIMESTAMP(timezone=True), # UTC Timestamp + sa_type=TIMESTAMP, sa_column_kwargs={ "server_default": text("(now() AT TIME ZONE 'utc'::text)"), "onupdate": text("(now() AT TIME ZONE 'utc'::text)"), From 27384da46f62b39e1c455c14e6dbe7871502fcdd Mon Sep 17 00:00:00 2001 From: Daryl Lim <5508348+daryllimyt@users.noreply.github.com> Date: Wed, 4 Dec 2024 15:22:49 -0800 Subject: [PATCH 3/3] refactor: Remove action key --- frontend/src/client/schemas.gen.ts | 12 ++---------- frontend/src/client/types.gen.ts | 2 -- tracecat/db/schemas.py | 6 ------ tracecat/identifiers/action.py | 7 ------- tracecat/workflow/actions/models.py | 2 -- tracecat/workflow/actions/router.py | 11 ++++++----- 6 files changed, 8 insertions(+), 32 deletions(-) diff --git a/frontend/src/client/schemas.gen.ts b/frontend/src/client/schemas.gen.ts index 79f56de94..4c79b8b64 100644 --- a/frontend/src/client/schemas.gen.ts +++ b/frontend/src/client/schemas.gen.ts @@ -105,16 +105,12 @@ export const $ActionRead = { type: 'object', title: 'Inputs' }, - key: { - type: 'string', - title: 'Key' - }, control_flow: { '$ref': '#/components/schemas/ActionControlFlow' } }, type: 'object', - required: ['id', 'type', 'title', 'description', 'status', 'inputs', 'key'], + required: ['id', 'type', 'title', 'description', 'status', 'inputs'], title: 'ActionRead' } as const; @@ -143,14 +139,10 @@ export const $ActionReadMinimal = { status: { type: 'string', title: 'Status' - }, - key: { - type: 'string', - title: 'Key' } }, type: 'object', - required: ['id', 'workflow_id', 'type', 'title', 'description', 'status', 'key'], + required: ['id', 'workflow_id', 'type', 'title', 'description', 'status'], title: 'ActionReadMinimal' } as const; diff --git a/frontend/src/client/types.gen.ts b/frontend/src/client/types.gen.ts index c1a6492e2..56f2bc4ca 100644 --- a/frontend/src/client/types.gen.ts +++ b/frontend/src/client/types.gen.ts @@ -31,7 +31,6 @@ export type ActionRead = { inputs: { [key: string]: unknown; }; - key: string; control_flow?: ActionControlFlow; }; @@ -42,7 +41,6 @@ export type ActionReadMinimal = { title: string; description: string; status: string; - key: string; }; export type ActionRetryPolicy = { diff --git a/tracecat/db/schemas.py b/tracecat/db/schemas.py index 01957c401..68c5663bc 100644 --- a/tracecat/db/schemas.py +++ b/tracecat/db/schemas.py @@ -399,12 +399,6 @@ class Action(Resource, table=True): back_populates="actions", sa_relationship_kwargs=DEFAULT_SA_RELATIONSHIP_KWARGS ) - @computed_field - @property - def key(self) -> str: - """Workflow-relative key for an Action.""" - return action.key(self.workflow_id, self.id) - @property def ref(self) -> str: """Slugified title of the action. Used for references.""" diff --git a/tracecat/identifiers/action.py b/tracecat/identifiers/action.py index 8ce73bc69..37b12e973 100644 --- a/tracecat/identifiers/action.py +++ b/tracecat/identifiers/action.py @@ -5,8 +5,6 @@ from pydantic import StringConstraints from slugify import slugify -from tracecat.identifiers.resource import ResourcePrefix - ActionID = Annotated[str, StringConstraints(pattern=r"act-[0-9a-f]{32}")] """A unique ID for an action. e.g. 'act-77932a0b140a4465a1a25a5c95edcfb8'""" @@ -20,8 +18,3 @@ def ref(text: str) -> ActionRef: """Return a slugified version of the text.""" return slugify(text, separator="_") - - -def key(workflow_id: str, action_ref: str) -> ActionKey: - """Identifier key for an action, using the workflow ID and action ref.""" - return f"{ResourcePrefix.ACTION}:{workflow_id}:{action_ref}" diff --git a/tracecat/workflow/actions/models.py b/tracecat/workflow/actions/models.py index 55111c93a..f2f7a659c 100644 --- a/tracecat/workflow/actions/models.py +++ b/tracecat/workflow/actions/models.py @@ -23,7 +23,6 @@ class ActionRead(BaseModel): description: str status: str inputs: dict[str, Any] - key: str # Computed field control_flow: ActionControlFlow = Field(default_factory=ActionControlFlow) @@ -34,7 +33,6 @@ class ActionReadMinimal(BaseModel): title: str description: str status: str - key: str class ActionCreate(BaseModel): diff --git a/tracecat/workflow/actions/router.py b/tracecat/workflow/actions/router.py index 040da51f2..d1078ce6b 100644 --- a/tracecat/workflow/actions/router.py +++ b/tracecat/workflow/actions/router.py @@ -37,7 +37,6 @@ async def list_actions( title=action.title, description=action.description, status=action.status, - key=action.key, ) for action in actions ] @@ -51,13 +50,18 @@ async def create_action( session: AsyncDBSession, ) -> ActionReadMinimal: """Create a new action for a workflow.""" + if role.workspace_id is None: + raise HTTPException( + status_code=status.HTTP_400_BAD_REQUEST, + detail="Workspace ID is required", + ) action = Action( owner_id=role.workspace_id, workflow_id=params.workflow_id, type=params.type, title=params.title, description="", # Default to empty string - ) + ) # type: ignore # Check if a clashing action ref exists statement = select(Action).where( Action.owner_id == role.workspace_id, @@ -82,7 +86,6 @@ async def create_action( title=action.title, description=action.description, status=action.status, - key=action.key, ) return action_metadata @@ -115,7 +118,6 @@ async def get_action( description=action.description, status=action.status, inputs=action.inputs, - key=action.key, control_flow=ActionControlFlow(**action.control_flow), ) @@ -163,7 +165,6 @@ async def update_action( description=action.description, status=action.status, inputs=action.inputs, - key=action.key, )