working commit

This commit is contained in:
2026-06-06 02:28:44 +02:00
parent 557aea269d
commit c96602e933
60 changed files with 2506 additions and 1273 deletions
-34
View File
@@ -1,34 +0,0 @@
package descr
const (
GrantModifyUsers = "modifyUsers"
GrantModifyDatabase = "modifyDatabase"
)
type Dump struct {
Timestamp string `json:"timestamp" yaml:"timestamp"`
Accounts []Account `json:"accounts" yaml:"accounts"`
Grants []Grant `json:"grants" yaml:"grants"`
}
type Account struct {
ID int64 `json:"id" yaml:"id" db:"id"`
Username string `json:"username" yaml:"username" db:"username"`
Passhash string `json:"passhash" yaml:"passhash" db:"passhash"`
Disabled bool `json:"disabled" yaml:"disabled" db:"disabled"`
CreatedAt string `json:"createdAt" yaml:"createdAt" db:"created_at"`
UpdatedAt string `json:"updatedAt" yaml:"updatedAt" db:"updated_at"`
}
type Grant struct {
ID int64 `json:"id" yaml:"id" db:"id"`
AccountID int64 `json:"accountID" yaml:"accountID" db:"account_id"`
Operation string `json:"operation" yaml:"operation" db:"operation"`
CreatedAt string `json:"createdAt" yaml:"createdAt" db:"created_at"`
}
type Server struct {
DatabaseInitialized bool `json:"databaseInitialized" yaml:"databaseInitialized"`
CreatedAt string `json:"createdAt" yaml:"createdAt"`
UpdatedAt string `json:"updatedAt" yaml:"updatedAt"`
}
+2 -2
View File
@@ -10,9 +10,9 @@ import (
"google.golang.org/grpc/status"
)
func (hand *Handler) Authentificate(ctx context.Context) (int64, error) {
func (hand *Handler) Authentificate(ctx context.Context) (string, error) {
var err error
var accountID int64
var accountID string
meta, _ := metadata.FromIncomingContext(ctx)
usernameArr := meta["username"]
+11 -11
View File
@@ -5,15 +5,15 @@ import (
"fmt"
"time"
"mbase/app/descr"
"mbase/pkg/auxid"
"mbase/pkg/descr"
"mbase/pkg/auxuuid"
"mbase/pkg/auxpwd"
"mbase/pkg/mbctl"
)
func (lg *Logic) ValidateAcount(ctx context.Context, username, password string) (bool, int64, error) {
func (lg *Logic) ValidateAcount(ctx context.Context, username, password string) (bool, string, error) {
var err error
var accountID int64
var accountID string
var valid bool
lg.WaitRestoring()
@@ -32,7 +32,7 @@ func (lg *Logic) ValidateAcount(ctx context.Context, username, password string)
return valid, accountID, err
}
func (lg *Logic) CreateAccount(ctx context.Context, accountID int64, params *mbctl.CreateAccountParams) (*mbctl.CreateAccountResult, error) {
func (lg *Logic) CreateAccount(ctx context.Context, accountID string, params *mbctl.CreateAccountParams) (*mbctl.CreateAccountResult, error) {
var err error
res := &mbctl.CreateAccountResult{}
@@ -68,7 +68,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 := &descr.Account{
ID: auxid.GenID(),
ID: auxuuid.NewUUID(),
Username: params.Username,
Passhash: passhash,
Disabled: false,
@@ -83,7 +83,7 @@ func (lg *Logic) CreateAccount(ctx context.Context, accountID int64, params *mbc
return res, err
}
func (lg *Logic) UpdateAccount(ctx context.Context, accountID int64, params *mbctl.UpdateAccountParams) (*mbctl.UpdateAccountResult, error) {
func (lg *Logic) UpdateAccount(ctx context.Context, accountID string, params *mbctl.UpdateAccountParams) (*mbctl.UpdateAccountResult, error) {
var err error
res := &mbctl.UpdateAccountResult{}
@@ -102,7 +102,7 @@ func (lg *Logic) UpdateAccount(ctx context.Context, accountID int64, params *mbc
var accountDescr *descr.Account
var accountExists bool
switch {
case params.AccountID != 0:
case params.AccountID != "":
accountExists, accountDescr, err = lg.db.GetAccountByID(ctx, params.AccountID)
if err != nil {
return res, err
@@ -140,7 +140,7 @@ func (lg *Logic) UpdateAccount(ctx context.Context, accountID int64, params *mbc
return res, err
}
func (lg *Logic) DeleteAccount(ctx context.Context, accountID int64, params *mbctl.DeleteAccountParams) (*mbctl.DeleteAccountResult, error) {
func (lg *Logic) DeleteAccount(ctx context.Context, accountID string, params *mbctl.DeleteAccountParams) (*mbctl.DeleteAccountResult, error) {
var err error
res := &mbctl.DeleteAccountResult{}
@@ -159,7 +159,7 @@ func (lg *Logic) DeleteAccount(ctx context.Context, accountID int64, params *mbc
var accountDescr *descr.Account
var accountExists bool
switch {
case params.AccountID != 0:
case params.AccountID != "":
accountExists, accountDescr, err = lg.db.GetAccountByID(ctx, params.AccountID)
if err != nil {
return res, err
@@ -186,7 +186,7 @@ func (lg *Logic) DeleteAccount(ctx context.Context, accountID int64, params *mbc
return res, err
}
func (lg *Logic) ListAccounts(ctx context.Context, accountID int64, params *mbctl.ListAccountsParams) (*mbctl.ListAccountsResult, error) {
func (lg *Logic) ListAccounts(ctx context.Context, accountID string, params *mbctl.ListAccountsParams) (*mbctl.ListAccountsResult, error) {
var err error
res := &mbctl.ListAccountsResult{
Accounts: make([]*mbctl.AccountShortDescr, 0),
+5 -7
View File
@@ -4,8 +4,8 @@ import (
"context"
"time"
"mbase/app/descr"
"mbase/pkg/auxid"
"mbase/pkg/descr"
"mbase/pkg/auxuuid"
"mbase/pkg/auxpwd"
)
@@ -23,9 +23,9 @@ func (lg *Logic) CleanDatabase(ctx context.Context) error {
return err
}
func (lg *Logic) SeedAccount(ctx context.Context) (int64, error) {
func (lg *Logic) SeedAccount(ctx context.Context) (string, error) {
var err error
var accountID int64
var accountID string
accountDescrs, err := lg.db.ReducedListAccounts(ctx)
if err != nil {
return accountID, err
@@ -35,7 +35,7 @@ func (lg *Logic) SeedAccount(ctx context.Context) (int64, error) {
now := time.Now().Format(time.RFC3339)
passhash := auxpwd.MakeSHA256Hash([]byte(defaultSeedPassword))
accountDescr := &descr.Account{
ID: auxid.GenID(),
ID: auxuuid.NewUUID(),
Username: defaultSeedUsername,
Passhash: passhash,
Disabled: false,
@@ -63,9 +63,7 @@ func (lg *Logic) SeedAccount(ctx context.Context) (int64, error) {
}
}
}
return accountID, err
}
+3 -3
View File
@@ -5,13 +5,13 @@ import (
"fmt"
"time"
"mbase/app/descr"
"mbase/pkg/descr"
"mbase/pkg/mbctl"
"go.yaml.in/yaml/v4"
)
func (lg *Logic) GetDump(ctx context.Context, accountID int64, params *mbctl.GetDumpParams) (*mbctl.GetDumpResult, error) {
func (lg *Logic) GetDump(ctx context.Context, accountID string, params *mbctl.GetDumpParams) (*mbctl.GetDumpResult, error) {
var err error
res := &mbctl.GetDumpResult{}
@@ -55,7 +55,7 @@ func (lg *Logic) GetDump(ctx context.Context, accountID int64, params *mbctl.Get
return res, err
}
func (lg *Logic) RestoreDump(ctx context.Context, accountID int64, params *mbctl.RestoreDumpParams) (*mbctl.RestoreDumpResult, error) {
func (lg *Logic) RestoreDump(ctx context.Context, accountID string, params *mbctl.RestoreDumpParams) (*mbctl.RestoreDumpResult, error) {
var err error
res := &mbctl.RestoreDumpResult{}
+7 -7
View File
@@ -5,12 +5,12 @@ import (
"fmt"
"time"
"mbase/app/descr"
"mbase/pkg/auxid"
"mbase/pkg/descr"
"mbase/pkg/auxuuid"
"mbase/pkg/mbctl"
)
func (lg *Logic) SetGrant(ctx context.Context, accountID int64, params *mbctl.SetGrantParams) (*mbctl.SetGrantResult, error) {
func (lg *Logic) SetGrant(ctx context.Context, accountID string, params *mbctl.SetGrantParams) (*mbctl.SetGrantResult, error) {
var err error
res := &mbctl.SetGrantResult{}
@@ -44,7 +44,7 @@ func (lg *Logic) SetGrant(ctx context.Context, accountID int64, params *mbctl.Se
var accountDescr *descr.Account
var accountExists bool
switch {
case params.AccountID != 0:
case params.AccountID != "":
accountExists, accountDescr, err = lg.db.GetAccountByID(ctx, params.AccountID)
if err != nil {
return res, err
@@ -70,7 +70,7 @@ func (lg *Logic) SetGrant(ctx context.Context, accountID int64, params *mbctl.Se
}
now := time.Now().Format(time.RFC3339)
grantDescr := &descr.Grant{
ID: auxid.GenID(),
ID: auxuuid.NewUUID(),
AccountID: accountDescr.ID,
CreatedAt: now,
Operation: params.Operation,
@@ -82,7 +82,7 @@ func (lg *Logic) SetGrant(ctx context.Context, accountID int64, params *mbctl.Se
return res, err
}
func (lg *Logic) DeleteGrant(ctx context.Context, accountID int64, params *mbctl.DeleteGrantParams) (*mbctl.DeleteGrantResult, error) {
func (lg *Logic) DeleteGrant(ctx context.Context, accountID string, params *mbctl.DeleteGrantParams) (*mbctl.DeleteGrantResult, error) {
var err error
res := &mbctl.DeleteGrantResult{}
@@ -116,7 +116,7 @@ func (lg *Logic) DeleteGrant(ctx context.Context, accountID int64, params *mbctl
var accountDescr *descr.Account
var accountExists bool
switch {
case params.AccountID != 0:
case params.AccountID != "":
accountExists, accountDescr, err = lg.db.GetAccountByID(ctx, params.AccountID)
if err != nil {
return res, err
+4 -4
View File
@@ -3,7 +3,7 @@ package maindb
import (
"context"
"mbase/app/descr"
"mbase/pkg/descr"
)
func (db *Database) InsertAccount(ctx context.Context, account *descr.Account) error {
@@ -19,7 +19,7 @@ func (db *Database) InsertAccount(ctx context.Context, account *descr.Account) e
return err
}
func (db *Database) UpdateAccountByID(ctx context.Context, accountID int64, account *descr.Account) error {
func (db *Database) UpdateAccountByID(ctx context.Context, accountID string, account *descr.Account) error {
var err error
request := `UPDATE account SET username = $1, passhash = $2, disabled = $3, updated_at = $4 WHERE id = $5`
@@ -52,7 +52,7 @@ func (db *Database) CompletedListAccounts(ctx context.Context) ([]descr.Account,
return res, err
}
func (db *Database) GetAccountByID(ctx context.Context, accountID int64) (bool, *descr.Account, error) {
func (db *Database) GetAccountByID(ctx context.Context, accountID string) (bool, *descr.Account, error) {
var err error
var res *descr.Account
var exists bool
@@ -91,7 +91,7 @@ func (db *Database) GetAccountByUsername(ctx context.Context, username string) (
return exists, res, err
}
func (db *Database) DeleteAccountByID(ctx context.Context, accountID int64) error {
func (db *Database) DeleteAccountByID(ctx context.Context, accountID string) error {
var err error
request := `DELETE FROM account WHERE id = $1`
+3 -34
View File
@@ -11,39 +11,9 @@ import (
)
const schema = `
--- DROP TABLE IF EXISTS issuer;
CREATE TABLE IF NOT EXISTS issuer (
id INT NOT NULL,
name TEXT NOT NULL,
cert TEXT NOT NULL,
key TEXT,
signer_id INT NOT NULL,
signer_name TEXT NOT NULL,
revoked BOOL
);
CREATE UNIQUE INDEX IF NOT EXISTS issuer_index01
ON issuer(id);
CREATE UNIQUE INDEX IF NOT EXISTS issuer_index02
ON issuer(name);
--- DROP TABLE IF EXISTS service;
CREATE TABLE IF NOT EXISTS service (
id INT NOT NULL,
issuer_id INT NOT NULL,
issuer_name TEXT NOT NULL,
name TEXT NOT NULL,
cert TEXT NOT NULL,
key TEXT NOT NULL,
revoked BOOL
);
CREATE UNIQUE INDEX IF NOT EXISTS service_index01
ON service(id);
CREATE UNIQUE INDEX IF NOT EXISTS service_index02
ON service(name);
--- DROP TABLE IF EXISTS account;
CREATE TABLE IF NOT EXISTS account (
id INT NOT NULL,
id TEXT NOT NULL,
username TEXT NOT NULL,
passhash TEXT NOT NULL,
created_at TEXT NOT NULL,
@@ -55,11 +25,10 @@ const schema = `
CREATE UNIQUE INDEX IF NOT EXISTS account_index02
ON account(username);
--- DROP TABLE IF EXISTS grant;
CREATE TABLE IF NOT EXISTS grant (
id INT NOT NULL,
account_id INT NOT NULL,
id TEXT NOT NULL,
account_id TEXT NOT NULL,
operation TEXT NOT NULL,
created_at TEXT NOT NULL
);
+5 -5
View File
@@ -3,7 +3,7 @@ package maindb
import (
"context"
"mbase/app/descr"
"mbase/pkg/descr"
)
func (db *Database) InsertGrant(ctx context.Context, grant *descr.Grant) error {
@@ -17,7 +17,7 @@ func (db *Database) InsertGrant(ctx context.Context, grant *descr.Grant) error {
return err
}
func (db *Database) ListGrantsByAccountID(ctx context.Context, accountID int64) ([]descr.Grant, error) {
func (db *Database) ListGrantsByAccountID(ctx context.Context, accountID string) ([]descr.Grant, error) {
var err error
request := `SELECT * FROM grant WHERE account_id = $1`
res := make([]descr.Grant, 0)
@@ -39,7 +39,7 @@ func (db *Database) ListGrants(ctx context.Context) ([]descr.Grant, error) {
return res, err
}
func (db *Database) GetGrant(ctx context.Context, accountID int64, operation string) (bool, *descr.Grant, error) {
func (db *Database) GetGrant(ctx context.Context, accountID, operation string) (bool, *descr.Grant, error) {
var err error
res := &descr.Grant{}
request := `SELECT * FROM grant WHERE account_id = $1 AND operation = $2 LIMIT 1`
@@ -56,7 +56,7 @@ func (db *Database) GetGrant(ctx context.Context, accountID int64, operation str
return true, res, err
}
func (db *Database) DeleteGrantByAccountID(ctx context.Context, grantID int64, operation string) error {
func (db *Database) DeleteGrantByAccountID(ctx context.Context, grantID, operation string) error {
var err error
request := `DELETE FROM grant WHERE account_id = $1 AND operation = $2`
_, err = db.db.Exec(request, grantID, operation)
@@ -66,7 +66,7 @@ func (db *Database) DeleteGrantByAccountID(ctx context.Context, grantID int64, o
return err
}
func (db *Database) DeleteAllGrantsForAccountID(ctx context.Context, grantID int64) error {
func (db *Database) DeleteAllGrantsForAccountID(ctx context.Context, grantID string) error {
var err error
request := `DELETE FROM grant WHERE account_id = $1`
_, err = db.db.Exec(request, grantID)
+1 -1
View File
@@ -12,7 +12,7 @@ import (
"mbase/app/config"
"mbase/app/maindb"
"mbase/app/descr"
"mbase/pkg/descr"
"mbase/app/logic"
"mbase/pkg/aux509"
"mbase/pkg/logger"