Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: Rename static inputs to variables #503

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions alembic/versions/01c0ce9cf72d_rename_static_inputs_to_variables.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
"""Rename static_inputs to variables

Revision ID: 01c0ce9cf72d
Revises: 046d417c113f
Create Date: 2024-11-08 18:18:54.464298

"""
from collections.abc import Sequence

import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

from alembic import op

# revision identifiers, used by Alembic.
revision: str = "01c0ce9cf72d"
down_revision: str | None = "046d417c113f"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None


def upgrade() -> None:
# Add new column
op.add_column(
"workflow",
sa.Column("variables", postgresql.JSONB(astext_type=sa.Text()), nullable=True),
)

# Transfer existing data from static_inputs to variables
op.execute("UPDATE workflow SET variables = static_inputs")

# Update WorkflowDefinition content field
op.execute(
"""
UPDATE workflowdefinition
SET content = jsonb_set(
content,
'{variables}',
content->'inputs'
) - 'inputs'
WHERE content ? 'inputs'
"""
)

# Drop old column
op.drop_column("workflow", "static_inputs")


def downgrade() -> None:
# Add old column back
op.add_column(
"workflow",
sa.Column(
"static_inputs",
postgresql.JSONB(astext_type=sa.Text()),
autoincrement=False,
nullable=True,
),
)

# Transfer data back from variables to static_inputs
op.execute("UPDATE workflow SET static_inputs = variables")

# Revert WorkflowDefinition content field changes
op.execute(
"""
UPDATE workflowdefinition
SET content = jsonb_set(
content,
'{inputs}',
content->'variables'
) - 'variables'
WHERE content ? 'variables'
"""
)

# Drop new column
op.drop_column("workflow", "variables")
# ### end Alembic commands ###
20 changes: 10 additions & 10 deletions frontend/src/client/schemas.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -733,9 +733,9 @@ Activities don't need access to this.`

export const $DSLContext = {
properties: {
INPUTS: {
VARS: {
type: 'object',
title: 'Inputs'
title: 'Vars'
},
ACTIONS: {
type: 'object',
Expand Down Expand Up @@ -834,10 +834,10 @@ export const $DSLInput = {
type: 'array',
title: 'Triggers'
},
inputs: {
variables: {
type: 'object',
title: 'Inputs',
description: 'Static input parameters'
title: 'Variables',
description: 'Variables for the workflow'
},
returns: {
anyOf: [
Expand Down Expand Up @@ -2898,7 +2898,7 @@ export const $UpdateWorkflowParams = {
],
title: 'Icon Url'
},
static_inputs: {
variables: {
anyOf: [
{
type: 'object'
Expand All @@ -2907,7 +2907,7 @@ export const $UpdateWorkflowParams = {
type: 'null'
}
],
title: 'Static Inputs'
title: 'Variables'
},
expects: {
anyOf: [
Expand Down Expand Up @@ -3626,9 +3626,9 @@ export const $WorkflowResponse = {
],
title: 'Entrypoint'
},
static_inputs: {
variables: {
type: 'object',
title: 'Static Inputs'
title: 'Variables'
},
expects: {
anyOf: [
Expand Down Expand Up @@ -3659,7 +3659,7 @@ export const $WorkflowResponse = {
}
},
type: 'object',
required: ['id', 'title', 'description', 'status', 'actions', 'object', 'owner_id', 'webhook', 'schedules', 'entrypoint', 'static_inputs', 'returns', 'config'],
required: ['id', 'title', 'description', 'status', 'actions', 'object', 'owner_id', 'webhook', 'schedules', 'entrypoint', 'variables', 'returns', 'config'],
title: 'WorkflowResponse'
} as const;

Expand Down
10 changes: 5 additions & 5 deletions frontend/src/client/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ export type DSLConfig_Output = {
};

export type DSLContext = {
INPUTS?: {
VARS?: {
[key: string]: unknown;
};
ACTIONS?: {
Expand Down Expand Up @@ -316,9 +316,9 @@ export type DSLInput = {
config?: DSLConfig_Output;
triggers?: Array<Trigger>;
/**
* Static input parameters
* Variables for the workflow
*/
inputs?: {
variables?: {
[key: string]: unknown;
};
/**
Expand Down Expand Up @@ -973,7 +973,7 @@ export type UpdateWorkflowParams = {
version?: number | null;
entrypoint?: string | null;
icon_url?: string | null;
static_inputs?: {
variables?: {
[key: string]: unknown;
} | null;
expects?: {
Expand Down Expand Up @@ -1155,7 +1155,7 @@ export type WorkflowResponse = {
webhook: WebhookResponse;
schedules: Array<Schedule>;
entrypoint: string | null;
static_inputs: {
variables: {
[key: string]: unknown;
};
expects?: {
Expand Down
22 changes: 11 additions & 11 deletions frontend/src/components/workbench/panel/workflow-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const workflowConfigFormSchema = z.object({
return z.NEVER
}
}),
static_inputs: z.string().transform((val, ctx) => {
variables: z.string().transform((val, ctx) => {
try {
return YAML.parse(val) || {}
} catch (error) {
Expand Down Expand Up @@ -123,9 +123,9 @@ export function WorkflowPanel({
environment: null,
})
: YAML.stringify(workflow.config),
static_inputs: isEmptyObjectOrNullish(workflow.static_inputs)
variables: isEmptyObjectOrNullish(workflow.variables)
? ""
: YAML.stringify(workflow.static_inputs),
: YAML.stringify(workflow.variables),
expects: isEmptyObjectOrNullish(workflow.expects)
? ""
: YAML.stringify(workflow.expects),
Expand Down Expand Up @@ -195,7 +195,7 @@ export function WorkflowPanel({
value="workflow-static-inputs"
>
<FileInputIcon className="mr-2 size-4" />
<span>Static Inputs</span>
<span>Variables</span>
</TabsTrigger>
</TabsList>
</div>
Expand Down Expand Up @@ -459,7 +459,7 @@ export function WorkflowPanel({
<AccordionTrigger className="px-4 text-xs font-bold tracking-wide">
<div className="flex items-center">
<FileInputIcon className="mr-3 size-4" />
<span>Static Inputs</span>
<span>Variables</span>
</div>
</AccordionTrigger>
<AccordionContent>
Expand All @@ -477,15 +477,15 @@ export function WorkflowPanel({
side="left"
sideOffset={20}
>
<StaticInputTooltip />
<VariablesTooltip />
</HoverCardContent>
</HoverCard>
<span className="text-xs text-muted-foreground">
Define optional static inputs for the workflow.
Define optional variables for the workflow.
</span>
</div>
<Controller
name="static_inputs"
name="variables"
control={methods.control}
render={({ field }) => (
<CustomEditor
Expand All @@ -508,11 +508,11 @@ export function WorkflowPanel({
)
}

function StaticInputTooltip() {
function VariablesTooltip() {
return (
<div className="w-full space-y-4">
<div className="flex w-full items-center justify-between text-muted-foreground ">
<span className="font-mono text-sm font-semibold">Static Inputs</span>
<span className="font-mono text-sm font-semibold">Variables</span>
<span className="text-xs text-muted-foreground/80">(optional)</span>
</div>
<div className="flex w-full flex-col items-center justify-between space-y-4 text-muted-foreground">
Expand All @@ -525,7 +525,7 @@ function StaticInputTooltip() {
</div>
<div className="rounded-md border bg-muted-foreground/10 p-2">
<pre className="text-xs text-foreground/70">
{"${{ INPUTS.my_static_key }}"}
{"${{ VARS.my_variable }}"}
</pre>
</div>
</div>
Expand Down
6 changes: 3 additions & 3 deletions playbooks/detect/webhook_alerts/elastic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ definition:
- type: webhook
ref: receive_elastic_alerts
entrypoint: deserialize_elastic_alerts
inputs:
variables:
child_workflow_id: REPLACE_WITH_CHILD_WORKFLOW_ID
limit: 10
batch_size: 10
Expand All @@ -35,10 +35,10 @@ definition:
- deserialize_elastic_alerts
for_each: ${{ for var.alert in ACTIONS.deserialize_elastic_alerts.result }}
args:
workflow_id: ${{ INPUTS.child_workflow_id }}
workflow_id: ${{ VARS.child_workflow_id }}
loop_strategy: parallel
fail_strategy: isolated
batch_size: ${{ INPUTS.batch_size }}
batch_size: ${{ VARS.batch_size }}
trigger_inputs:
title: ${{ var.alert.message }}
integration: Elastic Security
Expand Down
4 changes: 2 additions & 2 deletions playbooks/respond/notify_users/slack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ definition:
- type: webhook
ref: receive_alert
entrypoint: send_to_slack
inputs:
variables:
# ID to uniquely identify the actions in this playbook
slack_actions_id: alert-from-tracecat

Expand Down Expand Up @@ -63,7 +63,7 @@ definition:
text: "Respond to alert?"
emoji: true
- type: actions
block_id: ${{ INPUTS.slack_actions_id }}
block_id: ${{ VARS.slack_actions_id }}
elements:
- type: button
text:
Expand Down
Loading
Loading