diff --git a/Makefile.am b/Makefile.am index 7102d1e..ee62c94 100644 --- a/Makefile.am +++ b/Makefile.am @@ -113,10 +113,9 @@ if SYSTEMD endif endif - format: - for dir in $$(find app pkg cmd -type d); do \ - (cd $$dir && $(GO) fmt .); \ + @for dir in $$(find app pkg cmd -type d); do \ + (cd $$dir && echo "====$$dir====" && $(GO) fmt .); \ done run: @@ -137,8 +136,6 @@ clean-local: rm -f cmd/mbasectl/mbasectl rm -f cmd/mbased/mbased rm -f cmd/mbasedump/mbasedump - rm -f cmd/mbaselocal/mbaselocal - rm -f cmd/mbaserestore/mbaserestore rm -rf autom4te.cache rm -rf tmp/ diff --git a/Makefile.in b/Makefile.in index 66895d3..4132418 100644 --- a/Makefile.in +++ b/Makefile.in @@ -910,8 +910,8 @@ install-data-local: @LINUX_OS_TRUE@@SYSTEMD_TRUE@ $(INSTALL_DATA) initrc/mbased.service $(DESTDIR)$(LINUX_SYSTEMDDIR) format: - for dir in $$(find app pkg cmd -type d); do \ - (cd $$dir && $(GO) fmt .); \ + @for dir in $$(find app pkg cmd -type d); do \ + (cd $$dir && echo "====$$dir====" && $(GO) fmt .); \ done run: @@ -931,8 +931,6 @@ clean-local: rm -f cmd/mbasectl/mbasectl rm -f cmd/mbased/mbased rm -f cmd/mbasedump/mbasedump - rm -f cmd/mbaselocal/mbaselocal - rm -f cmd/mbaserestore/mbaserestore rm -rf autom4te.cache rm -rf tmp/ diff --git a/app/operator/account.go b/app/operator/account.go index d1d59f4..f3c251b 100644 --- a/app/operator/account.go +++ b/app/operator/account.go @@ -5,9 +5,9 @@ import ( "fmt" "time" - "mbase/pkg/descr" - "mbase/pkg/auxuuid" "mbase/pkg/auxpwd" + "mbase/pkg/auxuuid" + "mbase/pkg/descr" "mbase/pkg/mbctl" ) diff --git a/app/operator/database.go b/app/operator/database.go index 0a20a61..895ca08 100644 --- a/app/operator/database.go +++ b/app/operator/database.go @@ -4,9 +4,9 @@ import ( "context" "time" - "mbase/pkg/descr" - "mbase/pkg/auxuuid" "mbase/pkg/auxpwd" + "mbase/pkg/auxuuid" + "mbase/pkg/descr" ) const ( diff --git a/app/operator/grants.go b/app/operator/grants.go index d2bbfff..b75ff30 100644 --- a/app/operator/grants.go +++ b/app/operator/grants.go @@ -5,8 +5,8 @@ import ( "fmt" "time" - "mbase/pkg/descr" "mbase/pkg/auxuuid" + "mbase/pkg/descr" "mbase/pkg/mbctl" ) diff --git a/app/server/server.go b/app/server/server.go index fd2c877..516f11a 100644 --- a/app/server/server.go +++ b/app/server/server.go @@ -12,9 +12,9 @@ import ( "mbase/app/config" "mbase/app/maindb" - "mbase/pkg/descr" "mbase/app/operator" "mbase/pkg/aux509" + "mbase/pkg/descr" "mbase/pkg/logger" "mbase/pkg/netacl" diff --git a/cmd/mbaseadmin/account/create.go b/cmd/mbaseadmin/account/create.go index a6bbefb..bb1bf9c 100644 --- a/cmd/mbaseadmin/account/create.go +++ b/cmd/mbaseadmin/account/create.go @@ -13,27 +13,28 @@ func (util *Util) CreateAccount(cmd *cobra.Command, args []string) { printResponse(res, err) } -type createAccountParams struct{ - Username string - Password string +type createAccountParams struct { + Username string + Password string } type createAccountResult struct{} func (util *Util) createAccount(params createAccountParams) (createAccountResult, error) { var err error res := createAccountResult{} -/* - operParams := &mbctl.CreateAccountParams{ - Username: params.Username, - Password: params.Password, - } - res, err = util.lg.CreateAccount(ctx, operID, params) - if err != nil { - return res, err - } -*/ + /* + operParams := &mbctl.CreateAccountParams{ + Username: params.Username, + Password: params.Password, + } + res, err = util.lg.CreateAccount(ctx, operID, params) + if err != nil { + return res, err + } + */ return res, err } + /* func (util *Util) CreateAccount(ctx context.Context, operID string) (*mbctl.CreateAccountResult, error) { var err error diff --git a/cmd/mbaseadmin/account/util.go b/cmd/mbaseadmin/account/util.go index d5ed84e..f152959 100644 --- a/cmd/mbaseadmin/account/util.go +++ b/cmd/mbaseadmin/account/util.go @@ -7,15 +7,21 @@ import ( "mbase/app/operator" "github.com/spf13/cobra" + "github.com/spf13/viper" +) + +const ( + defaultHostname = "localhost:1025" ) type Util struct { - oper *operator.Logic - rootCmd *cobra.Command + oper *operator.Logic + subCmd *cobra.Command createAccountParams createAccountParams listAccountsParams listAccountsParams updateAccountParams updateAccountParams deleteAccountParams deleteAccountParams + commonParams CommonParams } func NewUtil(oper *operator.Logic) *Util { @@ -24,17 +30,33 @@ func NewUtil(oper *operator.Logic) *Util { } } +type CommonParams struct { + Username string + Password string +} + func (util *Util) GetRooCmd() *cobra.Command { - return util.rootCmd + return util.subCmd } func (util *Util) BuildCmds() *cobra.Command { - rootCmd := &cobra.Command{ + subCmd := &cobra.Command{ Use: "account", Short: "\nAccount operations", SilenceUsage: true, } - rootCmd.CompletionOptions.DisableDefaultCmd = true + subCmd.CompletionOptions.DisableDefaultCmd = true + + subCmd.PersistentFlags().StringVarP(&util.commonParams.Username, "user", "U", util.commonParams.Username, "Username") + subCmd.PersistentFlags().StringVarP(&util.commonParams.Password, "pass", "P", util.commonParams.Password, "Password") + subCmd.MarkFlagsRequiredTogether("user", "pass") + + vi := viper.New() + vi.SetEnvPrefix("mstore") + vi.BindEnv("user") + vi.BindEnv("pass") + util.commonParams.Username = vi.GetString("user") + util.commonParams.Password = vi.GetString("pass") var createAccountCmd = &cobra.Command{ Use: "create name password ", @@ -42,14 +64,14 @@ func (util *Util) BuildCmds() *cobra.Command { Args: cobra.ExactArgs(2), Run: util.CreateAccount, } - rootCmd.AddCommand(createAccountCmd) + subCmd.AddCommand(createAccountCmd) var listAccountsCmd = &cobra.Command{ Use: "list", Short: "List accounts", Run: util.ListAccounts, } - rootCmd.AddCommand(listAccountsCmd) + subCmd.AddCommand(listAccountsCmd) var updateAccountsCmd = &cobra.Command{ Use: "update name|id", @@ -57,7 +79,7 @@ func (util *Util) BuildCmds() *cobra.Command { Args: cobra.ExactArgs(1), Run: util.UpdateAccount, } - rootCmd.AddCommand(updateAccountsCmd) + subCmd.AddCommand(updateAccountsCmd) var deleteAccountCmd = &cobra.Command{ Use: "delete name|id", @@ -65,8 +87,8 @@ func (util *Util) BuildCmds() *cobra.Command { Args: cobra.ExactArgs(1), Run: util.DeleteAccount, } - rootCmd.AddCommand(deleteAccountCmd) + subCmd.AddCommand(deleteAccountCmd) - util.rootCmd = rootCmd - return util.rootCmd + util.subCmd = subCmd + return util.subCmd } diff --git a/cmd/mbaseadmin/grant/util.go b/cmd/mbaseadmin/grant/util.go index 772d413..f07328b 100644 --- a/cmd/mbaseadmin/grant/util.go +++ b/cmd/mbaseadmin/grant/util.go @@ -5,19 +5,20 @@ package grant import ( "github.com/spf13/cobra" - "mbase/app/operator" ) type Util struct { - lg *operator.Logic - rootCmd *cobra.Command + oper *operator.Logic + rootCmd *cobra.Command createGrantParams createGrantParams deleteGrantParams deleteGrantParams } -func NewUtil() *Util { - return &Util{} +func NewUtil(oper *operator.Logic) *Util { + return &Util{ + oper: oper, + } } func (util *Util) GetRooCmd() *cobra.Command { @@ -51,4 +52,3 @@ func (util *Util) BuildCmds() *cobra.Command { util.rootCmd = rootCmd return util.rootCmd } - diff --git a/cmd/mbaseadmin/util.go b/cmd/mbaseadmin/util.go index 7770059..55356ce 100644 --- a/cmd/mbaseadmin/util.go +++ b/cmd/mbaseadmin/util.go @@ -7,17 +7,18 @@ import ( "os" "path/filepath" - "mbase/cmd/mbaseadmin/account" "mbase/app/config" "mbase/app/maindb" "mbase/app/operator" + "mbase/cmd/mbaseadmin/account" + "mbase/cmd/mbaseadmin/grant" "github.com/spf13/cobra" ) type Util struct { - lg *operator.Logic - db *maindb.Database + lg *operator.Logic + db *maindb.Database rootCmd *cobra.Command } @@ -32,7 +33,7 @@ func (util *Util) GetRooCmd() *cobra.Command { func (util *Util) Build() error { var err error - conf := config.NewConfig() + conf := config.NewConfig() err = conf.ReadFile() if err != nil { return err @@ -67,8 +68,11 @@ func (util *Util) Build() error { } rootCmd.CompletionOptions.DisableDefaultCmd = true - accountUtil := account.NewUtil(util.lg) - rootCmd.AddCommand(accountUtil.BuildCmds()) + accountUtil := account.NewUtil(util.lg) + rootCmd.AddCommand(accountUtil.BuildCmds()) + + grantUtil := grant.NewUtil(util.lg) + rootCmd.AddCommand(grantUtil.BuildCmds()) util.rootCmd = rootCmd return err @@ -80,4 +84,3 @@ func (util *Util) Exec(args []string) error { err = util.rootCmd.Execute() return err } - diff --git a/cmd/mbasectl/account/util.go b/cmd/mbasectl/account/util.go index f7280e2..e791aae 100644 --- a/cmd/mbasectl/account/util.go +++ b/cmd/mbasectl/account/util.go @@ -65,4 +65,3 @@ func (util *Util) BuildCmds() *cobra.Command { util.rootCmd = rootCmd return util.rootCmd } - diff --git a/cmd/mbasectl/util.go b/cmd/mbasectl/util.go index 5d9fed9..3620820 100644 --- a/cmd/mbasectl/util.go +++ b/cmd/mbasectl/util.go @@ -7,7 +7,7 @@ import ( "os" "path/filepath" - "mbase/cmd/mbaseadmin/account" + "mbase/cmd/mbaseadmin/account" "github.com/spf13/cobra" ) @@ -34,8 +34,8 @@ func (util *Util) Build() error { } rootCmd.CompletionOptions.DisableDefaultCmd = true - accountUtil := account.NewUtil() - rootCmd.AddCommand(accountUtil.BuildCmds()) + accountUtil := account.NewUtil() + rootCmd.AddCommand(accountUtil.BuildCmds()) util.rootCmd = rootCmd return err diff --git a/cmd/mbasedump/dump.go b/cmd/mbasedump/dump.go index d167e88..153d935 100644 --- a/cmd/mbasedump/dump.go +++ b/cmd/mbasedump/dump.go @@ -9,8 +9,8 @@ import ( "mbase/app/config" "mbase/app/maindb" - "mbase/pkg/descr" "mbase/pkg/auxtool" + "mbase/pkg/descr" "github.com/spf13/cobra" "go.yaml.in/yaml/v4" @@ -80,4 +80,3 @@ func (util *Util) dumpDatabase(params dumpDatabaseParams) (dumpDatabaseResult, e } return res, err } - diff --git a/cmd/mbasedump/util.go b/cmd/mbasedump/util.go index d62093c..b750284 100644 --- a/cmd/mbasedump/util.go +++ b/cmd/mbasedump/util.go @@ -61,4 +61,3 @@ func (util *Util) Exec(args []string) error { err = util.rootCmd.Execute() return err } - diff --git a/go.mod b/go.mod index b6ef91f..48930ff 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/jmoiron/sqlx v1.4.0 github.com/mattn/go-sqlite3 v1.14.44 github.com/spf13/cobra v1.10.2 + github.com/spf13/viper v1.21.0 github.com/stretchr/testify v1.11.1 go.yaml.in/yaml/v4 v4.0.0-rc.4 google.golang.org/grpc v1.81.1 @@ -21,11 +22,13 @@ require ( github.com/bytedance/sonic/loader v0.5.0 // indirect github.com/cloudwego/base64x v0.1.6 // indirect github.com/davecgh/go-spew v1.1.1 // indirect + github.com/fsnotify/fsnotify v1.9.0 // indirect github.com/gabriel-vasile/mimetype v1.4.12 // indirect github.com/gin-contrib/sse v1.1.0 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-playground/validator/v10 v10.30.1 // indirect + github.com/go-viper/mapstructure/v2 v2.4.0 // indirect github.com/goccy/go-json v0.10.5 // indirect github.com/goccy/go-yaml v1.19.2 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect @@ -39,11 +42,17 @@ require ( github.com/pmezard/go-difflib v1.0.0 // indirect github.com/quic-go/qpack v0.6.0 // indirect github.com/quic-go/quic-go v0.59.0 // indirect - github.com/spf13/pflag v1.0.9 // indirect + github.com/sagikazarmark/locafero v0.11.0 // indirect + github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 // indirect + github.com/spf13/afero v1.15.0 // indirect + github.com/spf13/cast v1.10.0 // indirect + github.com/spf13/pflag v1.0.10 // indirect + github.com/subosito/gotenv v1.6.0 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.3.1 // indirect go.mongodb.org/mongo-driver/v2 v2.5.0 // indirect go.yaml.in/yaml/v2 v2.4.2 // indirect + go.yaml.in/yaml/v3 v3.0.4 // indirect golang.org/x/arch v0.22.0 // indirect golang.org/x/crypto v0.48.0 // indirect golang.org/x/net v0.51.0 // indirect diff --git a/go.sum b/go.sum index bdb21b0..fb20538 100644 --- a/go.sum +++ b/go.sum @@ -14,6 +14,10 @@ github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6N github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= +github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= +github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k= +github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0= github.com/gabriel-vasile/mimetype v1.4.12 h1:e9hWvmLYvtp846tLHam2o++qitpguFiYCKbn0w9jyqw= github.com/gabriel-vasile/mimetype v1.4.12/go.mod h1:d+9Oxyo1wTzWdyVUPMmXFvp4F9tea18J8ufA774AB3s= github.com/gin-contrib/sse v1.1.0 h1:n0w2GMuUpWDVp7qSpvze6fAu9iRxJY4Hmj6AmBOU05w= @@ -34,6 +38,8 @@ github.com/go-playground/validator/v10 v10.30.1 h1:f3zDSN/zOma+w6+1Wswgd9fLkdwy0 github.com/go-playground/validator/v10 v10.30.1/go.mod h1:oSuBIQzuJxL//3MelwSLD5hc2Tu889bF0Idm9Dg26cM= github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y= github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg= +github.com/go-viper/mapstructure/v2 v2.4.0 h1:EBsztssimR/CONLSZZ04E8qAkxNYq4Qp9LvH92wZUgs= +github.com/go-viper/mapstructure/v2 v2.4.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM= github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4= github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M= github.com/goccy/go-yaml v1.19.2 h1:PmFC1S6h8ljIz6gMRBopkjP1TVT7xuwrButHID66PoM= @@ -82,10 +88,21 @@ github.com/quic-go/quic-go v0.59.0/go.mod h1:upnsH4Ju1YkqpLXC305eW3yDZ4NfnNbmQRC github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/sagikazarmark/locafero v0.11.0 h1:1iurJgmM9G3PA/I+wWYIOw/5SyBtxapeHDcg+AAIFXc= +github.com/sagikazarmark/locafero v0.11.0/go.mod h1:nVIGvgyzw595SUSUE6tvCp3YYTeHs15MvlmU87WwIik= +github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 h1:+jumHNA0Wrelhe64i8F6HNlS8pkoyMv5sreGx2Ry5Rw= +github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8/go.mod h1:3n1Cwaq1E1/1lhQhtRK2ts/ZwZEhjcQeJQ1RuC6Q/8U= +github.com/spf13/afero v1.15.0 h1:b/YBCLWAJdFWJTN9cLhiXXcD7mzKn9Dm86dNnfyQw1I= +github.com/spf13/afero v1.15.0/go.mod h1:NC2ByUVxtQs4b3sIUphxK0NioZnmxgyCrfzeuq8lxMg= +github.com/spf13/cast v1.10.0 h1:h2x0u2shc1QuLHfxi+cTJvs30+ZAHOGRic8uyGTDWxY= +github.com/spf13/cast v1.10.0/go.mod h1:jNfB8QC9IA6ZuY2ZjDp0KtFO2LZZlg4S/7bzP6qqeHo= github.com/spf13/cobra v1.10.2 h1:DMTTonx5m65Ic0GOoRY2c16WCbHxOOw6xxezuLaBpcU= github.com/spf13/cobra v1.10.2/go.mod h1:7C1pvHqHw5A4vrJfjNwvOdzYu0Gml16OCs2GRiTUUS4= -github.com/spf13/pflag v1.0.9 h1:9exaQaMOCwffKiiiYk6/BndUBv+iRViNW+4lEMi0PvY= github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk= +github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/viper v1.21.0 h1:x5S+0EU27Lbphp4UKm1C+1oQO+rKx36vfCoaVebLFSU= +github.com/spf13/viper v1.21.0/go.mod h1:P0lhsswPGWD/1lZJ9ny3fYnVqxiegrlNrEmgLjbTCAY= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= @@ -97,6 +114,8 @@ github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXl github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= +github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= +github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= github.com/ugorji/go/codec v1.3.1 h1:waO7eEiFDwidsBN6agj1vJQ4AG7lh2yqXyOXqhgQuyY=