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
This commit is contained in:
R. Aidan Campbell 2021-10-11 05:37:33 -07:00 committed by GitHub
commit 083099a957
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
210 changed files with 506 additions and 662 deletions

View file

@ -21,11 +21,10 @@ package cliactions
import (
"context"
"github.com/sirupsen/logrus"
"github.com/superseriousbusiness/gotosocial/internal/config"
)
// GTSAction defines one *action* that can be taken by the gotosocial cli command.
// This can be either a long-running action (like server start) or something
// shorter like db init or db inspect.
type GTSAction func(context.Context, *config.Config, *logrus.Logger) error
type GTSAction func(context.Context, *config.Config) error

View file

@ -24,7 +24,6 @@ import (
"fmt"
"time"
"github.com/sirupsen/logrus"
"github.com/superseriousbusiness/gotosocial/internal/cliactions"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
@ -35,8 +34,8 @@ import (
)
// Create creates a new account in the database using the provided flags.
var Create cliactions.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error {
dbConn, err := bundb.NewBunDBService(ctx, c, log)
var Create cliactions.GTSAction = func(ctx context.Context, c *config.Config) error {
dbConn, err := bundb.NewBunDBService(ctx, c)
if err != nil {
return fmt.Errorf("error creating dbservice: %s", err)
}
@ -74,8 +73,8 @@ var Create cliactions.GTSAction = func(ctx context.Context, c *config.Config, lo
}
// Confirm sets a user to Approved, sets Email to the current UnconfirmedEmail value, and sets ConfirmedAt to now.
var Confirm cliactions.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error {
dbConn, err := bundb.NewBunDBService(ctx, c, log)
var Confirm cliactions.GTSAction = func(ctx context.Context, c *config.Config) error {
dbConn, err := bundb.NewBunDBService(ctx, c)
if err != nil {
return fmt.Errorf("error creating dbservice: %s", err)
}
@ -109,8 +108,8 @@ var Confirm cliactions.GTSAction = func(ctx context.Context, c *config.Config, l
}
// Promote sets a user to admin.
var Promote cliactions.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error {
dbConn, err := bundb.NewBunDBService(ctx, c, log)
var Promote cliactions.GTSAction = func(ctx context.Context, c *config.Config) error {
dbConn, err := bundb.NewBunDBService(ctx, c)
if err != nil {
return fmt.Errorf("error creating dbservice: %s", err)
}
@ -141,8 +140,8 @@ var Promote cliactions.GTSAction = func(ctx context.Context, c *config.Config, l
}
// Demote sets admin on a user to false.
var Demote cliactions.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error {
dbConn, err := bundb.NewBunDBService(ctx, c, log)
var Demote cliactions.GTSAction = func(ctx context.Context, c *config.Config) error {
dbConn, err := bundb.NewBunDBService(ctx, c)
if err != nil {
return fmt.Errorf("error creating dbservice: %s", err)
}
@ -173,8 +172,8 @@ var Demote cliactions.GTSAction = func(ctx context.Context, c *config.Config, lo
}
// Disable sets Disabled to true on a user.
var Disable cliactions.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error {
dbConn, err := bundb.NewBunDBService(ctx, c, log)
var Disable cliactions.GTSAction = func(ctx context.Context, c *config.Config) error {
dbConn, err := bundb.NewBunDBService(ctx, c)
if err != nil {
return fmt.Errorf("error creating dbservice: %s", err)
}
@ -205,14 +204,14 @@ var Disable cliactions.GTSAction = func(ctx context.Context, c *config.Config, l
}
// Suspend suspends the target account, cleanly removing all of its media, followers, following, likes, statuses, etc.
var Suspend cliactions.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error {
var Suspend cliactions.GTSAction = func(ctx context.Context, c *config.Config) error {
// TODO
return nil
}
// Password sets the password of target account.
var Password cliactions.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error {
dbConn, err := bundb.NewBunDBService(ctx, c, log)
var Password cliactions.GTSAction = func(ctx context.Context, c *config.Config) error {
dbConn, err := bundb.NewBunDBService(ctx, c)
if err != nil {
return fmt.Errorf("error creating dbservice: %s", err)
}

View file

@ -23,7 +23,6 @@ import (
"errors"
"fmt"
"github.com/sirupsen/logrus"
"github.com/superseriousbusiness/gotosocial/internal/cliactions"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db/bundb"
@ -31,13 +30,13 @@ import (
)
// Export exports info from the database into a file
var Export cliactions.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error {
dbConn, err := bundb.NewBunDBService(ctx, c, log)
var Export cliactions.GTSAction = func(ctx context.Context, c *config.Config) error {
dbConn, err := bundb.NewBunDBService(ctx, c)
if err != nil {
return fmt.Errorf("error creating dbservice: %s", err)
}
exporter := trans.NewExporter(dbConn, log)
exporter := trans.NewExporter(dbConn)
path, ok := c.ExportCLIFlags[config.TransPathFlag]
if !ok {

View file

@ -23,7 +23,6 @@ import (
"errors"
"fmt"
"github.com/sirupsen/logrus"
"github.com/superseriousbusiness/gotosocial/internal/cliactions"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db/bundb"
@ -31,13 +30,13 @@ import (
)
// Import imports info from a file into the database
var Import cliactions.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error {
dbConn, err := bundb.NewBunDBService(ctx, c, log)
var Import cliactions.GTSAction = func(ctx context.Context, c *config.Config) error {
dbConn, err := bundb.NewBunDBService(ctx, c)
if err != nil {
return fmt.Errorf("error creating dbservice: %s", err)
}
importer := trans.NewImporter(dbConn, log)
importer := trans.NewImporter(dbConn)
path, ok := c.ExportCLIFlags[config.TransPathFlag]
if !ok {

View file

@ -51,8 +51,8 @@ import (
)
// Start creates and starts a gotosocial server
var Start cliactions.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error {
dbService, err := bundb.NewBunDBService(ctx, c, log)
var Start cliactions.GTSAction = func(ctx context.Context, c *config.Config) error {
dbService, err := bundb.NewBunDBService(ctx, c)
if err != nil {
return fmt.Errorf("error creating dbservice: %s", err)
}
@ -69,9 +69,9 @@ var Start cliactions.GTSAction = func(ctx context.Context, c *config.Config, log
return fmt.Errorf("error creating instance instance: %s", err)
}
federatingDB := federatingdb.New(dbService, c, log)
federatingDB := federatingdb.New(dbService, c)
router, err := router.New(ctx, c, dbService, log)
router, err := router.New(ctx, c, dbService)
if err != nil {
return fmt.Errorf("error creating router: %s", err)
}
@ -83,48 +83,48 @@ var Start cliactions.GTSAction = func(ctx context.Context, c *config.Config, log
}
// build converters and util
typeConverter := typeutils.NewConverter(c, dbService, log)
timelineManager := timelineprocessing.NewManager(dbService, typeConverter, c, log)
typeConverter := typeutils.NewConverter(c, dbService)
timelineManager := timelineprocessing.NewManager(dbService, typeConverter, c)
// build backend handlers
mediaHandler := media.New(c, dbService, storage, log)
oauthServer := oauth.New(ctx, dbService, log)
transportController := transport.NewController(c, dbService, &federation.Clock{}, http.DefaultClient, log)
federator := federation.NewFederator(dbService, federatingDB, transportController, c, log, typeConverter, mediaHandler)
processor := processing.NewProcessor(c, typeConverter, federator, oauthServer, mediaHandler, storage, timelineManager, dbService, log)
mediaHandler := media.New(c, dbService, storage)
oauthServer := oauth.New(ctx, dbService)
transportController := transport.NewController(c, dbService, &federation.Clock{}, http.DefaultClient)
federator := federation.NewFederator(dbService, federatingDB, transportController, c, typeConverter, mediaHandler)
processor := processing.NewProcessor(c, typeConverter, federator, oauthServer, mediaHandler, storage, timelineManager, dbService)
if err := processor.Start(ctx); err != nil {
return fmt.Errorf("error starting processor: %s", err)
}
idp, err := oidc.NewIDP(ctx, c, log)
idp, err := oidc.NewIDP(ctx, c)
if err != nil {
return fmt.Errorf("error creating oidc idp: %s", err)
}
// build client api modules
authModule := auth.New(c, dbService, oauthServer, idp, log)
accountModule := account.New(c, processor, log)
instanceModule := instance.New(c, processor, log)
appsModule := app.New(c, processor, log)
followRequestsModule := followrequest.New(c, processor, log)
webfingerModule := webfinger.New(c, processor, log)
nodeInfoModule := nodeinfo.New(c, processor, log)
webBaseModule := web.New(c, processor, log)
usersModule := user.New(c, processor, log)
timelineModule := timeline.New(c, processor, log)
notificationModule := notification.New(c, processor, log)
searchModule := search.New(c, processor, log)
filtersModule := filter.New(c, processor, log)
emojiModule := emoji.New(c, processor, log)
listsModule := list.New(c, processor, log)
mm := mediaModule.New(c, processor, log)
fileServerModule := fileserver.New(c, processor, log)
adminModule := admin.New(c, processor, log)
statusModule := status.New(c, processor, log)
securityModule := security.New(c, dbService, log)
streamingModule := streaming.New(c, processor, log)
favouritesModule := favourites.New(c, processor, log)
blocksModule := blocks.New(c, processor, log)
authModule := auth.New(c, dbService, oauthServer, idp)
accountModule := account.New(c, processor)
instanceModule := instance.New(c, processor)
appsModule := app.New(c, processor)
followRequestsModule := followrequest.New(c, processor)
webfingerModule := webfinger.New(c, processor)
nodeInfoModule := nodeinfo.New(c, processor)
webBaseModule := web.New(c, processor)
usersModule := user.New(c, processor)
timelineModule := timeline.New(c, processor)
notificationModule := notification.New(c, processor)
searchModule := search.New(c, processor)
filtersModule := filter.New(c, processor)
emojiModule := emoji.New(c, processor)
listsModule := list.New(c, processor)
mm := mediaModule.New(c, processor)
fileServerModule := fileserver.New(c, processor)
adminModule := admin.New(c, processor)
statusModule := status.New(c, processor)
securityModule := security.New(c, dbService)
streamingModule := streaming.New(c, processor)
favouritesModule := favourites.New(c, processor)
blocksModule := blocks.New(c, processor)
apis := []api.ClientModule{
// modules with middleware go first
@ -174,13 +174,13 @@ var Start cliactions.GTSAction = func(ctx context.Context, c *config.Config, log
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, os.Interrupt, syscall.SIGTERM)
sig := <-sigs
log.Infof("received signal %s, shutting down", sig)
logrus.Infof("received signal %s, shutting down", sig)
// close down all running services in order
if err := gts.Stop(ctx); err != nil {
return fmt.Errorf("error closing gotosocial service: %s", err)
}
log.Info("done! exiting...")
logrus.Info("done! exiting...")
return nil
}

View file

@ -43,7 +43,7 @@ import (
)
// Start creates and starts a gotosocial testrig server
var Start cliactions.GTSAction = func(ctx context.Context, _ *config.Config, log *logrus.Logger) error {
var Start cliactions.GTSAction = func(ctx context.Context, _ *config.Config) error {
c := testrig.NewTestConfig()
dbService := testrig.NewTestDB()
testrig.StandardDBSetup(dbService, nil)
@ -67,35 +67,35 @@ var Start cliactions.GTSAction = func(ctx context.Context, _ *config.Config, log
return fmt.Errorf("error starting processor: %s", err)
}
idp, err := oidc.NewIDP(ctx, c, log)
idp, err := oidc.NewIDP(ctx, c)
if err != nil {
return fmt.Errorf("error creating oidc idp: %s", err)
}
// build client api modules
authModule := auth.New(c, dbService, oauthServer, idp, log)
accountModule := account.New(c, processor, log)
instanceModule := instance.New(c, processor, log)
appsModule := app.New(c, processor, log)
followRequestsModule := followrequest.New(c, processor, log)
webfingerModule := webfinger.New(c, processor, log)
nodeInfoModule := nodeinfo.New(c, processor, log)
webBaseModule := web.New(c, processor, log)
usersModule := user.New(c, processor, log)
timelineModule := timeline.New(c, processor, log)
notificationModule := notification.New(c, processor, log)
searchModule := search.New(c, processor, log)
filtersModule := filter.New(c, processor, log)
emojiModule := emoji.New(c, processor, log)
listsModule := list.New(c, processor, log)
mm := mediaModule.New(c, processor, log)
fileServerModule := fileserver.New(c, processor, log)
adminModule := admin.New(c, processor, log)
statusModule := status.New(c, processor, log)
securityModule := security.New(c, dbService, log)
streamingModule := streaming.New(c, processor, log)
favouritesModule := favourites.New(c, processor, log)
blocksModule := blocks.New(c, processor, log)
authModule := auth.New(c, dbService, oauthServer, idp)
accountModule := account.New(c, processor)
instanceModule := instance.New(c, processor)
appsModule := app.New(c, processor)
followRequestsModule := followrequest.New(c, processor)
webfingerModule := webfinger.New(c, processor)
nodeInfoModule := nodeinfo.New(c, processor)
webBaseModule := web.New(c, processor)
usersModule := user.New(c, processor)
timelineModule := timeline.New(c, processor)
notificationModule := notification.New(c, processor)
searchModule := search.New(c, processor)
filtersModule := filter.New(c, processor)
emojiModule := emoji.New(c, processor)
listsModule := list.New(c, processor)
mm := mediaModule.New(c, processor)
fileServerModule := fileserver.New(c, processor)
adminModule := admin.New(c, processor)
statusModule := status.New(c, processor)
securityModule := security.New(c, dbService)
streamingModule := streaming.New(c, processor)
favouritesModule := favourites.New(c, processor)
blocksModule := blocks.New(c, processor)
apis := []api.ClientModule{
// modules with middleware go first
@ -145,7 +145,7 @@ var Start cliactions.GTSAction = func(ctx context.Context, _ *config.Config, log
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, os.Interrupt, syscall.SIGTERM)
sig := <-sigs
log.Infof("received signal %s, shutting down", sig)
logrus.Infof("received signal %s, shutting down", sig)
testrig.StandardDBTeardown(dbService)
testrig.StandardStorageTeardown(storageBackend)
@ -155,6 +155,6 @@ var Start cliactions.GTSAction = func(ctx context.Context, _ *config.Config, log
return fmt.Errorf("error closing gotosocial service: %s", err)
}
log.Info("done! exiting...")
logrus.Info("done! exiting...")
return nil
}