working commit
This commit is contained in:
@@ -5,7 +5,7 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"mbase/app/descriptor"
|
||||
"mbase/app/descr"
|
||||
"mbase/pkg/auxid"
|
||||
"mbase/pkg/auxpwd"
|
||||
"mbase/pkg/mbctl"
|
||||
@@ -39,7 +39,7 @@ func (lg *Logic) CreateAccount(ctx context.Context, accountID int64, params *mbc
|
||||
lg.WaitDumping()
|
||||
lg.WaitRestoring()
|
||||
|
||||
grantExists, _, err := lg.db.GetGrant(ctx, accountID, descriptor.GrantModifyUsers)
|
||||
grantExists, _, err := lg.db.GetGrant(ctx, accountID, descr.GrantModifyUsers)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -67,7 +67,7 @@ func (lg *Logic) CreateAccount(ctx context.Context, accountID int64, params *mbc
|
||||
}
|
||||
now := time.Now().Format(time.RFC3339)
|
||||
passhash := auxpwd.MakeSHA256Hash([]byte(params.Password))
|
||||
accountDescr := &descriptor.Account{
|
||||
accountDescr := &descr.Account{
|
||||
ID: auxid.GenID(),
|
||||
Username: params.Username,
|
||||
Passhash: passhash,
|
||||
@@ -90,7 +90,7 @@ func (lg *Logic) UpdateAccount(ctx context.Context, accountID int64, params *mbc
|
||||
lg.WaitRestoring()
|
||||
lg.WaitDumping()
|
||||
|
||||
grantExists, _, err := lg.db.GetGrant(ctx, accountID, descriptor.GrantModifyUsers)
|
||||
grantExists, _, err := lg.db.GetGrant(ctx, accountID, descr.GrantModifyUsers)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -99,7 +99,7 @@ func (lg *Logic) UpdateAccount(ctx context.Context, accountID int64, params *mbc
|
||||
return res, err
|
||||
}
|
||||
|
||||
var accountDescr *descriptor.Account
|
||||
var accountDescr *descr.Account
|
||||
var accountExists bool
|
||||
switch {
|
||||
case params.AccountID != 0:
|
||||
@@ -147,7 +147,7 @@ func (lg *Logic) DeleteAccount(ctx context.Context, accountID int64, params *mbc
|
||||
lg.WaitDumping()
|
||||
lg.WaitRestoring()
|
||||
|
||||
grantExists, _, err := lg.db.GetGrant(ctx, accountID, descriptor.GrantModifyUsers)
|
||||
grantExists, _, err := lg.db.GetGrant(ctx, accountID, descr.GrantModifyUsers)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -156,7 +156,7 @@ func (lg *Logic) DeleteAccount(ctx context.Context, accountID int64, params *mbc
|
||||
return res, err
|
||||
}
|
||||
|
||||
var accountDescr *descriptor.Account
|
||||
var accountDescr *descr.Account
|
||||
var accountExists bool
|
||||
switch {
|
||||
case params.AccountID != 0:
|
||||
@@ -194,7 +194,7 @@ func (lg *Logic) ListAccounts(ctx context.Context, accountID int64, params *mbct
|
||||
|
||||
lg.WaitRestoring()
|
||||
|
||||
grantExists, _, err := lg.db.GetGrant(ctx, accountID, descriptor.GrantModifyUsers)
|
||||
grantExists, _, err := lg.db.GetGrant(ctx, accountID, descr.GrantModifyUsers)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"mbase/app/descriptor"
|
||||
"mbase/app/descr"
|
||||
"mbase/pkg/auxid"
|
||||
"mbase/pkg/auxpwd"
|
||||
)
|
||||
@@ -34,7 +34,7 @@ func (lg *Logic) SeedAccount(ctx context.Context) (int64, error) {
|
||||
if len(accountDescrs) == 0 {
|
||||
now := time.Now().Format(time.RFC3339)
|
||||
passhash := auxpwd.MakeSHA256Hash([]byte(defaultSeedPassword))
|
||||
accountDescr := &descriptor.Account{
|
||||
accountDescr := &descr.Account{
|
||||
ID: auxid.GenID(),
|
||||
Username: defaultSeedUsername,
|
||||
Passhash: passhash,
|
||||
@@ -48,11 +48,11 @@ func (lg *Logic) SeedAccount(ctx context.Context) (int64, error) {
|
||||
}
|
||||
accountID = accountDescr.ID
|
||||
grantTypes := []string{
|
||||
descriptor.GrantModifyUsers,
|
||||
descriptor.GrantModifyDatabase,
|
||||
descr.GrantModifyUsers,
|
||||
descr.GrantModifyDatabase,
|
||||
}
|
||||
for _, grantType := range grantTypes {
|
||||
grantDescr := &descriptor.Grant{
|
||||
grantDescr := &descr.Grant{
|
||||
AccountID: accountDescr.ID,
|
||||
Operation: grantType,
|
||||
CreatedAt: now,
|
||||
|
||||
+5
-5
@@ -5,7 +5,7 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"mbase/app/descriptor"
|
||||
"mbase/app/descr"
|
||||
"mbase/pkg/mbctl"
|
||||
|
||||
"go.yaml.in/yaml/v4"
|
||||
@@ -15,7 +15,7 @@ func (lg *Logic) GetDump(ctx context.Context, accountID int64, params *mbctl.Get
|
||||
var err error
|
||||
res := &mbctl.GetDumpResult{}
|
||||
|
||||
grantExists, _, err := lg.db.GetGrant(ctx, accountID, descriptor.GrantModifyDatabase)
|
||||
grantExists, _, err := lg.db.GetGrant(ctx, accountID, descr.GrantModifyDatabase)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -40,7 +40,7 @@ func (lg *Logic) GetDump(ctx context.Context, accountID int64, params *mbctl.Get
|
||||
}
|
||||
lg.DumpingSemDown()
|
||||
|
||||
dump := descriptor.Dump{
|
||||
dump := descr.Dump{
|
||||
Timestamp: time.Now().Format(time.RFC3339),
|
||||
Accounts: listAccounts,
|
||||
Grants: listGrants,
|
||||
@@ -59,7 +59,7 @@ func (lg *Logic) RestoreDump(ctx context.Context, accountID int64, params *mbctl
|
||||
var err error
|
||||
res := &mbctl.RestoreDumpResult{}
|
||||
|
||||
grantExists, _, err := lg.db.GetGrant(ctx, accountID, descriptor.GrantModifyDatabase)
|
||||
grantExists, _, err := lg.db.GetGrant(ctx, accountID, descr.GrantModifyDatabase)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -71,7 +71,7 @@ func (lg *Logic) RestoreDump(ctx context.Context, accountID int64, params *mbctl
|
||||
lg.WaitDumping()
|
||||
lg.WaitRestoring()
|
||||
|
||||
var dump descriptor.Dump
|
||||
var dump descr.Dump
|
||||
|
||||
err = yaml.Unmarshal([]byte(params.Dump), &dump)
|
||||
if err != nil {
|
||||
|
||||
+10
-10
@@ -5,7 +5,7 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"mbase/app/descriptor"
|
||||
"mbase/app/descr"
|
||||
"mbase/pkg/auxid"
|
||||
"mbase/pkg/mbctl"
|
||||
)
|
||||
@@ -16,7 +16,7 @@ func (lg *Logic) SetGrant(ctx context.Context, accountID int64, params *mbctl.Se
|
||||
|
||||
lg.WaitDumping()
|
||||
|
||||
grantExists, _, err := lg.db.GetGrant(ctx, accountID, descriptor.GrantModifyUsers)
|
||||
grantExists, _, err := lg.db.GetGrant(ctx, accountID, descr.GrantModifyUsers)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -26,8 +26,8 @@ func (lg *Logic) SetGrant(ctx context.Context, accountID int64, params *mbctl.Se
|
||||
}
|
||||
|
||||
grantTypes := []string{
|
||||
descriptor.GrantModifyUsers,
|
||||
descriptor.GrantModifyDatabase,
|
||||
descr.GrantModifyUsers,
|
||||
descr.GrantModifyDatabase,
|
||||
}
|
||||
var grantOk bool
|
||||
for _, grantType := range grantTypes {
|
||||
@@ -41,7 +41,7 @@ func (lg *Logic) SetGrant(ctx context.Context, accountID int64, params *mbctl.Se
|
||||
return res, err
|
||||
}
|
||||
|
||||
var accountDescr *descriptor.Account
|
||||
var accountDescr *descr.Account
|
||||
var accountExists bool
|
||||
switch {
|
||||
case params.AccountID != 0:
|
||||
@@ -69,7 +69,7 @@ func (lg *Logic) SetGrant(ctx context.Context, accountID int64, params *mbctl.Se
|
||||
return res, err
|
||||
}
|
||||
now := time.Now().Format(time.RFC3339)
|
||||
grantDescr := &descriptor.Grant{
|
||||
grantDescr := &descr.Grant{
|
||||
ID: auxid.GenID(),
|
||||
AccountID: accountDescr.ID,
|
||||
CreatedAt: now,
|
||||
@@ -88,7 +88,7 @@ func (lg *Logic) DeleteGrant(ctx context.Context, accountID int64, params *mbctl
|
||||
|
||||
lg.WaitDumping()
|
||||
|
||||
grantExists, _, err := lg.db.GetGrant(ctx, accountID, descriptor.GrantModifyUsers)
|
||||
grantExists, _, err := lg.db.GetGrant(ctx, accountID, descr.GrantModifyUsers)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -98,8 +98,8 @@ func (lg *Logic) DeleteGrant(ctx context.Context, accountID int64, params *mbctl
|
||||
}
|
||||
|
||||
grantTypes := []string{
|
||||
descriptor.GrantModifyUsers,
|
||||
descriptor.GrantModifyDatabase,
|
||||
descr.GrantModifyUsers,
|
||||
descr.GrantModifyDatabase,
|
||||
}
|
||||
var grantOk bool
|
||||
for _, grantType := range grantTypes {
|
||||
@@ -113,7 +113,7 @@ func (lg *Logic) DeleteGrant(ctx context.Context, accountID int64, params *mbctl
|
||||
return res, err
|
||||
}
|
||||
|
||||
var accountDescr *descriptor.Account
|
||||
var accountDescr *descr.Account
|
||||
var accountExists bool
|
||||
switch {
|
||||
case params.AccountID != 0:
|
||||
|
||||
+3
-3
@@ -4,17 +4,17 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"mbase/app/database"
|
||||
"mbase/app/maindb"
|
||||
"mbase/pkg/logger"
|
||||
)
|
||||
|
||||
type LogicConfig struct {
|
||||
Database *database.Database
|
||||
Database *maindb.Database
|
||||
}
|
||||
|
||||
type Logic struct {
|
||||
log *logger.Logger
|
||||
db *database.Database
|
||||
db *maindb.Database
|
||||
dumpingSem atomic.Bool
|
||||
restoringSem atomic.Bool
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user