working commit

This commit is contained in:
2026-02-12 12:00:17 +02:00
parent ae15bddb15
commit b279687623
20 changed files with 639 additions and 192 deletions
+25 -27
View File
@@ -10,13 +10,11 @@ import (
"mstore/pkg/auxuuid"
)
func (oper *Operator) ValidateAcount(ctx context.Context, username, password string) (bool, string, error) {
func (oper *Operator) ValidatePassword(ctx context.Context, username, password string) (bool, string, error) {
var err error
var accountID string
valid := false
//oper.WaitRestoring()
accountExists, accountDescr, err := oper.mdb.GetAccountByUsername(ctx, username)
if !accountExists {
err := fmt.Errorf("Account not exists")
@@ -32,8 +30,8 @@ func (oper *Operator) ValidateAcount(ctx context.Context, username, password str
}
type CreateAccountParams struct {
Username string
Password string
Username string `json:"username"`
Password string `json:"password"`
}
type CreateAccountResult struct {
AccountID string `json:"accountId"`
@@ -80,11 +78,11 @@ func (oper *Operator) CreateAccount(ctx context.Context, params *CreateAccountPa
}
type UpdateAccountParams struct {
Username string
AccountID string
NewUsername string
NewPassword string
Disabled bool
Username string `json:"username"`
AccountID string `json:"accountId"`
NewUsername string `json:"newUsername"`
NewPassword string `json:"newPassword"`
Disabled bool `json:"disabled"`
}
type UpdateAccountResult struct{}
@@ -137,8 +135,8 @@ func (oper *Operator) UpdateAccount(ctx context.Context, params *UpdateAccountPa
}
type DeleteAccountParams struct {
Username string
AccountID string
Username string `json:"username"`
AccountID string `json:"accountId"`
}
type DeleteAccountResult struct{}
@@ -182,13 +180,13 @@ func (oper *Operator) DeleteAccount(ctx context.Context, params *DeleteAccountPa
type ListAccountsParams struct{}
type ListAccountsResult struct {
Accounts []descr.AccountShortDescr `json:"accounts"`
Accounts []descr.AccountShort `json:"accounts"`
}
func (oper *Operator) ListAccounts(ctx context.Context, params *ListAccountsParams) (*ListAccountsResult, error) {
var err error
res := &ListAccountsResult{
Accounts: make([]descr.AccountShortDescr, 0),
Accounts: make([]descr.AccountShort, 0),
}
accountDescrs, err := oper.mdb.ReducedListAccounts(ctx)
@@ -196,35 +194,35 @@ func (oper *Operator) ListAccounts(ctx context.Context, params *ListAccountsPara
return res, err
}
for _, accountDescr := range accountDescrs {
accountShortDescr := descr.AccountShortDescr{
accountShort := descr.AccountShort{
Username: accountDescr.Username,
Disabled: accountDescr.Disabled,
CreatedAt: accountDescr.CreatedAt,
UpdatedAt: accountDescr.UpdatedAt,
Grants: make([]descr.GrantShortDescr, 0),
Grants: make([]descr.GrantShort, 0),
}
grantDescrs, err := oper.mdb.ListGrantsByAccountID(ctx, accountDescr.ID)
if err != nil {
return res, err
}
for _, grantDescrs := range grantDescrs {
grantShortDescrs := descr.GrantShortDescr{
grantShorts := descr.GrantShort{
Operation: grantDescrs.Operation,
CreatedAt: grantDescrs.CreatedAt,
}
accountShortDescr.Grants = append(accountShortDescr.Grants, grantShortDescrs)
accountShort.Grants = append(accountShort.Grants, grantShorts)
}
res.Accounts = append(res.Accounts, accountShortDescr)
res.Accounts = append(res.Accounts, accountShort)
}
return res, err
}
type GetAccountParams struct {
Username string
AccountID string
Username string `json:"username"`
AccountID string `json:"accountId"`
}
type GetAccountResult struct {
Account *descr.AccountShortDescr `json:"account"`
Account *descr.AccountShort `json:"account"`
}
func (oper *Operator) GetAccount(ctx context.Context, params *GetAccountParams) (*GetAccountResult, error) {
@@ -253,25 +251,25 @@ func (oper *Operator) GetAccount(ctx context.Context, params *GetAccountParams)
return res, err
}
}
accountShortDescr := &descr.AccountShortDescr{
accountShort := &descr.AccountShort{
Username: accountDescr.Username,
Disabled: accountDescr.Disabled,
CreatedAt: accountDescr.CreatedAt,
UpdatedAt: accountDescr.UpdatedAt,
Grants: make([]descr.GrantShortDescr, 0),
Grants: make([]descr.GrantShort, 0),
}
grantDescrs, err := oper.mdb.ListGrantsByAccountID(ctx, accountDescr.ID)
if err != nil {
return res, err
}
for _, grantDescrs := range grantDescrs {
grantShortDescrs := descr.GrantShortDescr{
grantShorts := descr.GrantShort{
Operation: grantDescrs.Operation,
CreatedAt: grantDescrs.CreatedAt,
}
accountShortDescr.Grants = append(accountShortDescr.Grants, grantShortDescrs)
accountShort.Grants = append(accountShort.Grants, grantShorts)
}
res.Account = accountShortDescr
res.Account = accountShort
return res, err
}
+8 -5
View File
@@ -56,7 +56,7 @@ func (oper *Operator) FileInfo(ctx context.Context, param *FileInfoParams) (int,
filename := path.Base(xfilepath)
collection := path.Dir(xfilepath)
exist, fileDescr, err := oper.mdb.GetFileByCollection(ctx, collection, filename)
exist, fileDescr, err := oper.mdb.GetFileByCollectionName(ctx, collection, filename)
if err != nil {
code := http.StatusInternalServerError
return code, res, err
@@ -86,6 +86,7 @@ type PutFileResult struct{}
const defaultContentType = "application/octet-stream"
// TODO: checking catalog and file names conflict
func (oper *Operator) PutFile(ctx context.Context, param *PutFileParams) (int, *PutFileResult, error) {
var err error
res := &PutFileResult{}
@@ -120,7 +121,7 @@ func (oper *Operator) PutFile(ctx context.Context, param *PutFileParams) (int, *
return code, res, err
}
descrExists, fileDescr, err := oper.mdb.GetFileByCollection(ctx, collection, filename)
descrExists, fileDescr, err := oper.mdb.GetFileByCollectionName(ctx, collection, filename)
if err != nil {
code := http.StatusInternalServerError
return code, res, err
@@ -189,7 +190,7 @@ func (oper *Operator) GetFile(ctx context.Context, param *GetFileParams) (int, *
filename := path.Base(xfilepath)
collection := path.Dir(xfilepath)
descrExists, fileDescr, err := oper.mdb.GetFileByCollection(ctx, collection, filename)
descrExists, fileDescr, err := oper.mdb.GetFileByCollectionName(ctx, collection, filename)
if err != nil {
code := http.StatusInternalServerError
return code, res, err
@@ -232,13 +233,13 @@ func (oper *Operator) DeleteFile(ctx context.Context, param *DeleteFileParams) (
filename := path.Base(xfilepath)
collection := path.Dir(xfilepath)
exist, _, err := oper.mdb.GetFileByCollection(ctx, collection, filename)
exist, _, err := oper.mdb.GetFileByCollectionName(ctx, collection, filename)
if err != nil {
code = http.StatusInternalServerError
return code, res, err
}
if exist {
err = oper.mdb.DeleteFileByCollection(ctx, collection, filename)
err = oper.mdb.DeleteFileByCollectionName(ctx, collection, filename)
if err != nil {
code = http.StatusInternalServerError
return code, res, err
@@ -258,12 +259,14 @@ type ListFilesParams struct {
}
type ListFilesResult struct {
Files []descr.File `json:"files,omitempty"`
//Catalogs []string `json:"files,omitempty"`
}
func (oper *Operator) ListFiles(ctx context.Context, param *ListFilesParams) (int, *ListFilesResult, error) {
var err error
res := &ListFilesResult{
Files: make([]descr.File, 0),
//Catalogs: make([]string, 0)
}
// TODO: convert file path to a unified and secure state
+182
View File
@@ -0,0 +1,182 @@
package operator
import (
"context"
"fmt"
"mstore/app/descr"
"mstore/pkg/auxtool"
"mstore/pkg/auxuuid"
)
type CreateGrantParams struct {
AccountID string `json:"accountID"`
Operation string `json:"operation"`
Pattern string `json:"pattern"`
}
type CreateGrantResult struct {
GrantID string `json:"grantId"`
}
func (oper *Operator) CreateGrant(ctx context.Context, params *CreateGrantParams) (*CreateGrantResult, error) {
var err error
res := &CreateGrantResult{}
if params.AccountID == "" {
err := fmt.Errorf("Empty accountId parameters")
return res, err
}
if params.Operation == "" {
err := fmt.Errorf("Empty operation parameter")
return res, err
}
if params.Pattern == "" {
err := fmt.Errorf("Empty pattern parameter")
return res, err
}
grantExists, _, err := oper.mdb.GetGrantByAccoundIDOperationPattern(ctx, params.AccountID, params.Operation, params.Pattern)
if err != nil {
return res, err
}
if grantExists {
err := fmt.Errorf("Grant with this parapeters already exists")
return res, err
}
now := auxtool.TimeNow()
grantDescr := &descr.Grant{
ID: auxuuid.NewUUID(),
AccountID: params.AccountID,
Operation: params.Operation,
Pattern: params.Pattern,
CreatedAt: now,
UpdatedAt: now,
}
err = oper.mdb.InsertGrant(ctx, grantDescr)
if err != nil {
return res, err
}
res.GrantID = grantDescr.ID
return res, err
}
type UpdateGrantParams struct {
GrantID string
NewPattern string
}
type UpdateGrantResult struct{}
func (oper *Operator) UpdateGrant(ctx context.Context, params *UpdateGrantParams) (*UpdateGrantResult, error) {
var err error
res := &UpdateGrantResult{}
if params.GrantID == "" {
err := fmt.Errorf("Empty grantId parameter")
return res, err
}
var grantDescr *descr.Grant
var grantExists bool
grantExists, grantDescr, err = oper.mdb.GetGrantByID(ctx, params.GrantID)
if err != nil {
return res, err
}
if !grantExists {
err := fmt.Errorf("Grant with ID %s dont exists", params.GrantID)
return res, err
}
now := auxtool.TimeNow()
if params.NewPattern != "" {
grantDescr.UpdatedAt = now
grantDescr.Pattern = params.NewPattern
}
err = oper.mdb.UpdateGrantByID(ctx, grantDescr.ID, grantDescr)
if err != nil {
return res, err
}
return res, err
}
type DeleteGrantParams struct {
GrantID string `json:"grantId"`
}
type DeleteGrantResult struct{}
func (oper *Operator) DeleteGrant(ctx context.Context, params *DeleteGrantParams) (*DeleteGrantResult, error) {
var err error
res := &DeleteGrantResult{}
if params.GrantID == "" {
err := fmt.Errorf("Empty grantId parameter")
return res, err
}
var grantDescr *descr.Grant
var grantExists bool
grantExists, grantDescr, err = oper.mdb.GetGrantByID(ctx, params.GrantID)
if err != nil {
return res, err
}
if !grantExists {
err := fmt.Errorf("Grant with ID %s dont exists", params.GrantID)
return res, err
}
err = oper.mdb.DeleteGrantByID(ctx, grantDescr.ID)
if err != nil {
return res, err
}
return res, err
}
type ListGrantsParams struct {
AccountID string `json:"accountId"`
}
type ListGrantsResult struct {
Grants []descr.Grant `json:"grants"`
}
func (oper *Operator) ListGrants(ctx context.Context, params *ListGrantsParams) (*ListGrantsResult, error) {
var err error
res := &ListGrantsResult{
Grants: make([]descr.Grant, 0),
}
grantDescrs, err := oper.mdb.ListGrantsByAccountID(ctx, params.AccountID)
if err != nil {
return res, err
}
res.Grants = grantDescrs
return res, err
}
type GetGrantParams struct {
GrantID string `json:"grantId"`
}
type GetGrantResult struct {
Grant *descr.Grant `json:"grant"`
}
func (oper *Operator) GetGrant(ctx context.Context, params *GetGrantParams) (*GetGrantResult, error) {
var err error
res := &GetGrantResult{}
if params.GrantID == "" {
err := fmt.Errorf("Empty grantId parameter")
return res, err
}
var grantDescr *descr.Grant
var grantExists bool
grantExists, grantDescr, err = oper.mdb.GetGrantByID(ctx, params.GrantID)
if err != nil {
return res, err
}
if !grantExists {
err := fmt.Errorf("Grant with ID %s dont exists", params.GrantID)
return res, err
}
res.Grant = grantDescr
return res, err
}