Skip to content

Commit

Permalink
Add Trace logs
Browse files Browse the repository at this point in the history
  • Loading branch information
benpate committed Aug 10, 2024
1 parent a9c24fc commit c1fe394
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions validator/deleted-objects.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package validator

import (
"io"
"net/http"

"github.com/benpate/derp"
"github.com/benpate/hannibal/streams"
"github.com/benpate/hannibal/vocab"
"github.com/benpate/remote"
"github.com/davecgh/go-spew/spew"
"github.com/rs/zerolog/log"
)

// DeletedObject validates "delete" activities by trying to retrieve the original object.
Expand Down Expand Up @@ -34,12 +37,16 @@ func (v DeletedObject) Validate(request *http.Request, document *streams.Documen
return ResultInvalid
}

log.Trace().Str("objectID", objectID).Str("location", location).Msg("Validating DeletedObject")

// Try to retrieve the original document
txn := remote.Get(objectID).
Header("Accept", "application/activity+json")

if err := txn.Send(); err != nil {

log.Trace().Err(err).Int("code", derp.ErrorCode(err)).Str("location", location).Msg("Received error code")

// If the document is marked "gone" or "not found",
// then this "delete" transaction is valid.
switch derp.ErrorCode(err) {
Expand All @@ -52,6 +59,10 @@ func (v DeletedObject) Validate(request *http.Request, document *streams.Documen
return ResultUnknown
}

log.Trace().Str("location", location).Msg("Delete is invalid / document still exists")
body, err := io.ReadAll(txn.Response().Body)
spew.Dump(string(body), err)

// Fall through means that the document still exists, so the "delete" transaction is invalid.
return ResultInvalid
}

0 comments on commit c1fe394

Please sign in to comment.