Skip to content

Commit

Permalink
feat(engine): Implement schedules (#214)
Browse files Browse the repository at this point in the history
* feat(engine): Add create schedule endpoint

* feat(engine): Add rest of the CRUD operations for schedules

* chore: Lower log level for action result

* feat(cli): Add cli utils

* feat(cli): Add schedules cli

* feat(engine): Use config for temporal cluster queue

* feat(engine): Add better error visibility on http 422

* refactor(playbook): Use slack secret over slack_channel

* docs: Update api docstrings

* feat(engine): Add more metdata fields to Schedule

* feat(engine): Make Schedule status online by default

* feat(ui): Update schedules UI

* feat(engine): Add update schedules

* feat(cli): Add cli update schedules
  • Loading branch information
daryllimyt authored Jun 29, 2024
1 parent 3a2af30 commit e2ba8b1
Show file tree
Hide file tree
Showing 21 changed files with 702 additions and 123 deletions.
30 changes: 26 additions & 4 deletions frontend/src/components/workspace/canvas/trigger-node.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export default React.memo(function TriggerNode({
<Table>
<TableHeader>
<TableRow>
<TableHead className="h-8 text-center text-xs">
<TableHead className="h-8 text-center text-xs" colSpan={2}>
<div className="flex items-center justify-center gap-1">
<CalendarCheck className="size-3" />
<span>Schedules</span>
Expand All @@ -136,9 +136,31 @@ export default React.memo(function TriggerNode({
</TableRow>
</TableHeader>
<TableBody>
{workflow.schedules.map(({ id, cron }) => (
<TableRow key={id}>
<TableCell>{cron}</TableCell>
{workflow.schedules.map(({ status, every }, idx) => (
<TableRow
key={idx}
className="items-center text-center text-xs text-muted-foreground"
>
<TableCell>
<div className="flex w-full items-center justify-center">
<span
className={cn(
status !== "online" &&
"bg-muted-foreground/5 text-muted-foreground/50"
)}
>
{every}
</span>
<span
className={cn(
"ml-2 inline-block size-2 rounded-full ",
workflow.webhook.status === "online"
? "bg-emerald-500"
: "bg-gray-300"
)}
/>
</div>
</TableCell>
</TableRow>
))}
</TableBody>
Expand Down
38 changes: 25 additions & 13 deletions frontend/src/components/workspace/panel/trigger-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -265,30 +265,42 @@ export function ScheduleControls({ schedules }: { schedules: Schedule[] }) {
<Table>
<TableHeader>
<TableRow>
<TableHead className="h-8 text-center text-xs">
<TableHead className="h-8 text-center text-xs" colSpan={4}>
<div className="flex items-center justify-center gap-1">
<WebhookIcon className="size-3" />
<span>Schedules</span>
</div>
</TableHead>
</TableRow>
<TableRow>
<TableHead className="h-8 text-center text-xs">ID</TableHead>
<TableHead className="h-8 text-center text-xs">Status</TableHead>
<TableHead className="h-8 text-center text-xs">Inputs</TableHead>
<TableHead className="h-8 text-center text-xs">Every</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{schedules.map(({ id, cron }) => (
<TableRow key={id}>
<TableCell>{cron}</TableCell>
{schedules.map(({ id, status, inputs, every }) => (
<TableRow key={id} className="text-xs text-muted-foreground">
<TableCell>{id}</TableCell>
<TableCell>{status}</TableCell>
<TableCell>{JSON.stringify(inputs)}</TableCell>
<TableCell>{every}</TableCell>
</TableRow>
))}
</TableBody>
<TableFooter className="flex w-full justify-center text-muted-foreground">
<Button
variant="ghost"
size="sm"
className="flex w-full items-center justify-center gap-2"
>
<PlusCircleIcon className="size-4" />
<span>Add Schedule</span>
</Button>
<TableFooter>
<TableCell colSpan={4}>
<Button
variant="ghost"
size="sm"
className="flex h-4 w-full items-center justify-center gap-2 text-muted-foreground/90"
disabled
>
<PlusCircleIcon className="size-4" />
<span>Add Schedule</span>
</Button>
</TableCell>
</TableFooter>
</Table>
</div>
Expand Down
9 changes: 7 additions & 2 deletions frontend/src/types/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,13 @@ export type Webhook = z.infer<typeof webhookSchema>
export const scheduleSchema = z
.object({
status: z.enum(["online", "offline"]),
entrypoint_payload: z.record(z.any()),
cron: z.string(),
inputs: z.record(z.any()),
cron: z.string().nullish(),
every: z.string(),
offset: z.string().nullable(),
start_at: strAsDate.nullable(),
end_at: strAsDate.nullable(),
workflow_id: z.string(),
})
.and(resourceSchema)
export type Schedule = z.infer<typeof scheduleSchema>
Expand Down
4 changes: 2 additions & 2 deletions playbooks/alert_management/aws-guardduty-to-slack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ actions:
- pull_aws_guardduty_findings
run_if: ${{ FN.is_empty(ACTIONS.pull_aws_guardduty_findings.result) }}
args:
url: ${{ SECRETS.slack_channel.SLACK_WEBHOOK }}
url: ${{ SECRETS.slack.SLACK_WEBHOOK }}
method: POST
headers:
Content-Type: application/json
Expand Down Expand Up @@ -61,7 +61,7 @@ actions:
# Assign each SMAC finding to a variable named `smac`
for_each: ${{ for var.smac in ACTIONS.reshape_findings_into_smac.result }}
args:
channel: ${{ SECRETS.slack_channel.SLACK_CHANNEL }}
channel: ${{ SECRETS.slack.SLACK_CHANNEL }}
text: GuardDuty findings
blocks:
- type: header
Expand Down
Loading

0 comments on commit e2ba8b1

Please sign in to comment.