mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
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
This commit is contained in:
@@ -26,7 +26,6 @@ import (
|
||||
"github.com/superseriousbusiness/gotosocial/internal/ap"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/api/model"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/cache"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/config"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
)
|
||||
@@ -192,15 +191,13 @@ type TypeConverter interface {
|
||||
}
|
||||
|
||||
type converter struct {
|
||||
config *config.Config
|
||||
db db.DB
|
||||
asCache cache.Cache
|
||||
}
|
||||
|
||||
// NewConverter returns a new Converter
|
||||
func NewConverter(config *config.Config, db db.DB) TypeConverter {
|
||||
func NewConverter(db db.DB) TypeConverter {
|
||||
return &converter{
|
||||
config: config,
|
||||
db: db,
|
||||
asCache: cache.New(),
|
||||
}
|
||||
|
@@ -21,7 +21,6 @@ package typeutils_test
|
||||
import (
|
||||
"github.com/stretchr/testify/suite"
|
||||
"github.com/superseriousbusiness/activity/streams/vocab"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/config"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
|
||||
@@ -324,7 +323,6 @@ const (
|
||||
|
||||
type TypeUtilsTestSuite struct {
|
||||
suite.Suite
|
||||
config *config.Config
|
||||
db db.DB
|
||||
testAccounts map[string]*gtsmodel.Account
|
||||
testStatuses map[string]*gtsmodel.Status
|
||||
@@ -334,13 +332,14 @@ type TypeUtilsTestSuite struct {
|
||||
}
|
||||
|
||||
func (suite *TypeUtilsTestSuite) SetupSuite() {
|
||||
suite.config = testrig.NewTestConfig()
|
||||
suite.db = testrig.NewTestDB()
|
||||
testrig.InitTestLog()
|
||||
testrig.InitTestConfig()
|
||||
|
||||
suite.db = testrig.NewTestDB()
|
||||
suite.testAccounts = testrig.NewTestAccounts()
|
||||
suite.testStatuses = testrig.NewTestStatuses()
|
||||
suite.testPeople = testrig.NewTestFediPeople()
|
||||
suite.typeconverter = typeutils.NewConverter(suite.config, suite.db)
|
||||
suite.typeconverter = typeutils.NewConverter(suite.db)
|
||||
}
|
||||
|
||||
func (suite *TypeUtilsTestSuite) SetupTest() {
|
||||
|
@@ -25,7 +25,7 @@ func (c *converter) FollowRequestToFollow(ctx context.Context, f *gtsmodel.Follo
|
||||
|
||||
func (c *converter) StatusToBoost(ctx context.Context, s *gtsmodel.Status, boostingAccount *gtsmodel.Account) (*gtsmodel.Status, error) {
|
||||
// the wrapper won't use the same ID as the boosted status so we generate some new UUIDs
|
||||
uris := util.GenerateURIsForAccount(boostingAccount.Username, c.config.Protocol, c.config.Host)
|
||||
uris := util.GenerateURIsForAccount(boostingAccount.Username)
|
||||
boostWrapperStatusID, err := id.NewULID()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@@ -25,9 +25,11 @@ import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
"github.com/superseriousbusiness/activity/pub"
|
||||
"github.com/superseriousbusiness/activity/streams"
|
||||
"github.com/superseriousbusiness/activity/streams/vocab"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/config"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
)
|
||||
@@ -620,7 +622,8 @@ func (c *converter) MentionToAS(ctx context.Context, m *gtsmodel.Mention) (vocab
|
||||
// name -- this should be the namestring of the mentioned user, something like @whatever@example.org
|
||||
var domain string
|
||||
if m.TargetAccount.Domain == "" {
|
||||
domain = c.config.AccountDomain
|
||||
accountDomain := viper.GetString(config.Keys.AccountDomain)
|
||||
domain = accountDomain
|
||||
} else {
|
||||
domain = m.TargetAccount.Domain
|
||||
}
|
||||
|
@@ -21,11 +21,14 @@ package typeutils
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/sirupsen/logrus"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"github.com/superseriousbusiness/gotosocial/internal/api/model"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/config"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
)
|
||||
@@ -567,34 +570,32 @@ func (c *converter) InstanceToAPIInstance(ctx context.Context, i *gtsmodel.Insta
|
||||
}
|
||||
|
||||
// if the requested instance is *this* instance, we can add some extra information
|
||||
if i.Domain == c.config.Host {
|
||||
userCountKey := "user_count"
|
||||
statusCountKey := "status_count"
|
||||
domainCountKey := "domain_count"
|
||||
|
||||
userCount, err := c.db.CountInstanceUsers(ctx, c.config.Host)
|
||||
keys := config.Keys
|
||||
host := viper.GetString(keys.Host)
|
||||
if i.Domain == host {
|
||||
userCount, err := c.db.CountInstanceUsers(ctx, host)
|
||||
if err == nil {
|
||||
mi.Stats[userCountKey] = userCount
|
||||
mi.Stats["user_count"] = userCount
|
||||
}
|
||||
|
||||
statusCount, err := c.db.CountInstanceStatuses(ctx, c.config.Host)
|
||||
statusCount, err := c.db.CountInstanceStatuses(ctx, host)
|
||||
if err == nil {
|
||||
mi.Stats[statusCountKey] = statusCount
|
||||
mi.Stats["status_count"] = statusCount
|
||||
}
|
||||
|
||||
domainCount, err := c.db.CountInstanceDomains(ctx, c.config.Host)
|
||||
domainCount, err := c.db.CountInstanceDomains(ctx, host)
|
||||
if err == nil {
|
||||
mi.Stats[domainCountKey] = domainCount
|
||||
mi.Stats["domain_count"] = domainCount
|
||||
}
|
||||
|
||||
mi.Registrations = c.config.AccountsConfig.OpenRegistration
|
||||
mi.ApprovalRequired = c.config.AccountsConfig.RequireApproval
|
||||
mi.Registrations = viper.GetBool(keys.AccountsRegistrationOpen)
|
||||
mi.ApprovalRequired = viper.GetBool(keys.AccountsApprovalRequired)
|
||||
mi.InvitesEnabled = false // TODO
|
||||
mi.MaxTootChars = uint(c.config.StatusesConfig.MaxChars)
|
||||
mi.MaxTootChars = uint(viper.GetInt(keys.StatusesMaxChars))
|
||||
mi.URLS = &model.InstanceURLs{
|
||||
StreamingAPI: fmt.Sprintf("wss://%s", c.config.Host),
|
||||
StreamingAPI: fmt.Sprintf("wss://%s", host),
|
||||
}
|
||||
mi.Version = c.config.SoftwareVersion
|
||||
mi.Version = viper.GetString(keys.SoftwareVersion)
|
||||
}
|
||||
|
||||
// get the instance account if it exists and just skip if it doesn't
|
||||
|
@@ -33,7 +33,7 @@ func (c *converter) WrapPersonInUpdate(person vocab.ActivityStreamsPerson, origi
|
||||
return nil, err
|
||||
}
|
||||
|
||||
idString := util.GenerateURIForUpdate(originAccount.Username, c.config.Protocol, c.config.Host, newID)
|
||||
idString := util.GenerateURIForUpdate(originAccount.Username, newID)
|
||||
idURI, err := url.Parse(idString)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("WrapPersonInUpdate: error parsing url %s: %s", idString, err)
|
||||
|
Reference in New Issue
Block a user