diff options
author | 2021-10-11 05:37:33 -0700 | |
---|---|---|
committer | 2021-10-11 14:37:33 +0200 | |
commit | 083099a9575f8b2fac22c1d4a51a9dd0e2201243 (patch) | |
tree | d1787aa544679c433f797d2313ce532250fe574f /internal/api/s2s | |
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/api/s2s')
-rw-r--r-- | internal/api/s2s/nodeinfo/nodeinfo.go | 5 | ||||
-rw-r--r-- | internal/api/s2s/nodeinfo/nodeinfoget.go | 2 | ||||
-rw-r--r-- | internal/api/s2s/nodeinfo/wellknownget.go | 2 | ||||
-rw-r--r-- | internal/api/s2s/user/followers.go | 2 | ||||
-rw-r--r-- | internal/api/s2s/user/following.go | 2 | ||||
-rw-r--r-- | internal/api/s2s/user/inboxpost.go | 2 | ||||
-rw-r--r-- | internal/api/s2s/user/inboxpost_test.go | 8 | ||||
-rw-r--r-- | internal/api/s2s/user/publickeyget.go | 2 | ||||
-rw-r--r-- | internal/api/s2s/user/repliesget.go | 2 | ||||
-rw-r--r-- | internal/api/s2s/user/repliesget_test.go | 6 | ||||
-rw-r--r-- | internal/api/s2s/user/statusget.go | 2 | ||||
-rw-r--r-- | internal/api/s2s/user/user.go | 5 | ||||
-rw-r--r-- | internal/api/s2s/user/user_test.go | 8 | ||||
-rw-r--r-- | internal/api/s2s/user/userget.go | 2 | ||||
-rw-r--r-- | internal/api/s2s/user/userget_test.go | 2 | ||||
-rw-r--r-- | internal/api/s2s/webfinger/webfinger.go | 5 | ||||
-rw-r--r-- | internal/api/s2s/webfinger/webfinger_test.go | 8 | ||||
-rw-r--r-- | internal/api/s2s/webfinger/webfingerget.go | 2 | ||||
-rw-r--r-- | internal/api/s2s/webfinger/webfingerget_test.go | 8 |
19 files changed, 31 insertions, 44 deletions
diff --git a/internal/api/s2s/nodeinfo/nodeinfo.go b/internal/api/s2s/nodeinfo/nodeinfo.go index 85617f52c..5d1d03b24 100644 --- a/internal/api/s2s/nodeinfo/nodeinfo.go +++ b/internal/api/s2s/nodeinfo/nodeinfo.go @@ -21,7 +21,6 @@ package nodeinfo import ( "net/http" - "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/api" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/processing" @@ -39,15 +38,13 @@ const ( type Module struct { config *config.Config processor processing.Processor - log *logrus.Logger } // New returns a new nodeinfo module -func New(config *config.Config, processor processing.Processor, log *logrus.Logger) api.FederationModule { +func New(config *config.Config, processor processing.Processor) api.FederationModule { return &Module{ config: config, processor: processor, - log: log, } } diff --git a/internal/api/s2s/nodeinfo/nodeinfoget.go b/internal/api/s2s/nodeinfo/nodeinfoget.go index c362e1d2e..547aa2cf9 100644 --- a/internal/api/s2s/nodeinfo/nodeinfoget.go +++ b/internal/api/s2s/nodeinfo/nodeinfoget.go @@ -28,7 +28,7 @@ import ( // NodeInfoGETHandler returns a compliant nodeinfo response to node info queries. // See: https://nodeinfo.diaspora.software/ func (m *Module) NodeInfoGETHandler(c *gin.Context) { - l := m.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "NodeInfoGETHandler", "user-agent": c.Request.UserAgent(), }) diff --git a/internal/api/s2s/nodeinfo/wellknownget.go b/internal/api/s2s/nodeinfo/wellknownget.go index fd2c84408..e5aa39aad 100644 --- a/internal/api/s2s/nodeinfo/wellknownget.go +++ b/internal/api/s2s/nodeinfo/wellknownget.go @@ -28,7 +28,7 @@ import ( // NodeInfoWellKnownGETHandler returns a well known response to a query to /.well-known/nodeinfo, // directing (but not redirecting...) callers to the NodeInfoGETHandler. func (m *Module) NodeInfoWellKnownGETHandler(c *gin.Context) { - l := m.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "NodeInfoWellKnownGETHandler", "user-agent": c.Request.UserAgent(), }) diff --git a/internal/api/s2s/user/followers.go b/internal/api/s2s/user/followers.go index 63d43db91..288e60f30 100644 --- a/internal/api/s2s/user/followers.go +++ b/internal/api/s2s/user/followers.go @@ -29,7 +29,7 @@ import ( // FollowersGETHandler returns a collection of URIs for followers of the target user, formatted so that other AP servers can understand it. func (m *Module) FollowersGETHandler(c *gin.Context) { - l := m.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "FollowersGETHandler", "url": c.Request.RequestURI, }) diff --git a/internal/api/s2s/user/following.go b/internal/api/s2s/user/following.go index 3a3e1146e..6c7b60d32 100644 --- a/internal/api/s2s/user/following.go +++ b/internal/api/s2s/user/following.go @@ -29,7 +29,7 @@ import ( // FollowingGETHandler returns a collection of URIs for accounts that the target user follows, formatted so that other AP servers can understand it. func (m *Module) FollowingGETHandler(c *gin.Context) { - l := m.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "FollowingGETHandler", "url": c.Request.RequestURI, }) diff --git a/internal/api/s2s/user/inboxpost.go b/internal/api/s2s/user/inboxpost.go index d59555e15..c2992bffd 100644 --- a/internal/api/s2s/user/inboxpost.go +++ b/internal/api/s2s/user/inboxpost.go @@ -29,7 +29,7 @@ import ( // InboxPOSTHandler deals with incoming POST requests to an actor's inbox. // Eg., POST to https://example.org/users/whatever/inbox. func (m *Module) InboxPOSTHandler(c *gin.Context) { - l := m.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "InboxPOSTHandler", "url": c.Request.RequestURI, }) diff --git a/internal/api/s2s/user/inboxpost_test.go b/internal/api/s2s/user/inboxpost_test.go index 94b3e6507..79c44116d 100644 --- a/internal/api/s2s/user/inboxpost_test.go +++ b/internal/api/s2s/user/inboxpost_test.go @@ -86,7 +86,7 @@ func (suite *InboxPostTestSuite) TestPostBlock() { tc := testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db) federator := testrig.NewTestFederator(suite.db, tc, suite.storage) processor := testrig.NewTestProcessor(suite.db, suite.storage, federator) - userModule := user.New(suite.config, processor, suite.log).(*user.Module) + userModule := user.New(suite.config, processor).(*user.Module) // setup request recorder := httptest.NewRecorder() @@ -185,7 +185,7 @@ func (suite *InboxPostTestSuite) TestPostUnblock() { tc := testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db) federator := testrig.NewTestFederator(suite.db, tc, suite.storage) processor := testrig.NewTestProcessor(suite.db, suite.storage, federator) - userModule := user.New(suite.config, processor, suite.log).(*user.Module) + userModule := user.New(suite.config, processor).(*user.Module) // setup request recorder := httptest.NewRecorder() @@ -274,7 +274,7 @@ func (suite *InboxPostTestSuite) TestPostUpdate() { tc := testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db) federator := testrig.NewTestFederator(suite.db, tc, suite.storage) processor := testrig.NewTestProcessor(suite.db, suite.storage, federator) - userModule := user.New(suite.config, processor, suite.log).(*user.Module) + userModule := user.New(suite.config, processor).(*user.Module) // setup request recorder := httptest.NewRecorder() @@ -394,7 +394,7 @@ func (suite *InboxPostTestSuite) TestPostDelete() { processor := testrig.NewTestProcessor(suite.db, suite.storage, federator) err = processor.Start(context.Background()) suite.NoError(err) - userModule := user.New(suite.config, processor, suite.log).(*user.Module) + userModule := user.New(suite.config, processor).(*user.Module) // setup request recorder := httptest.NewRecorder() diff --git a/internal/api/s2s/user/publickeyget.go b/internal/api/s2s/user/publickeyget.go index 8b9d3aa02..bf7116833 100644 --- a/internal/api/s2s/user/publickeyget.go +++ b/internal/api/s2s/user/publickeyget.go @@ -33,7 +33,7 @@ import ( // in the form of a vocab.ActivityStreamsPerson. The account will only contain the id, // public key, username, and type of the account. func (m *Module) PublicKeyGETHandler(c *gin.Context) { - l := m.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "PublicKeyGETHandler", "url": c.Request.RequestURI, }) diff --git a/internal/api/s2s/user/repliesget.go b/internal/api/s2s/user/repliesget.go index 13b9061ed..b24dead31 100644 --- a/internal/api/s2s/user/repliesget.go +++ b/internal/api/s2s/user/repliesget.go @@ -85,7 +85,7 @@ import ( // '404': // description: not found func (m *Module) StatusRepliesGETHandler(c *gin.Context) { - l := m.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "StatusRepliesGETHandler", "url": c.Request.RequestURI, }) diff --git a/internal/api/s2s/user/repliesget_test.go b/internal/api/s2s/user/repliesget_test.go index f8e833741..44717ad42 100644 --- a/internal/api/s2s/user/repliesget_test.go +++ b/internal/api/s2s/user/repliesget_test.go @@ -50,7 +50,7 @@ func (suite *RepliesGetTestSuite) TestGetReplies() { tc := testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db) federator := testrig.NewTestFederator(suite.db, tc, suite.storage) processor := testrig.NewTestProcessor(suite.db, suite.storage, federator) - userModule := user.New(suite.config, processor, suite.log).(*user.Module) + userModule := user.New(suite.config, processor).(*user.Module) // setup request recorder := httptest.NewRecorder() @@ -109,7 +109,7 @@ func (suite *RepliesGetTestSuite) TestGetRepliesNext() { tc := testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db) federator := testrig.NewTestFederator(suite.db, tc, suite.storage) processor := testrig.NewTestProcessor(suite.db, suite.storage, federator) - userModule := user.New(suite.config, processor, suite.log).(*user.Module) + userModule := user.New(suite.config, processor).(*user.Module) // setup request recorder := httptest.NewRecorder() @@ -171,7 +171,7 @@ func (suite *RepliesGetTestSuite) TestGetRepliesLast() { tc := testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db) federator := testrig.NewTestFederator(suite.db, tc, suite.storage) processor := testrig.NewTestProcessor(suite.db, suite.storage, federator) - userModule := user.New(suite.config, processor, suite.log).(*user.Module) + userModule := user.New(suite.config, processor).(*user.Module) // setup request recorder := httptest.NewRecorder() diff --git a/internal/api/s2s/user/statusget.go b/internal/api/s2s/user/statusget.go index 74615424d..91c29e3cb 100644 --- a/internal/api/s2s/user/statusget.go +++ b/internal/api/s2s/user/statusget.go @@ -29,7 +29,7 @@ import ( // StatusGETHandler serves the target status as an activitystreams NOTE so that other AP servers can parse it. func (m *Module) StatusGETHandler(c *gin.Context) { - l := m.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "StatusGETHandler", "url": c.Request.RequestURI, }) diff --git a/internal/api/s2s/user/user.go b/internal/api/s2s/user/user.go index cd57ab14e..ef0057f98 100644 --- a/internal/api/s2s/user/user.go +++ b/internal/api/s2s/user/user.go @@ -21,7 +21,6 @@ package user import ( "net/http" - "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/api" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/processing" @@ -65,15 +64,13 @@ const ( type Module struct { config *config.Config processor processing.Processor - log *logrus.Logger } // New returns a new auth module -func New(config *config.Config, processor processing.Processor, log *logrus.Logger) api.FederationModule { +func New(config *config.Config, processor processing.Processor) api.FederationModule { return &Module{ config: config, processor: processor, - log: log, } } diff --git a/internal/api/s2s/user/user_test.go b/internal/api/s2s/user/user_test.go index 86aa0bdf4..268523724 100644 --- a/internal/api/s2s/user/user_test.go +++ b/internal/api/s2s/user/user_test.go @@ -20,7 +20,6 @@ package user_test import ( "git.iim.gay/grufwub/go-store/kv" - "github.com/sirupsen/logrus" "github.com/stretchr/testify/suite" "github.com/superseriousbusiness/gotosocial/internal/api/s2s/user" "github.com/superseriousbusiness/gotosocial/internal/api/security" @@ -38,7 +37,6 @@ type UserStandardTestSuite struct { suite.Suite config *config.Config db db.DB - log *logrus.Logger tc typeutils.TypeConverter federator federation.Federator processor processing.Processor @@ -75,11 +73,11 @@ func (suite *UserStandardTestSuite) SetupTest() { suite.db = testrig.NewTestDB() suite.tc = testrig.NewTestTypeConverter(suite.db) suite.storage = testrig.NewTestStorage() - suite.log = testrig.NewTestLog() + testrig.InitTestLog() suite.federator = testrig.NewTestFederator(suite.db, testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db), suite.storage) suite.processor = testrig.NewTestProcessor(suite.db, suite.storage, suite.federator) - suite.userModule = user.New(suite.config, suite.processor, suite.log).(*user.Module) - suite.securityModule = security.New(suite.config, suite.db, suite.log).(*security.Module) + suite.userModule = user.New(suite.config, suite.processor).(*user.Module) + suite.securityModule = security.New(suite.config, suite.db).(*security.Module) testrig.StandardDBSetup(suite.db, suite.testAccounts) testrig.StandardStorageSetup(suite.storage, "../../../../testrig/media") } diff --git a/internal/api/s2s/user/userget.go b/internal/api/s2s/user/userget.go index 105ffd7bc..2af692b3c 100644 --- a/internal/api/s2s/user/userget.go +++ b/internal/api/s2s/user/userget.go @@ -37,7 +37,7 @@ import ( // And of course, the request should be refused if the account or server making the // request is blocked. func (m *Module) UsersGETHandler(c *gin.Context) { - l := m.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "UsersGETHandler", "url": c.Request.RequestURI, }) diff --git a/internal/api/s2s/user/userget_test.go b/internal/api/s2s/user/userget_test.go index f560125ca..d8d1df148 100644 --- a/internal/api/s2s/user/userget_test.go +++ b/internal/api/s2s/user/userget_test.go @@ -48,7 +48,7 @@ func (suite *UserGetTestSuite) TestGetUser() { tc := testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db) federator := testrig.NewTestFederator(suite.db, tc, suite.storage) processor := testrig.NewTestProcessor(suite.db, suite.storage, federator) - userModule := user.New(suite.config, processor, suite.log).(*user.Module) + userModule := user.New(suite.config, processor).(*user.Module) // setup request recorder := httptest.NewRecorder() diff --git a/internal/api/s2s/webfinger/webfinger.go b/internal/api/s2s/webfinger/webfinger.go index 6d48dc80a..c447d730e 100644 --- a/internal/api/s2s/webfinger/webfinger.go +++ b/internal/api/s2s/webfinger/webfinger.go @@ -21,7 +21,6 @@ package webfinger import ( "net/http" - "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/api" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/processing" @@ -37,15 +36,13 @@ const ( type Module struct { config *config.Config processor processing.Processor - log *logrus.Logger } // New returns a new webfinger module -func New(config *config.Config, processor processing.Processor, log *logrus.Logger) api.FederationModule { +func New(config *config.Config, processor processing.Processor) api.FederationModule { return &Module{ config: config, processor: processor, - log: log, } } diff --git a/internal/api/s2s/webfinger/webfinger_test.go b/internal/api/s2s/webfinger/webfinger_test.go index 5c8dfd2f6..ee1ff6607 100644 --- a/internal/api/s2s/webfinger/webfinger_test.go +++ b/internal/api/s2s/webfinger/webfinger_test.go @@ -24,7 +24,6 @@ import ( "time" "git.iim.gay/grufwub/go-store/kv" - "github.com/sirupsen/logrus" "github.com/stretchr/testify/suite" "github.com/superseriousbusiness/gotosocial/internal/ap" "github.com/superseriousbusiness/gotosocial/internal/api/s2s/webfinger" @@ -43,7 +42,6 @@ type WebfingerStandardTestSuite struct { suite.Suite config *config.Config db db.DB - log *logrus.Logger tc typeutils.TypeConverter federator federation.Federator processor processing.Processor @@ -78,11 +76,11 @@ func (suite *WebfingerStandardTestSuite) SetupTest() { suite.db = testrig.NewTestDB() suite.tc = testrig.NewTestTypeConverter(suite.db) suite.storage = testrig.NewTestStorage() - suite.log = testrig.NewTestLog() + testrig.InitTestLog() suite.federator = testrig.NewTestFederator(suite.db, testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db), suite.storage) suite.processor = testrig.NewTestProcessor(suite.db, suite.storage, suite.federator) - suite.webfingerModule = webfinger.New(suite.config, suite.processor, suite.log).(*webfinger.Module) - suite.securityModule = security.New(suite.config, suite.db, suite.log).(*security.Module) + suite.webfingerModule = webfinger.New(suite.config, suite.processor).(*webfinger.Module) + suite.securityModule = security.New(suite.config, suite.db).(*security.Module) testrig.StandardDBSetup(suite.db, suite.testAccounts) testrig.StandardStorageSetup(suite.storage, "../../../../testrig/media") } diff --git a/internal/api/s2s/webfinger/webfingerget.go b/internal/api/s2s/webfinger/webfingerget.go index 01e5e8e8a..3552394f2 100644 --- a/internal/api/s2s/webfinger/webfingerget.go +++ b/internal/api/s2s/webfinger/webfingerget.go @@ -31,7 +31,7 @@ import ( // WebfingerGETRequest handles requests to, for example, https://example.org/.well-known/webfinger?resource=acct:some_user@example.org func (m *Module) WebfingerGETRequest(c *gin.Context) { - l := m.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "WebfingerGETRequest", "user-agent": c.Request.UserAgent(), }) diff --git a/internal/api/s2s/webfinger/webfingerget_test.go b/internal/api/s2s/webfinger/webfingerget_test.go index b5de5d887..3b38c5a7e 100644 --- a/internal/api/s2s/webfinger/webfingerget_test.go +++ b/internal/api/s2s/webfinger/webfingerget_test.go @@ -65,8 +65,8 @@ func (suite *WebfingerGetTestSuite) TestFingerUser() { func (suite *WebfingerGetTestSuite) TestFingerUserWithDifferentAccountDomainByHost() { suite.config.Host = "gts.example.org" suite.config.AccountDomain = "example.org" - suite.processor = processing.NewProcessor(suite.config, suite.tc, suite.federator, testrig.NewTestOauthServer(suite.db), testrig.NewTestMediaHandler(suite.db, suite.storage), suite.storage, testrig.NewTestTimelineManager(suite.db), suite.db, suite.log) - suite.webfingerModule = webfinger.New(suite.config, suite.processor, suite.log).(*webfinger.Module) + suite.processor = processing.NewProcessor(suite.config, suite.tc, suite.federator, testrig.NewTestOauthServer(suite.db), testrig.NewTestMediaHandler(suite.db, suite.storage), suite.storage, testrig.NewTestTimelineManager(suite.db), suite.db) + suite.webfingerModule = webfinger.New(suite.config, suite.processor).(*webfinger.Module) targetAccount := accountDomainAccount() if err := suite.db.Put(context.Background(), targetAccount); err != nil { @@ -97,8 +97,8 @@ func (suite *WebfingerGetTestSuite) TestFingerUserWithDifferentAccountDomainByHo func (suite *WebfingerGetTestSuite) TestFingerUserWithDifferentAccountDomainByAccountDomain() { suite.config.Host = "gts.example.org" suite.config.AccountDomain = "example.org" - suite.processor = processing.NewProcessor(suite.config, suite.tc, suite.federator, testrig.NewTestOauthServer(suite.db), testrig.NewTestMediaHandler(suite.db, suite.storage), suite.storage, testrig.NewTestTimelineManager(suite.db), suite.db, suite.log) - suite.webfingerModule = webfinger.New(suite.config, suite.processor, suite.log).(*webfinger.Module) + suite.processor = processing.NewProcessor(suite.config, suite.tc, suite.federator, testrig.NewTestOauthServer(suite.db), testrig.NewTestMediaHandler(suite.db, suite.storage), suite.storage, testrig.NewTestTimelineManager(suite.db), suite.db) + suite.webfingerModule = webfinger.New(suite.config, suite.processor).(*webfinger.Module) targetAccount := accountDomainAccount() if err := suite.db.Put(context.Background(), targetAccount); err != nil { |