working commit
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
package handler
|
package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"mbase/app/logic"
|
"mbase/app/operator"
|
||||||
"mbase/pkg/logger"
|
"mbase/pkg/logger"
|
||||||
"mbase/pkg/mbctl"
|
"mbase/pkg/mbctl"
|
||||||
|
|
||||||
@@ -9,12 +9,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type HandlerConfig struct {
|
type HandlerConfig struct {
|
||||||
Logic *logic.Logic
|
Logic *operator.Logic
|
||||||
}
|
}
|
||||||
|
|
||||||
type Handler struct {
|
type Handler struct {
|
||||||
mbctl.UnimplementedControlServer
|
mbctl.UnimplementedControlServer
|
||||||
lg *logic.Logic
|
lg *operator.Logic
|
||||||
log *logger.Logger
|
log *logger.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package logic
|
package operator
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package logic
|
package operator
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package logic
|
package operator
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package logic
|
package operator
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package logic
|
package operator
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package logic
|
package operator
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
"mbase/app/config"
|
"mbase/app/config"
|
||||||
"mbase/app/maindb"
|
"mbase/app/maindb"
|
||||||
"mbase/pkg/descr"
|
"mbase/pkg/descr"
|
||||||
"mbase/app/logic"
|
"mbase/app/operator"
|
||||||
"mbase/pkg/aux509"
|
"mbase/pkg/aux509"
|
||||||
"mbase/pkg/logger"
|
"mbase/pkg/logger"
|
||||||
"mbase/pkg/netacl"
|
"mbase/pkg/netacl"
|
||||||
@@ -26,7 +26,7 @@ import (
|
|||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
conf *config.Config
|
conf *config.Config
|
||||||
lg *logic.Logic
|
lg *operator.Logic
|
||||||
svc *service.Service
|
svc *service.Service
|
||||||
hand *handler.Handler
|
hand *handler.Handler
|
||||||
log *logger.Logger
|
log *logger.Logger
|
||||||
@@ -176,10 +176,10 @@ func (srv *Server) Build() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// Create logic
|
// Create logic
|
||||||
logicConfig := &logic.LogicConfig{
|
logicConfig := &operator.LogicConfig{
|
||||||
Database: srv.db,
|
Database: srv.db,
|
||||||
}
|
}
|
||||||
srv.lg, err = logic.NewLogic(logicConfig)
|
srv.lg, err = operator.NewLogic(logicConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
|
|
||||||
"mbase/app/handler"
|
"mbase/app/handler"
|
||||||
"mbase/app/logic"
|
"mbase/app/operator"
|
||||||
"mbase/pkg/logger"
|
"mbase/pkg/logger"
|
||||||
"mbase/pkg/netacl"
|
"mbase/pkg/netacl"
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ import (
|
|||||||
|
|
||||||
type ServiceConfig struct {
|
type ServiceConfig struct {
|
||||||
Handler *handler.Handler
|
Handler *handler.Handler
|
||||||
Logic *logic.Logic
|
Logic *operator.Logic
|
||||||
NetACL *netacl.NetACL
|
NetACL *netacl.NetACL
|
||||||
Portnum uint32
|
Portnum uint32
|
||||||
Address string
|
Address string
|
||||||
@@ -33,7 +33,7 @@ type ServiceConfig struct {
|
|||||||
type Service struct {
|
type Service struct {
|
||||||
gsrv *grpc.Server
|
gsrv *grpc.Server
|
||||||
hand *handler.Handler
|
hand *handler.Handler
|
||||||
lg *logic.Logic
|
lg *operator.Logic
|
||||||
log *logger.Logger
|
log *logger.Logger
|
||||||
nacl *netacl.NetACL
|
nacl *netacl.NetACL
|
||||||
portnum uint32
|
portnum uint32
|
||||||
|
|||||||
@@ -13,11 +13,40 @@ func (util *Util) CreateAccount(cmd *cobra.Command, args []string) {
|
|||||||
printResponse(res, err)
|
printResponse(res, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
type createAccountParams struct{}
|
type createAccountParams struct{
|
||||||
|
Username string
|
||||||
|
Password string
|
||||||
|
}
|
||||||
type createAccountResult struct{}
|
type createAccountResult struct{}
|
||||||
|
|
||||||
func (util *Util) createAccount(params createAccountParams) (createAccountResult, error) {
|
func (util *Util) createAccount(params createAccountParams) (createAccountResult, error) {
|
||||||
var err error
|
var err error
|
||||||
res := createAccountResult{}
|
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
|
return res, err
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
func (util *Util) CreateAccount(ctx context.Context, operID string) (*mbctl.CreateAccountResult, error) {
|
||||||
|
var err error
|
||||||
|
res := &mbctl.CreateAccountResult{}
|
||||||
|
|
||||||
|
params := &mbctl.CreateAccountParams{
|
||||||
|
Username: util.username,
|
||||||
|
Password: util.password,
|
||||||
|
}
|
||||||
|
res, err = util.lg.CreateAccount(ctx, operID, params)
|
||||||
|
if err != nil {
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|||||||
@@ -4,10 +4,13 @@
|
|||||||
package account
|
package account
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"mbase/app/operator"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Util struct {
|
type Util struct {
|
||||||
|
oper *operator.Logic
|
||||||
rootCmd *cobra.Command
|
rootCmd *cobra.Command
|
||||||
createAccountParams createAccountParams
|
createAccountParams createAccountParams
|
||||||
listAccountsParams listAccountsParams
|
listAccountsParams listAccountsParams
|
||||||
@@ -15,8 +18,10 @@ type Util struct {
|
|||||||
deleteAccountParams deleteAccountParams
|
deleteAccountParams deleteAccountParams
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewUtil() *Util {
|
func NewUtil(oper *operator.Logic) *Util {
|
||||||
return &Util{}
|
return &Util{
|
||||||
|
oper: oper,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (util *Util) GetRooCmd() *cobra.Command {
|
func (util *Util) GetRooCmd() *cobra.Command {
|
||||||
@@ -65,4 +70,3 @@ func (util *Util) BuildCmds() *cobra.Command {
|
|||||||
util.rootCmd = rootCmd
|
util.rootCmd = rootCmd
|
||||||
return util.rootCmd
|
return util.rootCmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+36
-1
@@ -8,11 +8,17 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"mbase/cmd/mbaseadmin/account"
|
"mbase/cmd/mbaseadmin/account"
|
||||||
|
"mbase/app/config"
|
||||||
|
"mbase/app/maindb"
|
||||||
|
"mbase/app/operator"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Util struct {
|
type Util struct {
|
||||||
|
lg *operator.Logic
|
||||||
|
db *maindb.Database
|
||||||
|
|
||||||
rootCmd *cobra.Command
|
rootCmd *cobra.Command
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,6 +32,34 @@ func (util *Util) GetRooCmd() *cobra.Command {
|
|||||||
|
|
||||||
func (util *Util) Build() error {
|
func (util *Util) Build() error {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
conf := config.NewConfig()
|
||||||
|
err = conf.ReadFile()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = conf.ReadEnv()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
db, err := maindb.NewDatabase(conf.DataDir)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = db.OpenDatabase()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
util.db = db
|
||||||
|
logicConfig := &operator.LogicConfig{
|
||||||
|
Database: util.db,
|
||||||
|
}
|
||||||
|
util.lg, err = operator.NewLogic(logicConfig)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
execName := filepath.Base(os.Args[0])
|
execName := filepath.Base(os.Args[0])
|
||||||
rootCmd := &cobra.Command{
|
rootCmd := &cobra.Command{
|
||||||
Use: execName,
|
Use: execName,
|
||||||
@@ -34,7 +68,7 @@ func (util *Util) Build() error {
|
|||||||
}
|
}
|
||||||
rootCmd.CompletionOptions.DisableDefaultCmd = true
|
rootCmd.CompletionOptions.DisableDefaultCmd = true
|
||||||
|
|
||||||
accountUtil := account.NewUtil()
|
accountUtil := account.NewUtil(util.lg)
|
||||||
rootCmd.AddCommand(accountUtil.BuildCmds())
|
rootCmd.AddCommand(accountUtil.BuildCmds())
|
||||||
|
|
||||||
util.rootCmd = rootCmd
|
util.rootCmd = rootCmd
|
||||||
@@ -47,3 +81,4 @@ func (util *Util) Exec(args []string) error {
|
|||||||
err = util.rootCmd.Execute()
|
err = util.rootCmd.Execute()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user