diff options
author | 2021-12-07 13:31:39 +0100 | |
---|---|---|
committer | 2021-12-07 13:31:39 +0100 | |
commit | 0884f89431cd26bcc9674b3b7ab628b090f5881e (patch) | |
tree | cdd3b3f77f780a8b59d075dbcc3d4d013811e405 /internal/db/bundb/admin.go | |
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/db/bundb/admin.go')
-rw-r--r-- | internal/db/bundb/admin.go | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/internal/db/bundb/admin.go b/internal/db/bundb/admin.go index accdf7e53..4b05fdd56 100644 --- a/internal/db/bundb/admin.go +++ b/internal/db/bundb/admin.go @@ -30,6 +30,7 @@ import ( "time" "github.com/sirupsen/logrus" + "github.com/spf13/viper" "github.com/superseriousbusiness/gotosocial/internal/ap" "github.com/superseriousbusiness/gotosocial/internal/config" @@ -41,8 +42,7 @@ import ( ) type adminDB struct { - config *config.Config - conn *DBConn + conn *DBConn } func (a *adminDB) IsUsernameAvailable(ctx context.Context, username string) (bool, db.Error) { @@ -101,7 +101,7 @@ func (a *adminDB) NewSignup(ctx context.Context, username string, reason string, Scan(ctx) if err != nil { // we just don't have an account yet create one - newAccountURIs := util.GenerateURIsForAccount(username, a.config.Protocol, a.config.Host) + newAccountURIs := util.GenerateURIsForAccount(username) newAccountID, err := id.NewRandomULID() if err != nil { return nil, err @@ -176,7 +176,7 @@ func (a *adminDB) NewSignup(ctx context.Context, username string, reason string, } func (a *adminDB) CreateInstanceAccount(ctx context.Context) db.Error { - username := a.config.Host + username := viper.GetString(config.Keys.Host) q := a.conn. NewSelect(). @@ -204,10 +204,10 @@ func (a *adminDB) CreateInstanceAccount(ctx context.Context) db.Error { return err } - newAccountURIs := util.GenerateURIsForAccount(username, a.config.Protocol, a.config.Host) + newAccountURIs := util.GenerateURIsForAccount(username) acct := >smodel.Account{ ID: aID, - Username: a.config.Host, + Username: username, DisplayName: username, URL: newAccountURIs.UserURL, PrivateKey: key, @@ -235,13 +235,14 @@ func (a *adminDB) CreateInstanceAccount(ctx context.Context) db.Error { } func (a *adminDB) CreateInstanceInstance(ctx context.Context) db.Error { - domain := a.config.Host + protocol := viper.GetString(config.Keys.Protocol) + host := viper.GetString(config.Keys.Host) // check if instance entry already exists q := a.conn. NewSelect(). Model(>smodel.Instance{}). - Where("domain = ?", domain) + Where("domain = ?", host) exists, err := a.conn.Exists(ctx, q) if err != nil { @@ -259,9 +260,9 @@ func (a *adminDB) CreateInstanceInstance(ctx context.Context) db.Error { i := >smodel.Instance{ ID: iID, - Domain: domain, - Title: domain, - URI: fmt.Sprintf("%s://%s", a.config.Protocol, a.config.Host), + Domain: host, + Title: host, + URI: fmt.Sprintf("%s://%s", protocol, host), } insertQ := a.conn. @@ -273,6 +274,6 @@ func (a *adminDB) CreateInstanceInstance(ctx context.Context) db.Error { return a.conn.ProcessError(err) } - logrus.Infof("created instance instance %s with id %s", domain, i.ID) + logrus.Infof("created instance instance %s with id %s", host, i.ID) return nil } |