Skip to content

Commit

Permalink
feat: delete user endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe authored and moshloop committed Sep 12, 2024
1 parent 94a300e commit c52c66f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
21 changes: 21 additions & 0 deletions echo/people.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,24 @@ func (t *PersonController) UpdatePerson(c echov4.Context) error {

return c.JSON(http.StatusOK, identity.Traits)
}

func (t *PersonController) DeletePerson(c echov4.Context) error {
ctx := c.Request().Context().(context.Context)

if vars.AuthMode != auth.Kratos {
return api.Errorf(api.EINVALID, "deleting a person is only supported when using Kratos auth mode")
}

id := c.Param("id")
response, err := t.kratos.IdentityApi.DeleteIdentity(ctx, id).Execute()
if err != nil {
var clientErr *client.GenericOpenAPIError
if errors.As(err, &clientErr) {
return c.String(http.StatusBadRequest, string(clientErr.Body()))
}

return err
}

return c.Stream(response.StatusCode, "application/json", response.Body)
}
1 change: 1 addition & 0 deletions echo/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ func New(ctx context.Context) *echov4.Echo {

personController := PersonController{kratos: auth.NewAPIClient(auth.KratosAPI)}
e.POST("/people/update", personController.UpdatePerson, rbac.Authorization(rbac.ObjectPeople, rbac.ActionUpdate))
e.DELETE("/people/:id", personController.DeletePerson, rbac.Authorization(rbac.ObjectPeople, rbac.ActionDelete))

if dutyApi.DefaultConfig.Postgrest.URL != "" {
Forward(ctx, e, "/db", dutyApi.DefaultConfig.Postgrest.URL,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/containrrr/shoutrrr v0.8.0
github.com/fergusstrange/embedded-postgres v1.25.0 // indirect
github.com/flanksource/commons v1.29.10
github.com/flanksource/duty v1.0.639
github.com/flanksource/duty v1.0.640
github.com/flanksource/gomplate/v3 v3.24.30
github.com/flanksource/kopper v1.0.9
github.com/gomarkdown/markdown v0.0.0-20240419095408-642f0ee99ae2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -877,8 +877,8 @@ github.com/flanksource/artifacts v1.0.14 h1:Vv70bccsae0MwGaf/uSPp34J5V1/PyKfct9z
github.com/flanksource/artifacts v1.0.14/go.mod h1:qHVCnQu5k50aWNJ5UhpcAKEl7pAzqUrFFKGSm147G70=
github.com/flanksource/commons v1.29.10 h1:T/S95Pl8kASEFvQjQ7fJjTUqeVdhxQXg1vfkULTYFJQ=
github.com/flanksource/commons v1.29.10/go.mod h1:iTbrXOSp3Spv570Nly97D/U9cQjLZoVlmWCXqWzsvRU=
github.com/flanksource/duty v1.0.639 h1:Dzx8sp7luUgJVh2R3XGbSaTDdIJPuuNQox/8O3vLm1I=
github.com/flanksource/duty v1.0.639/go.mod h1:Oj9zIX94CR2U+nmnt97gNLMrsBWILyIhIBeJynIIgqE=
github.com/flanksource/duty v1.0.640 h1:hv9iQUlP2fOux8SErSj0s93x6FO25JD+noXWtkujxY4=
github.com/flanksource/duty v1.0.640/go.mod h1:Oj9zIX94CR2U+nmnt97gNLMrsBWILyIhIBeJynIIgqE=
github.com/flanksource/gomplate/v3 v3.20.4/go.mod h1:27BNWhzzSjDed1z8YShO6W+z6G9oZXuxfNFGd/iGSdc=
github.com/flanksource/gomplate/v3 v3.24.30 h1:6Y25KnAMX4iCuEXe1C8d1kB2PdV+zD1ZulZrv6DV14Q=
github.com/flanksource/gomplate/v3 v3.24.30/go.mod h1:/lAM7+fkcCCfghCAjzdCqwgWxN5Ow8Sk6nkdFPjejCE=
Expand Down

0 comments on commit c52c66f

Please sign in to comment.