diff options
author | 2021-12-07 13:31:39 +0100 | |
---|---|---|
committer | 2021-12-07 13:31:39 +0100 | |
commit | 0884f89431cd26bcc9674b3b7ab628b090f5881e (patch) | |
tree | cdd3b3f77f780a8b59d075dbcc3d4d013811e405 /internal/api/client/account | |
parent | Update dependencies (#333) (diff) | |
download | gotosocial-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/api/client/account')
-rw-r--r-- | internal/api/client/account/account.go | 5 | ||||
-rw-r--r-- | internal/api/client/account/account_test.go | 11 | ||||
-rw-r--r-- | internal/api/client/account/accountcreate.go | 14 |
3 files changed, 17 insertions, 13 deletions
diff --git a/internal/api/client/account/account.go b/internal/api/client/account/account.go index 6e8b1e242..d75fb8e9c 100644 --- a/internal/api/client/account/account.go +++ b/internal/api/client/account/account.go @@ -24,7 +24,6 @@ import ( "github.com/gin-gonic/gin" "github.com/superseriousbusiness/gotosocial/internal/api" - "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/processing" "github.com/superseriousbusiness/gotosocial/internal/router" @@ -76,14 +75,12 @@ const ( // Module implements the ClientAPIModule interface for account-related actions type Module struct { - config *config.Config processor processing.Processor } // New returns a new account module -func New(config *config.Config, processor processing.Processor) api.ClientModule { +func New(processor processing.Processor) api.ClientModule { return &Module{ - config: config, processor: processor, } } diff --git a/internal/api/client/account/account_test.go b/internal/api/client/account/account_test.go index 315ddfce3..f7dfa4520 100644 --- a/internal/api/client/account/account_test.go +++ b/internal/api/client/account/account_test.go @@ -8,6 +8,7 @@ import ( "codeberg.org/gruf/go-store/kv" "github.com/gin-gonic/gin" + "github.com/spf13/viper" "github.com/stretchr/testify/suite" "github.com/superseriousbusiness/gotosocial/internal/api/client/account" "github.com/superseriousbusiness/gotosocial/internal/config" @@ -24,7 +25,6 @@ import ( type AccountStandardTestSuite struct { // standard suite interfaces suite.Suite - config *config.Config db db.DB tc typeutils.TypeConverter storage *kv.KVStore @@ -57,7 +57,7 @@ func (suite *AccountStandardTestSuite) SetupSuite() { } func (suite *AccountStandardTestSuite) SetupTest() { - suite.config = testrig.NewTestConfig() + testrig.InitTestConfig() suite.db = testrig.NewTestDB() suite.storage = testrig.NewTestStorage() testrig.InitTestLog() @@ -65,7 +65,7 @@ func (suite *AccountStandardTestSuite) SetupTest() { suite.sentEmails = make(map[string]string) suite.emailSender = testrig.NewEmailSender("../../../../web/template/", suite.sentEmails) suite.processor = testrig.NewTestProcessor(suite.db, suite.storage, suite.federator, suite.emailSender) - suite.accountModule = account.New(suite.config, suite.processor).(*account.Module) + suite.accountModule = account.New(suite.processor).(*account.Module) testrig.StandardDBSetup(suite.db, nil) testrig.StandardStorageSetup(suite.storage, "../../../../testrig/media") } @@ -83,7 +83,10 @@ func (suite *AccountStandardTestSuite) newContext(recorder *httptest.ResponseRec ctx.Set(oauth.SessionAuthorizedApplication, suite.testApplications["application_1"]) ctx.Set(oauth.SessionAuthorizedUser, suite.testUsers["local_account_1"]) - baseURI := fmt.Sprintf("%s://%s", suite.config.Protocol, suite.config.Host) + protocol := viper.GetString(config.Keys.Protocol) + host := viper.GetString(config.Keys.Host) + + baseURI := fmt.Sprintf("%s://%s", protocol, host) requestURI := fmt.Sprintf("%s/%s", baseURI, requestPath) ctx.Request = httptest.NewRequest(http.MethodPatch, requestURI, bytes.NewReader(requestBody)) // the endpoint we're hitting diff --git a/internal/api/client/account/accountcreate.go b/internal/api/client/account/accountcreate.go index 6497d4d01..ae9d7b0d7 100644 --- a/internal/api/client/account/accountcreate.go +++ b/internal/api/client/account/accountcreate.go @@ -20,10 +20,12 @@ package account import ( "errors" - "github.com/sirupsen/logrus" "net" "net/http" + "github.com/sirupsen/logrus" + "github.com/spf13/viper" + "github.com/gin-gonic/gin" "github.com/superseriousbusiness/gotosocial/internal/api/model" "github.com/superseriousbusiness/gotosocial/internal/config" @@ -85,7 +87,7 @@ func (m *Module) AccountCreatePOSTHandler(c *gin.Context) { } l.Tracef("validating form %+v", form) - if err := validateCreateAccount(form, m.config.AccountsConfig); err != nil { + if err := validateCreateAccount(form); err != nil { l.Debugf("error validating form: %s", err) c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) return @@ -114,8 +116,10 @@ func (m *Module) AccountCreatePOSTHandler(c *gin.Context) { // validateCreateAccount checks through all the necessary prerequisites for creating a new account, // according to the provided account create request. If the account isn't eligible, an error will be returned. -func validateCreateAccount(form *model.AccountCreateRequest, c *config.AccountsConfig) error { - if !c.OpenRegistration { +func validateCreateAccount(form *model.AccountCreateRequest) error { + keys := config.Keys + + if !viper.GetBool(keys.AccountsRegistrationOpen) { return errors.New("registration is not open for this server") } @@ -139,7 +143,7 @@ func validateCreateAccount(form *model.AccountCreateRequest, c *config.AccountsC return err } - if err := validate.SignUpReason(form.Reason, c.ReasonRequired); err != nil { + if err := validate.SignUpReason(form.Reason, viper.GetBool(keys.AccountsReasonRequired)); err != nil { return err } |