summaryrefslogtreecommitdiff
path: root/internal/cliactions
diff options
context:
space:
mode:
Diffstat (limited to 'internal/cliactions')
-rw-r--r--internal/cliactions/action.go30
-rw-r--r--internal/cliactions/admin/account/account.go257
-rw-r--r--internal/cliactions/admin/trans/export.go51
-rw-r--r--internal/cliactions/admin/trans/import.go51
-rw-r--r--internal/cliactions/server/server.go204
-rw-r--r--internal/cliactions/testrig/testrig.go167
6 files changed, 0 insertions, 760 deletions
diff --git a/internal/cliactions/action.go b/internal/cliactions/action.go
deleted file mode 100644
index b72ae92b8..000000000
--- a/internal/cliactions/action.go
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- GoToSocial
- Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-package cliactions
-
-import (
- "context"
-
- "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) error
diff --git a/internal/cliactions/admin/account/account.go b/internal/cliactions/admin/account/account.go
deleted file mode 100644
index 5bdee9a41..000000000
--- a/internal/cliactions/admin/account/account.go
+++ /dev/null
@@ -1,257 +0,0 @@
-/*
- GoToSocial
- Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-package account
-
-import (
- "context"
- "errors"
- "fmt"
- "time"
-
- "github.com/superseriousbusiness/gotosocial/internal/cliactions"
- "github.com/superseriousbusiness/gotosocial/internal/config"
- "github.com/superseriousbusiness/gotosocial/internal/db"
- "github.com/superseriousbusiness/gotosocial/internal/db/bundb"
- "github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
- "github.com/superseriousbusiness/gotosocial/internal/validate"
- "golang.org/x/crypto/bcrypt"
-)
-
-// Create creates a new account in the database using the provided flags.
-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)
- }
-
- username, ok := c.AccountCLIFlags[config.UsernameFlag]
- if !ok {
- return errors.New("no username set")
- }
- if err := validate.Username(username); err != nil {
- return err
- }
-
- email, ok := c.AccountCLIFlags[config.EmailFlag]
- if !ok {
- return errors.New("no email set")
- }
- if err := validate.Email(email); err != nil {
- return err
- }
-
- password, ok := c.AccountCLIFlags[config.PasswordFlag]
- if !ok {
- return errors.New("no password set")
- }
- if err := validate.NewPassword(password); err != nil {
- return err
- }
-
- _, err = dbConn.NewSignup(ctx, username, "", false, email, password, nil, "", "", false, false)
- if err != nil {
- return err
- }
-
- return dbConn.Stop(ctx)
-}
-
-// 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) error {
- dbConn, err := bundb.NewBunDBService(ctx, c)
- if err != nil {
- return fmt.Errorf("error creating dbservice: %s", err)
- }
-
- username, ok := c.AccountCLIFlags[config.UsernameFlag]
- if !ok {
- return errors.New("no username set")
- }
- if err := validate.Username(username); err != nil {
- return err
- }
-
- a, err := dbConn.GetLocalAccountByUsername(ctx, username)
- if err != nil {
- return err
- }
-
- u := &gtsmodel.User{}
- if err := dbConn.GetWhere(ctx, []db.Where{{Key: "account_id", Value: a.ID}}, u); err != nil {
- return err
- }
-
- u.Approved = true
- u.Email = u.UnconfirmedEmail
- u.ConfirmedAt = time.Now()
- if err := dbConn.UpdateByPrimaryKey(ctx, u); err != nil {
- return err
- }
-
- return dbConn.Stop(ctx)
-}
-
-// Promote sets a user to admin.
-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)
- }
-
- username, ok := c.AccountCLIFlags[config.UsernameFlag]
- if !ok {
- return errors.New("no username set")
- }
- if err := validate.Username(username); err != nil {
- return err
- }
-
- a, err := dbConn.GetLocalAccountByUsername(ctx, username)
- if err != nil {
- return err
- }
-
- u := &gtsmodel.User{}
- if err := dbConn.GetWhere(ctx, []db.Where{{Key: "account_id", Value: a.ID}}, u); err != nil {
- return err
- }
- u.Admin = true
- if err := dbConn.UpdateByPrimaryKey(ctx, u); err != nil {
- return err
- }
-
- return dbConn.Stop(ctx)
-}
-
-// Demote sets admin on a user to false.
-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)
- }
-
- username, ok := c.AccountCLIFlags[config.UsernameFlag]
- if !ok {
- return errors.New("no username set")
- }
- if err := validate.Username(username); err != nil {
- return err
- }
-
- a, err := dbConn.GetLocalAccountByUsername(ctx, username)
- if err != nil {
- return err
- }
-
- u := &gtsmodel.User{}
- if err := dbConn.GetWhere(ctx, []db.Where{{Key: "account_id", Value: a.ID}}, u); err != nil {
- return err
- }
- u.Admin = false
- if err := dbConn.UpdateByPrimaryKey(ctx, u); err != nil {
- return err
- }
-
- return dbConn.Stop(ctx)
-}
-
-// Disable sets Disabled to true on a user.
-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)
- }
-
- username, ok := c.AccountCLIFlags[config.UsernameFlag]
- if !ok {
- return errors.New("no username set")
- }
- if err := validate.Username(username); err != nil {
- return err
- }
-
- a, err := dbConn.GetLocalAccountByUsername(ctx, username)
- if err != nil {
- return err
- }
-
- u := &gtsmodel.User{}
- if err := dbConn.GetWhere(ctx, []db.Where{{Key: "account_id", Value: a.ID}}, u); err != nil {
- return err
- }
- u.Disabled = true
- if err := dbConn.UpdateByPrimaryKey(ctx, u); err != nil {
- return err
- }
-
- return dbConn.Stop(ctx)
-}
-
-// 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) error {
- // TODO
- return nil
-}
-
-// Password sets the password of target account.
-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)
- }
-
- username, ok := c.AccountCLIFlags[config.UsernameFlag]
- if !ok {
- return errors.New("no username set")
- }
- if err := validate.Username(username); err != nil {
- return err
- }
-
- password, ok := c.AccountCLIFlags[config.PasswordFlag]
- if !ok {
- return errors.New("no password set")
- }
- if err := validate.NewPassword(password); err != nil {
- return err
- }
-
- a, err := dbConn.GetLocalAccountByUsername(ctx, username)
- if err != nil {
- return err
- }
-
- u := &gtsmodel.User{}
- if err := dbConn.GetWhere(ctx, []db.Where{{Key: "account_id", Value: a.ID}}, u); err != nil {
- return err
- }
-
- pw, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
- if err != nil {
- return fmt.Errorf("error hashing password: %s", err)
- }
-
- u.EncryptedPassword = string(pw)
-
- if err := dbConn.UpdateByPrimaryKey(ctx, u); err != nil {
- return err
- }
-
- return nil
-}
diff --git a/internal/cliactions/admin/trans/export.go b/internal/cliactions/admin/trans/export.go
deleted file mode 100644
index 89a22a357..000000000
--- a/internal/cliactions/admin/trans/export.go
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- GoToSocial
- Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-package trans
-
-import (
- "context"
- "errors"
- "fmt"
-
- "github.com/superseriousbusiness/gotosocial/internal/cliactions"
- "github.com/superseriousbusiness/gotosocial/internal/config"
- "github.com/superseriousbusiness/gotosocial/internal/db/bundb"
- "github.com/superseriousbusiness/gotosocial/internal/trans"
-)
-
-// Export exports info from the database into a file
-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)
-
- path, ok := c.ExportCLIFlags[config.TransPathFlag]
- if !ok {
- return errors.New("no path set")
- }
-
- if err := exporter.ExportMinimal(ctx, path); err != nil {
- return err
- }
-
- return dbConn.Stop(ctx)
-}
diff --git a/internal/cliactions/admin/trans/import.go b/internal/cliactions/admin/trans/import.go
deleted file mode 100644
index 9ab85d62f..000000000
--- a/internal/cliactions/admin/trans/import.go
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- GoToSocial
- Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-package trans
-
-import (
- "context"
- "errors"
- "fmt"
-
- "github.com/superseriousbusiness/gotosocial/internal/cliactions"
- "github.com/superseriousbusiness/gotosocial/internal/config"
- "github.com/superseriousbusiness/gotosocial/internal/db/bundb"
- "github.com/superseriousbusiness/gotosocial/internal/trans"
-)
-
-// Import imports info from a file into the database
-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)
-
- path, ok := c.ExportCLIFlags[config.TransPathFlag]
- if !ok {
- return errors.New("no path set")
- }
-
- if err := importer.Import(ctx, path); err != nil {
- return err
- }
-
- return dbConn.Stop(ctx)
-}
diff --git a/internal/cliactions/server/server.go b/internal/cliactions/server/server.go
deleted file mode 100644
index 3e6acfe84..000000000
--- a/internal/cliactions/server/server.go
+++ /dev/null
@@ -1,204 +0,0 @@
-package server
-
-import (
- "context"
- "fmt"
- "net/http"
- "os"
- "os/signal"
- "syscall"
-
- "codeberg.org/gruf/go-store/kv"
- "github.com/sirupsen/logrus"
- "github.com/superseriousbusiness/gotosocial/internal/api"
- "github.com/superseriousbusiness/gotosocial/internal/api/client/account"
- "github.com/superseriousbusiness/gotosocial/internal/api/client/admin"
- "github.com/superseriousbusiness/gotosocial/internal/api/client/app"
- "github.com/superseriousbusiness/gotosocial/internal/api/client/auth"
- "github.com/superseriousbusiness/gotosocial/internal/api/client/blocks"
- "github.com/superseriousbusiness/gotosocial/internal/api/client/emoji"
- "github.com/superseriousbusiness/gotosocial/internal/api/client/favourites"
- "github.com/superseriousbusiness/gotosocial/internal/api/client/fileserver"
- "github.com/superseriousbusiness/gotosocial/internal/api/client/filter"
- "github.com/superseriousbusiness/gotosocial/internal/api/client/followrequest"
- "github.com/superseriousbusiness/gotosocial/internal/api/client/instance"
- "github.com/superseriousbusiness/gotosocial/internal/api/client/list"
- mediaModule "github.com/superseriousbusiness/gotosocial/internal/api/client/media"
- "github.com/superseriousbusiness/gotosocial/internal/api/client/notification"
- "github.com/superseriousbusiness/gotosocial/internal/api/client/search"
- "github.com/superseriousbusiness/gotosocial/internal/api/client/status"
- "github.com/superseriousbusiness/gotosocial/internal/api/client/streaming"
- "github.com/superseriousbusiness/gotosocial/internal/api/client/timeline"
- userClient "github.com/superseriousbusiness/gotosocial/internal/api/client/user"
- "github.com/superseriousbusiness/gotosocial/internal/api/s2s/nodeinfo"
- "github.com/superseriousbusiness/gotosocial/internal/api/s2s/user"
- "github.com/superseriousbusiness/gotosocial/internal/api/s2s/webfinger"
- "github.com/superseriousbusiness/gotosocial/internal/api/security"
- "github.com/superseriousbusiness/gotosocial/internal/cliactions"
- "github.com/superseriousbusiness/gotosocial/internal/config"
- "github.com/superseriousbusiness/gotosocial/internal/db/bundb"
- "github.com/superseriousbusiness/gotosocial/internal/email"
- "github.com/superseriousbusiness/gotosocial/internal/federation"
- "github.com/superseriousbusiness/gotosocial/internal/federation/federatingdb"
- "github.com/superseriousbusiness/gotosocial/internal/gotosocial"
- "github.com/superseriousbusiness/gotosocial/internal/media"
- "github.com/superseriousbusiness/gotosocial/internal/oauth"
- "github.com/superseriousbusiness/gotosocial/internal/oidc"
- "github.com/superseriousbusiness/gotosocial/internal/processing"
- "github.com/superseriousbusiness/gotosocial/internal/router"
- timelineprocessing "github.com/superseriousbusiness/gotosocial/internal/timeline"
- "github.com/superseriousbusiness/gotosocial/internal/transport"
- "github.com/superseriousbusiness/gotosocial/internal/typeutils"
- "github.com/superseriousbusiness/gotosocial/internal/web"
-)
-
-// Start creates and starts a gotosocial server
-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)
- }
-
- if err := dbService.CreateInstanceAccount(ctx); err != nil {
- return fmt.Errorf("error creating instance account: %s", err)
- }
-
- if err := dbService.CreateInstanceInstance(ctx); err != nil {
- return fmt.Errorf("error creating instance instance: %s", err)
- }
-
- federatingDB := federatingdb.New(dbService, c)
-
- router, err := router.New(ctx, c, dbService)
- if err != nil {
- return fmt.Errorf("error creating router: %s", err)
- }
-
- // build converters and util
- typeConverter := typeutils.NewConverter(c, dbService)
- timelineManager := timelineprocessing.NewManager(dbService, typeConverter, c)
-
- // Open the storage backend
- storage, err := kv.OpenFile(c.StorageConfig.BasePath, nil)
- if err != nil {
- return fmt.Errorf("error creating storage backend: %s", err)
- }
-
- // build backend handlers
- 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)
-
- // decide whether to create a noop email sender (won't send emails) or a real one
- var emailSender email.Sender
- if c.SMTPConfig.Host != "" {
- // host is defined so create a proper sender
- emailSender, err = email.NewSender(c)
- if err != nil {
- return fmt.Errorf("error creating email sender: %s", err)
- }
- } else {
- // no host is defined so create a noop sender
- emailSender, err = email.NewNoopSender(c.TemplateConfig.BaseDir, nil)
- if err != nil {
- return fmt.Errorf("error creating noop email sender: %s", err)
- }
- }
-
- // create and start the message processor using the other services we've created so far
- processor := processing.NewProcessor(c, typeConverter, federator, oauthServer, mediaHandler, storage, timelineManager, dbService, emailSender)
- if err := processor.Start(ctx); err != nil {
- return fmt.Errorf("error starting processor: %s", err)
- }
-
- 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)
- 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, oauthServer)
- streamingModule := streaming.New(c, processor)
- favouritesModule := favourites.New(c, processor)
- blocksModule := blocks.New(c, processor)
- userClientModule := userClient.New(c, processor)
-
- apis := []api.ClientModule{
- // modules with middleware go first
- securityModule,
- authModule,
-
- // now everything else
- webBaseModule,
- accountModule,
- instanceModule,
- appsModule,
- followRequestsModule,
- mm,
- fileServerModule,
- adminModule,
- statusModule,
- webfingerModule,
- nodeInfoModule,
- usersModule,
- timelineModule,
- notificationModule,
- searchModule,
- filtersModule,
- emojiModule,
- listsModule,
- streamingModule,
- favouritesModule,
- blocksModule,
- userClientModule,
- }
-
- for _, m := range apis {
- if err := m.Route(router); err != nil {
- return fmt.Errorf("routing error: %s", err)
- }
- }
-
- gts, err := gotosocial.NewServer(dbService, router, federator, c)
- if err != nil {
- return fmt.Errorf("error creating gotosocial service: %s", err)
- }
-
- if err := gts.Start(ctx); err != nil {
- return fmt.Errorf("error starting gotosocial service: %s", err)
- }
-
- // catch shutdown signals from the operating system
- sigs := make(chan os.Signal, 1)
- signal.Notify(sigs, os.Interrupt, syscall.SIGTERM)
- sig := <-sigs
- 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)
- }
-
- logrus.Info("done! exiting...")
- return nil
-}
diff --git a/internal/cliactions/testrig/testrig.go b/internal/cliactions/testrig/testrig.go
deleted file mode 100644
index 5e55c3d03..000000000
--- a/internal/cliactions/testrig/testrig.go
+++ /dev/null
@@ -1,167 +0,0 @@
-package testrig
-
-import (
- "bytes"
- "context"
- "fmt"
- "io/ioutil"
- "net/http"
- "os"
- "os/signal"
- "syscall"
-
- "github.com/sirupsen/logrus"
- "github.com/superseriousbusiness/gotosocial/internal/api"
- "github.com/superseriousbusiness/gotosocial/internal/api/client/account"
- "github.com/superseriousbusiness/gotosocial/internal/api/client/admin"
- "github.com/superseriousbusiness/gotosocial/internal/api/client/app"
- "github.com/superseriousbusiness/gotosocial/internal/api/client/auth"
- "github.com/superseriousbusiness/gotosocial/internal/api/client/blocks"
- "github.com/superseriousbusiness/gotosocial/internal/api/client/emoji"
- "github.com/superseriousbusiness/gotosocial/internal/api/client/favourites"
- "github.com/superseriousbusiness/gotosocial/internal/api/client/fileserver"
- "github.com/superseriousbusiness/gotosocial/internal/api/client/filter"
- "github.com/superseriousbusiness/gotosocial/internal/api/client/followrequest"
- "github.com/superseriousbusiness/gotosocial/internal/api/client/instance"
- "github.com/superseriousbusiness/gotosocial/internal/api/client/list"
- mediaModule "github.com/superseriousbusiness/gotosocial/internal/api/client/media"
- "github.com/superseriousbusiness/gotosocial/internal/api/client/notification"
- "github.com/superseriousbusiness/gotosocial/internal/api/client/search"
- "github.com/superseriousbusiness/gotosocial/internal/api/client/status"
- "github.com/superseriousbusiness/gotosocial/internal/api/client/streaming"
- "github.com/superseriousbusiness/gotosocial/internal/api/client/timeline"
- userClient "github.com/superseriousbusiness/gotosocial/internal/api/client/user"
- "github.com/superseriousbusiness/gotosocial/internal/api/s2s/nodeinfo"
- "github.com/superseriousbusiness/gotosocial/internal/api/s2s/user"
- "github.com/superseriousbusiness/gotosocial/internal/api/s2s/webfinger"
- "github.com/superseriousbusiness/gotosocial/internal/api/security"
- "github.com/superseriousbusiness/gotosocial/internal/cliactions"
- "github.com/superseriousbusiness/gotosocial/internal/config"
- "github.com/superseriousbusiness/gotosocial/internal/gotosocial"
- "github.com/superseriousbusiness/gotosocial/internal/oidc"
- "github.com/superseriousbusiness/gotosocial/internal/web"
- "github.com/superseriousbusiness/gotosocial/testrig"
-)
-
-// Start creates and starts a gotosocial testrig server
-var Start cliactions.GTSAction = func(ctx context.Context, _ *config.Config) error {
- testrig.InitTestLog()
-
- c := testrig.NewTestConfig()
- dbService := testrig.NewTestDB()
- testrig.StandardDBSetup(dbService, nil)
- router := testrig.NewTestRouter(dbService)
- storageBackend := testrig.NewTestStorage()
- testrig.StandardStorageSetup(storageBackend, "./testrig/media")
-
- // build backend handlers
- oauthServer := testrig.NewTestOauthServer(dbService)
- transportController := testrig.NewTestTransportController(testrig.NewMockHTTPClient(func(req *http.Request) (*http.Response, error) {
- r := ioutil.NopCloser(bytes.NewReader([]byte{}))
- return &http.Response{
- StatusCode: 200,
- Body: r,
- }, nil
- }), dbService)
- federator := testrig.NewTestFederator(dbService, transportController, storageBackend)
-
- emailSender := testrig.NewEmailSender("./web/template/", nil)
-
- processor := testrig.NewTestProcessor(dbService, storageBackend, federator, emailSender)
- if err := processor.Start(ctx); err != nil {
- return fmt.Errorf("error starting processor: %s", err)
- }
-
- 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)
- 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, oauthServer)
- streamingModule := streaming.New(c, processor)
- favouritesModule := favourites.New(c, processor)
- blocksModule := blocks.New(c, processor)
- userClientModule := userClient.New(c, processor)
-
- apis := []api.ClientModule{
- // modules with middleware go first
- securityModule,
- authModule,
-
- // now everything else
- webBaseModule,
- accountModule,
- instanceModule,
- appsModule,
- followRequestsModule,
- mm,
- fileServerModule,
- adminModule,
- statusModule,
- webfingerModule,
- nodeInfoModule,
- usersModule,
- timelineModule,
- notificationModule,
- searchModule,
- filtersModule,
- emojiModule,
- listsModule,
- streamingModule,
- favouritesModule,
- blocksModule,
- userClientModule,
- }
-
- for _, m := range apis {
- if err := m.Route(router); err != nil {
- return fmt.Errorf("routing error: %s", err)
- }
- }
-
- gts, err := gotosocial.NewServer(dbService, router, federator, c)
- if err != nil {
- return fmt.Errorf("error creating gotosocial service: %s", err)
- }
-
- if err := gts.Start(ctx); err != nil {
- return fmt.Errorf("error starting gotosocial service: %s", err)
- }
-
- // catch shutdown signals from the operating system
- sigs := make(chan os.Signal, 1)
- signal.Notify(sigs, os.Interrupt, syscall.SIGTERM)
- sig := <-sigs
- logrus.Infof("received signal %s, shutting down", sig)
-
- testrig.StandardDBTeardown(dbService)
- testrig.StandardStorageTeardown(storageBackend)
-
- // close down all running services in order
- if err := gts.Stop(ctx); err != nil {
- return fmt.Errorf("error closing gotosocial service: %s", err)
- }
-
- logrus.Info("done! exiting...")
- return nil
-}