working commit
This commit is contained in:
@@ -60,6 +60,7 @@ func (oper *Operator) CreateAccount(ctx context.Context, operatorID string, para
|
||||
return res, err
|
||||
}
|
||||
|
||||
// GetAccount
|
||||
type GetAccountParams struct {
|
||||
Username string `json:"username"`
|
||||
AccountID string `json:"accountId"`
|
||||
@@ -114,14 +115,14 @@ func (oper *Operator) GetAccount(ctx context.Context, params *GetAccountParams)
|
||||
CreatedBy: accountDescr.CreatedBy,
|
||||
UpdatedBy: accountDescr.UpdatedBy,
|
||||
Disabled: accountDescr.Disabled,
|
||||
Grants: make([]descr.GrantShort, 0),
|
||||
Grants: make([]descr.Grant, 0),
|
||||
}
|
||||
grantDescrs, err := oper.mdb.ListGrantsByAccountID(ctx, accountDescr.ID)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
for _, grantDescrs := range grantDescrs {
|
||||
grantShorts := descr.GrantShort{
|
||||
grantShorts := descr.Grant{
|
||||
Right: grantDescrs.Right,
|
||||
Pattern: grantDescrs.Pattern,
|
||||
CreatedAt: grantDescrs.CreatedAt,
|
||||
@@ -282,14 +283,14 @@ func (oper *Operator) ListAccounts(ctx context.Context, params *ListAccountsPara
|
||||
UpdatedAt: accountDescr.UpdatedAt,
|
||||
CreatedBy: accountDescr.CreatedBy,
|
||||
UpdatedBy: accountDescr.UpdatedBy,
|
||||
Grants: make([]descr.GrantShort, 0),
|
||||
Grants: make([]descr.Grant, 0),
|
||||
}
|
||||
grantDescrs, err := oper.mdb.ListGrantsByAccountID(ctx, accountDescr.ID)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
for _, grantDescrs := range grantDescrs {
|
||||
grantShorts := descr.GrantShort{
|
||||
grantShorts := descr.Grant{
|
||||
Right: grantDescrs.Right,
|
||||
Pattern: grantDescrs.Pattern,
|
||||
CreatedAt: grantDescrs.CreatedAt,
|
||||
|
||||
+28
-5
@@ -35,6 +35,11 @@ type FileInfoResult struct {
|
||||
ContentType string
|
||||
ContentSize string
|
||||
ContentDigest string
|
||||
|
||||
ContentCreatedAt string
|
||||
ContentCreatedBy string
|
||||
ContentUpdatedAt string
|
||||
ContentUpdatedBy string
|
||||
}
|
||||
|
||||
func cleanFilepath(filename string) (string, error) {
|
||||
@@ -42,7 +47,7 @@ func cleanFilepath(filename string) (string, error) {
|
||||
return filepath.Clean(filename), nil
|
||||
}
|
||||
|
||||
func (oper *Operator) FileInfo(ctx context.Context, param *FileInfoParams) (int, *FileInfoResult, error) {
|
||||
func (oper *Operator) FileInfo(ctx context.Context, operID string, param *FileInfoParams) (int, *FileInfoResult, error) {
|
||||
var err error
|
||||
code := http.StatusOK
|
||||
res := &FileInfoResult{}
|
||||
@@ -71,6 +76,11 @@ func (oper *Operator) FileInfo(ctx context.Context, param *FileInfoParams) (int,
|
||||
ContentSize: strconv.FormatInt(fileDescr.Size, 10),
|
||||
ContentType: fileDescr.Type,
|
||||
ContentDigest: fileDescr.Checksum,
|
||||
|
||||
ContentCreatedAt: fileDescr.CreatedAt,
|
||||
ContentCreatedBy: fileDescr.CreatedBy,
|
||||
ContentUpdatedAt: fileDescr.UpdatedAt,
|
||||
ContentUpdatedBy: fileDescr.UpdatedBy,
|
||||
}
|
||||
return code, res, err
|
||||
}
|
||||
@@ -87,7 +97,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) {
|
||||
func (oper *Operator) PutFile(ctx context.Context, operID string, param *PutFileParams) (int, *PutFileResult, error) {
|
||||
var err error
|
||||
res := &PutFileResult{}
|
||||
|
||||
@@ -133,6 +143,7 @@ func (oper *Operator) PutFile(ctx context.Context, param *PutFileParams) (int, *
|
||||
fileDescr.Checksum = checksum
|
||||
fileDescr.UpdatedAt = now
|
||||
fileDescr.Type = contentType
|
||||
fileDescr.UpdatedBy = operID
|
||||
err = oper.mdb.UpdateFileByID(ctx, fileDescr.ID, fileDescr)
|
||||
if err != nil {
|
||||
code := http.StatusInternalServerError
|
||||
@@ -148,6 +159,8 @@ func (oper *Operator) PutFile(ctx context.Context, param *PutFileParams) (int, *
|
||||
Checksum: checksum,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
CreatedBy: operID,
|
||||
UpdatedBy: operID,
|
||||
}
|
||||
err = oper.mdb.InsertFile(ctx, fileDescr)
|
||||
if err != nil {
|
||||
@@ -174,9 +187,14 @@ type GetFileResult struct {
|
||||
ContentSize string
|
||||
ContentDigest string
|
||||
Source io.ReadCloser
|
||||
|
||||
ContentCreatedAt string
|
||||
ContentCreatedBy string
|
||||
ContentUpdatedAt string
|
||||
ContentUpdatedBy string
|
||||
}
|
||||
|
||||
func (oper *Operator) GetFile(ctx context.Context, param *GetFileParams) (int, *GetFileResult, error) {
|
||||
func (oper *Operator) GetFile(ctx context.Context, operID string, param *GetFileParams) (int, *GetFileResult, error) {
|
||||
var err error
|
||||
res := &GetFileResult{}
|
||||
|
||||
@@ -209,6 +227,11 @@ func (oper *Operator) GetFile(ctx context.Context, param *GetFileParams) (int, *
|
||||
ContentType: fileDescr.Type,
|
||||
ContentDigest: fileDescr.Checksum,
|
||||
Source: reader,
|
||||
|
||||
ContentCreatedAt: fileDescr.CreatedAt,
|
||||
ContentCreatedBy: fileDescr.CreatedBy,
|
||||
ContentUpdatedAt: fileDescr.UpdatedAt,
|
||||
ContentUpdatedBy: fileDescr.UpdatedBy,
|
||||
}
|
||||
code := http.StatusOK
|
||||
return code, res, err
|
||||
@@ -220,7 +243,7 @@ type DeleteFileParams struct {
|
||||
}
|
||||
type DeleteFileResult struct{}
|
||||
|
||||
func (oper *Operator) DeleteFile(ctx context.Context, param *DeleteFileParams) (int, *DeleteFileResult, error) {
|
||||
func (oper *Operator) DeleteFile(ctx context.Context, operID string, param *DeleteFileParams) (int, *DeleteFileResult, error) {
|
||||
var err error
|
||||
res := &DeleteFileResult{}
|
||||
code := http.StatusOK
|
||||
@@ -262,7 +285,7 @@ type ListFilesResult struct {
|
||||
//Catalogs []string `json:"files,omitempty"`
|
||||
}
|
||||
|
||||
func (oper *Operator) ListFiles(ctx context.Context, param *ListFilesParams) (int, *ListFilesResult, error) {
|
||||
func (oper *Operator) ListFiles(ctx context.Context, operID string, param *ListFilesParams) (int, *ListFilesResult, error) {
|
||||
var err error
|
||||
res := &ListFilesResult{
|
||||
Files: make([]descr.File, 0),
|
||||
|
||||
+48
-9
@@ -9,6 +9,7 @@ import (
|
||||
"mstore/pkg/auxuuid"
|
||||
)
|
||||
|
||||
// CreateGrant
|
||||
type CreateGrantParams struct {
|
||||
AccountID string `json:"accountID"`
|
||||
Right string `json:"operation"`
|
||||
@@ -18,7 +19,7 @@ type CreateGrantResult struct {
|
||||
GrantID string `json:"grantId"`
|
||||
}
|
||||
|
||||
func (oper *Operator) CreateGrant(ctx context.Context, params *CreateGrantParams) (*CreateGrantResult, error) {
|
||||
func (oper *Operator) CreateGrant(ctx context.Context, operID string, params *CreateGrantParams) (*CreateGrantResult, error) {
|
||||
var err error
|
||||
res := &CreateGrantResult{}
|
||||
|
||||
@@ -40,9 +41,10 @@ func (oper *Operator) CreateGrant(ctx context.Context, params *CreateGrantParams
|
||||
return res, err
|
||||
}
|
||||
if grantExists {
|
||||
err := fmt.Errorf("Grant with this parapeters already exists")
|
||||
err := fmt.Errorf("Grant with this right already exists")
|
||||
return res, err
|
||||
}
|
||||
oper.logg.Debugf("Call CreateGrant")
|
||||
now := auxtool.TimeNow()
|
||||
grantDescr := &descr.Grant{
|
||||
ID: auxuuid.NewUUID(),
|
||||
@@ -51,6 +53,8 @@ func (oper *Operator) CreateGrant(ctx context.Context, params *CreateGrantParams
|
||||
Pattern: params.Pattern,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
CreatedBy: operID,
|
||||
UpdatedBy: operID,
|
||||
}
|
||||
err = oper.mdb.InsertGrant(ctx, grantDescr)
|
||||
if err != nil {
|
||||
@@ -60,16 +64,21 @@ func (oper *Operator) CreateGrant(ctx context.Context, params *CreateGrantParams
|
||||
return res, err
|
||||
}
|
||||
|
||||
// UpdateGrant
|
||||
type UpdateGrantParams struct {
|
||||
GrantID string
|
||||
NewPattern string
|
||||
}
|
||||
type UpdateGrantResult struct{}
|
||||
|
||||
func (oper *Operator) UpdateGrant(ctx context.Context, params *UpdateGrantParams) (*UpdateGrantResult, error) {
|
||||
func (oper *Operator) UpdateGrant(ctx context.Context, operID string, params *UpdateGrantParams) (*UpdateGrantResult, error) {
|
||||
var err error
|
||||
res := &UpdateGrantResult{}
|
||||
|
||||
if params.NewPattern == "" {
|
||||
err := fmt.Errorf("Empty newPattern parameter")
|
||||
return res, err
|
||||
}
|
||||
if params.GrantID == "" {
|
||||
err := fmt.Errorf("Empty grantId parameter")
|
||||
return res, err
|
||||
@@ -88,6 +97,7 @@ func (oper *Operator) UpdateGrant(ctx context.Context, params *UpdateGrantParams
|
||||
now := auxtool.TimeNow()
|
||||
if params.NewPattern != "" {
|
||||
grantDescr.UpdatedAt = now
|
||||
grantDescr.UpdatedBy = operID
|
||||
grantDescr.Pattern = params.NewPattern
|
||||
}
|
||||
err = oper.mdb.UpdateGrantByID(ctx, grantDescr.ID, grantDescr)
|
||||
@@ -97,12 +107,13 @@ func (oper *Operator) UpdateGrant(ctx context.Context, params *UpdateGrantParams
|
||||
return res, err
|
||||
}
|
||||
|
||||
// DeleteGrant
|
||||
type DeleteGrantParams struct {
|
||||
GrantID string `json:"grantId"`
|
||||
}
|
||||
type DeleteGrantResult struct{}
|
||||
|
||||
func (oper *Operator) DeleteGrant(ctx context.Context, params *DeleteGrantParams) (*DeleteGrantResult, error) {
|
||||
func (oper *Operator) DeleteGrant(ctx context.Context, operID string, params *DeleteGrantParams) (*DeleteGrantResult, error) {
|
||||
var err error
|
||||
res := &DeleteGrantResult{}
|
||||
|
||||
@@ -129,20 +140,47 @@ func (oper *Operator) DeleteGrant(ctx context.Context, params *DeleteGrantParams
|
||||
return res, err
|
||||
}
|
||||
|
||||
// ListGrants
|
||||
type ListGrantsParams struct {
|
||||
AccountID string `json:"accountId"`
|
||||
Username string
|
||||
AccountID string
|
||||
}
|
||||
type ListGrantsResult struct {
|
||||
Grants []descr.Grant `json:"grants"`
|
||||
}
|
||||
|
||||
func (oper *Operator) ListGrants(ctx context.Context, params *ListGrantsParams) (*ListGrantsResult, error) {
|
||||
func (oper *Operator) ListGrants(ctx context.Context, operID string, params *ListGrantsParams) (*ListGrantsResult, error) {
|
||||
var err error
|
||||
res := &ListGrantsResult{
|
||||
Grants: make([]descr.Grant, 0),
|
||||
}
|
||||
|
||||
grantDescrs, err := oper.mdb.ListGrantsByAccountID(ctx, params.AccountID)
|
||||
var accountDescr *descr.Account
|
||||
var accountExists bool
|
||||
switch {
|
||||
case params.AccountID != "":
|
||||
accountExists, accountDescr, err = oper.mdb.GetAccountByID(ctx, params.AccountID)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
if !accountExists {
|
||||
err := fmt.Errorf("Account with ID %s dont exists", params.AccountID)
|
||||
return res, err
|
||||
}
|
||||
case params.Username != "":
|
||||
accountExists, accountDescr, err = oper.mdb.GetAccountByUsername(ctx, params.Username)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
if !accountExists {
|
||||
err := fmt.Errorf("Account with name %s dont exists", params.Username)
|
||||
return res, err
|
||||
}
|
||||
default:
|
||||
err := fmt.Errorf("Empty username and accountId parameter")
|
||||
return res, err
|
||||
}
|
||||
accountID := accountDescr.ID
|
||||
grantDescrs, err := oper.mdb.ListGrantsByAccountID(ctx, accountID)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -150,6 +188,7 @@ func (oper *Operator) ListGrants(ctx context.Context, params *ListGrantsParams)
|
||||
return res, err
|
||||
}
|
||||
|
||||
// Get Grants
|
||||
type GetGrantParams struct {
|
||||
GrantID string `json:"grantId"`
|
||||
}
|
||||
@@ -157,7 +196,7 @@ type GetGrantResult struct {
|
||||
Grant *descr.Grant `json:"grant"`
|
||||
}
|
||||
|
||||
func (oper *Operator) GetGrant(ctx context.Context, params *GetGrantParams) (*GetGrantResult, error) {
|
||||
func (oper *Operator) GetGrant(ctx context.Context, operID string, params *GetGrantParams) (*GetGrantResult, error) {
|
||||
var err error
|
||||
res := &GetGrantResult{}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user