mirror of
https://github.com/hatchet-dev/hatchet.git
synced 2025-12-21 08:40:10 -06:00
Feat: Dynamic (Event) Filters (#1704)
* feat: add events tables * fix: tweak PK * feat: migration * feat: gen models * fix: add external id col + index * fix: uuid pk * fix: types * chore: gen * feat: add index * Feat: Write events into OLAP tables (#1634) * feat: query for event creation * feat: olap impl * feat: wire up the olap event write * feat: goroutine? * feat: start wiring up inserts to triggers * fix: no `RETURNING` * fix: hack * fix: inner join * feat: attempt 2 * fix: return errors * chore: lint * fix: diff * feat: add new partitions * fix: eof * fix: write external ids into table * chore: gen * fix: wiring * fix: event deduping * fix: insert in bulk * fix: bug * refactor: return type of trigger * fix: unnest ids * fix: unnest tenant ids * fix: run ids in bulk insert * feat: two bulk inserts, one tx * fix: cruft * fix: bug * Update pkg/repository/v1/olap.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix: rework to avoid n^2 loop * fix: transaction timeout * fix: lint * fix: use error * fix: rm penultimate version * fix: rm penultimate test part ii * Feat: CEL-based filtering of events (#1676) * feat: add optional expression to workflow trigger event ref * feat: proto field for expression * feat: write and parse the expression * feat: wire up through put workflow ver request * feat: query * fix: naming * fix: cleanup * fix: rebase * Update pkg/repository/v1/trigger.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix: skip workflow on cel eval failure * fix: zero value * fix: cel evaluator * fix: usage * fix: naming + type * fix: rm event filter from v0 defn * feat: tests + fix typing * fix: usage * fix: construct input * feat: always write events --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix: select existing partitions * feat: add prio to push event request * feat: priority from pushed events * fix: missed a spot * fix: write events even if they're not tied to any workflows * fix: revert cel event filtering * fix: couple more * fix: simplify * feat: filters api * feat: table for storing filters * feat: migration * fix: pk ordering * feat: wiring up initial api * feat: impl filter list * feat: wire up inserts of filters * feat: add resource hint to push event * feat: multi-select filters * feat: wire up resource hint on event push * feat: filtering * fix: small bug * fix: rm version id * fix: query * fix: panic * fix: schema * fix: naming * fix: rm python changes * chore: lint * fix: uuid hint Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix: use overwrite for listing filters b/c of nullable arg * fix: naming * feat: add events tables * fix: tweak PK * feat: migration * feat: gen models * fix: add external id col + index * fix: uuid pk * fix: types * chore: gen * feat: add index * Feat: Write events into OLAP tables (#1634) * feat: query for event creation * feat: olap impl * feat: wire up the olap event write * feat: goroutine? * feat: start wiring up inserts to triggers * fix: no `RETURNING` * fix: hack * fix: inner join * feat: attempt 2 * fix: return errors * chore: lint * fix: diff * feat: add new partitions * fix: eof * fix: write external ids into table * chore: gen * fix: wiring * fix: event deduping * fix: insert in bulk * fix: bug * refactor: return type of trigger * fix: unnest ids * fix: unnest tenant ids * fix: run ids in bulk insert * feat: two bulk inserts, one tx * fix: cruft * fix: bug * Update pkg/repository/v1/olap.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix: rework to avoid n^2 loop * fix: transaction timeout * fix: lint * fix: use error * fix: rm penultimate version * fix: rm penultimate test part ii * Feat: CEL-based filtering of events (#1676) * feat: add optional expression to workflow trigger event ref * feat: proto field for expression * feat: write and parse the expression * feat: wire up through put workflow ver request * feat: query * fix: naming * fix: cleanup * fix: rebase * Update pkg/repository/v1/trigger.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix: skip workflow on cel eval failure * fix: zero value * fix: cel evaluator * fix: usage * fix: naming + type * fix: rm event filter from v0 defn * feat: tests + fix typing * fix: usage * fix: construct input * feat: always write events --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix: select existing partitions * feat: add prio to push event request * feat: priority from pushed events * fix: missed a spot * fix: write events even if they're not tied to any workflows * fix: revert cel event filtering * fix: couple more * fix: simplify * fix: gen api * fix: merge issues * feat: filter delete endpoint * fix: overwrite * fix: delete filter api wiring * fix: migration patch * chore: gen * fix: merge hell * Revert "Revert "Feat: Events in the OLAP Repo (#1633)" (#1706)" This reverts commitbf29269a27. * Feat: Events Frontend (#1678) * feat: add events tables * fix: tweak PK * feat: migration * feat: gen models * fix: add external id col + index * fix: uuid pk * fix: types * chore: gen * feat: add index * Feat: Write events into OLAP tables (#1634) * feat: query for event creation * feat: olap impl * feat: wire up the olap event write * feat: goroutine? * feat: start wiring up inserts to triggers * fix: no `RETURNING` * fix: hack * fix: inner join * feat: attempt 2 * fix: return errors * chore: lint * fix: diff * feat: add new partitions * fix: eof * fix: write external ids into table * chore: gen * fix: wiring * fix: event deduping * fix: insert in bulk * fix: bug * refactor: return type of trigger * fix: unnest ids * fix: unnest tenant ids * fix: run ids in bulk insert * feat: two bulk inserts, one tx * fix: cruft * fix: bug * Update pkg/repository/v1/olap.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix: rework to avoid n^2 loop * fix: transaction timeout * fix: lint * fix: use error * fix: rm penultimate version * fix: rm penultimate test part ii * Feat: CEL-based filtering of events (#1676) * feat: add optional expression to workflow trigger event ref * feat: proto field for expression * feat: write and parse the expression * feat: wire up through put workflow ver request * feat: query * fix: naming * fix: cleanup * fix: rebase * Update pkg/repository/v1/trigger.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix: skip workflow on cel eval failure * fix: zero value * fix: cel evaluator * fix: usage * fix: naming + type * fix: rm event filter from v0 defn * feat: tests + fix typing * fix: usage * fix: construct input * feat: always write events --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix: select existing partitions * feat: add prio to push event request * feat: priority from pushed events * fix: missed a spot * fix: write events even if they're not tied to any workflows * fix: revert cel event filtering * fix: couple more * fix: simplify * feat: initial API work * chore: gen ts * feat: fe skeleton * feat: wiring up skeleton data * feat: hook * fix: bugs * fix: lint on gen * fix: couple more * feat: wire up counts * feat: initial events cols + styling * feat: layout * feat: styling * fix: cleanup * feat: use external ids on the FE * fix: separate openapi spec for new events route * fix: required param * fix: update queries and api * feat: event detail * fix: page * fix: rebase * tweak: table * feat: add events page to sidebar * feat: modify queries to allow fetching by triggering event * feat: add triggering event id to api * chore: lint * feat: wire up events api * fix: rm log * fix: gen * feat: wire up status counts * fix: rm time series * fix: rm state * fix: lint * fix: eof * chore: lint * feat: wire up filters * fix: lint * chore: api gen * feat: add events tables * fix: tweak PK * feat: migration * feat: gen models * fix: add external id col + index * fix: uuid pk * fix: types * chore: gen * feat: add index * Feat: Write events into OLAP tables (#1634) * feat: query for event creation * feat: olap impl * feat: wire up the olap event write * feat: goroutine? * feat: start wiring up inserts to triggers * fix: no `RETURNING` * fix: hack * fix: inner join * feat: attempt 2 * fix: return errors * chore: lint * fix: diff * feat: add new partitions * fix: eof * fix: write external ids into table * chore: gen * fix: wiring * fix: event deduping * fix: insert in bulk * fix: bug * refactor: return type of trigger * fix: unnest ids * fix: unnest tenant ids * fix: run ids in bulk insert * feat: two bulk inserts, one tx * fix: cruft * fix: bug * Update pkg/repository/v1/olap.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix: rework to avoid n^2 loop * fix: transaction timeout * fix: lint * fix: use error * fix: rm penultimate version * fix: rm penultimate test part ii * Feat: CEL-based filtering of events (#1676) * feat: add optional expression to workflow trigger event ref * feat: proto field for expression * feat: write and parse the expression * feat: wire up through put workflow ver request * feat: query * fix: naming * fix: cleanup * fix: rebase * Update pkg/repository/v1/trigger.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix: skip workflow on cel eval failure * fix: zero value * fix: cel evaluator * fix: usage * fix: naming + type * fix: rm event filter from v0 defn * feat: tests + fix typing * fix: usage * fix: construct input * feat: always write events --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix: select existing partitions * feat: add prio to push event request * feat: priority from pushed events * fix: missed a spot * fix: write events even if they're not tied to any workflows * fix: revert cel event filtering * fix: couple more * fix: simplify * fix: gen api * fix: gen * fix: more merge issues * chore: gen * fix: lockfile * fix: merge issues * chore: gen again * fix: rm unused fields from openapi spec --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix: migration ver * fix: insert trigger, event types * fix: bunch o refs * fix: migration * fix: queries * fix: finish wiring up inserts * fix: misc bugs * fix: fe filtering * chore: gen * fix: migration ver * chore: lint * fix: missed a couple * fix: whitespace * fix: formatting, gen * fix: uuid id for filters * feat: rest api for filters * fix: tag * feat: add event id, payload, and metadata to cel env * fix: rename resource hint to scope * chore: gen * fix: same conflict, different day * feat: send filter payload with input * fix: lint * fix: invert filter to "positive" case * fix: naming * feat: send payloads back with trigger data * fix: add case to check if no filters were found * fix: send additional meta back on bulk push * fix: cleanup from self review * fix: more small cleanup * feat: initial pr feedback * feat: validation * fix: populator * Feat: SDK changes for event filtering (#1677) * feat: query for event creation * feat: wire up the olap event write * feat: goroutine? * feat: start wiring up inserts to triggers * fix: no `RETURNING` * fix: hack * fix: inner join * feat: attempt 2 * fix: return errors * fix: diff * feat: add new partitions * fix: write external ids into table * chore: gen * fix: wiring * fix: event deduping * fix: insert in bulk * fix: unnest ids * fix: run ids in bulk insert * feat: two bulk inserts, one tx * fix: rework to avoid n^2 loop * feat: proto field for expression * fix: rm event filter from v0 defn * chore: gen python * Revert "fix: select existing partitions" This reverts commit fefbdd5122b85c5d807c3dce3aed7d974f01a7d8. * fix: rebase hell * feat: prio * chore: docs * feat: gen ts * feat: ts wiring * feat: go * fix: prio test bug * chore: gen * fix: validation bug * feat: extend events client * feat: e2e test * chore: docs * fix: test * fix: unwind event filter * fix: rm should skip * chore: gen * chore: gen * chore: gen * feat: resource hints + more e2e tests * fix: use `cached_property` for id * fix: raises * fix: rm print cruft * feat: wiring + e2e test * chore: gen * feat: wire up python sdk * feat: static payload in test * fix: use test run id in payload * fix: longer sleeps * feat: more tests * feat: intermediate work * feat: add validator for filter payload * fix: rm cruft * fix: event example * fix: event example * fix: e2e tests * fix: finish cleaning up tests * fix: __hash__ method * fix: copilot comments! * fix: apply namespaces to workflow names in a couple of the feature clients * fix: handle case where namespace is falsey * refactor: factor out * fix: all the other refs to namespaced things * fix: put `apply_namespace` on the client config * fix: namespace overrides * fix: implicitly use function name for hatchet task * fix: name * fix: refs * chore: ver * fix: durable tests * feat: add a changelog! * fix: changelog format * feat: start wiring up filters in ts * feat: scopes on event push * feat: wire up triggering event id filter * feat: initial ts e2e test work * fix: run the test * fix: drive-by bug in AI-gen slop * fix: test naming * feat: more test cleanup * fix: api * fix: ns override * fix: test + API * fix: lint * fix: cruft * chore: gen * fix: dont run in ci? * fix: wire up Go SDK * fix: compiler * fix: examples * fix: event snippet, I think * chore: docs * Revert "fix: examples" This reverts commitcbf33d6299. * Revert "fix: compiler" This reverts commit52336abeb2. * fix: add push opt funcs for prio and scope * chore: ver --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -43,6 +43,7 @@ func (t *EventService) EventCreateBulk(ctx echo.Context, request gen.EventCreate
|
||||
Data: dataBytes,
|
||||
AdditionalMetadata: additionalMetadata,
|
||||
Priority: event.Priority,
|
||||
Scope: event.Scope,
|
||||
}
|
||||
}
|
||||
events, err := t.config.Ingestor.BulkIngestEvent(ctx.Request().Context(), tenant, eventOpts)
|
||||
|
||||
@@ -32,7 +32,7 @@ func (t *EventService) EventCreate(ctx echo.Context, request gen.EventCreateRequ
|
||||
}
|
||||
}
|
||||
|
||||
newEvent, err := t.config.Ingestor.IngestEvent(ctx.Request().Context(), tenant, request.Body.Key, dataBytes, additionalMetadata, request.Body.Priority)
|
||||
newEvent, err := t.config.Ingestor.IngestEvent(ctx.Request().Context(), tenant, request.Body.Key, dataBytes, additionalMetadata, request.Body.Priority, request.Body.Scope)
|
||||
|
||||
if err != nil {
|
||||
if err == metered.ErrResourceExhausted {
|
||||
|
||||
@@ -64,7 +64,7 @@ func (i *IngestorsService) SnsUpdate(ctx echo.Context, req gen.SnsUpdateRequestO
|
||||
return nil, err
|
||||
}
|
||||
default:
|
||||
_, err := i.config.Ingestor.IngestEvent(ctx.Request().Context(), tenant, req.Event, body, nil, nil)
|
||||
_, err := i.config.Ingestor.IngestEvent(ctx.Request().Context(), tenant, req.Event, body, nil, nil, nil)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
49
api/v1/server/handlers/v1/filters/create.go
Normal file
49
api/v1/server/handlers/v1/filters/create.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package filtersv1
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/hatchet-dev/hatchet/api/v1/server/oas/apierrors"
|
||||
"github.com/hatchet-dev/hatchet/api/v1/server/oas/gen"
|
||||
"github.com/hatchet-dev/hatchet/api/v1/server/oas/transformers/v1"
|
||||
"github.com/hatchet-dev/hatchet/pkg/repository/postgres/dbsqlc"
|
||||
"github.com/hatchet-dev/hatchet/pkg/repository/postgres/sqlchelpers"
|
||||
v1 "github.com/hatchet-dev/hatchet/pkg/repository/v1"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
func (t *V1FiltersService) V1FilterCreate(ctx echo.Context, request gen.V1FilterCreateRequestObject) (gen.V1FilterCreateResponseObject, error) {
|
||||
tenant := ctx.Get("tenant").(*dbsqlc.Tenant)
|
||||
|
||||
var payload []byte
|
||||
if request.Body.Payload != nil {
|
||||
marshalledPayload, err := json.Marshal(request.Body.Payload)
|
||||
|
||||
if err != nil {
|
||||
return gen.V1FilterCreate400JSONResponse(apierrors.NewAPIErrors("failed to marshal payload to json")), nil
|
||||
}
|
||||
payload = marshalledPayload
|
||||
}
|
||||
|
||||
params := v1.CreateFilterOpts{
|
||||
Workflowid: sqlchelpers.UUIDFromStr(request.Body.WorkflowId.String()),
|
||||
Scope: request.Body.Scope,
|
||||
Expression: request.Body.Expression,
|
||||
Payload: payload,
|
||||
}
|
||||
|
||||
filter, err := t.config.V1.Filters().CreateFilter(
|
||||
ctx.Request().Context(),
|
||||
tenant.ID.String(),
|
||||
params,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create filter")
|
||||
}
|
||||
|
||||
transformed := transformers.ToV1Filter(filter)
|
||||
|
||||
return gen.V1FilterCreate200JSONResponse(transformed), nil
|
||||
}
|
||||
29
api/v1/server/handlers/v1/filters/delete.go
Normal file
29
api/v1/server/handlers/v1/filters/delete.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package filtersv1
|
||||
|
||||
import (
|
||||
"github.com/hatchet-dev/hatchet/api/v1/server/oas/apierrors"
|
||||
"github.com/hatchet-dev/hatchet/api/v1/server/oas/gen"
|
||||
"github.com/hatchet-dev/hatchet/api/v1/server/oas/transformers/v1"
|
||||
"github.com/hatchet-dev/hatchet/pkg/repository/v1/sqlcv1"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
func (t *V1FiltersService) V1FilterDelete(ctx echo.Context, request gen.V1FilterDeleteRequestObject) (gen.V1FilterDeleteResponseObject, error) {
|
||||
filter := ctx.Get("v1-filter").(*sqlcv1.V1Filter)
|
||||
|
||||
filter, err := t.config.V1.Filters().DeleteFilter(
|
||||
ctx.Request().Context(),
|
||||
filter.TenantID.String(),
|
||||
filter.ID.String(),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return gen.V1FilterDelete400JSONResponse(apierrors.NewAPIErrors("failed to delete filter")), nil
|
||||
}
|
||||
|
||||
transformed := transformers.ToV1Filter(filter)
|
||||
|
||||
return gen.V1FilterDelete200JSONResponse(
|
||||
transformed,
|
||||
), nil
|
||||
}
|
||||
18
api/v1/server/handlers/v1/filters/get.go
Normal file
18
api/v1/server/handlers/v1/filters/get.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package filtersv1
|
||||
|
||||
import (
|
||||
"github.com/hatchet-dev/hatchet/api/v1/server/oas/gen"
|
||||
"github.com/hatchet-dev/hatchet/api/v1/server/oas/transformers/v1"
|
||||
"github.com/hatchet-dev/hatchet/pkg/repository/v1/sqlcv1"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
func (t *V1FiltersService) V1FilterGet(ctx echo.Context, request gen.V1FilterGetRequestObject) (gen.V1FilterGetResponseObject, error) {
|
||||
filter := ctx.Get("v1-filter").(*sqlcv1.V1Filter)
|
||||
|
||||
transformed := transformers.ToV1Filter(filter)
|
||||
|
||||
return gen.V1FilterGet200JSONResponse(
|
||||
transformed,
|
||||
), nil
|
||||
}
|
||||
68
api/v1/server/handlers/v1/filters/list.go
Normal file
68
api/v1/server/handlers/v1/filters/list.go
Normal file
@@ -0,0 +1,68 @@
|
||||
package filtersv1
|
||||
|
||||
import (
|
||||
"github.com/hatchet-dev/hatchet/api/v1/server/oas/apierrors"
|
||||
"github.com/hatchet-dev/hatchet/api/v1/server/oas/gen"
|
||||
"github.com/hatchet-dev/hatchet/api/v1/server/oas/transformers/v1"
|
||||
"github.com/hatchet-dev/hatchet/pkg/repository/postgres/dbsqlc"
|
||||
"github.com/hatchet-dev/hatchet/pkg/repository/postgres/sqlchelpers"
|
||||
v1 "github.com/hatchet-dev/hatchet/pkg/repository/v1"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
func (t *V1FiltersService) V1FilterList(ctx echo.Context, request gen.V1FilterListRequestObject) (gen.V1FilterListResponseObject, error) {
|
||||
tenant := ctx.Get("tenant").(*dbsqlc.Tenant)
|
||||
|
||||
scopes := request.Params.Scopes
|
||||
workflowIds := request.Params.WorkflowIds
|
||||
|
||||
if scopes != nil && workflowIds != nil && len(*scopes) != len(*workflowIds) {
|
||||
return gen.V1FilterList400JSONResponse(apierrors.NewAPIErrors("scopes and workflow ids must be the same length")), nil
|
||||
}
|
||||
|
||||
numScopesOrIds := 1
|
||||
|
||||
if scopes != nil {
|
||||
numScopesOrIds = len(*scopes)
|
||||
} else if workflowIds != nil {
|
||||
numScopesOrIds = len(*workflowIds)
|
||||
}
|
||||
|
||||
workflowIdParams := make([]pgtype.UUID, numScopesOrIds)
|
||||
|
||||
if workflowIds != nil {
|
||||
for ix, id := range *workflowIds {
|
||||
workflowIdParams[ix] = sqlchelpers.UUIDFromStr(id.String())
|
||||
}
|
||||
}
|
||||
|
||||
scopeParams := make([]*string, numScopesOrIds)
|
||||
|
||||
if scopes != nil {
|
||||
for ix, scope := range *scopes {
|
||||
scopeParams[ix] = &scope
|
||||
}
|
||||
}
|
||||
|
||||
filters, err := t.config.V1.Filters().ListFilters(
|
||||
ctx.Request().Context(),
|
||||
tenant.ID.String(),
|
||||
v1.ListFiltersOpts{
|
||||
WorkflowIds: workflowIdParams,
|
||||
Scopes: scopeParams,
|
||||
FilterLimit: request.Params.Limit,
|
||||
FilterOffset: request.Params.Offset,
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return gen.V1FilterList400JSONResponse(apierrors.NewAPIErrors("failed to list filters")), nil
|
||||
}
|
||||
|
||||
transformed := transformers.ToV1FilterList(filters)
|
||||
|
||||
return gen.V1FilterList200JSONResponse(
|
||||
transformed,
|
||||
), nil
|
||||
}
|
||||
16
api/v1/server/handlers/v1/filters/service.go
Normal file
16
api/v1/server/handlers/v1/filters/service.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package filtersv1
|
||||
|
||||
import (
|
||||
"github.com/hatchet-dev/hatchet/pkg/config/server"
|
||||
)
|
||||
|
||||
type V1FiltersService struct {
|
||||
config *server.ServerConfig
|
||||
}
|
||||
|
||||
func NewV1FiltersService(config *server.ServerConfig) *V1FiltersService {
|
||||
|
||||
return &V1FiltersService{
|
||||
config: config,
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
40
api/v1/server/oas/transformers/v1/filters.go
Normal file
40
api/v1/server/oas/transformers/v1/filters.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package transformers
|
||||
|
||||
import (
|
||||
"github.com/google/uuid"
|
||||
"github.com/hatchet-dev/hatchet/api/v1/server/oas/gen"
|
||||
"github.com/hatchet-dev/hatchet/pkg/repository/v1/sqlcv1"
|
||||
)
|
||||
|
||||
func ToV1Filter(filter *sqlcv1.V1Filter) gen.V1Filter {
|
||||
var payload map[string]interface{}
|
||||
|
||||
if filter.Payload != nil {
|
||||
payload = jsonToMap(filter.Payload)
|
||||
}
|
||||
|
||||
return gen.V1Filter{
|
||||
Expression: filter.Expression,
|
||||
Metadata: gen.APIResourceMeta{
|
||||
CreatedAt: filter.InsertedAt.Time,
|
||||
UpdatedAt: filter.UpdatedAt.Time,
|
||||
Id: filter.ID.String(),
|
||||
},
|
||||
Payload: payload,
|
||||
Scope: filter.Scope,
|
||||
TenantId: filter.TenantID.String(),
|
||||
WorkflowId: uuid.MustParse(filter.WorkflowID.String()),
|
||||
}
|
||||
}
|
||||
|
||||
func ToV1FilterList(filters []*sqlcv1.V1Filter) gen.V1FilterList {
|
||||
rows := make([]gen.V1Filter, len(filters))
|
||||
|
||||
for i, filter := range filters {
|
||||
rows[i] = ToV1Filter(filter)
|
||||
}
|
||||
|
||||
return gen.V1FilterList{
|
||||
Rows: &rows,
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,7 @@ import (
|
||||
"github.com/hatchet-dev/hatchet/api/v1/server/handlers/tenants"
|
||||
"github.com/hatchet-dev/hatchet/api/v1/server/handlers/users"
|
||||
eventsv1 "github.com/hatchet-dev/hatchet/api/v1/server/handlers/v1/events"
|
||||
filtersv1 "github.com/hatchet-dev/hatchet/api/v1/server/handlers/v1/filters"
|
||||
"github.com/hatchet-dev/hatchet/api/v1/server/handlers/v1/tasks"
|
||||
workflowrunsv1 "github.com/hatchet-dev/hatchet/api/v1/server/handlers/v1/workflow-runs"
|
||||
webhookworker "github.com/hatchet-dev/hatchet/api/v1/server/handlers/webhook-worker"
|
||||
@@ -61,6 +62,7 @@ type apiService struct {
|
||||
*tasks.TasksService
|
||||
*workflowrunsv1.V1WorkflowRunsService
|
||||
*eventsv1.V1EventsService
|
||||
*filtersv1.V1FiltersService
|
||||
}
|
||||
|
||||
func newAPIService(config *server.ServerConfig) *apiService {
|
||||
@@ -84,6 +86,7 @@ func newAPIService(config *server.ServerConfig) *apiService {
|
||||
TasksService: tasks.NewTasksService(config),
|
||||
V1WorkflowRunsService: workflowrunsv1.NewV1WorkflowRunsService(config),
|
||||
V1EventsService: eventsv1.NewV1EventsService(config),
|
||||
V1FiltersService: filtersv1.NewV1FiltersService(config),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -390,6 +393,19 @@ func (t *APIServer) registerSpec(g *echo.Group, spec *openapi3.T) (*populator.Po
|
||||
|
||||
return workflowRun, sqlchelpers.UUIDToStr(workflowRun.WorkflowRun.TenantID), nil
|
||||
})
|
||||
populatorMW.RegisterGetter("v1-filter", func(config *server.ServerConfig, parentId, id string) (result interface{}, uniqueParentId string, err error) {
|
||||
filter, err := t.config.V1.Filters().GetFilter(
|
||||
context.Background(),
|
||||
parentId,
|
||||
id,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
|
||||
return filter, sqlchelpers.UUIDToStr(filter.TenantID), nil
|
||||
})
|
||||
|
||||
authnMW := authn.NewAuthN(t.config)
|
||||
authzMW := authz.NewAuthZ(t.config)
|
||||
|
||||
Reference in New Issue
Block a user