Skip to content

Commit

Permalink
Merge branch 'feat--demo-page' of github.com:hatchet-dev/hatchet into…
Browse files Browse the repository at this point in the history
… feat--demo-page
  • Loading branch information
abelanger5 committed Jun 27, 2024
2 parents 3874cd4 + 92eba57 commit 6179f88
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 41 deletions.
22 changes: 2 additions & 20 deletions api/v1/server/handlers/api-tokens/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,10 @@ package apitokens
import (
"github.com/labstack/echo/v4"

"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/pkg/repository/prisma/db"
)

func (a *APITokenService) ApiTokenCreate(ctx echo.Context, request gen.ApiTokenCreateRequestObject) (gen.ApiTokenCreateResponseObject, error) {
tenant := ctx.Get("tenant").(*db.TenantModel)

// validate the request
if apiErrors, err := a.config.Validator.ValidateAPI(request.Body); err != nil {
return nil, err
} else if apiErrors != nil {
return gen.ApiTokenCreate400JSONResponse(*apiErrors), nil
}

token, err := a.config.Auth.JWTManager.GenerateTenantToken(ctx.Request().Context(), tenant.ID, request.Body.Name)

if err != nil {
return nil, err
}

// This is the only time the token is sent over the API
return gen.ApiTokenCreate200JSONResponse{
Token: token.Token,
}, nil
return gen.ApiTokenCreate403JSONResponse(apierrors.NewAPIErrors("this is disabled for the demo")), nil
}
12 changes: 2 additions & 10 deletions api/v1/server/handlers/api-tokens/revoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,10 @@ package apitokens
import (
"github.com/labstack/echo/v4"

"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/pkg/repository/prisma/db"
)

func (a *APITokenService) ApiTokenUpdateRevoke(ctx echo.Context, request gen.ApiTokenUpdateRevokeRequestObject) (gen.ApiTokenUpdateRevokeResponseObject, error) {
apiToken := ctx.Get("api-token").(*db.APITokenModel)

err := a.config.APIRepository.APIToken().RevokeAPIToken(apiToken.ID)

if err != nil {
return nil, err
}

return gen.ApiTokenUpdateRevoke204Response{}, nil
return gen.ApiTokenUpdateRevoke403JSONResponse(apierrors.NewAPIErrors("this is disabled for the demo")), nil
}
13 changes: 2 additions & 11 deletions api/v1/server/handlers/workflows/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,10 @@ package workflows
import (
"github.com/labstack/echo/v4"

"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/pkg/repository/prisma/db"
)

func (t *WorkflowService) WorkflowDelete(ctx echo.Context, request gen.WorkflowDeleteRequestObject) (gen.WorkflowDeleteResponseObject, error) {
tenant := ctx.Get("tenant").(*db.TenantModel)
workflow := ctx.Get("workflow").(*db.WorkflowModel)

workflow, err := t.config.APIRepository.Workflow().DeleteWorkflow(tenant.ID, workflow.ID)

if err != nil {
return nil, err
}

return gen.WorkflowDelete204Response{}, nil
return gen.WorkflowDelete403JSONResponse(apierrors.NewAPIErrors("this is disabled for the demo")), nil
}

0 comments on commit 6179f88

Please sign in to comment.