From 0884f89431cd26bcc9674b3b7ab628b090f5881e Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Tue, 7 Dec 2021 13:31:39 +0100 Subject: 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 --- internal/api/client/account/accountcreate.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'internal/api/client/account/accountcreate.go') 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 } -- cgit v1.2.3