working commit
This commit is contained in:
@@ -23,7 +23,7 @@ func (hand *Handler) Authentificate(ctx context.Context) (string, error) {
|
||||
}
|
||||
username := meta["username"][0]
|
||||
password := meta["password"][0]
|
||||
validated, accountID, err := hand.lg.ValidateAccount(ctx, username, password)
|
||||
validated, accountID, err := hand.oper.ValidateAccount(ctx, username, password)
|
||||
if !validated {
|
||||
err := status.Errorf(codes.PermissionDenied, "Wrong auth data")
|
||||
return accountID, err
|
||||
@@ -39,7 +39,7 @@ func (hand *Handler) CreateAccount(ctx context.Context, params *mbctl.CreateAcco
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
res, err = hand.lg.CreateAccount(ctx, accountID, params)
|
||||
res, err = hand.oper.CreateAccount(ctx, accountID, params)
|
||||
return res, err
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ func (hand *Handler) DeleteAccount(ctx context.Context, params *mbctl.DeleteAcco
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
res, err = hand.lg.DeleteAccount(ctx, accountID, params)
|
||||
res, err = hand.oper.DeleteAccount(ctx, accountID, params)
|
||||
return res, err
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ func (hand *Handler) ListAccounts(ctx context.Context, params *mbctl.ListAccount
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
res, err = hand.lg.ListAccounts(ctx, accountID, params)
|
||||
res, err = hand.oper.ListAccounts(ctx, accountID, params)
|
||||
return res, err
|
||||
}
|
||||
|
||||
@@ -75,6 +75,6 @@ func (hand *Handler) UpdateAccount(ctx context.Context, params *mbctl.UpdateAcco
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
res, err = hand.lg.UpdateAccount(ctx, accountID, params)
|
||||
res, err = hand.oper.UpdateAccount(ctx, accountID, params)
|
||||
return res, err
|
||||
}
|
||||
|
||||
+2
-2
@@ -14,7 +14,7 @@ func (hand *Handler) GetDump(ctx context.Context, params *mbctl.GetDumpParams) (
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
res, err = hand.lg.GetDump(ctx, accountID, params)
|
||||
res, err = hand.oper.GetDump(ctx, accountID, params)
|
||||
return res, err
|
||||
}
|
||||
|
||||
@@ -26,6 +26,6 @@ func (hand *Handler) RestoreDump(ctx context.Context, params *mbctl.RestoreDumpP
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
res, err = hand.lg.RestoreDump(ctx, accountID, params)
|
||||
res, err = hand.oper.RestoreDump(ctx, accountID, params)
|
||||
return res, err
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ func (hand *Handler) SetGrant(ctx context.Context, params *mbctl.SetGrantParams)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
res, err = hand.lg.SetGrant(ctx, accountID, params)
|
||||
res, err = hand.oper.SetGrant(ctx, accountID, params)
|
||||
return res, err
|
||||
}
|
||||
|
||||
@@ -26,6 +26,6 @@ func (hand *Handler) DeleteGrant(ctx context.Context, params *mbctl.DeleteGrantP
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
res, err = hand.lg.DeleteGrant(ctx, accountID, params)
|
||||
res, err = hand.oper.DeleteGrant(ctx, accountID, params)
|
||||
return res, err
|
||||
}
|
||||
|
||||
@@ -9,18 +9,18 @@ import (
|
||||
)
|
||||
|
||||
type HandlerConfig struct {
|
||||
Logic *operator.Logic
|
||||
Operator *operator.Operator
|
||||
}
|
||||
|
||||
type Handler struct {
|
||||
mbctl.UnimplementedControlServer
|
||||
lg *operator.Logic
|
||||
log *logger.Logger
|
||||
oper *operator.Operator
|
||||
log *logger.Logger
|
||||
}
|
||||
|
||||
func NewHandler(conf *HandlerConfig) *Handler {
|
||||
hand := Handler{
|
||||
lg: conf.Logic,
|
||||
oper: conf.Operator,
|
||||
}
|
||||
hand.log = logger.NewLogger("ghandler")
|
||||
return &hand
|
||||
|
||||
@@ -9,6 +9,6 @@ import (
|
||||
func (hand *Handler) GetHello(ctx context.Context, params *mbctl.GetHelloParams) (*mbctl.GetHelloResult, error) {
|
||||
var err error
|
||||
hand.log.Debugf("Handle getHello call")
|
||||
res, err := hand.lg.GetHello(ctx, params)
|
||||
res, err := hand.oper.GetHello(ctx, params)
|
||||
return res, err
|
||||
}
|
||||
|
||||
+29
-29
@@ -11,14 +11,14 @@ import (
|
||||
"mbase/pkg/mbctl"
|
||||
)
|
||||
|
||||
func (lg *Logic) ValidateAccount(ctx context.Context, username, password string) (bool, string, error) {
|
||||
func (oper *Operator) ValidateAccount(ctx context.Context, username, password string) (bool, string, error) {
|
||||
var err error
|
||||
var accountID string
|
||||
var valid bool
|
||||
|
||||
lg.WaitRestoring()
|
||||
oper.WaitRestoring()
|
||||
|
||||
accountExists, accountDescr, err := lg.db.GetAccountByUsername(ctx, username)
|
||||
accountExists, accountDescr, err := oper.db.GetAccountByUsername(ctx, username)
|
||||
if !accountExists {
|
||||
err := fmt.Errorf("Account not exists")
|
||||
return valid, accountID, err
|
||||
@@ -32,14 +32,14 @@ func (lg *Logic) ValidateAccount(ctx context.Context, username, password string)
|
||||
return valid, accountID, err
|
||||
}
|
||||
|
||||
func (lg *Logic) CreateAccount(ctx context.Context, accountID string, params *mbctl.CreateAccountParams) (*mbctl.CreateAccountResult, error) {
|
||||
func (oper *Operator) CreateAccount(ctx context.Context, accountID string, params *mbctl.CreateAccountParams) (*mbctl.CreateAccountResult, error) {
|
||||
var err error
|
||||
res := &mbctl.CreateAccountResult{}
|
||||
|
||||
lg.WaitDumping()
|
||||
lg.WaitRestoring()
|
||||
oper.WaitDumping()
|
||||
oper.WaitRestoring()
|
||||
|
||||
grantExists, _, err := lg.db.GetGrant(ctx, accountID, descr.GrantModifyUsers)
|
||||
grantExists, _, err := oper.db.GetGrant(ctx, accountID, descr.GrantModifyUsers)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -57,7 +57,7 @@ func (lg *Logic) CreateAccount(ctx context.Context, accountID string, params *mb
|
||||
return res, err
|
||||
}
|
||||
|
||||
accountExists, _, err := lg.db.GetAccountByUsername(ctx, params.Username)
|
||||
accountExists, _, err := oper.db.GetAccountByUsername(ctx, params.Username)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -75,7 +75,7 @@ func (lg *Logic) CreateAccount(ctx context.Context, accountID string, params *mb
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
err = lg.db.InsertAccount(ctx, accountDescr)
|
||||
err = oper.db.InsertAccount(ctx, accountDescr)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -83,14 +83,14 @@ func (lg *Logic) CreateAccount(ctx context.Context, accountID string, params *mb
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (lg *Logic) UpdateAccount(ctx context.Context, accountID string, params *mbctl.UpdateAccountParams) (*mbctl.UpdateAccountResult, error) {
|
||||
func (oper *Operator) UpdateAccount(ctx context.Context, accountID string, params *mbctl.UpdateAccountParams) (*mbctl.UpdateAccountResult, error) {
|
||||
var err error
|
||||
res := &mbctl.UpdateAccountResult{}
|
||||
|
||||
lg.WaitRestoring()
|
||||
lg.WaitDumping()
|
||||
oper.WaitRestoring()
|
||||
oper.WaitDumping()
|
||||
|
||||
grantExists, _, err := lg.db.GetGrant(ctx, accountID, descr.GrantModifyUsers)
|
||||
grantExists, _, err := oper.db.GetGrant(ctx, accountID, descr.GrantModifyUsers)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -103,12 +103,12 @@ func (lg *Logic) UpdateAccount(ctx context.Context, accountID string, params *mb
|
||||
var accountExists bool
|
||||
switch {
|
||||
case params.AccountID != "":
|
||||
accountExists, accountDescr, err = lg.db.GetAccountByID(ctx, params.AccountID)
|
||||
accountExists, accountDescr, err = oper.db.GetAccountByID(ctx, params.AccountID)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
case params.Username != "":
|
||||
accountExists, accountDescr, err = lg.db.GetAccountByUsername(ctx, params.Username)
|
||||
accountExists, accountDescr, err = oper.db.GetAccountByUsername(ctx, params.Username)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -133,21 +133,21 @@ func (lg *Logic) UpdateAccount(ctx context.Context, accountID string, params *mb
|
||||
accountDescr.Disabled = params.Disabled
|
||||
}
|
||||
|
||||
err = lg.db.UpdateAccountByID(ctx, accountDescr.ID, accountDescr)
|
||||
err = oper.db.UpdateAccountByID(ctx, accountDescr.ID, accountDescr)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (lg *Logic) DeleteAccount(ctx context.Context, accountID string, params *mbctl.DeleteAccountParams) (*mbctl.DeleteAccountResult, error) {
|
||||
func (oper *Operator) DeleteAccount(ctx context.Context, accountID string, params *mbctl.DeleteAccountParams) (*mbctl.DeleteAccountResult, error) {
|
||||
var err error
|
||||
res := &mbctl.DeleteAccountResult{}
|
||||
|
||||
lg.WaitDumping()
|
||||
lg.WaitRestoring()
|
||||
oper.WaitDumping()
|
||||
oper.WaitRestoring()
|
||||
|
||||
grantExists, _, err := lg.db.GetGrant(ctx, accountID, descr.GrantModifyUsers)
|
||||
grantExists, _, err := oper.db.GetGrant(ctx, accountID, descr.GrantModifyUsers)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -160,12 +160,12 @@ func (lg *Logic) DeleteAccount(ctx context.Context, accountID string, params *mb
|
||||
var accountExists bool
|
||||
switch {
|
||||
case params.AccountID != "":
|
||||
accountExists, accountDescr, err = lg.db.GetAccountByID(ctx, params.AccountID)
|
||||
accountExists, accountDescr, err = oper.db.GetAccountByID(ctx, params.AccountID)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
case params.Username != "":
|
||||
accountExists, accountDescr, err = lg.db.GetAccountByUsername(ctx, params.Username)
|
||||
accountExists, accountDescr, err = oper.db.GetAccountByUsername(ctx, params.Username)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -175,26 +175,26 @@ func (lg *Logic) DeleteAccount(ctx context.Context, accountID string, params *mb
|
||||
return res, err
|
||||
}
|
||||
|
||||
err = lg.db.DeleteAllGrantsForAccountID(ctx, accountDescr.ID)
|
||||
err = oper.db.DeleteAllGrantsForAccountID(ctx, accountDescr.ID)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
err = lg.db.DeleteAccountByID(ctx, accountDescr.ID)
|
||||
err = oper.db.DeleteAccountByID(ctx, accountDescr.ID)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (lg *Logic) ListAccounts(ctx context.Context, accountID string, params *mbctl.ListAccountsParams) (*mbctl.ListAccountsResult, error) {
|
||||
func (oper *Operator) ListAccounts(ctx context.Context, accountID string, params *mbctl.ListAccountsParams) (*mbctl.ListAccountsResult, error) {
|
||||
var err error
|
||||
res := &mbctl.ListAccountsResult{
|
||||
Accounts: make([]*mbctl.AccountShortDescr, 0),
|
||||
}
|
||||
|
||||
lg.WaitRestoring()
|
||||
oper.WaitRestoring()
|
||||
|
||||
grantExists, _, err := lg.db.GetGrant(ctx, accountID, descr.GrantModifyUsers)
|
||||
grantExists, _, err := oper.db.GetGrant(ctx, accountID, descr.GrantModifyUsers)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -203,7 +203,7 @@ func (lg *Logic) ListAccounts(ctx context.Context, accountID string, params *mbc
|
||||
return res, err
|
||||
}
|
||||
|
||||
accountDescrs, err := lg.db.ReducedListAccounts(ctx)
|
||||
accountDescrs, err := oper.db.ReducedListAccounts(ctx)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -215,7 +215,7 @@ func (lg *Logic) ListAccounts(ctx context.Context, accountID string, params *mbc
|
||||
UpdatedAt: accountDescr.UpdatedAt,
|
||||
Grants: make([]*mbctl.GrantShortDescr, 0),
|
||||
}
|
||||
grantDescrs, err := lg.db.ListGrantsByAccountID(ctx, accountDescr.ID)
|
||||
grantDescrs, err := oper.db.ListGrantsByAccountID(ctx, accountDescr.ID)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
@@ -14,23 +14,23 @@ const (
|
||||
defaultSeedPassword = "mbase"
|
||||
)
|
||||
|
||||
func (lg *Logic) CleanDatabase(ctx context.Context) error {
|
||||
func (oper *Operator) CleanDatabase(ctx context.Context) error {
|
||||
var err error
|
||||
err = lg.db.CleanDatabase(ctx)
|
||||
err = oper.db.CleanDatabase(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (lg *Logic) SeedAccount(ctx context.Context) (string, error) {
|
||||
func (oper *Operator) SeedAccount(ctx context.Context) (string, error) {
|
||||
var err error
|
||||
var accountID string
|
||||
accountDescrs, err := lg.db.ReducedListAccounts(ctx)
|
||||
accountDescrs, err := oper.db.ReducedListAccounts(ctx)
|
||||
if err != nil {
|
||||
return accountID, err
|
||||
}
|
||||
lg.log.Debugf("Seed account")
|
||||
oper.log.Debugf("Seed account")
|
||||
if len(accountDescrs) == 0 {
|
||||
now := time.Now().Format(time.RFC3339)
|
||||
passhash := auxpwd.MakeSHA256Hash([]byte(defaultSeedPassword))
|
||||
@@ -42,7 +42,7 @@ func (lg *Logic) SeedAccount(ctx context.Context) (string, error) {
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
err = lg.db.InsertAccount(ctx, accountDescr)
|
||||
err = oper.db.InsertAccount(ctx, accountDescr)
|
||||
if err != nil {
|
||||
return accountID, err
|
||||
}
|
||||
@@ -57,7 +57,7 @@ func (lg *Logic) SeedAccount(ctx context.Context) (string, error) {
|
||||
Operation: grantType,
|
||||
CreatedAt: now,
|
||||
}
|
||||
err = lg.db.InsertGrant(ctx, grantDescr)
|
||||
err = oper.db.InsertGrant(ctx, grantDescr)
|
||||
if err != nil {
|
||||
return accountID, err
|
||||
}
|
||||
|
||||
+22
-22
@@ -11,11 +11,11 @@ import (
|
||||
"go.yaml.in/yaml/v4"
|
||||
)
|
||||
|
||||
func (lg *Logic) GetDump(ctx context.Context, accountID string, params *mbctl.GetDumpParams) (*mbctl.GetDumpResult, error) {
|
||||
func (oper *Operator) GetDump(ctx context.Context, accountID string, params *mbctl.GetDumpParams) (*mbctl.GetDumpResult, error) {
|
||||
var err error
|
||||
res := &mbctl.GetDumpResult{}
|
||||
|
||||
grantExists, _, err := lg.db.GetGrant(ctx, accountID, descr.GrantModifyDatabase)
|
||||
grantExists, _, err := oper.db.GetGrant(ctx, accountID, descr.GrantModifyDatabase)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -24,21 +24,21 @@ func (lg *Logic) GetDump(ctx context.Context, accountID string, params *mbctl.Ge
|
||||
return res, err
|
||||
}
|
||||
|
||||
lg.WaitRestoring()
|
||||
lg.WaitDumping()
|
||||
oper.WaitRestoring()
|
||||
oper.WaitDumping()
|
||||
|
||||
lg.DumpingSemUp()
|
||||
defer lg.DumpingSemDown()
|
||||
oper.DumpingSemUp()
|
||||
defer oper.DumpingSemDown()
|
||||
|
||||
listAccounts, err := lg.db.CompletedListAccounts(ctx)
|
||||
listAccounts, err := oper.db.CompletedListAccounts(ctx)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
listGrants, err := lg.db.ListGrants(ctx)
|
||||
listGrants, err := oper.db.ListGrants(ctx)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
lg.DumpingSemDown()
|
||||
oper.DumpingSemDown()
|
||||
|
||||
dump := descr.Dump{
|
||||
Timestamp: time.Now().Format(time.RFC3339),
|
||||
@@ -55,11 +55,11 @@ func (lg *Logic) GetDump(ctx context.Context, accountID string, params *mbctl.Ge
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (lg *Logic) RestoreDump(ctx context.Context, accountID string, params *mbctl.RestoreDumpParams) (*mbctl.RestoreDumpResult, error) {
|
||||
func (oper *Operator) RestoreDump(ctx context.Context, accountID string, params *mbctl.RestoreDumpParams) (*mbctl.RestoreDumpResult, error) {
|
||||
var err error
|
||||
res := &mbctl.RestoreDumpResult{}
|
||||
|
||||
grantExists, _, err := lg.db.GetGrant(ctx, accountID, descr.GrantModifyDatabase)
|
||||
grantExists, _, err := oper.db.GetGrant(ctx, accountID, descr.GrantModifyDatabase)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -68,8 +68,8 @@ func (lg *Logic) RestoreDump(ctx context.Context, accountID string, params *mbct
|
||||
return res, err
|
||||
}
|
||||
|
||||
lg.WaitDumping()
|
||||
lg.WaitRestoring()
|
||||
oper.WaitDumping()
|
||||
oper.WaitRestoring()
|
||||
|
||||
var dump descr.Dump
|
||||
|
||||
@@ -78,28 +78,28 @@ func (lg *Logic) RestoreDump(ctx context.Context, accountID string, params *mbct
|
||||
return res, err
|
||||
}
|
||||
|
||||
lg.RestoringSemUp()
|
||||
defer lg.RestoringSemDown()
|
||||
oper.RestoringSemUp()
|
||||
defer oper.RestoringSemDown()
|
||||
|
||||
if params.DeleteAllRecords {
|
||||
err = lg.db.CleanDatabase(ctx)
|
||||
err = oper.db.CleanDatabase(ctx)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
}
|
||||
|
||||
for _, account := range dump.Accounts {
|
||||
lg.log.Infof("Insert account %s", account.Username)
|
||||
err = lg.db.InsertAccount(ctx, &account)
|
||||
oper.log.Infof("Insert account %s", account.Username)
|
||||
err = oper.db.InsertAccount(ctx, &account)
|
||||
if err != nil {
|
||||
lg.log.Errorf("Insert account error: %v", err)
|
||||
oper.log.Errorf("Insert account error: %v", err)
|
||||
}
|
||||
}
|
||||
for _, grant := range dump.Grants {
|
||||
lg.log.Infof("Insert grant %s for account %d", grant.Operation, grant.AccountID)
|
||||
err = lg.db.InsertGrant(ctx, &grant)
|
||||
oper.log.Infof("Insert grant %s for account %d", grant.Operation, grant.AccountID)
|
||||
err = oper.db.InsertGrant(ctx, &grant)
|
||||
if err != nil {
|
||||
lg.log.Errorf("Insert account error: %v", err)
|
||||
oper.log.Errorf("Insert account error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+14
-14
@@ -10,13 +10,13 @@ import (
|
||||
"mbase/pkg/mbctl"
|
||||
)
|
||||
|
||||
func (lg *Logic) SetGrant(ctx context.Context, accountID string, params *mbctl.SetGrantParams) (*mbctl.SetGrantResult, error) {
|
||||
func (oper *Operator) SetGrant(ctx context.Context, accountID string, params *mbctl.SetGrantParams) (*mbctl.SetGrantResult, error) {
|
||||
var err error
|
||||
res := &mbctl.SetGrantResult{}
|
||||
|
||||
lg.WaitDumping()
|
||||
oper.WaitDumping()
|
||||
|
||||
grantExists, _, err := lg.db.GetGrant(ctx, accountID, descr.GrantModifyUsers)
|
||||
grantExists, _, err := oper.db.GetGrant(ctx, accountID, descr.GrantModifyUsers)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -45,12 +45,12 @@ func (lg *Logic) SetGrant(ctx context.Context, accountID string, params *mbctl.S
|
||||
var accountExists bool
|
||||
switch {
|
||||
case params.AccountID != "":
|
||||
accountExists, accountDescr, err = lg.db.GetAccountByID(ctx, params.AccountID)
|
||||
accountExists, accountDescr, err = oper.db.GetAccountByID(ctx, params.AccountID)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
case params.Username != "":
|
||||
accountExists, accountDescr, err = lg.db.GetAccountByUsername(ctx, params.Username)
|
||||
accountExists, accountDescr, err = oper.db.GetAccountByUsername(ctx, params.Username)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -60,7 +60,7 @@ func (lg *Logic) SetGrant(ctx context.Context, accountID string, params *mbctl.S
|
||||
return res, err
|
||||
}
|
||||
|
||||
grantExists, _, err = lg.db.GetGrant(ctx, accountDescr.ID, params.Operation)
|
||||
grantExists, _, err = oper.db.GetGrant(ctx, accountDescr.ID, params.Operation)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -75,20 +75,20 @@ func (lg *Logic) SetGrant(ctx context.Context, accountID string, params *mbctl.S
|
||||
CreatedAt: now,
|
||||
Operation: params.Operation,
|
||||
}
|
||||
err = lg.db.InsertGrant(ctx, grantDescr)
|
||||
err = oper.db.InsertGrant(ctx, grantDescr)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (lg *Logic) DeleteGrant(ctx context.Context, accountID string, params *mbctl.DeleteGrantParams) (*mbctl.DeleteGrantResult, error) {
|
||||
func (oper *Operator) DeleteGrant(ctx context.Context, accountID string, params *mbctl.DeleteGrantParams) (*mbctl.DeleteGrantResult, error) {
|
||||
var err error
|
||||
res := &mbctl.DeleteGrantResult{}
|
||||
|
||||
lg.WaitDumping()
|
||||
oper.WaitDumping()
|
||||
|
||||
grantExists, _, err := lg.db.GetGrant(ctx, accountID, descr.GrantModifyUsers)
|
||||
grantExists, _, err := oper.db.GetGrant(ctx, accountID, descr.GrantModifyUsers)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -117,12 +117,12 @@ func (lg *Logic) DeleteGrant(ctx context.Context, accountID string, params *mbct
|
||||
var accountExists bool
|
||||
switch {
|
||||
case params.AccountID != "":
|
||||
accountExists, accountDescr, err = lg.db.GetAccountByID(ctx, params.AccountID)
|
||||
accountExists, accountDescr, err = oper.db.GetAccountByID(ctx, params.AccountID)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
case params.Username != "":
|
||||
accountExists, accountDescr, err = lg.db.GetAccountByUsername(ctx, params.Username)
|
||||
accountExists, accountDescr, err = oper.db.GetAccountByUsername(ctx, params.Username)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -132,7 +132,7 @@ func (lg *Logic) DeleteGrant(ctx context.Context, accountID string, params *mbct
|
||||
return res, err
|
||||
}
|
||||
|
||||
grantExists, _, err = lg.db.GetGrant(ctx, accountDescr.ID, params.Operation)
|
||||
grantExists, _, err = oper.db.GetGrant(ctx, accountDescr.ID, params.Operation)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -140,7 +140,7 @@ func (lg *Logic) DeleteGrant(ctx context.Context, accountID string, params *mbct
|
||||
err := fmt.Errorf("Requested grant for the user not found")
|
||||
return res, err
|
||||
}
|
||||
err = lg.db.DeleteGrantByAccountID(ctx, accountDescr.ID, params.Operation)
|
||||
err = oper.db.DeleteGrantByAccountID(ctx, accountDescr.ID, params.Operation)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"mbase/pkg/mbctl"
|
||||
)
|
||||
|
||||
func (lg *Logic) GetHello(ctx context.Context, params *mbctl.GetHelloParams) (*mbctl.GetHelloResult, error) {
|
||||
func (oper *Operator) GetHello(ctx context.Context, params *mbctl.GetHelloParams) (*mbctl.GetHelloResult, error) {
|
||||
var err error
|
||||
res := &mbctl.GetHelloResult{
|
||||
Message: "hello",
|
||||
|
||||
+18
-18
@@ -8,54 +8,54 @@ import (
|
||||
"mbase/pkg/logger"
|
||||
)
|
||||
|
||||
type LogicConfig struct {
|
||||
type OperatorConfig struct {
|
||||
Database *maindb.Database
|
||||
}
|
||||
|
||||
type Logic struct {
|
||||
type Operator struct {
|
||||
log *logger.Logger
|
||||
db *maindb.Database
|
||||
dumpingSem atomic.Bool
|
||||
restoringSem atomic.Bool
|
||||
}
|
||||
|
||||
func NewLogic(conf *LogicConfig) (*Logic, error) {
|
||||
func NewOperator(conf *OperatorConfig) (*Operator, error) {
|
||||
var err error
|
||||
lg := &Logic{
|
||||
oper := &Operator{
|
||||
db: conf.Database,
|
||||
}
|
||||
lg.log = logger.NewLogger("logic")
|
||||
return lg, err
|
||||
oper.log = logger.NewLogger("Operator")
|
||||
return oper, err
|
||||
}
|
||||
|
||||
func (lg *Logic) DumpingSemUp() {
|
||||
lg.dumpingSem.Store(true)
|
||||
func (oper *Operator) DumpingSemUp() {
|
||||
oper.dumpingSem.Store(true)
|
||||
}
|
||||
|
||||
func (lg *Logic) DumpingSemDown() {
|
||||
lg.dumpingSem.Store(false)
|
||||
func (oper *Operator) DumpingSemDown() {
|
||||
oper.dumpingSem.Store(false)
|
||||
}
|
||||
|
||||
func (lg *Logic) WaitDumping() {
|
||||
func (oper *Operator) WaitDumping() {
|
||||
for {
|
||||
if !lg.dumpingSem.Load() {
|
||||
if !oper.dumpingSem.Load() {
|
||||
return
|
||||
}
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
|
||||
func (lg *Logic) RestoringSemUp() {
|
||||
lg.restoringSem.Store(true)
|
||||
func (oper *Operator) RestoringSemUp() {
|
||||
oper.restoringSem.Store(true)
|
||||
}
|
||||
|
||||
func (lg *Logic) RestoringSemDown() {
|
||||
lg.restoringSem.Store(false)
|
||||
func (oper *Operator) RestoringSemDown() {
|
||||
oper.restoringSem.Store(false)
|
||||
}
|
||||
|
||||
func (lg *Logic) WaitRestoring() {
|
||||
func (oper *Operator) WaitRestoring() {
|
||||
for {
|
||||
if !lg.restoringSem.Load() {
|
||||
if !oper.restoringSem.Load() {
|
||||
return
|
||||
}
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
|
||||
@@ -26,7 +26,7 @@ import (
|
||||
|
||||
type Server struct {
|
||||
conf *config.Config
|
||||
lg *operator.Logic
|
||||
oper *operator.Operator
|
||||
svc *service.Service
|
||||
hand *handler.Handler
|
||||
log *logger.Logger
|
||||
@@ -175,11 +175,11 @@ func (srv *Server) Build() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Create logic
|
||||
logicConfig := &operator.LogicConfig{
|
||||
// Create operator
|
||||
operConfig := &operator.OperatorConfig{
|
||||
Database: srv.db,
|
||||
}
|
||||
srv.lg, err = operator.NewLogic(logicConfig)
|
||||
srv.oper, err = operator.NewOperator(operConfig)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -198,7 +198,7 @@ func (srv *Server) Build() error {
|
||||
}
|
||||
// Create handler
|
||||
handlerConfig := &handler.HandlerConfig{
|
||||
Logic: srv.lg,
|
||||
Operator: srv.oper,
|
||||
}
|
||||
srv.hand = handler.NewHandler(handlerConfig)
|
||||
if err != nil {
|
||||
@@ -212,7 +212,7 @@ func (srv *Server) Build() error {
|
||||
Hostname: srv.conf.Hostname,
|
||||
|
||||
Handler: srv.hand,
|
||||
Logic: srv.lg,
|
||||
Operator: srv.oper,
|
||||
X509Cert: srv.x509cert,
|
||||
X509Key: srv.x509key,
|
||||
NetACL: srv.nacl,
|
||||
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
|
||||
type ServiceConfig struct {
|
||||
Handler *handler.Handler
|
||||
Logic *operator.Logic
|
||||
Operator *operator.Operator
|
||||
NetACL *netacl.NetACL
|
||||
Portnum uint32
|
||||
Address string
|
||||
@@ -33,7 +33,7 @@ type ServiceConfig struct {
|
||||
type Service struct {
|
||||
gsrv *grpc.Server
|
||||
hand *handler.Handler
|
||||
lg *operator.Logic
|
||||
oper *operator.Operator
|
||||
log *logger.Logger
|
||||
nacl *netacl.NetACL
|
||||
portnum uint32
|
||||
@@ -49,7 +49,7 @@ type Service struct {
|
||||
func NewService(conf *ServiceConfig) *Service {
|
||||
svc := Service{
|
||||
hand: conf.Handler,
|
||||
lg: conf.Logic,
|
||||
oper: conf.Operator,
|
||||
nacl: conf.NetACL,
|
||||
portnum: conf.Portnum,
|
||||
address: conf.Address,
|
||||
|
||||
Reference in New Issue
Block a user