MCPcopy
hub / github.com/ory/keto / deleteRelations

Method deleteRelations

internal/relationtuple/transact_server.go:198–238  ·  view source on GitHub ↗

swagger:route DELETE /admin/relation-tuples relationship deleteRelationships # Delete Relationships Use this endpoint to delete relationships Consumes: - application/x-www-form-urlencoded Produces: - application/json Schemes: http, https Responses: 204: emptyResponse 400: errorGen

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

196// Extensions:
197// x-ory-ratelimit-bucket: keto-admin-high
198func (h *Handler) deleteRelations(w http.ResponseWriter, r *http.Request) {
199 ctx := r.Context()
200
201 if err := validate.All(r,
202 validate.NoExtraQueryParams(ketoapi.RelationQueryKeys...),
203 validate.QueryParamsContainsOneOf(ketoapi.NamespaceKey),
204 validate.HasEmptyBody(),
205 ); err != nil {
206 h.d.Writer().WriteError(w, r, err)
207 return
208 }
209
210 q := r.URL.Query()
211 query, err := (&ketoapi.RelationQuery{}).FromURLQuery(q)
212 if err != nil {
213 h.d.Writer().WriteError(w, r, herodot.ErrBadRequest.WithError(err.Error()))
214 return
215 }
216
217 l := h.d.Logger()
218 for k := range q {
219 l = l.WithField(k, q.Get(k))
220 }
221 l.Debug("deleting relationships")
222
223 iq, err := h.d.ReadOnlyMapper().FromQuery(ctx, query)
224 if err != nil {
225 h.d.Logger().WithError(err).Errorf("could not map fields to UUIDs")
226 h.d.Writer().WriteError(w, r, err)
227 return
228 }
229 if err := h.d.RelationTupleManager().DeleteAllRelationTuples(ctx, iq); err != nil {
230 l.WithError(err).Errorf("got an error while deleting relationships")
231 h.d.Writer().WriteError(w, r, herodot.ErrInternalServerError.WithError(err.Error()))
232 return
233 }
234
235 trace.SpanFromContext(ctx).AddEvent(events.NewRelationtuplesDeleted(ctx))
236
237 w.WriteHeader(http.StatusNoContent)
238}
239
240func internalTuplesWithAction(deltas []*ketoapi.PatchDelta, action ketoapi.PatchAction) (filtered []*ketoapi.RelationTuple) {
241 for _, d := range deltas {

Callers

nothing calls this directly

Calls 15

AllFunction · 0.92
NoExtraQueryParamsFunction · 0.92
QueryParamsContainsOneOfFunction · 0.92
HasEmptyBodyFunction · 0.92
NewRelationtuplesDeletedFunction · 0.92
WithErrorMethod · 0.80
WithFieldMethod · 0.80
DebugMethod · 0.80
FromQueryMethod · 0.80
WriterMethod · 0.65
LoggerMethod · 0.65
ReadOnlyMapperMethod · 0.65

Tested by

no test coverage detected