summaryrefslogtreecommitdiff
path: root/internal/processing
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2021-12-07 13:31:39 +0100
committerLibravatar GitHub <noreply@github.com>2021-12-07 13:31:39 +0100
commit0884f89431cd26bcc9674b3b7ab628b090f5881e (patch)
treecdd3b3f77f780a8b59d075dbcc3d4d013811e405 /internal/processing
parentUpdate dependencies (#333) (diff)
downloadgotosocial-0884f89431cd26bcc9674b3b7ab628b090f5881e.tar.xz
Implement Cobra CLI tooling, Viper config tooling (#336)
* start pulling out + replacing urfave and config * replace many many instances of config * move more stuff => viper * properly remove urfave * move some flags to root command * add testrig commands to root * alias config file keys * start adding cli parsing tests * reorder viper init * remove config path alias * fmt * change config file keys to non-nested * we're more or less in business now * tidy up the common func * go fmt * get tests passing again * add note about the cliparsing tests * reorganize * update docs with changes * structure cmd dir better * rename + move some files around * fix dangling comma
Diffstat (limited to 'internal/processing')
-rw-r--r--internal/processing/account/account.go7
-rw-r--r--internal/processing/account/account_test.go9
-rw-r--r--internal/processing/account/create.go10
-rw-r--r--internal/processing/account/createblock.go2
-rw-r--r--internal/processing/account/createfollow.go2
-rw-r--r--internal/processing/account/update.go15
-rw-r--r--internal/processing/admin/admin.go5
-rw-r--r--internal/processing/blocks.go13
-rw-r--r--internal/processing/federation/federation.go5
-rw-r--r--internal/processing/federation/getnodeinfo.go14
-rw-r--r--internal/processing/federation/getwebfinger.go6
-rw-r--r--internal/processing/instance.go13
-rw-r--r--internal/processing/media/media.go5
-rw-r--r--internal/processing/processor.go16
-rw-r--r--internal/processing/processor_test.go9
-rw-r--r--internal/processing/search.go5
-rw-r--r--internal/processing/status/create.go2
-rw-r--r--internal/processing/status/fave.go2
-rw-r--r--internal/processing/status/status.go7
-rw-r--r--internal/processing/status/status_test.go32
-rw-r--r--internal/processing/status/util_test.go30
-rw-r--r--internal/processing/streaming/streaming_test.go4
-rw-r--r--internal/processing/timeline.go16
-rw-r--r--internal/processing/user/emailconfirm.go7
-rw-r--r--internal/processing/user/user.go5
-rw-r--r--internal/processing/user/user_test.go7
26 files changed, 132 insertions, 116 deletions
diff --git a/internal/processing/account/account.go b/internal/processing/account/account.go
index 4e807540c..c37261adc 100644
--- a/internal/processing/account/account.go
+++ b/internal/processing/account/account.go
@@ -23,7 +23,6 @@ import (
"mime/multipart"
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
- "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/federation"
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
@@ -78,7 +77,6 @@ type Processor interface {
type processor struct {
tc typeutils.TypeConverter
- config *config.Config
mediaHandler media.Handler
fromClientAPI chan messages.FromClientAPI
oauthServer oauth.Server
@@ -89,15 +87,14 @@ type processor struct {
}
// New returns a new account processor.
-func New(db db.DB, tc typeutils.TypeConverter, mediaHandler media.Handler, oauthServer oauth.Server, fromClientAPI chan messages.FromClientAPI, federator federation.Federator, config *config.Config) Processor {
+func New(db db.DB, tc typeutils.TypeConverter, mediaHandler media.Handler, oauthServer oauth.Server, fromClientAPI chan messages.FromClientAPI, federator federation.Federator) Processor {
return &processor{
tc: tc,
- config: config,
mediaHandler: mediaHandler,
fromClientAPI: fromClientAPI,
oauthServer: oauthServer,
filter: visibility.NewFilter(db),
- formatter: text.NewFormatter(config, db),
+ formatter: text.NewFormatter(db),
db: db,
federator: federator,
}
diff --git a/internal/processing/account/account_test.go b/internal/processing/account/account_test.go
index 9bc97a77b..17893b4c0 100644
--- a/internal/processing/account/account_test.go
+++ b/internal/processing/account/account_test.go
@@ -22,7 +22,6 @@ import (
"codeberg.org/gruf/go-store/kv"
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/activity/pub"
- "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/email"
"github.com/superseriousbusiness/gotosocial/internal/federation"
@@ -39,7 +38,6 @@ import (
type AccountStandardTestSuite struct {
// standard suite interfaces
suite.Suite
- config *config.Config
db db.DB
tc typeutils.TypeConverter
storage *kv.KVStore
@@ -76,9 +74,10 @@ func (suite *AccountStandardTestSuite) SetupSuite() {
}
func (suite *AccountStandardTestSuite) SetupTest() {
- suite.config = testrig.NewTestConfig()
- suite.db = testrig.NewTestDB()
testrig.InitTestLog()
+ testrig.InitTestConfig()
+
+ suite.db = testrig.NewTestDB()
suite.tc = testrig.NewTestTypeConverter(suite.db)
suite.storage = testrig.NewTestStorage()
suite.mediaHandler = testrig.NewTestMediaHandler(suite.db, suite.storage)
@@ -89,7 +88,7 @@ func (suite *AccountStandardTestSuite) SetupTest() {
suite.federator = testrig.NewTestFederator(suite.db, suite.transportController, suite.storage)
suite.sentEmails = make(map[string]string)
suite.emailSender = testrig.NewEmailSender("../../../web/template/", suite.sentEmails)
- suite.accountProcessor = account.New(suite.db, suite.tc, suite.mediaHandler, suite.oauthServer, suite.fromClientAPIChan, suite.federator, suite.config)
+ suite.accountProcessor = account.New(suite.db, suite.tc, suite.mediaHandler, suite.oauthServer, suite.fromClientAPIChan, suite.federator)
testrig.StandardDBSetup(suite.db, nil)
testrig.StandardStorageSetup(suite.storage, "../../../testrig/media")
}
diff --git a/internal/processing/account/create.go b/internal/processing/account/create.go
index a13e84a78..3d024417b 100644
--- a/internal/processing/account/create.go
+++ b/internal/processing/account/create.go
@@ -23,9 +23,11 @@ import (
"fmt"
"github.com/sirupsen/logrus"
+ "github.com/spf13/viper"
"github.com/superseriousbusiness/gotosocial/internal/ap"
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
+ "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/messages"
"github.com/superseriousbusiness/gotosocial/internal/text"
@@ -51,14 +53,18 @@ func (p *processor) Create(ctx context.Context, applicationToken oauth2.TokenInf
return nil, fmt.Errorf("username %s in use", form.Username)
}
+ keys := config.Keys
+ reasonRequired := viper.GetBool(keys.AccountsReasonRequired)
+ approvalRequired := viper.GetBool(keys.AccountsApprovalRequired)
+
// don't store a reason if we don't require one
reason := form.Reason
- if !p.config.AccountsConfig.ReasonRequired {
+ if !reasonRequired {
reason = ""
}
l.Trace("creating new username and account")
- user, err := p.db.NewSignup(ctx, form.Username, text.RemoveHTML(reason), p.config.AccountsConfig.RequireApproval, form.Email, form.Password, form.IP, form.Locale, application.ID, false, false)
+ user, err := p.db.NewSignup(ctx, form.Username, text.RemoveHTML(reason), approvalRequired, form.Email, form.Password, form.IP, form.Locale, application.ID, false, false)
if err != nil {
return nil, fmt.Errorf("error creating new signup in the database: %s", err)
}
diff --git a/internal/processing/account/createblock.go b/internal/processing/account/createblock.go
index 347f19bee..6785ffed1 100644
--- a/internal/processing/account/createblock.go
+++ b/internal/processing/account/createblock.go
@@ -57,7 +57,7 @@ func (p *processor) BlockCreate(ctx context.Context, requestingAccount *gtsmodel
block.Account = requestingAccount
block.TargetAccountID = targetAccountID
block.TargetAccount = targetAccount
- block.URI = util.GenerateURIForBlock(requestingAccount.Username, p.config.Protocol, p.config.Host, newBlockID)
+ block.URI = util.GenerateURIForBlock(requestingAccount.Username, newBlockID)
// whack it in the database
if err := p.db.Put(ctx, block); err != nil {
diff --git a/internal/processing/account/createfollow.go b/internal/processing/account/createfollow.go
index d3ca386ed..9b082187b 100644
--- a/internal/processing/account/createfollow.go
+++ b/internal/processing/account/createfollow.go
@@ -76,7 +76,7 @@ func (p *processor) FollowCreate(ctx context.Context, requestingAccount *gtsmode
AccountID: requestingAccount.ID,
TargetAccountID: form.ID,
ShowReblogs: true,
- URI: util.GenerateURIForFollow(requestingAccount.Username, p.config.Protocol, p.config.Host, newFollowID),
+ URI: util.GenerateURIForFollow(requestingAccount.Username, newFollowID),
Notify: false,
}
if form.Reblogs != nil {
diff --git a/internal/processing/account/update.go b/internal/processing/account/update.go
index 54bf372e7..ca386eb39 100644
--- a/internal/processing/account/update.go
+++ b/internal/processing/account/update.go
@@ -23,12 +23,15 @@ import (
"context"
"errors"
"fmt"
- "github.com/sirupsen/logrus"
"io"
"mime/multipart"
+ "github.com/sirupsen/logrus"
+ "github.com/spf13/viper"
+
"github.com/superseriousbusiness/gotosocial/internal/ap"
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
+ "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/media"
"github.com/superseriousbusiness/gotosocial/internal/messages"
@@ -135,8 +138,9 @@ func (p *processor) Update(ctx context.Context, account *gtsmodel.Account, form
// the account's new avatar image.
func (p *processor) UpdateAvatar(ctx context.Context, avatar *multipart.FileHeader, accountID string) (*gtsmodel.MediaAttachment, error) {
var err error
- if int(avatar.Size) > p.config.MediaConfig.MaxImageSize {
- err = fmt.Errorf("avatar with size %d exceeded max image size of %d bytes", avatar.Size, p.config.MediaConfig.MaxImageSize)
+ maxImageSize := viper.GetInt(config.Keys.MediaImageMaxSize)
+ if int(avatar.Size) > maxImageSize {
+ err = fmt.Errorf("avatar with size %d exceeded max image size of %d bytes", avatar.Size, maxImageSize)
return nil, err
}
f, err := avatar.Open()
@@ -168,8 +172,9 @@ func (p *processor) UpdateAvatar(ctx context.Context, avatar *multipart.FileHead
// the account's new header image.
func (p *processor) UpdateHeader(ctx context.Context, header *multipart.FileHeader, accountID string) (*gtsmodel.MediaAttachment, error) {
var err error
- if int(header.Size) > p.config.MediaConfig.MaxImageSize {
- err = fmt.Errorf("header with size %d exceeded max image size of %d bytes", header.Size, p.config.MediaConfig.MaxImageSize)
+ maxImageSize := viper.GetInt(config.Keys.MediaImageMaxSize)
+ if int(header.Size) > maxImageSize {
+ err = fmt.Errorf("header with size %d exceeded max image size of %d bytes", header.Size, maxImageSize)
return nil, err
}
f, err := header.Open()
diff --git a/internal/processing/admin/admin.go b/internal/processing/admin/admin.go
index 1aaaced5e..8b46ab6b7 100644
--- a/internal/processing/admin/admin.go
+++ b/internal/processing/admin/admin.go
@@ -23,7 +23,6 @@ import (
"mime/multipart"
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
- "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
@@ -44,17 +43,15 @@ type Processor interface {
type processor struct {
tc typeutils.TypeConverter
- config *config.Config
mediaHandler media.Handler
fromClientAPI chan messages.FromClientAPI
db db.DB
}
// New returns a new admin processor.
-func New(db db.DB, tc typeutils.TypeConverter, mediaHandler media.Handler, fromClientAPI chan messages.FromClientAPI, config *config.Config) Processor {
+func New(db db.DB, tc typeutils.TypeConverter, mediaHandler media.Handler, fromClientAPI chan messages.FromClientAPI) Processor {
return &processor{
tc: tc,
- config: config,
mediaHandler: mediaHandler,
fromClientAPI: fromClientAPI,
db: db,
diff --git a/internal/processing/blocks.go b/internal/processing/blocks.go
index 1144579a4..ad5553be9 100644
--- a/internal/processing/blocks.go
+++ b/internal/processing/blocks.go
@@ -23,7 +23,9 @@ import (
"fmt"
"net/url"
+ "github.com/spf13/viper"
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
+ "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
"github.com/superseriousbusiness/gotosocial/internal/oauth"
@@ -62,17 +64,20 @@ func (p *processor) packageBlocksResponse(accounts []*apimodel.Account, path str
// prepare the next and previous links
if len(accounts) != 0 {
+ protocol := viper.GetString(config.Keys.Protocol)
+ host := viper.GetString(config.Keys.Host)
+
nextLink := &url.URL{
- Scheme: p.config.Protocol,
- Host: p.config.Host,
+ Scheme: protocol,
+ Host: host,
Path: path,
RawQuery: fmt.Sprintf("limit=%d&max_id=%s", limit, nextMaxID),
}
next := fmt.Sprintf("<%s>; rel=\"next\"", nextLink.String())
prevLink := &url.URL{
- Scheme: p.config.Protocol,
- Host: p.config.Host,
+ Scheme: protocol,
+ Host: host,
Path: path,
RawQuery: fmt.Sprintf("limit=%d&min_id=%s", limit, prevMinID),
}
diff --git a/internal/processing/federation/federation.go b/internal/processing/federation/federation.go
index b050406c5..a3e25c2aa 100644
--- a/internal/processing/federation/federation.go
+++ b/internal/processing/federation/federation.go
@@ -24,7 +24,6 @@ import (
"net/url"
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
- "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/federation"
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
@@ -83,7 +82,6 @@ type Processor interface {
type processor struct {
db db.DB
- config *config.Config
federator federation.Federator
tc typeutils.TypeConverter
filter visibility.Filter
@@ -91,10 +89,9 @@ type processor struct {
}
// New returns a new federation processor.
-func New(db db.DB, tc typeutils.TypeConverter, config *config.Config, federator federation.Federator, fromFederator chan messages.FromFederator) Processor {
+func New(db db.DB, tc typeutils.TypeConverter, federator federation.Federator, fromFederator chan messages.FromFederator) Processor {
return &processor{
db: db,
- config: config,
federator: federator,
tc: tc,
filter: visibility.NewFilter(db),
diff --git a/internal/processing/federation/getnodeinfo.go b/internal/processing/federation/getnodeinfo.go
index 4eb8ad3b7..78e03a744 100644
--- a/internal/processing/federation/getnodeinfo.go
+++ b/internal/processing/federation/getnodeinfo.go
@@ -23,7 +23,9 @@ import (
"fmt"
"net/http"
+ "github.com/spf13/viper"
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
+ "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
)
@@ -38,29 +40,35 @@ var (
)
func (p *processor) GetNodeInfoRel(ctx context.Context, request *http.Request) (*apimodel.WellKnownResponse, gtserror.WithCode) {
+ protocol := viper.GetString(config.Keys.Protocol)
+ host := viper.GetString(config.Keys.Host)
+
return &apimodel.WellKnownResponse{
Links: []apimodel.Link{
{
Rel: nodeInfoRel,
- Href: fmt.Sprintf("%s://%s/nodeinfo/%s", p.config.Protocol, p.config.Host, nodeInfoVersion),
+ Href: fmt.Sprintf("%s://%s/nodeinfo/%s", protocol, host, nodeInfoVersion),
},
},
}, nil
}
func (p *processor) GetNodeInfo(ctx context.Context, request *http.Request) (*apimodel.Nodeinfo, gtserror.WithCode) {
+ openRegistration := viper.GetBool(config.Keys.AccountsRegistrationOpen)
+ softwareVersion := viper.GetString(config.Keys.SoftwareVersion)
+
return &apimodel.Nodeinfo{
Version: nodeInfoVersion,
Software: apimodel.NodeInfoSoftware{
Name: nodeInfoSoftwareName,
- Version: p.config.SoftwareVersion,
+ Version: softwareVersion,
},
Protocols: nodeInfoProtocols,
Services: apimodel.NodeInfoServices{
Inbound: []string{},
Outbound: []string{},
},
- OpenRegistrations: p.config.AccountsConfig.OpenRegistration,
+ OpenRegistrations: openRegistration,
Usage: apimodel.NodeInfoUsage{
Users: apimodel.NodeInfoUsers{},
},
diff --git a/internal/processing/federation/getwebfinger.go b/internal/processing/federation/getwebfinger.go
index aaa7687be..e16b3e139 100644
--- a/internal/processing/federation/getwebfinger.go
+++ b/internal/processing/federation/getwebfinger.go
@@ -22,7 +22,9 @@ import (
"context"
"fmt"
+ "github.com/spf13/viper"
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
+ "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
)
@@ -41,9 +43,11 @@ func (p *processor) GetWebfingerAccount(ctx context.Context, requestedUsername s
return nil, gtserror.NewErrorNotFound(fmt.Errorf("database error getting account with username %s: %s", requestedUsername, err))
}
+ accountDomain := viper.GetString(config.Keys.AccountDomain)
+
// return the webfinger representation
return &apimodel.WellKnownResponse{
- Subject: fmt.Sprintf("%s:%s@%s", webfingerAccount, requestedAccount.Username, p.config.AccountDomain),
+ Subject: fmt.Sprintf("%s:%s@%s", webfingerAccount, requestedAccount.Username, accountDomain),
Aliases: []string{
requestedAccount.URI,
requestedAccount.URL,
diff --git a/internal/processing/instance.go b/internal/processing/instance.go
index 75d17d13a..995a841e3 100644
--- a/internal/processing/instance.go
+++ b/internal/processing/instance.go
@@ -22,7 +22,9 @@ import (
"context"
"fmt"
+ "github.com/spf13/viper"
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
+ "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
@@ -33,7 +35,7 @@ import (
func (p *processor) InstanceGet(ctx context.Context, domain string) (*apimodel.Instance, gtserror.WithCode) {
i := &gtsmodel.Instance{}
if err := p.db.GetWhere(ctx, []db.Where{{Key: "domain", Value: domain}}, i); err != nil {
- return nil, gtserror.NewErrorInternalError(fmt.Errorf("db error fetching instance %s: %s", p.config.Host, err))
+ return nil, gtserror.NewErrorInternalError(fmt.Errorf("db error fetching instance %s: %s", domain, err))
}
ai, err := p.tc.InstanceToAPIInstance(ctx, i)
@@ -47,14 +49,15 @@ func (p *processor) InstanceGet(ctx context.Context, domain string) (*apimodel.I
func (p *processor) InstancePatch(ctx context.Context, form *apimodel.InstanceSettingsUpdateRequest) (*apimodel.Instance, gtserror.WithCode) {
// fetch the instance entry from the db for processing
i := &gtsmodel.Instance{}
- if err := p.db.GetWhere(ctx, []db.Where{{Key: "domain", Value: p.config.Host}}, i); err != nil {
- return nil, gtserror.NewErrorInternalError(fmt.Errorf("db error fetching instance %s: %s", p.config.Host, err))
+ host := viper.GetString(config.Keys.Host)
+ if err := p.db.GetWhere(ctx, []db.Where{{Key: "domain", Value: host}}, i); err != nil {
+ return nil, gtserror.NewErrorInternalError(fmt.Errorf("db error fetching instance %s: %s", host, err))
}
// fetch the instance account from the db for processing
ia, err := p.db.GetInstanceAccount(ctx, "")
if err != nil {
- return nil, gtserror.NewErrorInternalError(fmt.Errorf("db error fetching instance account %s: %s", p.config.Host, err))
+ return nil, gtserror.NewErrorInternalError(fmt.Errorf("db error fetching instance account %s: %s", host, err))
}
// validate & update site title if it's set on the form
@@ -148,7 +151,7 @@ func (p *processor) InstancePatch(ctx context.Context, form *apimodel.InstanceSe
}
if err := p.db.UpdateByPrimaryKey(ctx, i); err != nil {
- return nil, gtserror.NewErrorInternalError(fmt.Errorf("db error updating instance %s: %s", p.config.Host, err))
+ return nil, gtserror.NewErrorInternalError(fmt.Errorf("db error updating instance %s: %s", host, err))
}
ai, err := p.tc.InstanceToAPIInstance(ctx, i)
diff --git a/internal/processing/media/media.go b/internal/processing/media/media.go
index cf8ec8562..54dbd1478 100644
--- a/internal/processing/media/media.go
+++ b/internal/processing/media/media.go
@@ -23,7 +23,6 @@ import (
"codeberg.org/gruf/go-store/kv"
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
- "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
@@ -44,17 +43,15 @@ type Processor interface {
type processor struct {
tc typeutils.TypeConverter
- config *config.Config
mediaHandler media.Handler
storage *kv.KVStore
db db.DB
}
// New returns a new media processor.
-func New(db db.DB, tc typeutils.TypeConverter, mediaHandler media.Handler, storage *kv.KVStore, config *config.Config) Processor {
+func New(db db.DB, tc typeutils.TypeConverter, mediaHandler media.Handler, storage *kv.KVStore) Processor {
return &processor{
tc: tc,
- config: config,
mediaHandler: mediaHandler,
storage: storage,
db: db,
diff --git a/internal/processing/processor.go b/internal/processing/processor.go
index a65ef23d9..ebfabb0de 100644
--- a/internal/processing/processor.go
+++ b/internal/processing/processor.go
@@ -26,7 +26,6 @@ import (
"codeberg.org/gruf/go-store/kv"
"github.com/sirupsen/logrus"
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
- "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/email"
"github.com/superseriousbusiness/gotosocial/internal/federation"
@@ -234,7 +233,6 @@ type processor struct {
fromFederator chan messages.FromFederator
federator federation.Federator
stop chan interface{}
- config *config.Config
tc typeutils.TypeConverter
oauthServer oauth.Server
mediaHandler media.Handler
@@ -258,7 +256,6 @@ type processor struct {
// NewProcessor returns a new Processor.
func NewProcessor(
- config *config.Config,
tc typeutils.TypeConverter,
federator federation.Federator,
oauthServer oauth.Server,
@@ -270,20 +267,19 @@ func NewProcessor(
fromClientAPI := make(chan messages.FromClientAPI, 1000)
fromFederator := make(chan messages.FromFederator, 1000)
- statusProcessor := status.New(db, tc, config, fromClientAPI)
+ statusProcessor := status.New(db, tc, fromClientAPI)
streamingProcessor := streaming.New(db, oauthServer)
- accountProcessor := account.New(db, tc, mediaHandler, oauthServer, fromClientAPI, federator, config)
- adminProcessor := admin.New(db, tc, mediaHandler, fromClientAPI, config)
- mediaProcessor := mediaProcessor.New(db, tc, mediaHandler, storage, config)
- userProcessor := user.New(db, emailSender, config)
- federationProcessor := federationProcessor.New(db, tc, config, federator, fromFederator)
+ accountProcessor := account.New(db, tc, mediaHandler, oauthServer, fromClientAPI, federator)
+ adminProcessor := admin.New(db, tc, mediaHandler, fromClientAPI)
+ mediaProcessor := mediaProcessor.New(db, tc, mediaHandler, storage)
+ userProcessor := user.New(db, emailSender)
+ federationProcessor := federationProcessor.New(db, tc, federator, fromFederator)
return &processor{
fromClientAPI: fromClientAPI,
fromFederator: fromFederator,
federator: federator,
stop: make(chan interface{}),
- config: config,
tc: tc,
oauthServer: oauthServer,
mediaHandler: mediaHandler,
diff --git a/internal/processing/processor_test.go b/internal/processing/processor_test.go
index 181cfa63a..2ed1e1d44 100644
--- a/internal/processing/processor_test.go
+++ b/internal/processing/processor_test.go
@@ -29,7 +29,6 @@ import (
"codeberg.org/gruf/go-store/kv"
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/activity/streams"
- "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/email"
"github.com/superseriousbusiness/gotosocial/internal/federation"
@@ -46,7 +45,6 @@ import (
type ProcessingStandardTestSuite struct {
// standard suite interfaces
suite.Suite
- config *config.Config
db db.DB
storage *kv.KVStore
typeconverter typeutils.TypeConverter
@@ -93,14 +91,15 @@ func (suite *ProcessingStandardTestSuite) SetupSuite() {
Account: suite.testAccounts["local_account_1"],
},
}
- suite.testActivities = testrig.NewTestActivities(suite.testAccounts)
suite.testBlocks = testrig.NewTestBlocks()
}
func (suite *ProcessingStandardTestSuite) SetupTest() {
testrig.InitTestLog()
- suite.config = testrig.NewTestConfig()
+ testrig.InitTestConfig()
+
suite.db = testrig.NewTestDB()
+ suite.testActivities = testrig.NewTestActivities(suite.testAccounts)
suite.storage = testrig.NewTestStorage()
suite.typeconverter = testrig.NewTestTypeConverter(suite.db)
@@ -223,7 +222,7 @@ func (suite *ProcessingStandardTestSuite) SetupTest() {
suite.timelineManager = testrig.NewTestTimelineManager(suite.db)
suite.emailSender = testrig.NewEmailSender("../../web/template/", nil)
- suite.processor = processing.NewProcessor(suite.config, suite.typeconverter, suite.federator, suite.oauthServer, suite.mediaHandler, suite.storage, suite.timelineManager, suite.db, suite.emailSender)
+ suite.processor = processing.NewProcessor(suite.typeconverter, suite.federator, suite.oauthServer, suite.mediaHandler, suite.storage, suite.timelineManager, suite.db, suite.emailSender)
testrig.StandardDBSetup(suite.db, suite.testAccounts)
testrig.StandardStorageSetup(suite.storage, "../../testrig/media")
diff --git a/internal/processing/search.go b/internal/processing/search.go
index fbcfb02be..a7a2b3109 100644
--- a/internal/processing/search.go
+++ b/internal/processing/search.go
@@ -25,7 +25,9 @@ import (
"strings"
"github.com/sirupsen/logrus"
+ "github.com/spf13/viper"
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
+ "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
@@ -164,7 +166,8 @@ func (p *processor) searchAccountByMention(ctx context.Context, authed *oauth.Au
// if it's a local account we can skip a whole bunch of stuff
maybeAcct := &gtsmodel.Account{}
- if domain == p.config.Host {
+ host := viper.GetString(config.Keys.Host)
+ if domain == host {
maybeAcct, err = p.db.GetLocalAccountByUsername(ctx, username)
if err != nil {
return nil, fmt.Errorf("searchAccountByMention: error getting local account by username: %s", err)
diff --git a/internal/processing/status/create.go b/internal/processing/status/create.go
index 655be5b17..9bcb32b78 100644
--- a/internal/processing/status/create.go
+++ b/internal/processing/status/create.go
@@ -34,7 +34,7 @@ import (
)
func (p *processor) Create(ctx context.Context, account *gtsmodel.Account, application *gtsmodel.Application, form *apimodel.AdvancedStatusCreateForm) (*apimodel.Status, gtserror.WithCode) {
- uris := util.GenerateURIsForAccount(account.Username, p.config.Protocol, p.config.Host)
+ uris := util.GenerateURIsForAccount(account.Username)
thisStatusID, err := id.NewULID()
if err != nil {
return nil, gtserror.NewErrorInternalError(err)
diff --git a/internal/processing/status/fave.go b/internal/processing/status/fave.go
index 571e0715c..581caf055 100644
--- a/internal/processing/status/fave.go
+++ b/internal/processing/status/fave.go
@@ -76,7 +76,7 @@ func (p *processor) Fave(ctx context.Context, requestingAccount *gtsmodel.Accoun
TargetAccount: targetStatus.Account,
StatusID: targetStatus.ID,
Status: targetStatus,
- URI: util.GenerateURIForLike(requestingAccount.Username, p.config.Protocol, p.config.Host, thisFaveID),
+ URI: util.GenerateURIForLike(requestingAccount.Username, thisFaveID),
}
if err := p.db.Put(ctx, gtsFave); err != nil {
diff --git a/internal/processing/status/status.go b/internal/processing/status/status.go
index 666c237b7..da0abd6f4 100644
--- a/internal/processing/status/status.go
+++ b/internal/processing/status/status.go
@@ -22,7 +22,6 @@ import (
"context"
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
- "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
@@ -71,7 +70,6 @@ type Processor interface {
type processor struct {
tc typeutils.TypeConverter
- config *config.Config
db db.DB
filter visibility.Filter
formatter text.Formatter
@@ -79,13 +77,12 @@ type processor struct {
}
// New returns a new status processor.
-func New(db db.DB, tc typeutils.TypeConverter, config *config.Config, fromClientAPI chan messages.FromClientAPI) Processor {
+func New(db db.DB, tc typeutils.TypeConverter, fromClientAPI chan messages.FromClientAPI) Processor {
return &processor{
tc: tc,
- config: config,
db: db,
filter: visibility.NewFilter(db),
- formatter: text.NewFormatter(config, db),
+ formatter: text.NewFormatter(db),
fromClientAPI: fromClientAPI,
}
}
diff --git a/internal/processing/status/status_test.go b/internal/processing/status/status_test.go
index c5c439057..2ed37bf2a 100644
--- a/internal/processing/status/status_test.go
+++ b/internal/processing/status/status_test.go
@@ -20,18 +20,16 @@ package status_test
import (
"github.com/stretchr/testify/suite"
- "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/messages"
"github.com/superseriousbusiness/gotosocial/internal/processing/status"
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
+ "github.com/superseriousbusiness/gotosocial/testrig"
)
-// nolint
type StatusStandardTestSuite struct {
suite.Suite
- config *config.Config
db db.DB
typeConverter typeutils.TypeConverter
fromClientAPIChan chan messages.FromClientAPI
@@ -50,3 +48,31 @@ type StatusStandardTestSuite struct {
// module being tested
status status.Processor
}
+
+func (suite *StatusStandardTestSuite) SetupSuite() {
+ suite.testTokens = testrig.NewTestTokens()
+ suite.testClients = testrig.NewTestClients()
+ suite.testApplications = testrig.NewTestApplications()
+ suite.testUsers = testrig.NewTestUsers()
+ suite.testAccounts = testrig.NewTestAccounts()
+ suite.testAttachments = testrig.NewTestAttachments()
+ suite.testStatuses = testrig.NewTestStatuses()
+ suite.testTags = testrig.NewTestTags()
+ suite.testMentions = testrig.NewTestMentions()
+}
+
+func (suite *StatusStandardTestSuite) SetupTest() {
+ testrig.InitTestLog()
+ testrig.InitTestConfig()
+
+ suite.db = testrig.NewTestDB()
+ suite.typeConverter = testrig.NewTestTypeConverter(suite.db)
+ suite.fromClientAPIChan = make(chan messages.FromClientAPI, 100)
+ suite.status = status.New(suite.db, suite.typeConverter, suite.fromClientAPIChan)
+
+ testrig.StandardDBSetup(suite.db, nil)
+}
+
+func (suite *StatusStandardTestSuite) TearDownTest() {
+ testrig.StandardDBTeardown(suite.db)
+}
diff --git a/internal/processing/status/util_test.go b/internal/processing/status/util_test.go
index 37e2f2dfc..4ec66a4f7 100644
--- a/internal/processing/status/util_test.go
+++ b/internal/processing/status/util_test.go
@@ -27,9 +27,6 @@ import (
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/api/model"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
- "github.com/superseriousbusiness/gotosocial/internal/messages"
- "github.com/superseriousbusiness/gotosocial/internal/processing/status"
- "github.com/superseriousbusiness/gotosocial/testrig"
)
const statusText1 = `Another test @foss_satan@fossbros-anonymous.io
@@ -52,33 +49,6 @@ type UtilTestSuite struct {
StatusStandardTestSuite
}
-func (suite *UtilTestSuite) SetupSuite() {
- suite.testTokens = testrig.NewTestTokens()
- suite.testClients = testrig.NewTestClients()
- suite.testApplications = testrig.NewTestApplications()
- suite.testUsers = testrig.NewTestUsers()
- suite.testAccounts = testrig.NewTestAccounts()
- suite.testAttachments = testrig.NewTestAttachments()
- suite.testStatuses = testrig.NewTestStatuses()
- suite.testTags = testrig.NewTestTags()
- suite.testMentions = testrig.NewTestMentions()
-}
-
-func (suite *UtilTestSuite) SetupTest() {
- suite.config = testrig.NewTestConfig()
- suite.db = testrig.NewTestDB()
- testrig.InitTestLog()
- suite.typeConverter = testrig.NewTestTypeConverter(suite.db)
- suite.fromClientAPIChan = make(chan messages.FromClientAPI, 100)
- suite.status = status.New(suite.db, suite.typeConverter, suite.config, suite.fromClientAPIChan)
-
- testrig.StandardDBSetup(suite.db, nil)
-}
-
-func (suite *UtilTestSuite) TearDownTest() {
- testrig.StandardDBTeardown(suite.db)
-}
-
func (suite *UtilTestSuite) TestProcessMentions1() {
creatingAccount := suite.testAccounts["local_account_1"]
mentionedAccount := suite.testAccounts["remote_account_1"]
diff --git a/internal/processing/streaming/streaming_test.go b/internal/processing/streaming/streaming_test.go
index cbb899d12..ac143636f 100644
--- a/internal/processing/streaming/streaming_test.go
+++ b/internal/processing/streaming/streaming_test.go
@@ -38,11 +38,13 @@ type StreamingTestSuite struct {
}
func (suite *StreamingTestSuite) SetupTest() {
+ testrig.InitTestLog()
+ testrig.InitTestConfig()
+
suite.testAccounts = testrig.NewTestAccounts()
suite.testTokens = testrig.NewTestTokens()
suite.db = testrig.NewTestDB()
suite.oauthServer = testrig.NewTestOauthServer(suite.db)
- testrig.InitTestLog()
suite.streamingProcessor = streaming.New(suite.db, suite.oauthServer)
testrig.StandardDBSetup(suite.db, suite.testAccounts)
diff --git a/internal/processing/timeline.go b/internal/processing/timeline.go
index 64238225f..b3a4a80ae 100644
--- a/internal/processing/timeline.go
+++ b/internal/processing/timeline.go
@@ -21,10 +21,13 @@ package processing
import (
"context"
"fmt"
- "github.com/sirupsen/logrus"
"net/url"
+ "github.com/sirupsen/logrus"
+ "github.com/spf13/viper"
+
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
+ "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
@@ -39,17 +42,20 @@ func (p *processor) packageStatusResponse(statuses []*apimodel.Status, path stri
// prepare the next and previous links
if len(statuses) != 0 {
+ protocol := viper.GetString(config.Keys.Protocol)
+ host := viper.GetString(config.Keys.Host)
+
nextLink := &url.URL{
- Scheme: p.config.Protocol,
- Host: p.config.Host,
+ Scheme: protocol,
+ Host: host,
Path: path,
RawQuery: fmt.Sprintf("limit=%d&max_id=%s", limit, nextMaxID),
}
next := fmt.Sprintf("<%s>; rel=\"next\"", nextLink.String())
prevLink := &url.URL{
- Scheme: p.config.Protocol,
- Host: p.config.Host,
+ Scheme: protocol,
+ Host: host,
Path: path,
RawQuery: fmt.Sprintf("limit=%d&min_id=%s", limit, prevMinID),
}
diff --git a/internal/processing/user/emailconfirm.go b/internal/processing/user/emailconfirm.go
index 1f9cb0a10..3e19c61d4 100644
--- a/internal/processing/user/emailconfirm.go
+++ b/internal/processing/user/emailconfirm.go
@@ -25,6 +25,8 @@ import (
"time"
"github.com/google/uuid"
+ "github.com/spf13/viper"
+ "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/email"
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
@@ -51,11 +53,12 @@ func (p *processor) SendConfirmEmail(ctx context.Context, user *gtsmodel.User, u
// equivalent to the odds of creating a few tens of trillions of UUIDs in a
// year and having one duplicate.
confirmationToken := uuid.NewString()
- confirmationLink := util.GenerateURIForEmailConfirm(p.config.Protocol, p.config.Host, confirmationToken)
+ confirmationLink := util.GenerateURIForEmailConfirm(confirmationToken)
// pull our instance entry from the database so we can greet the user nicely in the email
instance := &gtsmodel.Instance{}
- if err := p.db.GetWhere(ctx, []db.Where{{Key: "domain", Value: p.config.Host}}, instance); err != nil {
+ host := viper.GetString(config.Keys.Host)
+ if err := p.db.GetWhere(ctx, []db.Where{{Key: "domain", Value: host}}, instance); err != nil {
return fmt.Errorf("SendConfirmEmail: error getting instance: %s", err)
}
diff --git a/internal/processing/user/user.go b/internal/processing/user/user.go
index 73cdb4901..2ddf12d7b 100644
--- a/internal/processing/user/user.go
+++ b/internal/processing/user/user.go
@@ -21,7 +21,6 @@ package user
import (
"context"
- "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/email"
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
@@ -40,15 +39,13 @@ type Processor interface {
}
type processor struct {
- config *config.Config
emailSender email.Sender
db db.DB
}
// New returns a new user processor
-func New(db db.DB, emailSender email.Sender, config *config.Config) Processor {
+func New(db db.DB, emailSender email.Sender) Processor {
return &processor{
- config: config,
emailSender: emailSender,
db: db,
}
diff --git a/internal/processing/user/user_test.go b/internal/processing/user/user_test.go
index 5c3cd7597..f9514d720 100644
--- a/internal/processing/user/user_test.go
+++ b/internal/processing/user/user_test.go
@@ -20,7 +20,6 @@ package user_test
import (
"github.com/stretchr/testify/suite"
- "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/email"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
@@ -30,7 +29,6 @@ import (
type UserStandardTestSuite struct {
suite.Suite
- config *config.Config
emailSender email.Sender
db db.DB
@@ -43,13 +41,14 @@ type UserStandardTestSuite struct {
func (suite *UserStandardTestSuite) SetupTest() {
testrig.InitTestLog()
- suite.config = testrig.NewTestConfig()
+ testrig.InitTestConfig()
+
suite.db = testrig.NewTestDB()
suite.sentEmails = make(map[string]string)
suite.emailSender = testrig.NewEmailSender("../../../web/template/", suite.sentEmails)
suite.testUsers = testrig.NewTestUsers()
- suite.user = user.New(suite.db, suite.emailSender, suite.config)
+ suite.user = user.New(suite.db, suite.emailSender)
testrig.StandardDBSetup(suite.db, nil)
}