diff options
author | 2021-10-11 05:37:33 -0700 | |
---|---|---|
committer | 2021-10-11 14:37:33 +0200 | |
commit | 083099a9575f8b2fac22c1d4a51a9dd0e2201243 (patch) | |
tree | d1787aa544679c433f797d2313ce532250fe574f /internal/federation | |
parent | Handle forwarded messages (#273) (diff) | |
download | gotosocial-083099a9575f8b2fac22c1d4a51a9dd0e2201243.tar.xz |
reference global logrus (#274)
* reference logrus' global logger instead of passing and storing a logger reference everywhere
* always directly use global logrus logger instead of referencing an instance
* test suites should also directly use the global logrus logger
* rename gin logging function to clarify that it's middleware
* correct comments which erroneously referenced removed logger parameter
* setting log level for tests now uses logrus' exported type instead of the string value, to guarantee error isn't possible
Diffstat (limited to 'internal/federation')
24 files changed, 54 insertions, 76 deletions
diff --git a/internal/federation/authenticate.go b/internal/federation/authenticate.go index da5d2b93d..78cfe2b5d 100644 --- a/internal/federation/authenticate.go +++ b/internal/federation/authenticate.go @@ -25,6 +25,7 @@ import ( "encoding/pem" "errors" "fmt" + "github.com/sirupsen/logrus" "net/url" "strings" @@ -112,7 +113,7 @@ func getPublicKeyFromResponse(c context.Context, b []byte, keyID *url.URL) (voca // Also note that this function *does not* dereference the remote account that the signature key is associated with. // Other functions should use the returned URL to dereference the remote account, if required. func (f *federator) AuthenticateFederatedRequest(ctx context.Context, requestedUsername string) (*url.URL, bool, error) { - l := f.log.WithField("func", "AuthenticateFederatedRequest") + l := logrus.WithField("func", "AuthenticateFederatedRequest") var publicKey interface{} var pkOwnerURI *url.URL diff --git a/internal/federation/dereferencing/account.go b/internal/federation/dereferencing/account.go index 6acb3b06d..7d8e2ff94 100644 --- a/internal/federation/dereferencing/account.go +++ b/internal/federation/dereferencing/account.go @@ -59,7 +59,7 @@ func (d *deref) EnrichRemoteAccount(ctx context.Context, username string, accoun updated, err := d.db.UpdateAccount(ctx, account) if err != nil { - d.log.Errorf("EnrichRemoteAccount: error updating account: %s", err) + logrus.Errorf("EnrichRemoteAccount: error updating account: %s", err) return account, nil } @@ -203,7 +203,7 @@ func (d *deref) dereferenceAccountable(ctx context.Context, username string, rem // PopulateAccountFields populates any fields on the given account that weren't populated by the initial // dereferencing. This includes things like header and avatar etc. func (d *deref) PopulateAccountFields(ctx context.Context, account *gtsmodel.Account, requestingUsername string, refresh bool) error { - l := d.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "PopulateAccountFields", "requestingUsername": requestingUsername, }) diff --git a/internal/federation/dereferencing/attachment.go b/internal/federation/dereferencing/attachment.go index fd0cfba18..3a4213cdb 100644 --- a/internal/federation/dereferencing/attachment.go +++ b/internal/federation/dereferencing/attachment.go @@ -34,7 +34,7 @@ func (d *deref) GetRemoteAttachment(ctx context.Context, requestingUsername stri } remoteAttachmentURL := minAttachment.RemoteURL - l := d.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "username": requestingUsername, "remoteAttachmentURL": remoteAttachmentURL, }) diff --git a/internal/federation/dereferencing/dereferencer.go b/internal/federation/dereferencing/dereferencer.go index ea347b30e..76fd830a2 100644 --- a/internal/federation/dereferencing/dereferencer.go +++ b/internal/federation/dereferencing/dereferencer.go @@ -23,7 +23,6 @@ import ( "net/url" "sync" - "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/ap" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" @@ -79,7 +78,6 @@ type Dereferencer interface { } type deref struct { - log *logrus.Logger db db.DB typeConverter typeutils.TypeConverter transportController transport.Controller @@ -90,9 +88,8 @@ type deref struct { } // NewDereferencer returns a Dereferencer initialized with the given parameters. -func NewDereferencer(config *config.Config, db db.DB, typeConverter typeutils.TypeConverter, transportController transport.Controller, mediaHandler media.Handler, log *logrus.Logger) Dereferencer { +func NewDereferencer(config *config.Config, db db.DB, typeConverter typeutils.TypeConverter, transportController transport.Controller, mediaHandler media.Handler) Dereferencer { return &deref{ - log: log, db: db, typeConverter: typeConverter, transportController: transportController, diff --git a/internal/federation/dereferencing/dereferencer_test.go b/internal/federation/dereferencing/dereferencer_test.go index 0eeabc64a..051bf95ce 100644 --- a/internal/federation/dereferencing/dereferencer_test.go +++ b/internal/federation/dereferencing/dereferencer_test.go @@ -41,7 +41,6 @@ type DereferencerStandardTestSuite struct { suite.Suite config *config.Config db db.DB - log *logrus.Logger storage *kv.KVStore testRemoteStatuses map[string]vocab.ActivityStreamsNote @@ -64,14 +63,9 @@ func (suite *DereferencerStandardTestSuite) SetupSuite() { func (suite *DereferencerStandardTestSuite) SetupTest() { suite.config = testrig.NewTestConfig() suite.db = testrig.NewTestDB() - suite.log = testrig.NewTestLog() + testrig.InitTestLog() suite.storage = testrig.NewTestStorage() - suite.dereferencer = dereferencing.NewDereferencer(suite.config, - suite.db, - testrig.NewTestTypeConverter(suite.db), - suite.mockTransportController(), - testrig.NewTestMediaHandler(suite.db, suite.storage), - suite.log) + suite.dereferencer = dereferencing.NewDereferencer(suite.config, suite.db, testrig.NewTestTypeConverter(suite.db), suite.mockTransportController(), testrig.NewTestMediaHandler(suite.db, suite.storage)) testrig.StandardDBSetup(suite.db, nil) } @@ -85,7 +79,7 @@ func (suite *DereferencerStandardTestSuite) TearDownTest() { // or note or attachment that we have stored, then just a 200 code will be returned, with an empty body. func (suite *DereferencerStandardTestSuite) mockTransportController() transport.Controller { do := func(req *http.Request) (*http.Response, error) { - suite.log.Debugf("received request for %s", req.URL) + logrus.Debugf("received request for %s", req.URL) responseBytes := []byte{} responseType := "" @@ -140,7 +134,7 @@ func (suite *DereferencerStandardTestSuite) mockTransportController() transport. if len(responseBytes) != 0 { // we found something, so print what we're going to return - suite.log.Debugf("returning response %s", string(responseBytes)) + logrus.Debugf("returning response %s", string(responseBytes)) } responseLength = len(responseBytes) diff --git a/internal/federation/dereferencing/status.go b/internal/federation/dereferencing/status.go index 435bc9217..c4102a8f3 100644 --- a/internal/federation/dereferencing/status.go +++ b/internal/federation/dereferencing/status.go @@ -236,7 +236,7 @@ func (d *deref) dereferenceStatusable(ctx context.Context, username string, remo // and attach them to the status. The status itself will not be added to the database yet, // that's up the caller to do. func (d *deref) populateStatusFields(ctx context.Context, status *gtsmodel.Status, requestingUsername string, includeParent bool) error { - l := d.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "dereferenceStatusFields", "status": fmt.Sprintf("%+v", status), }) @@ -292,8 +292,6 @@ func (d *deref) populateStatusFields(ctx context.Context, status *gtsmodel.Statu } func (d *deref) populateStatusMentions(ctx context.Context, status *gtsmodel.Status, requestingUsername string) error { - l := d.log - // At this point, mentions should have the namestring and mentionedAccountURI set on them. // We can use these to find the accounts. @@ -302,20 +300,20 @@ func (d *deref) populateStatusMentions(ctx context.Context, status *gtsmodel.Sta for _, m := range status.Mentions { if m.ID != "" { // we've already populated this mention, since it has an ID - l.Debug("populateStatusMentions: mention already populated") + logrus.Debug("populateStatusMentions: mention already populated") mentionIDs = append(mentionIDs, m.ID) newMentions = append(newMentions, m) continue } if m.TargetAccountURI == "" { - l.Debug("populateStatusMentions: target URI not set on mention") + logrus.Debug("populateStatusMentions: target URI not set on mention") continue } targetAccountURI, err := url.Parse(m.TargetAccountURI) if err != nil { - l.Debugf("populateStatusMentions: error parsing mentioned account uri %s: %s", m.TargetAccountURI, err) + logrus.Debugf("populateStatusMentions: error parsing mentioned account uri %s: %s", m.TargetAccountURI, err) continue } @@ -326,7 +324,7 @@ func (d *deref) populateStatusMentions(ctx context.Context, status *gtsmodel.Sta if a, err := d.db.GetAccountByURI(ctx, targetAccountURI.String()); err != nil { errs = append(errs, err.Error()) } else { - l.Debugf("populateStatusMentions: got target account %s with id %s through GetAccountByURI", targetAccountURI, a.ID) + logrus.Debugf("populateStatusMentions: got target account %s with id %s through GetAccountByURI", targetAccountURI, a.ID) targetAccount = a } @@ -336,13 +334,13 @@ func (d *deref) populateStatusMentions(ctx context.Context, status *gtsmodel.Sta if a, _, err := d.GetRemoteAccount(ctx, requestingUsername, targetAccountURI, false); err != nil { errs = append(errs, err.Error()) } else { - l.Debugf("populateStatusMentions: got target account %s with id %s through GetRemoteAccount", targetAccountURI, a.ID) + logrus.Debugf("populateStatusMentions: got target account %s with id %s through GetRemoteAccount", targetAccountURI, a.ID) targetAccount = a } } if targetAccount == nil { - l.Debugf("populateStatusMentions: couldn't get target account %s: %s", m.TargetAccountURI, strings.Join(errs, " : ")) + logrus.Debugf("populateStatusMentions: couldn't get target account %s: %s", m.TargetAccountURI, strings.Join(errs, " : ")) continue } @@ -382,8 +380,6 @@ func (d *deref) populateStatusMentions(ctx context.Context, status *gtsmodel.Sta } func (d *deref) populateStatusAttachments(ctx context.Context, status *gtsmodel.Status, requestingUsername string) error { - l := d.log - // At this point we should know: // * the media type of the file we're looking for (a.File.ContentType) // * the file type (a.Type) @@ -399,7 +395,7 @@ func (d *deref) populateStatusAttachments(ctx context.Context, status *gtsmodel. attachment, err := d.GetRemoteAttachment(ctx, requestingUsername, a) if err != nil { - l.Errorf("populateStatusAttachments: couldn't get remote attachment %s: %s", a.RemoteURL, err) + logrus.Errorf("populateStatusAttachments: couldn't get remote attachment %s: %s", a.RemoteURL, err) continue } diff --git a/internal/federation/dereferencing/thread.go b/internal/federation/dereferencing/thread.go index 87cc42918..4912bc591 100644 --- a/internal/federation/dereferencing/thread.go +++ b/internal/federation/dereferencing/thread.go @@ -35,7 +35,7 @@ import ( // presented by remote instances as part of their replies collections, and will likely involve making several calls to // multiple different hosts. func (d *deref) DereferenceThread(ctx context.Context, username string, statusIRI *url.URL) error { - l := d.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "DereferenceThread", "username": username, "statusIRI": statusIRI.String(), @@ -69,7 +69,7 @@ func (d *deref) DereferenceThread(ctx context.Context, username string, statusIR // iterateAncestors has the goal of reaching the oldest ancestor of a given status, and stashing all statuses along the way. func (d *deref) iterateAncestors(ctx context.Context, username string, statusIRI url.URL) error { - l := d.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "iterateAncestors", "username": username, "statusIRI": statusIRI.String(), @@ -121,7 +121,7 @@ func (d *deref) iterateAncestors(ctx context.Context, username string, statusIRI } func (d *deref) iterateDescendants(ctx context.Context, username string, statusIRI url.URL, statusable ap.Statusable) error { - l := d.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "iterateDescendants", "username": username, "statusIRI": statusIRI.String(), diff --git a/internal/federation/federatingdb/accept.go b/internal/federation/federatingdb/accept.go index 0d2d3a270..8d295161c 100644 --- a/internal/federation/federatingdb/accept.go +++ b/internal/federation/federatingdb/accept.go @@ -33,13 +33,13 @@ import ( ) func (f *federatingDB) Accept(ctx context.Context, accept vocab.ActivityStreamsAccept) error { - l := f.log.WithFields( + l := logrus.WithFields( logrus.Fields{ "func": "Accept", }, ) - if f.log.Level >= logrus.DebugLevel { + if logrus.GetLevel() >= logrus.DebugLevel { i, err := marshalItem(accept) if err != nil { return err diff --git a/internal/federation/federatingdb/announce.go b/internal/federation/federatingdb/announce.go index 49ec84509..7a40cd051 100644 --- a/internal/federation/federatingdb/announce.go +++ b/internal/federation/federatingdb/announce.go @@ -29,13 +29,13 @@ import ( ) func (f *federatingDB) Announce(ctx context.Context, announce vocab.ActivityStreamsAnnounce) error { - l := f.log.WithFields( + l := logrus.WithFields( logrus.Fields{ "func": "Announce", }, ) - if f.log.Level >= logrus.DebugLevel { + if logrus.GetLevel() >= logrus.DebugLevel { i, err := marshalItem(announce) if err != nil { return err diff --git a/internal/federation/federatingdb/create.go b/internal/federation/federatingdb/create.go index 4262dfcb4..862f84473 100644 --- a/internal/federation/federatingdb/create.go +++ b/internal/federation/federatingdb/create.go @@ -46,13 +46,13 @@ import ( // Under certain conditions and network activities, Create may be called // multiple times for the same ActivityStreams object. func (f *federatingDB) Create(ctx context.Context, asType vocab.Type) error { - l := f.log.WithFields( + l := logrus.WithFields( logrus.Fields{ "func": "Create", }, ) - if f.log.Level >= logrus.DebugLevel { + if logrus.GetLevel() >= logrus.DebugLevel { i, err := marshalItem(asType) if err != nil { return err @@ -169,7 +169,7 @@ func (f *federatingDB) activityCreate(ctx context.Context, asType vocab.Type, re // createNote handles a Create activity with a Note type. func (f *federatingDB) createNote(ctx context.Context, note vocab.ActivityStreamsNote, receivingAccount *gtsmodel.Account, requestingAccount *gtsmodel.Account, fromFederatorChan chan messages.FromFederator) error { - l := f.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "createNote", "receivingAccount": receivingAccount.URI, "requestingAccount": requestingAccount.URI, diff --git a/internal/federation/federatingdb/db.go b/internal/federation/federatingdb/db.go index 8d41d082e..039c70168 100644 --- a/internal/federation/federatingdb/db.go +++ b/internal/federation/federatingdb/db.go @@ -25,7 +25,6 @@ import ( "github.com/go-fed/activity/pub" "github.com/go-fed/activity/streams/vocab" - "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/typeutils" @@ -47,20 +46,18 @@ type federatingDB struct { pool sync.Pool db db.DB config *config.Config - log *logrus.Logger typeConverter typeutils.TypeConverter } -// New returns a DB interface using the given database, config, and logger. -func New(db db.DB, config *config.Config, log *logrus.Logger) DB { +// New returns a DB interface using the given database and config +func New(db db.DB, config *config.Config) DB { fdb := federatingDB{ mutex: sync.Mutex{}, locks: make(map[string]*mutex, 100), pool: sync.Pool{New: func() interface{} { return &mutex{} }}, db: db, config: config, - log: log, - typeConverter: typeutils.NewConverter(config, db, log), + typeConverter: typeutils.NewConverter(config, db), } go fdb.cleanupLocks() return &fdb diff --git a/internal/federation/federatingdb/delete.go b/internal/federation/federatingdb/delete.go index 77c3f502b..7d41d1b76 100644 --- a/internal/federation/federatingdb/delete.go +++ b/internal/federation/federatingdb/delete.go @@ -36,7 +36,7 @@ import ( // // The library makes this call only after acquiring a lock first. func (f *federatingDB) Delete(ctx context.Context, id *url.URL) error { - l := f.log.WithFields( + l := logrus.WithFields( logrus.Fields{ "func": "Delete", "id": id, diff --git a/internal/federation/federatingdb/exists.go b/internal/federation/federatingdb/exists.go index ec5599c24..01c14a720 100644 --- a/internal/federation/federatingdb/exists.go +++ b/internal/federation/federatingdb/exists.go @@ -32,7 +32,7 @@ import ( // // Implementation note: this just straight up isn't implemented, and doesn't *really* need to be either. func (f *federatingDB) Exists(c context.Context, id *url.URL) (exists bool, err error) { - l := f.log.WithFields( + l := logrus.WithFields( logrus.Fields{ "func": "Exists", "id": id, diff --git a/internal/federation/federatingdb/federatingdb_test.go b/internal/federation/federatingdb/federatingdb_test.go index 3c22480f7..9198266eb 100644 --- a/internal/federation/federatingdb/federatingdb_test.go +++ b/internal/federation/federatingdb/federatingdb_test.go @@ -21,7 +21,6 @@ package federatingdb_test import ( "context" - "github.com/sirupsen/logrus" "github.com/stretchr/testify/suite" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" @@ -37,7 +36,6 @@ type FederatingDBTestSuite struct { suite.Suite config *config.Config db db.DB - log *logrus.Logger tc typeutils.TypeConverter federatingDB federatingdb.DB @@ -68,7 +66,7 @@ func (suite *FederatingDBTestSuite) SetupTest() { suite.config = testrig.NewTestConfig() suite.db = testrig.NewTestDB() suite.tc = testrig.NewTestTypeConverter(suite.db) - suite.log = testrig.NewTestLog() + testrig.InitTestLog() suite.federatingDB = testrig.NewTestFederatingDB(suite.db) testrig.StandardDBSetup(suite.db, suite.testAccounts) } diff --git a/internal/federation/federatingdb/followers.go b/internal/federation/federatingdb/followers.go index 61c5d4287..2eccf167d 100644 --- a/internal/federation/federatingdb/followers.go +++ b/internal/federation/federatingdb/followers.go @@ -17,7 +17,7 @@ import ( // // The library makes this call only after acquiring a lock first. func (f *federatingDB) Followers(ctx context.Context, actorIRI *url.URL) (followers vocab.ActivityStreamsCollection, err error) { - l := f.log.WithFields( + l := logrus.WithFields( logrus.Fields{ "func": "Followers", "id": actorIRI, diff --git a/internal/federation/federatingdb/following.go b/internal/federation/federatingdb/following.go index 2cc024832..cc6111715 100644 --- a/internal/federation/federatingdb/following.go +++ b/internal/federation/federatingdb/following.go @@ -17,7 +17,7 @@ import ( // // The library makes this call only after acquiring a lock first. func (f *federatingDB) Following(ctx context.Context, actorIRI *url.URL) (following vocab.ActivityStreamsCollection, err error) { - l := f.log.WithFields( + l := logrus.WithFields( logrus.Fields{ "func": "Following", "id": actorIRI, diff --git a/internal/federation/federatingdb/get.go b/internal/federation/federatingdb/get.go index 505891ca4..6c629d717 100644 --- a/internal/federation/federatingdb/get.go +++ b/internal/federation/federatingdb/get.go @@ -32,7 +32,7 @@ import ( // // The library makes this call only after acquiring a lock first. func (f *federatingDB) Get(ctx context.Context, id *url.URL) (value vocab.Type, err error) { - l := f.log.WithFields( + l := logrus.WithFields( logrus.Fields{ "func": "Get", "id": id, diff --git a/internal/federation/federatingdb/owns.go b/internal/federation/federatingdb/owns.go index 04a417490..8846c52bb 100644 --- a/internal/federation/federatingdb/owns.go +++ b/internal/federation/federatingdb/owns.go @@ -33,7 +33,7 @@ import ( // the database has an entry for the IRI. // The library makes this call only after acquiring a lock first. func (f *federatingDB) Owns(ctx context.Context, id *url.URL) (bool, error) { - l := f.log.WithFields( + l := logrus.WithFields( logrus.Fields{ "func": "Owns", "id": id, diff --git a/internal/federation/federatingdb/undo.go b/internal/federation/federatingdb/undo.go index 3d4cb1d53..934b5970d 100644 --- a/internal/federation/federatingdb/undo.go +++ b/internal/federation/federatingdb/undo.go @@ -31,13 +31,13 @@ import ( ) func (f *federatingDB) Undo(ctx context.Context, undo vocab.ActivityStreamsUndo) error { - l := f.log.WithFields( + l := logrus.WithFields( logrus.Fields{ "func": "Undo", }, ) - if f.log.Level >= logrus.DebugLevel { + if logrus.GetLevel() >= logrus.DebugLevel { i, err := marshalItem(undo) if err != nil { return err diff --git a/internal/federation/federatingdb/update.go b/internal/federation/federatingdb/update.go index b3a27b462..646b155dc 100644 --- a/internal/federation/federatingdb/update.go +++ b/internal/federation/federatingdb/update.go @@ -41,13 +41,13 @@ import ( // // The library makes this call only after acquiring a lock first. func (f *federatingDB) Update(ctx context.Context, asType vocab.Type) error { - l := f.log.WithFields( + l := logrus.WithFields( logrus.Fields{ "func": "Update", }, ) - if f.log.Level >= logrus.DebugLevel { + if logrus.GetLevel() >= logrus.DebugLevel { i, err := marshalItem(asType) if err != nil { return err diff --git a/internal/federation/federatingdb/util.go b/internal/federation/federatingdb/util.go index 49a95a449..3fd9653af 100644 --- a/internal/federation/federatingdb/util.go +++ b/internal/federation/federatingdb/util.go @@ -63,13 +63,13 @@ func sameActor(activityActor vocab.ActivityStreamsActorProperty, followActor voc // The go-fed library will handle setting the 'id' property on the // activity or object provided with the value returned. func (f *federatingDB) NewID(ctx context.Context, t vocab.Type) (idURL *url.URL, err error) { - l := f.log.WithFields( + l := logrus.WithFields( logrus.Fields{ "func": "NewID", }, ) - if f.log.Level >= logrus.DebugLevel { + if logrus.GetLevel() >= logrus.DebugLevel { i, err := marshalItem(t) if err != nil { return nil, err diff --git a/internal/federation/federatingprotocol.go b/internal/federation/federatingprotocol.go index afa763d98..ea9084609 100644 --- a/internal/federation/federatingprotocol.go +++ b/internal/federation/federatingprotocol.go @@ -61,7 +61,7 @@ import ( // write a response to the ResponseWriter as is expected that the caller // to PostInbox will do so when handling the error. func (f *federator) PostInboxRequestBodyHook(ctx context.Context, r *http.Request, activity pub.Activity) (context.Context, error) { - l := f.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "PostInboxRequestBodyHook", "useragent": r.UserAgent(), "url": r.URL.String(), @@ -93,7 +93,7 @@ func (f *federator) PostInboxRequestBodyHook(ctx context.Context, r *http.Reques // authenticated must be true and error nil. The request will continue // to be processed. func (f *federator) AuthenticatePostInbox(ctx context.Context, w http.ResponseWriter, r *http.Request) (context.Context, bool, error) { - l := f.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "AuthenticatePostInbox", "useragent": r.UserAgent(), "url": r.URL.String(), @@ -177,7 +177,7 @@ func (f *federator) AuthenticatePostInbox(ctx context.Context, w http.ResponseWr // blocked must be false and error nil. The request will continue // to be processed. func (f *federator) Blocked(ctx context.Context, actorIRIs []*url.URL) (bool, error) { - l := f.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "Blocked", }) l.Debugf("entering BLOCKED function with IRI list: %+v", actorIRIs) @@ -185,7 +185,7 @@ func (f *federator) Blocked(ctx context.Context, actorIRIs []*url.URL) (bool, er receivingAccountI := ctx.Value(util.APReceivingAccount) receivingAccount, ok := receivingAccountI.(*gtsmodel.Account) if !ok { - f.log.Errorf("receiving account not set on request context") + l.Errorf("receiving account not set on request context") return false, errors.New("receiving account not set on request context, so couldn't determine blocks") } @@ -276,7 +276,7 @@ func (f *federator) FederatingCallbacks(ctx context.Context) (wrapped pub.Federa // type and extension, so the unhandled ones are passed to // DefaultCallback. func (f *federator) DefaultCallback(ctx context.Context, activity pub.Activity) error { - l := f.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "DefaultCallback", "aptype": activity.GetTypeName(), }) diff --git a/internal/federation/federator.go b/internal/federation/federator.go index a385c4504..2813f6ff8 100644 --- a/internal/federation/federator.go +++ b/internal/federation/federator.go @@ -23,7 +23,6 @@ import ( "net/url" "github.com/go-fed/activity/pub" - "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/ap" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" @@ -83,12 +82,11 @@ type federator struct { dereferencer dereferencing.Dereferencer mediaHandler media.Handler actor pub.FederatingActor - log *logrus.Logger } // NewFederator returns a new federator -func NewFederator(db db.DB, federatingDB federatingdb.DB, transportController transport.Controller, config *config.Config, log *logrus.Logger, typeConverter typeutils.TypeConverter, mediaHandler media.Handler) Federator { - dereferencer := dereferencing.NewDereferencer(config, db, typeConverter, transportController, mediaHandler, log) +func NewFederator(db db.DB, federatingDB federatingdb.DB, transportController transport.Controller, config *config.Config, typeConverter typeutils.TypeConverter, mediaHandler media.Handler) Federator { + dereferencer := dereferencing.NewDereferencer(config, db, typeConverter, transportController, mediaHandler) clock := &Clock{} f := &federator{ @@ -100,7 +98,6 @@ func NewFederator(db db.DB, federatingDB federatingdb.DB, transportController tr transportController: transportController, dereferencer: dereferencer, mediaHandler: mediaHandler, - log: log, } actor := newFederatingActor(f, f, federatingDB, clock) f.actor = actor diff --git a/internal/federation/federator_test.go b/internal/federation/federator_test.go index 76e16a04f..04c3b3449 100644 --- a/internal/federation/federator_test.go +++ b/internal/federation/federator_test.go @@ -27,7 +27,6 @@ import ( "git.iim.gay/grufwub/go-store/kv" "github.com/go-fed/activity/pub" "github.com/go-fed/httpsig" - "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" @@ -44,7 +43,6 @@ type ProtocolTestSuite struct { suite.Suite config *config.Config db db.DB - log *logrus.Logger storage *kv.KVStore typeConverter typeutils.TypeConverter accounts map[string]*gtsmodel.Account @@ -56,7 +54,7 @@ func (suite *ProtocolTestSuite) SetupSuite() { // setup standard items suite.config = testrig.NewTestConfig() suite.db = testrig.NewTestDB() - suite.log = testrig.NewTestLog() + testrig.InitTestLog() suite.storage = testrig.NewTestStorage() suite.typeConverter = testrig.NewTestTypeConverter(suite.db) suite.accounts = testrig.NewTestAccounts() @@ -82,7 +80,7 @@ func (suite *ProtocolTestSuite) TestPostInboxRequestBodyHook() { return nil, nil }), suite.db) // setup module being tested - federator := federation.NewFederator(suite.db, testrig.NewTestFederatingDB(suite.db), tc, suite.config, suite.log, suite.typeConverter, testrig.NewTestMediaHandler(suite.db, suite.storage)) + federator := federation.NewFederator(suite.db, testrig.NewTestFederatingDB(suite.db), tc, suite.config, suite.typeConverter, testrig.NewTestMediaHandler(suite.db, suite.storage)) // setup request ctx := context.Background() @@ -111,7 +109,7 @@ func (suite *ProtocolTestSuite) TestAuthenticatePostInbox() { tc := testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db) // now setup module being tested, with the mock transport controller - federator := federation.NewFederator(suite.db, testrig.NewTestFederatingDB(suite.db), tc, suite.config, suite.log, suite.typeConverter, testrig.NewTestMediaHandler(suite.db, suite.storage)) + federator := federation.NewFederator(suite.db, testrig.NewTestFederatingDB(suite.db), tc, suite.config, suite.typeConverter, testrig.NewTestMediaHandler(suite.db, suite.storage)) request := httptest.NewRequest(http.MethodPost, "http://localhost:8080/users/the_mighty_zork/inbox", nil) // we need these headers for the request to be validated |