uuid used

This commit is contained in:
2026-02-20 15:06:15 +02:00
parent 35e83ed705
commit 8546ad496f
31 changed files with 265 additions and 238 deletions
+3 -2
View File
@@ -34,7 +34,6 @@ EXTRA_mstored_SOURCES = \
pkg/descr/file.go \ pkg/descr/file.go \
pkg/descr/grant.go \ pkg/descr/grant.go \
pkg/descr/manifest.go \ pkg/descr/manifest.go \
pkg/descr/response.go \
pkg/descr/server.go \ pkg/descr/server.go \
\ \
app/handler/aaafunc.go \ app/handler/aaafunc.go \
@@ -107,6 +106,7 @@ EXTRA_mstored_SOURCES = \
pkg/client/service.go pkg/client/service.go
EXTRA_DIST = vendor/ \ EXTRA_DIST = vendor/ \
\
Containerfile \ Containerfile \
go.mod \ go.mod \
go.sum \ go.sum \
@@ -171,7 +171,8 @@ EXTRA_DIST = vendor/ \
format: format:
@dirs=$$($(FIND) $(CWD) -name '*.go' | $(XARGS) -n1 dirname | $(SORT) | $(UNIQ)); \ @dirs=$$($(FIND) $(CWD)/app $(CWD)/cmd $(CWD)/pkg $(CWD)/test \
-name '*.go' | $(XARGS) -n1 dirname | $(SORT) | $(UNIQ)); \
for dir in $$dirs;do \ for dir in $$dirs;do \
(echo "====$$dir===="; cd $$dir && $(GO) fmt .); \ (echo "====$$dir===="; cd $$dir && $(GO) fmt .); \
done done
+3 -2
View File
@@ -329,7 +329,6 @@ EXTRA_mstored_SOURCES = \
pkg/descr/file.go \ pkg/descr/file.go \
pkg/descr/grant.go \ pkg/descr/grant.go \
pkg/descr/manifest.go \ pkg/descr/manifest.go \
pkg/descr/response.go \
pkg/descr/server.go \ pkg/descr/server.go \
\ \
app/handler/aaafunc.go \ app/handler/aaafunc.go \
@@ -402,6 +401,7 @@ EXTRA_mstored_SOURCES = \
pkg/client/service.go pkg/client/service.go
EXTRA_DIST = vendor/ \ EXTRA_DIST = vendor/ \
\
Containerfile \ Containerfile \
go.mod \ go.mod \
go.sum \ go.sum \
@@ -987,7 +987,8 @@ run: $(mstored_SOURCES)
cd cmd/mstored && env CGO_ENABLED=1 $(GO) run . -daemon=false cd cmd/mstored && env CGO_ENABLED=1 $(GO) run . -daemon=false
format: format:
@dirs=$$($(FIND) $(CWD) -name '*.go' | $(XARGS) -n1 dirname | $(SORT) | $(UNIQ)); \ @dirs=$$($(FIND) $(CWD)/app $(CWD)/cmd $(CWD)/pkg $(CWD)/test \
-name '*.go' | $(XARGS) -n1 dirname | $(SORT) | $(UNIQ)); \
for dir in $$dirs;do \ for dir in $$dirs;do \
(echo "====$$dir===="; cd $$dir && $(GO) fmt .); \ (echo "====$$dir===="; cd $$dir && $(GO) fmt .); \
done done
+7 -12
View File
@@ -17,6 +17,7 @@ import (
"mstore/app/router" "mstore/app/router"
"mstore/pkg/auxhttp" "mstore/pkg/auxhttp"
"mstore/pkg/auxpwd" "mstore/pkg/auxpwd"
"mstore/pkg/auxuuid"
"mstore/pkg/terms" "mstore/pkg/terms"
) )
@@ -29,40 +30,35 @@ func (hand *Handler) AuthMiddleware(next router.Handler) router.Handler {
var handlerFunc router.HandlerFunc var handlerFunc router.HandlerFunc
handlerFunc = func(rctx *router.Context) { handlerFunc = func(rctx *router.Context) {
//hand.logg.Debugf("Call authorization middleware")
success, accountID, err := hand.CheckAccess(rctx) success, accountID, err := hand.CheckAccess(rctx)
if success { if success {
rctx.SetBool(authTag, true) rctx.SetBool(authTag, true)
rctx.SetString(userTag, accountID) rctx.SetString(userTag, string(accountID))
//hand.logg.Debugf("Authorization for accountID [%s]", rctx.Strings[userTag])
} }
if err != nil { if err != nil {
hand.logg.Errorf("Authorization middleware error: %v", err) hand.logg.Errorf("Authorization middleware error: %v", err)
} }
next.ServeHTTP(rctx) next.ServeHTTP(rctx)
} }
return handlerFunc return handlerFunc
} }
// Authentification // Authentification
func (hand *Handler) CheckAccess(rctx *router.Context) (bool, string, error) { func (hand *Handler) CheckAccess(rctx *router.Context) (bool, auxuuid.UUID, error) {
var err error var err error
var success bool var success bool
var username string var username string
var password string var password string
var accountID string var accountID auxuuid.UUID
accountID = terms.AnonymousID accountID = terms.AnonymousID
authHeader := rctx.GetHeader("Authorization") authHeader := rctx.GetHeader("Authorization")
if authHeader != "" { if authHeader != "" {
//hand.logg.Debugf("Authorization header is %s", authHeader)
username, password, err = auxhttp.ParseBasicAuth(authHeader) username, password, err = auxhttp.ParseBasicAuth(authHeader)
if err != nil { if err != nil {
return success, accountID, err return success, accountID, err
} }
//hand.logg.Debugf("Authorization pair is %s:%s", username, password)
if username == "" || password == "" { if username == "" || password == "" {
goto anonymous goto anonymous
} }
@@ -84,9 +80,9 @@ anonymous:
return success, accountID, err return success, accountID, err
} }
func (hand *Handler) ValidatePassword(ctx context.Context, username, password string) (bool, string, error) { func (hand *Handler) ValidatePassword(ctx context.Context, username, password string) (bool, auxuuid.UUID, error) {
var err error var err error
var accountID string var accountID auxuuid.UUID
valid := false valid := false
accountExists, accountDescr, err := hand.mdb.GetAccountByUsername(ctx, username) accountExists, accountDescr, err := hand.mdb.GetAccountByUsername(ctx, username)
@@ -106,7 +102,7 @@ func (hand *Handler) ValidatePassword(ctx context.Context, username, password st
// Authorization // Authorization
func (hand *Handler) CheckRight(ctx context.Context, accountID, reqRight, subject string) (bool, error) { func (hand *Handler) CheckRight(ctx context.Context, accountID auxuuid.UUID, reqRight, subject string) (bool, error) {
var err error var err error
var res bool var res bool
//hand.logg.Debugf("Cop check your right %s: %s %s", accountID, reqRight, subject) //hand.logg.Debugf("Cop check your right %s: %s %s", accountID, reqRight, subject)
@@ -142,6 +138,5 @@ func (hand *Handler) CheckRight(ctx context.Context, accountID, reqRight, subjec
// NOP // NOP
} }
res = true res = true
//hand.logg.Debugf("Result of checking right %s for %s: %v", reqRight, accountID, res)
return res, err return res, err
} }
+10 -9
View File
@@ -14,6 +14,7 @@ import (
"mstore/app/operator" "mstore/app/operator"
"mstore/app/router" "mstore/app/router"
"mstore/pkg/auxuuid"
"mstore/pkg/terms" "mstore/pkg/terms"
) )
@@ -29,7 +30,7 @@ func (hand *Handler) CreateAccount(rctx *router.Context) {
} }
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightWriteAccounts, "") opEnable, err := hand.CheckRight(rctx.Ctx, auxuuid.UUID(operatorID), terms.RightWriteAccounts, "")
if err != nil { if err != nil {
err := fmt.Errorf("Operation error: %v", err) err := fmt.Errorf("Operation error: %v", err)
hand.SendError(rctx, err) hand.SendError(rctx, err)
@@ -41,7 +42,7 @@ func (hand *Handler) CreateAccount(rctx *router.Context) {
return return
} }
// Execution of the operation // Execution of the operation
res, err := hand.oper.CreateAccount(rctx.Ctx, operatorID, params) res, err := hand.oper.CreateAccount(rctx.Ctx, auxuuid.UUID(operatorID), params)
if err != nil { if err != nil {
hand.logg.Errorf("Operation error: %v", err) hand.logg.Errorf("Operation error: %v", err)
hand.SendError(rctx, err) hand.SendError(rctx, err)
@@ -62,7 +63,7 @@ func (hand *Handler) GetAccount(rctx *router.Context) {
} }
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightWriteAccounts, "") opEnable, err := hand.CheckRight(rctx.Ctx, auxuuid.UUID(operatorID), terms.RightWriteAccounts, "")
if err != nil { if err != nil {
err := fmt.Errorf("Operation error: %v", err) err := fmt.Errorf("Operation error: %v", err)
hand.SendError(rctx, err) hand.SendError(rctx, err)
@@ -74,7 +75,7 @@ func (hand *Handler) GetAccount(rctx *router.Context) {
return return
} }
// Execution of the operation // Execution of the operation
res, err := hand.oper.GetAccount(rctx.Ctx, params) res, err := hand.oper.GetAccount(rctx.Ctx, auxuuid.UUID(operatorID), params)
if err != nil { if err != nil {
hand.logg.Errorf("Operation error: %v", err) hand.logg.Errorf("Operation error: %v", err)
hand.SendError(rctx, err) hand.SendError(rctx, err)
@@ -95,7 +96,7 @@ func (hand *Handler) ListAccounts(rctx *router.Context) {
} }
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightWriteAccounts, "") opEnable, err := hand.CheckRight(rctx.Ctx, auxuuid.UUID(operatorID), terms.RightWriteAccounts, "")
if err != nil { if err != nil {
err := fmt.Errorf("Operation error: %v", err) err := fmt.Errorf("Operation error: %v", err)
hand.SendError(rctx, err) hand.SendError(rctx, err)
@@ -128,7 +129,7 @@ func (hand *Handler) UpdateAccount(rctx *router.Context) {
} }
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightWriteAccounts, "") opEnable, err := hand.CheckRight(rctx.Ctx, auxuuid.UUID(operatorID), terms.RightWriteAccounts, "")
if err != nil { if err != nil {
err := fmt.Errorf("Operation error: %v", err) err := fmt.Errorf("Operation error: %v", err)
hand.SendError(rctx, err) hand.SendError(rctx, err)
@@ -140,7 +141,7 @@ func (hand *Handler) UpdateAccount(rctx *router.Context) {
return return
} }
// Execution of the operation // Execution of the operation
res, err := hand.oper.UpdateAccount(rctx.Ctx, params) res, err := hand.oper.UpdateAccount(rctx.Ctx, auxuuid.UUID(operatorID), params)
if err != nil { if err != nil {
hand.logg.Errorf("UpdateAccount error: %v", err) hand.logg.Errorf("UpdateAccount error: %v", err)
hand.SendError(rctx, err) hand.SendError(rctx, err)
@@ -161,7 +162,7 @@ func (hand *Handler) DeleteAccount(rctx *router.Context) {
} }
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightWriteAccounts, params.Username) opEnable, err := hand.CheckRight(rctx.Ctx, auxuuid.UUID(operatorID), terms.RightWriteAccounts, params.Username)
if err != nil { if err != nil {
err := fmt.Errorf("Operation error: %v", err) err := fmt.Errorf("Operation error: %v", err)
hand.SendError(rctx, err) hand.SendError(rctx, err)
@@ -173,7 +174,7 @@ func (hand *Handler) DeleteAccount(rctx *router.Context) {
return return
} }
// Execution of the operation // Execution of the operation
res, err := hand.oper.DeleteAccount(rctx.Ctx, params) res, err := hand.oper.DeleteAccount(rctx.Ctx, auxuuid.UUID(operatorID), params)
if err != nil { if err != nil {
hand.logg.Errorf("DeleteAccount error: %v", err) hand.logg.Errorf("DeleteAccount error: %v", err)
hand.SendError(rctx, err) hand.SendError(rctx, err)
+8 -7
View File
@@ -16,6 +16,7 @@ import (
"mstore/app/operator" "mstore/app/operator"
"mstore/app/router" "mstore/app/router"
"mstore/pkg/auxuuid"
"mstore/pkg/terms" "mstore/pkg/terms"
) )
@@ -32,7 +33,7 @@ func (hand *Handler) BlobExists(rctx *router.Context) {
} }
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightReadImages, "") opEnable, err := hand.CheckRight(rctx.Ctx, auxuuid.UUID(operatorID), terms.RightReadImages, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
@@ -72,7 +73,7 @@ func (hand *Handler) PostUpload(rctx *router.Context) {
} }
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightWriteImages, "") opEnable, err := hand.CheckRight(rctx.Ctx, auxuuid.UUID(operatorID), terms.RightWriteImages, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
@@ -88,7 +89,7 @@ func (hand *Handler) PostUpload(rctx *router.Context) {
} else { } else {
rctx.SetHeader("Location", res.Location) rctx.SetHeader("Location", res.Location)
rctx.SetHeader("Content-Length", res.ContentLength) rctx.SetHeader("Content-Length", res.ContentLength)
rctx.SetHeader("Docker-Upload-UUID", res.DockerUploadUUID) rctx.SetHeader("Docker-Upload-UUID", string(res.DockerUploadUUID))
} }
rctx.SetStatus(code) rctx.SetStatus(code)
} }
@@ -117,7 +118,7 @@ func (hand *Handler) PatchUpload(rctx *router.Context) {
} }
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightWriteImages, "") opEnable, err := hand.CheckRight(rctx.Ctx, auxuuid.UUID(operatorID), terms.RightWriteImages, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
@@ -161,7 +162,7 @@ func (hand *Handler) PutUpload(rctx *router.Context) {
} }
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightWriteImages, "") opEnable, err := hand.CheckRight(rctx.Ctx, auxuuid.UUID(operatorID), terms.RightWriteImages, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
@@ -191,7 +192,7 @@ func (hand *Handler) GetBlob(rctx *router.Context) {
} }
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightReadImages, "") opEnable, err := hand.CheckRight(rctx.Ctx, auxuuid.UUID(operatorID), terms.RightReadImages, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
@@ -237,7 +238,7 @@ func (hand *Handler) DeleteBlob(rctx *router.Context) {
} }
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightWriteImages, "") opEnable, err := hand.CheckRight(rctx.Ctx, auxuuid.UUID(operatorID), terms.RightWriteImages, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
+19 -18
View File
@@ -15,6 +15,7 @@ import (
"mstore/app/operator" "mstore/app/operator"
"mstore/app/router" "mstore/app/router"
"mstore/pkg/auxuuid"
"mstore/pkg/terms" "mstore/pkg/terms"
) )
@@ -28,7 +29,7 @@ func (hand *Handler) FileInfo(rctx *router.Context) {
} }
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightReadFiles, "") opEnable, err := hand.CheckRight(rctx.Ctx, auxuuid.UUID(operatorID), terms.RightReadFiles, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
@@ -39,7 +40,7 @@ func (hand *Handler) FileInfo(rctx *router.Context) {
} }
// Execution of the operation // Execution of the operation
ctx := rctx.GetContext() ctx := rctx.GetContext()
code, res, err := hand.oper.FileInfo(ctx, operatorID, params) code, res, err := hand.oper.FileInfo(ctx, auxuuid.UUID(operatorID), params)
if err != nil { if err != nil {
hand.logg.Errorf("FileInfo error: %v", err) hand.logg.Errorf("FileInfo error: %v", err)
rctx.SetStatus(code) rctx.SetStatus(code)
@@ -52,9 +53,9 @@ func (hand *Handler) FileInfo(rctx *router.Context) {
rctx.SetHeader("Content-Digest", res.ContentDigest) rctx.SetHeader("Content-Digest", res.ContentDigest)
rctx.SetHeader("Content-CreatedAt", res.ContentCreatedAt) rctx.SetHeader("Content-CreatedAt", res.ContentCreatedAt)
rctx.SetHeader("Content-CreatedBy", res.ContentCreatedBy) rctx.SetHeader("Content-CreatedBy", string(res.ContentCreatedBy))
rctx.SetHeader("Content-UpdatedAt", res.ContentUpdatedAt) rctx.SetHeader("Content-UpdatedAt", res.ContentUpdatedAt)
rctx.SetHeader("Content-UpdatedBy", res.ContentUpdatedBy) rctx.SetHeader("Content-UpdatedBy", string(res.ContentUpdatedBy))
rctx.SetHeader("Content-Length", zeroContentLength) rctx.SetHeader("Content-Length", zeroContentLength)
rctx.SetStatus(code) rctx.SetStatus(code)
@@ -73,7 +74,7 @@ func (hand *Handler) PutFile(rctx *router.Context) {
} }
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightWriteFiles, "") opEnable, err := hand.CheckRight(rctx.Ctx, auxuuid.UUID(operatorID), terms.RightWriteFiles, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
@@ -84,7 +85,7 @@ func (hand *Handler) PutFile(rctx *router.Context) {
} }
// Execution of the operation // Execution of the operation
ctx := rctx.GetContext() ctx := rctx.GetContext()
code, _, err := hand.oper.PutFile(ctx, operatorID, params) code, _, err := hand.oper.PutFile(ctx, auxuuid.UUID(operatorID), params)
if err != nil { if err != nil {
hand.logg.Errorf("PutFile error: %v", err) hand.logg.Errorf("PutFile error: %v", err)
rctx.SetStatus(code) rctx.SetStatus(code)
@@ -101,7 +102,7 @@ func (hand *Handler) GetFile(rctx *router.Context) {
} }
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightReadFiles, "") opEnable, err := hand.CheckRight(rctx.Ctx, auxuuid.UUID(operatorID), terms.RightReadFiles, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
@@ -112,7 +113,7 @@ func (hand *Handler) GetFile(rctx *router.Context) {
} }
// Execution of the operation // Execution of the operation
ctx := rctx.GetContext() ctx := rctx.GetContext()
code, res, err := hand.oper.GetFile(ctx, operatorID, params) code, res, err := hand.oper.GetFile(ctx, auxuuid.UUID(operatorID), params)
if err != nil { if err != nil {
hand.logg.Errorf("PutFile error: %v", err) hand.logg.Errorf("PutFile error: %v", err)
rctx.SetStatus(code) rctx.SetStatus(code)
@@ -125,9 +126,9 @@ func (hand *Handler) GetFile(rctx *router.Context) {
rctx.SetHeader("Content-Length", res.ContentSize) rctx.SetHeader("Content-Length", res.ContentSize)
rctx.SetHeader("Content-CreatedAt", res.ContentCreatedAt) rctx.SetHeader("Content-CreatedAt", res.ContentCreatedAt)
rctx.SetHeader("Content-CreatedBy", res.ContentCreatedBy) rctx.SetHeader("Content-CreatedBy", string(res.ContentCreatedBy))
rctx.SetHeader("Content-UpdatedAt", res.ContentUpdatedAt) rctx.SetHeader("Content-UpdatedAt", res.ContentUpdatedAt)
rctx.SetHeader("Content-UpdatedBy", res.ContentUpdatedBy) rctx.SetHeader("Content-UpdatedBy", string(res.ContentUpdatedBy))
rctx.SetStatus(code) rctx.SetStatus(code)
@@ -149,7 +150,7 @@ func (hand *Handler) DeleteFile(rctx *router.Context) {
} }
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightWriteFiles, "") opEnable, err := hand.CheckRight(rctx.Ctx, auxuuid.UUID(operatorID), terms.RightWriteFiles, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
@@ -160,7 +161,7 @@ func (hand *Handler) DeleteFile(rctx *router.Context) {
} }
// Execution of the operation // Execution of the operation
ctx := rctx.GetContext() ctx := rctx.GetContext()
code, _, err := hand.oper.DeleteFile(ctx, operatorID, params) code, _, err := hand.oper.DeleteFile(ctx, auxuuid.UUID(operatorID), params)
if err != nil { if err != nil {
hand.logg.Errorf("DeleteFIle error: %v", err) hand.logg.Errorf("DeleteFIle error: %v", err)
} }
@@ -186,7 +187,7 @@ func (hand *Handler) ListFiles(rctx *router.Context) {
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightReadFiles, "") opEnable, err := hand.CheckRight(rctx.Ctx, auxuuid.UUID(operatorID), terms.RightReadFiles, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
@@ -197,7 +198,7 @@ func (hand *Handler) ListFiles(rctx *router.Context) {
} }
// Execution of the operation // Execution of the operation
ctx := rctx.GetContext() ctx := rctx.GetContext()
code, res, err := hand.oper.ListFiles(ctx, operatorID, params) code, res, err := hand.oper.ListFiles(ctx, auxuuid.UUID(operatorID), params)
if err != nil { if err != nil {
hand.logg.Errorf("ListFiles error: %v", err) hand.logg.Errorf("ListFiles error: %v", err)
rctx.SetStatus(code) rctx.SetStatus(code)
@@ -223,7 +224,7 @@ func (hand *Handler) ListCollections(rctx *router.Context) {
} }
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightReadFiles, "") opEnable, err := hand.CheckRight(rctx.Ctx, auxuuid.UUID(operatorID), terms.RightReadFiles, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
@@ -234,7 +235,7 @@ func (hand *Handler) ListCollections(rctx *router.Context) {
} }
// Execution of the operation // Execution of the operation
ctx := rctx.GetContext() ctx := rctx.GetContext()
code, res, err := hand.oper.ListCollections(ctx, operatorID, params) code, res, err := hand.oper.ListCollections(ctx, auxuuid.UUID(operatorID), params)
if err != nil { if err != nil {
hand.logg.Errorf("ListCollections error: %v", err) hand.logg.Errorf("ListCollections error: %v", err)
rctx.SetStatus(code) rctx.SetStatus(code)
@@ -261,7 +262,7 @@ func (hand *Handler) DeleteCollection(rctx *router.Context) {
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightReadFiles, "") opEnable, err := hand.CheckRight(rctx.Ctx, auxuuid.UUID(operatorID), terms.RightReadFiles, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
@@ -272,7 +273,7 @@ func (hand *Handler) DeleteCollection(rctx *router.Context) {
} }
// Execution of the operation // Execution of the operation
ctx := rctx.GetContext() ctx := rctx.GetContext()
code, res, err := hand.oper.DeleteColletion(ctx, operatorID, params) code, res, err := hand.oper.DeleteColletion(ctx, auxuuid.UUID(operatorID), params)
if err != nil { if err != nil {
hand.logg.Errorf("DeleteColletion error: %v", err) hand.logg.Errorf("DeleteColletion error: %v", err)
rctx.SetStatus(code) rctx.SetStatus(code)
+11 -10
View File
@@ -14,6 +14,7 @@ import (
"mstore/app/operator" "mstore/app/operator"
"mstore/app/router" "mstore/app/router"
"mstore/pkg/auxuuid"
"mstore/pkg/terms" "mstore/pkg/terms"
) )
@@ -29,7 +30,7 @@ func (hand *Handler) CreateGrant(rctx *router.Context) {
} }
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightWriteAccounts, "") opEnable, err := hand.CheckRight(rctx.Ctx, auxuuid.UUID(operatorID), terms.RightWriteAccounts, "")
if err != nil { if err != nil {
err := fmt.Errorf("Operation error: %v", err) err := fmt.Errorf("Operation error: %v", err)
hand.SendError(rctx, err) hand.SendError(rctx, err)
@@ -41,7 +42,7 @@ func (hand *Handler) CreateGrant(rctx *router.Context) {
return return
} }
// Execution of the operation // Execution of the operation
res, err := hand.oper.CreateGrant(rctx.Ctx, operatorID, params) res, err := hand.oper.CreateGrant(rctx.Ctx, auxuuid.UUID(operatorID), params)
if err != nil { if err != nil {
hand.logg.Errorf("CreateGrant error: %v", err) hand.logg.Errorf("CreateGrant error: %v", err)
hand.SendError(rctx, err) hand.SendError(rctx, err)
@@ -62,7 +63,7 @@ func (hand *Handler) GetGrant(rctx *router.Context) {
} }
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightReadAccounts, "") opEnable, err := hand.CheckRight(rctx.Ctx, auxuuid.UUID(operatorID), terms.RightReadAccounts, "")
if err != nil { if err != nil {
err := fmt.Errorf("Operation error: %v", err) err := fmt.Errorf("Operation error: %v", err)
hand.SendError(rctx, err) hand.SendError(rctx, err)
@@ -74,7 +75,7 @@ func (hand *Handler) GetGrant(rctx *router.Context) {
return return
} }
// Execution of the operation // Execution of the operation
res, err := hand.oper.GetGrant(rctx.Ctx, operatorID, params) res, err := hand.oper.GetGrant(rctx.Ctx, auxuuid.UUID(operatorID), params)
if err != nil { if err != nil {
hand.logg.Errorf("CreateGrant error: %v", err) hand.logg.Errorf("CreateGrant error: %v", err)
hand.SendError(rctx, err) hand.SendError(rctx, err)
@@ -95,7 +96,7 @@ func (hand *Handler) ListGrants(rctx *router.Context) {
} }
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightReadAccounts, "") opEnable, err := hand.CheckRight(rctx.Ctx, auxuuid.UUID(operatorID), terms.RightReadAccounts, "")
if err != nil { if err != nil {
err := fmt.Errorf("Operation error: %v", err) err := fmt.Errorf("Operation error: %v", err)
hand.SendError(rctx, err) hand.SendError(rctx, err)
@@ -107,7 +108,7 @@ func (hand *Handler) ListGrants(rctx *router.Context) {
return return
} }
// Execution of the operation // Execution of the operation
res, err := hand.oper.ListGrants(rctx.Ctx, operatorID, params) res, err := hand.oper.ListGrants(rctx.Ctx, auxuuid.UUID(operatorID), params)
if err != nil { if err != nil {
hand.logg.Errorf("ListGrants error: %v", err) hand.logg.Errorf("ListGrants error: %v", err)
hand.SendError(rctx, err) hand.SendError(rctx, err)
@@ -128,7 +129,7 @@ func (hand *Handler) UpdateGrant(rctx *router.Context) {
} }
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightWriteAccounts, "") opEnable, err := hand.CheckRight(rctx.Ctx, auxuuid.UUID(operatorID), terms.RightWriteAccounts, "")
if err != nil { if err != nil {
err := fmt.Errorf("Operation error: %v", err) err := fmt.Errorf("Operation error: %v", err)
hand.SendError(rctx, err) hand.SendError(rctx, err)
@@ -140,7 +141,7 @@ func (hand *Handler) UpdateGrant(rctx *router.Context) {
return return
} }
// Execution of the operation // Execution of the operation
res, err := hand.oper.UpdateGrant(rctx.Ctx, operatorID, params) res, err := hand.oper.UpdateGrant(rctx.Ctx, auxuuid.UUID(operatorID), params)
if err != nil { if err != nil {
hand.logg.Errorf("UpdateGrant error: %v", err) hand.logg.Errorf("UpdateGrant error: %v", err)
hand.SendError(rctx, err) hand.SendError(rctx, err)
@@ -161,7 +162,7 @@ func (hand *Handler) DeleteGrant(rctx *router.Context) {
} }
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightWriteAccounts, "") opEnable, err := hand.CheckRight(rctx.Ctx, auxuuid.UUID(operatorID), terms.RightWriteAccounts, "")
if err != nil { if err != nil {
err := fmt.Errorf("Operation error: %v", err) err := fmt.Errorf("Operation error: %v", err)
hand.SendError(rctx, err) hand.SendError(rctx, err)
@@ -173,7 +174,7 @@ func (hand *Handler) DeleteGrant(rctx *router.Context) {
return return
} }
// Execution of the operation // Execution of the operation
res, err := hand.oper.DeleteGrant(rctx.Ctx, operatorID, params) res, err := hand.oper.DeleteGrant(rctx.Ctx, auxuuid.UUID(operatorID), params)
if err != nil { if err != nil {
hand.logg.Errorf("DeleteGrant error: %v", err) hand.logg.Errorf("DeleteGrant error: %v", err)
hand.SendError(rctx, err) hand.SendError(rctx, err)
+7 -6
View File
@@ -14,6 +14,7 @@ import (
"mstore/app/operator" "mstore/app/operator"
"mstore/app/router" "mstore/app/router"
"mstore/pkg/auxuuid"
"mstore/pkg/terms" "mstore/pkg/terms"
) )
@@ -29,7 +30,7 @@ func (hand *Handler) ManifestExists(rctx *router.Context) {
} }
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightReadImages, "") opEnable, err := hand.CheckRight(rctx.Ctx, auxuuid.UUID(operatorID), terms.RightReadImages, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
@@ -71,7 +72,7 @@ func (hand *Handler) PutManifest(rctx *router.Context) {
} }
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightWriteImages, "") opEnable, err := hand.CheckRight(rctx.Ctx, auxuuid.UUID(operatorID), terms.RightWriteImages, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
@@ -104,7 +105,7 @@ func (hand *Handler) GetManifest(rctx *router.Context) {
} }
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightReadImages, "") opEnable, err := hand.CheckRight(rctx.Ctx, auxuuid.UUID(operatorID), terms.RightReadImages, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
@@ -144,7 +145,7 @@ func (hand *Handler) DeleteManifest(rctx *router.Context) {
} }
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightWriteImages, "") opEnable, err := hand.CheckRight(rctx.Ctx, auxuuid.UUID(operatorID), terms.RightWriteImages, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
@@ -173,7 +174,7 @@ func (hand *Handler) GetReferer(rctx *router.Context) {
} }
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightReadImages, "") opEnable, err := hand.CheckRight(rctx.Ctx, auxuuid.UUID(operatorID), terms.RightReadImages, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
@@ -199,7 +200,7 @@ func (hand *Handler) GetTags(rctx *router.Context) {
} }
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightReadImages, "") opEnable, err := hand.CheckRight(rctx.Ctx, auxuuid.UUID(operatorID), terms.RightReadImages, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
+4 -3
View File
@@ -3,6 +3,7 @@ package maindb
import ( import (
"context" "context"
"mstore/pkg/auxuuid"
"mstore/pkg/descr" "mstore/pkg/descr"
) )
@@ -19,7 +20,7 @@ func (db *Database) InsertAccount(ctx context.Context, account *descr.Account) e
return err return err
} }
func (db *Database) UpdateAccountByID(ctx context.Context, accountID string, account *descr.Account) error { func (db *Database) UpdateAccountByID(ctx context.Context, accountID auxuuid.UUID, account *descr.Account) error {
var err error var err error
request := `UPDATE accounts SET username = $1, passhash = $2, disabled = $3, updated_at = $4, updated_by = $5 WHERE id = $6` request := `UPDATE accounts SET username = $1, passhash = $2, disabled = $3, updated_at = $4, updated_by = $5 WHERE id = $6`
_, err = db.db.Exec(request, account.Username, account.Passhash, account.Disabled, account.UpdatedAt, account.UpdatedBy, accountID) _, err = db.db.Exec(request, account.Username, account.Passhash, account.Disabled, account.UpdatedAt, account.UpdatedBy, accountID)
@@ -51,7 +52,7 @@ func (db *Database) ListAccounts(ctx context.Context) ([]descr.Account, error) {
return res, err return res, err
} }
func (db *Database) GetAccountByID(ctx context.Context, accountID string) (bool, *descr.Account, error) { func (db *Database) GetAccountByID(ctx context.Context, accountID auxuuid.UUID) (bool, *descr.Account, error) {
var err error var err error
var res *descr.Account var res *descr.Account
var exists bool = false var exists bool = false
@@ -90,7 +91,7 @@ func (db *Database) GetAccountByUsername(ctx context.Context, username string) (
return exists, res, err return exists, res, err
} }
func (db *Database) DeleteAccountByID(ctx context.Context, accountID string) error { func (db *Database) DeleteAccountByID(ctx context.Context, accountID auxuuid.UUID) error {
var err error var err error
request := `DELETE FROM accounts WHERE id = $1` request := `DELETE FROM accounts WHERE id = $1`
+2 -1
View File
@@ -12,6 +12,7 @@ package maindb
import ( import (
"context" "context"
"mstore/pkg/auxuuid"
"mstore/pkg/descr" "mstore/pkg/descr"
) )
@@ -27,7 +28,7 @@ func (db *Database) InsertFile(ctx context.Context, file *descr.File) error {
return err return err
} }
func (db *Database) UpdateFileByID(ctx context.Context, fileID string, file *descr.File) error { func (db *Database) UpdateFileByID(ctx context.Context, fileID auxuuid.UUID, file *descr.File) error {
var err error var err error
request := `UPDATE files SET id = $1, collection = $2, name = $3, type = $4, checksum = $5, request := `UPDATE files SET id = $1, collection = $2, name = $3, type = $4, checksum = $5,
size = $6, updated_at = $7, created_by = $8, updated_by = $9 size = $6, updated_at = $7, created_by = $8, updated_by = $9
+1 -1
View File
@@ -35,7 +35,7 @@ func TestFile(t *testing.T) {
id := auxuuid.NewUUID() id := auxuuid.NewUUID()
timenow := auxtool.TimeNow() timenow := auxtool.TimeNow()
creator := "some" creator := auxuuid.NewUUID()
collection := "foo" collection := "foo"
newFile := &descr.File{ newFile := &descr.File{
ID: id, ID: id,
+10 -9
View File
@@ -12,6 +12,7 @@ package maindb
import ( import (
"context" "context"
"mstore/pkg/auxuuid"
"mstore/pkg/descr" "mstore/pkg/descr"
) )
@@ -27,7 +28,7 @@ func (db *Database) InsertGrant(ctx context.Context, grant *descr.Grant) error {
return err return err
} }
func (db *Database) UpdateGrantByID(ctx context.Context, grantID string, grant *descr.Grant) error { func (db *Database) UpdateGrantByID(ctx context.Context, grantID auxuuid.UUID, grant *descr.Grant) error {
var err error var err error
request := `UPDATE grants SET pattern = $1, updated_at = $2, updated_by = $3 WHERE id = $4` request := `UPDATE grants SET pattern = $1, updated_at = $2, updated_by = $3 WHERE id = $4`
_, err = db.db.Exec(request, grant.Pattern, grant.UpdatedAt, grant.UpdatedBy, grantID) _, err = db.db.Exec(request, grant.Pattern, grant.UpdatedAt, grant.UpdatedBy, grantID)
@@ -37,7 +38,7 @@ func (db *Database) UpdateGrantByID(ctx context.Context, grantID string, grant *
return err return err
} }
func (db *Database) ListGrantsByAccountID(ctx context.Context, accountID string) ([]descr.Grant, error) { func (db *Database) ListGrantsByAccountID(ctx context.Context, accountID auxuuid.UUID) ([]descr.Grant, error) {
var err error var err error
request := `SELECT * FROM grants WHERE account_id = $1` request := `SELECT * FROM grants WHERE account_id = $1`
res := make([]descr.Grant, 0) res := make([]descr.Grant, 0)
@@ -59,7 +60,7 @@ func (db *Database) ListGrants(ctx context.Context) ([]descr.Grant, error) {
return res, err return res, err
} }
func (db *Database) GetGrantByID(ctx context.Context, id string) (bool, *descr.Grant, error) { func (db *Database) GetGrantByID(ctx context.Context, id auxuuid.UUID) (bool, *descr.Grant, error) {
var err error var err error
res := &descr.Grant{} res := &descr.Grant{}
request := `SELECT * FROM grants WHERE id = $1 LIMIT 1` request := `SELECT * FROM grants WHERE id = $1 LIMIT 1`
@@ -76,7 +77,7 @@ func (db *Database) GetGrantByID(ctx context.Context, id string) (bool, *descr.G
return true, res, err return true, res, err
} }
func (db *Database) GetGrantByAccoundIDRight(ctx context.Context, accountID, right string) (bool, *descr.Grant, error) { func (db *Database) GetGrantByAccoundIDRight(ctx context.Context, accountID auxuuid.UUID, right string) (bool, *descr.Grant, error) {
var err error var err error
res := &descr.Grant{} res := &descr.Grant{}
request := `SELECT * FROM grants WHERE account_id = $1 AND right = $2 LIMIT 1` request := `SELECT * FROM grants WHERE account_id = $1 AND right = $2 LIMIT 1`
@@ -93,7 +94,7 @@ func (db *Database) GetGrantByAccoundIDRight(ctx context.Context, accountID, rig
return true, res, err return true, res, err
} }
func (db *Database) ListGrantsByAccoundIDRight(ctx context.Context, accountID, right string) (bool, []descr.Grant, error) { func (db *Database) ListGrantsByAccoundIDRight(ctx context.Context, accountID auxuuid.UUID, right string) (bool, []descr.Grant, error) {
var err error var err error
request := `SELECT * FROM grants WHERE account_id = $1 AND right = $2` request := `SELECT * FROM grants WHERE account_id = $1 AND right = $2`
res := make([]descr.Grant, 0) res := make([]descr.Grant, 0)
@@ -107,7 +108,7 @@ func (db *Database) ListGrantsByAccoundIDRight(ctx context.Context, accountID, r
return true, res, err return true, res, err
} }
func (db *Database) GetGrantByAccoundIDRightPattern(ctx context.Context, accountID, right, pattern string) (bool, *descr.Grant, error) { func (db *Database) GetGrantByAccoundIDRightPattern(ctx context.Context, accountID auxuuid.UUID, right, pattern string) (bool, *descr.Grant, error) {
var err error var err error
res := &descr.Grant{} res := &descr.Grant{}
request := `SELECT * FROM grants WHERE account_id = $1 AND right = $2 AND pattern = $3 LIMIT 1` request := `SELECT * FROM grants WHERE account_id = $1 AND right = $2 AND pattern = $3 LIMIT 1`
@@ -124,7 +125,7 @@ func (db *Database) GetGrantByAccoundIDRightPattern(ctx context.Context, account
return true, res, err return true, res, err
} }
func (db *Database) DeleteGrantByAccountIDRightPattern(ctx context.Context, accountID, right, pattern string) error { func (db *Database) DeleteGrantByAccountIDRightPattern(ctx context.Context, accountID auxuuid.UUID, right, pattern string) error {
var err error var err error
request := `DELETE FROM grants WHERE account_id = $1 AND right = $2 AND pattern = $3` request := `DELETE FROM grants WHERE account_id = $1 AND right = $2 AND pattern = $3`
_, err = db.db.Exec(request, accountID, right, pattern) _, err = db.db.Exec(request, accountID, right, pattern)
@@ -134,7 +135,7 @@ func (db *Database) DeleteGrantByAccountIDRightPattern(ctx context.Context, acco
return err return err
} }
func (db *Database) DeleteGrantByID(ctx context.Context, grantID string) error { func (db *Database) DeleteGrantByID(ctx context.Context, grantID auxuuid.UUID) error {
var err error var err error
request := `DELETE FROM grants WHERE id = $1` request := `DELETE FROM grants WHERE id = $1`
_, err = db.db.Exec(request, grantID) _, err = db.db.Exec(request, grantID)
@@ -144,7 +145,7 @@ func (db *Database) DeleteGrantByID(ctx context.Context, grantID string) error {
return err return err
} }
func (db *Database) DeleteAllGrantsForAccountID(ctx context.Context, grantID string) error { func (db *Database) DeleteAllGrantsForAccountID(ctx context.Context, grantID auxuuid.UUID) error {
var err error var err error
request := `DELETE FROM grants WHERE account_id = $1` request := `DELETE FROM grants WHERE account_id = $1`
_, err = db.db.Exec(request, grantID) _, err = db.db.Exec(request, grantID)
+5 -1
View File
@@ -11,6 +11,7 @@ package maindb
import ( import (
"context" "context"
"fmt"
"testing" "testing"
"time" "time"
@@ -36,7 +37,7 @@ func TestGrant(t *testing.T) {
id := auxuuid.NewUUID() id := auxuuid.NewUUID()
accountID := auxuuid.NewUUID() accountID := auxuuid.NewUUID()
timenow := auxtool.TimeNow() timenow := auxtool.TimeNow()
creator := "some" creator := auxuuid.NewUUID()
newGrant := &descr.Grant{ newGrant := &descr.Grant{
ID: id, ID: id,
AccountID: accountID, AccountID: accountID,
@@ -57,4 +58,7 @@ func TestGrant(t *testing.T) {
require.Equal(t, len(files), 1) require.Equal(t, len(files), 1)
require.Equal(t, files[0].ID, id) require.Equal(t, files[0].ID, id)
require.Equal(t, files[0].AccountID, accountID) require.Equal(t, files[0].AccountID, accountID)
require.Equal(t, files[0].CreatedBy, creator)
fmt.Println(files[0].CreatedBy)
} }
+14 -14
View File
@@ -15,10 +15,10 @@ type CreateAccountParams struct {
Password string `json:"password"` Password string `json:"password"`
} }
type CreateAccountResult struct { type CreateAccountResult struct {
AccountID string `json:"accountId"` AccountID auxuuid.UUID `json:"accountId"`
} }
func (oper *Operator) CreateAccount(ctx context.Context, operatorID string, params *CreateAccountParams) (*CreateAccountResult, error) { func (oper *Operator) CreateAccount(ctx context.Context, operatorID auxuuid.UUID, params *CreateAccountParams) (*CreateAccountResult, error) {
var err error var err error
res := &CreateAccountResult{} res := &CreateAccountResult{}
@@ -62,14 +62,14 @@ func (oper *Operator) CreateAccount(ctx context.Context, operatorID string, para
// GetAccount // GetAccount
type GetAccountParams struct { type GetAccountParams struct {
Username string `json:"username"` Username string `json:"username"`
AccountID string `json:"accountId"` AccountID auxuuid.UUID `json:"accountId"`
} }
type GetAccountResult struct { type GetAccountResult struct {
Account *descr.AccountShort `json:"account"` Account *descr.AccountShort `json:"account"`
} }
func (oper *Operator) GetAccount(ctx context.Context, params *GetAccountParams) (*GetAccountResult, error) { func (oper *Operator) GetAccount(ctx context.Context, operatorID auxuuid.UUID, params *GetAccountParams) (*GetAccountResult, error) {
var err error var err error
res := &GetAccountResult{} res := &GetAccountResult{}
@@ -128,15 +128,15 @@ func (oper *Operator) GetAccount(ctx context.Context, params *GetAccountParams)
} }
type UpdateAccountParams struct { type UpdateAccountParams struct {
Username string `json:"username"` Username string `json:"username"`
AccountID string `json:"accountId"` AccountID auxuuid.UUID `json:"accountId"`
NewUsername string `json:"newUsername"` NewUsername string `json:"newUsername"`
NewPassword string `json:"newPassword"` NewPassword string `json:"newPassword"`
Disabled bool `json:"disabled"` Disabled bool `json:"disabled"`
} }
type UpdateAccountResult struct{} type UpdateAccountResult struct{}
func (oper *Operator) UpdateAccount(ctx context.Context, params *UpdateAccountParams) (*UpdateAccountResult, error) { func (oper *Operator) UpdateAccount(ctx context.Context, operatorID auxuuid.UUID, params *UpdateAccountParams) (*UpdateAccountResult, error) {
var err error var err error
res := &UpdateAccountResult{} res := &UpdateAccountResult{}
if params.Username == "" && params.AccountID == "" { if params.Username == "" && params.AccountID == "" {
@@ -195,12 +195,12 @@ func (oper *Operator) UpdateAccount(ctx context.Context, params *UpdateAccountPa
} }
type DeleteAccountParams struct { type DeleteAccountParams struct {
Username string `json:"username"` Username string `json:"username"`
AccountID string `json:"accountId"` AccountID auxuuid.UUID `json:"accountId"`
} }
type DeleteAccountResult struct{} type DeleteAccountResult struct{}
func (oper *Operator) DeleteAccount(ctx context.Context, params *DeleteAccountParams) (*DeleteAccountResult, error) { func (oper *Operator) DeleteAccount(ctx context.Context, operatorID auxuuid.UUID, params *DeleteAccountParams) (*DeleteAccountResult, error) {
var err error var err error
res := &DeleteAccountResult{} res := &DeleteAccountResult{}
+1 -1
View File
@@ -73,7 +73,7 @@ type PostUploadParams struct {
From string From string
} }
type PostUploadResult struct { type PostUploadResult struct {
DockerUploadUUID string DockerUploadUUID auxuuid.UUID
Location string Location string
ContentLength string ContentLength string
} }
+14 -14
View File
@@ -41,9 +41,9 @@ type FileInfoResult struct {
ContentDigest string ContentDigest string
ContentCreatedAt string ContentCreatedAt string
ContentCreatedBy string ContentCreatedBy auxuuid.UUID
ContentUpdatedAt string ContentUpdatedAt string
ContentUpdatedBy string ContentUpdatedBy auxuuid.UUID
} }
func cleanFilepath(filename string) (string, error) { func cleanFilepath(filename string) (string, error) {
@@ -51,7 +51,7 @@ func cleanFilepath(filename string) (string, error) {
return filepath.Clean(filename), nil return filepath.Clean(filename), nil
} }
func (oper *Operator) FileInfo(ctx context.Context, operID string, param *FileInfoParams) (int, *FileInfoResult, error) { func (oper *Operator) FileInfo(ctx context.Context, operatorID auxuuid.UUID, param *FileInfoParams) (int, *FileInfoResult, error) {
var err error var err error
code := http.StatusOK code := http.StatusOK
res := &FileInfoResult{} res := &FileInfoResult{}
@@ -101,7 +101,7 @@ type PutFileResult struct{}
const defaultContentType = "application/octet-stream" const defaultContentType = "application/octet-stream"
// TODO: checking catalog and file names conflict // TODO: checking catalog and file names conflict
func (oper *Operator) PutFile(ctx context.Context, operID string, param *PutFileParams) (int, *PutFileResult, error) { func (oper *Operator) PutFile(ctx context.Context, operatorID auxuuid.UUID, param *PutFileParams) (int, *PutFileResult, error) {
var err error var err error
res := &PutFileResult{} res := &PutFileResult{}
@@ -147,7 +147,7 @@ func (oper *Operator) PutFile(ctx context.Context, operID string, param *PutFile
fileDescr.Checksum = checksum fileDescr.Checksum = checksum
fileDescr.UpdatedAt = now fileDescr.UpdatedAt = now
fileDescr.Type = contentType fileDescr.Type = contentType
fileDescr.UpdatedBy = operID fileDescr.UpdatedBy = operatorID
err = oper.mdb.UpdateFileByID(ctx, fileDescr.ID, fileDescr) err = oper.mdb.UpdateFileByID(ctx, fileDescr.ID, fileDescr)
if err != nil { if err != nil {
code := http.StatusInternalServerError code := http.StatusInternalServerError
@@ -163,8 +163,8 @@ func (oper *Operator) PutFile(ctx context.Context, operID string, param *PutFile
Checksum: checksum, Checksum: checksum,
CreatedAt: now, CreatedAt: now,
UpdatedAt: now, UpdatedAt: now,
CreatedBy: operID, CreatedBy: operatorID,
UpdatedBy: operID, UpdatedBy: operatorID,
} }
err = oper.mdb.InsertFile(ctx, fileDescr) err = oper.mdb.InsertFile(ctx, fileDescr)
if err != nil { if err != nil {
@@ -193,12 +193,12 @@ type GetFileResult struct {
Source io.ReadCloser Source io.ReadCloser
ContentCreatedAt string ContentCreatedAt string
ContentCreatedBy string ContentCreatedBy auxuuid.UUID
ContentUpdatedAt string ContentUpdatedAt string
ContentUpdatedBy string ContentUpdatedBy auxuuid.UUID
} }
func (oper *Operator) GetFile(ctx context.Context, operID string, param *GetFileParams) (int, *GetFileResult, error) { func (oper *Operator) GetFile(ctx context.Context, operatorID auxuuid.UUID, param *GetFileParams) (int, *GetFileResult, error) {
var err error var err error
res := &GetFileResult{} res := &GetFileResult{}
@@ -247,7 +247,7 @@ type DeleteFileParams struct {
} }
type DeleteFileResult struct{} type DeleteFileResult struct{}
func (oper *Operator) DeleteFile(ctx context.Context, operID string, param *DeleteFileParams) (int, *DeleteFileResult, error) { func (oper *Operator) DeleteFile(ctx context.Context, operatorID auxuuid.UUID, param *DeleteFileParams) (int, *DeleteFileResult, error) {
var err error var err error
res := &DeleteFileResult{} res := &DeleteFileResult{}
code := http.StatusOK code := http.StatusOK
@@ -294,7 +294,7 @@ type ListFilesResult struct {
Files []descr.File `json:"files,omitempty"` Files []descr.File `json:"files,omitempty"`
} }
func (oper *Operator) ListFiles(ctx context.Context, operID string, params *ListFilesParams) (int, *ListFilesResult, error) { func (oper *Operator) ListFiles(ctx context.Context, operatorID auxuuid.UUID, params *ListFilesParams) (int, *ListFilesResult, error) {
var err error var err error
res := &ListFilesResult{ res := &ListFilesResult{
Files: make([]descr.File, 0), Files: make([]descr.File, 0),
@@ -406,7 +406,7 @@ type ListCollectionsResult struct {
Collections []string `json:"collection,omitempty"` Collections []string `json:"collection,omitempty"`
} }
func (oper *Operator) ListCollections(ctx context.Context, operID string, param *ListCollectionsParams) (int, *ListCollectionsResult, error) { func (oper *Operator) ListCollections(ctx context.Context, operatorID auxuuid.UUID, param *ListCollectionsParams) (int, *ListCollectionsResult, error) {
var err error var err error
res := &ListCollectionsResult{ res := &ListCollectionsResult{
Collections: make([]string, 0), Collections: make([]string, 0),
@@ -539,7 +539,7 @@ type DeleteColletionResult struct {
Files []descr.File `json:"files,omitempty"` Files []descr.File `json:"files,omitempty"`
} }
func (oper *Operator) DeleteColletion(ctx context.Context, operID string, param *DeleteColletionParams) (int, *DeleteColletionResult, error) { func (oper *Operator) DeleteColletion(ctx context.Context, operatorID auxuuid.UUID, param *DeleteColletionParams) (int, *DeleteColletionResult, error) {
var err error var err error
res := &DeleteColletionResult{ res := &DeleteColletionResult{
Files: make([]descr.File, 0), Files: make([]descr.File, 0),
+17 -17
View File
@@ -12,16 +12,16 @@ import (
// CreateGrant // CreateGrant
type CreateGrantParams struct { type CreateGrantParams struct {
AccountID string `json:"accountID"` AccountID auxuuid.UUID `json:"accountID"`
Username string `json:"username"` Username string `json:"username"`
Right string `json:"operation"` Right string `json:"operation"`
Pattern string `json:"pattern"` Pattern string `json:"pattern"`
} }
type CreateGrantResult struct { type CreateGrantResult struct {
GrantID string `json:"grantId"` GrantID auxuuid.UUID `json:"grantId"`
} }
func (oper *Operator) CreateGrant(ctx context.Context, operID string, params *CreateGrantParams) (*CreateGrantResult, error) { func (oper *Operator) CreateGrant(ctx context.Context, operatorID auxuuid.UUID, params *CreateGrantParams) (*CreateGrantResult, error) {
var err error var err error
res := &CreateGrantResult{} res := &CreateGrantResult{}
@@ -86,8 +86,8 @@ func (oper *Operator) CreateGrant(ctx context.Context, operID string, params *Cr
Pattern: params.Pattern, Pattern: params.Pattern,
CreatedAt: now, CreatedAt: now,
UpdatedAt: now, UpdatedAt: now,
CreatedBy: operID, CreatedBy: operatorID,
UpdatedBy: operID, UpdatedBy: operatorID,
} }
err = oper.mdb.InsertGrant(ctx, grantDescr) err = oper.mdb.InsertGrant(ctx, grantDescr)
if err != nil { if err != nil {
@@ -99,12 +99,12 @@ func (oper *Operator) CreateGrant(ctx context.Context, operID string, params *Cr
// UpdateGrant // UpdateGrant
type UpdateGrantParams struct { type UpdateGrantParams struct {
GrantID string GrantID auxuuid.UUID
NewPattern string NewPattern string
} }
type UpdateGrantResult struct{} type UpdateGrantResult struct{}
func (oper *Operator) UpdateGrant(ctx context.Context, operID string, params *UpdateGrantParams) (*UpdateGrantResult, error) { func (oper *Operator) UpdateGrant(ctx context.Context, operatorID auxuuid.UUID, params *UpdateGrantParams) (*UpdateGrantResult, error) {
var err error var err error
res := &UpdateGrantResult{} res := &UpdateGrantResult{}
@@ -130,7 +130,7 @@ func (oper *Operator) UpdateGrant(ctx context.Context, operID string, params *Up
now := auxtool.TimeNow() now := auxtool.TimeNow()
if params.NewPattern != "" { if params.NewPattern != "" {
grantDescr.UpdatedAt = now grantDescr.UpdatedAt = now
grantDescr.UpdatedBy = operID grantDescr.UpdatedBy = operatorID
grantDescr.Pattern = params.NewPattern grantDescr.Pattern = params.NewPattern
} }
err = oper.mdb.UpdateGrantByID(ctx, grantDescr.ID, grantDescr) err = oper.mdb.UpdateGrantByID(ctx, grantDescr.ID, grantDescr)
@@ -142,11 +142,11 @@ func (oper *Operator) UpdateGrant(ctx context.Context, operID string, params *Up
// DeleteGrant // DeleteGrant
type DeleteGrantParams struct { type DeleteGrantParams struct {
GrantID string `json:"grantId"` GrantID auxuuid.UUID `json:"grantId"`
} }
type DeleteGrantResult struct{} type DeleteGrantResult struct{}
func (oper *Operator) DeleteGrant(ctx context.Context, operID string, params *DeleteGrantParams) (*DeleteGrantResult, error) { func (oper *Operator) DeleteGrant(ctx context.Context, operatorID auxuuid.UUID, params *DeleteGrantParams) (*DeleteGrantResult, error) {
var err error var err error
res := &DeleteGrantResult{} res := &DeleteGrantResult{}
@@ -176,13 +176,13 @@ func (oper *Operator) DeleteGrant(ctx context.Context, operID string, params *De
// ListGrants // ListGrants
type ListGrantsParams struct { type ListGrantsParams struct {
Username string Username string
AccountID string AccountID auxuuid.UUID
} }
type ListGrantsResult struct { type ListGrantsResult struct {
Grants []descr.Grant `json:"grants"` Grants []descr.Grant `json:"grants"`
} }
func (oper *Operator) ListGrants(ctx context.Context, operID string, params *ListGrantsParams) (*ListGrantsResult, error) { func (oper *Operator) ListGrants(ctx context.Context, operatorID auxuuid.UUID, params *ListGrantsParams) (*ListGrantsResult, error) {
var err error var err error
res := &ListGrantsResult{ res := &ListGrantsResult{
Grants: make([]descr.Grant, 0), Grants: make([]descr.Grant, 0),
@@ -223,13 +223,13 @@ func (oper *Operator) ListGrants(ctx context.Context, operID string, params *Lis
// Get Grants // Get Grants
type GetGrantParams struct { type GetGrantParams struct {
GrantID string `json:"grantId"` GrantID auxuuid.UUID `json:"grantId"`
} }
type GetGrantResult struct { type GetGrantResult struct {
Grant *descr.Grant `json:"grant"` Grant *descr.Grant `json:"grant"`
} }
func (oper *Operator) GetGrant(ctx context.Context, operID string, params *GetGrantParams) (*GetGrantResult, error) { func (oper *Operator) GetGrant(ctx context.Context, operatorID auxuuid.UUID, params *GetGrantParams) (*GetGrantResult, error) {
var err error var err error
res := &GetGrantResult{} res := &GetGrantResult{}
+1 -1
View File
@@ -80,7 +80,7 @@ func (store *Storage) WriteTempFile(source io.Reader) (string, int64, string, er
var size int64 var size int64
var csum string var csum string
tmpname := auxuuid.NewUUID() tmpname := string(auxuuid.NewUUID())
tmpname = fmt.Sprintf("file-%s.tmp", tmpname) tmpname = fmt.Sprintf("file-%s.tmp", tmpname)
tmppath := store.makeTmppath(tmpname) tmppath := store.makeTmppath(tmpname)
+11 -10
View File
@@ -18,6 +18,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/viper" "github.com/spf13/viper"
"mstore/pkg/auxuuid"
"mstore/pkg/client" "mstore/pkg/client"
"mstore/pkg/descr" "mstore/pkg/descr"
"mstore/pkg/terms" "mstore/pkg/terms"
@@ -125,8 +126,8 @@ type CreateAccountParams struct {
NewPassword string NewPassword string
} }
type CreateAccountResult struct { type CreateAccountResult struct {
AccountID string `yaml:"accountId"` AccountID auxuuid.UUID `yaml:"accountId"`
Grants map[string]string `yaml:"grantsIds,omitempty"` Grants map[auxuuid.UUID]string `yaml:"grantsIds,omitempty"`
} }
func (util *AccountUtil) CreateAccount(cmd *cobra.Command, args []string) { func (util *AccountUtil) CreateAccount(cmd *cobra.Command, args []string) {
@@ -140,7 +141,7 @@ func (util *AccountUtil) CreateAccount(cmd *cobra.Command, args []string) {
func (util *AccountUtil) createAccount(common *CommonAccountParams, params *CreateAccountParams) (*CreateAccountResult, error) { func (util *AccountUtil) createAccount(common *CommonAccountParams, params *CreateAccountParams) (*CreateAccountResult, error) {
var err error var err error
res := &CreateAccountResult{ res := &CreateAccountResult{
Grants: make(map[string]string, 0), Grants: make(map[auxuuid.UUID]string, 0),
} }
hostname, err := packUserinfo(common.Hostname, common.Username, common.Password) hostname, err := packUserinfo(common.Hostname, common.Username, common.Password)
if err != nil { if err != nil {
@@ -202,7 +203,7 @@ func (util *AccountUtil) updateAccount(common *CommonAccountParams, params *Upda
re := regexp.MustCompile(uuidRegex) re := regexp.MustCompile(uuidRegex)
id := strings.ToLower(params.AccountID) id := strings.ToLower(params.AccountID)
if re.MatchString(id) { if re.MatchString(id) {
err = client.NewClient().UpdateAccountByID(ctx, hostname, id, params.NewUsername, params.NewPassword) err = client.NewClient().UpdateAccountByID(ctx, hostname, auxuuid.UUID(id), params.NewUsername, params.NewPassword)
} else { } else {
err = client.NewClient().UpdateAccountByName(ctx, hostname, params.AccountID, params.NewUsername, params.NewPassword) err = client.NewClient().UpdateAccountByName(ctx, hostname, params.AccountID, params.NewUsername, params.NewPassword)
} }
@@ -243,7 +244,7 @@ func (util *AccountUtil) getAccount(common *CommonAccountParams, params *GetAcco
re := regexp.MustCompile(uuidRegex) re := regexp.MustCompile(uuidRegex)
id := strings.ToLower(params.AccountID) id := strings.ToLower(params.AccountID)
if re.MatchString(id) { if re.MatchString(id) {
opRes, err = client.NewClient().GetAccountByID(ctx, hostname, id) opRes, err = client.NewClient().GetAccountByID(ctx, hostname, auxuuid.UUID(id))
} else { } else {
opRes, err = client.NewClient().GetAccountByName(ctx, hostname, params.AccountID) opRes, err = client.NewClient().GetAccountByName(ctx, hostname, params.AccountID)
} }
@@ -280,7 +281,7 @@ func (util *AccountUtil) deleteAccount(common *CommonAccountParams, params *Dele
re := regexp.MustCompile(uuidRegex) re := regexp.MustCompile(uuidRegex)
id := strings.ToLower(params.AccountID) id := strings.ToLower(params.AccountID)
if re.MatchString(id) { if re.MatchString(id) {
err = client.NewClient().DeleteAccountByID(ctx, hostname, id) err = client.NewClient().DeleteAccountByID(ctx, hostname, auxuuid.UUID(id))
} else { } else {
err = client.NewClient().DeleteAccountByName(ctx, hostname, params.AccountID) err = client.NewClient().DeleteAccountByName(ctx, hostname, params.AccountID)
} }
@@ -298,9 +299,9 @@ type ListAccountsParams struct {
} }
type Userinfo struct { type Userinfo struct {
Username string `yaml:"username,omitempty"` Username string `yaml:"username,omitempty"`
AccountID string `yaml:"accountId,omitempty"` AccountID auxuuid.UUID `yaml:"accountId,omitempty"`
Rights map[string]string `yaml:"rights,omitempty"` Rights map[auxuuid.UUID]string `yaml:"rights,omitempty"`
} }
type ListAccountsResult struct { type ListAccountsResult struct {
@@ -349,7 +350,7 @@ func (util *AccountUtil) listAccounts(common *CommonAccountParams, params *ListA
userinfo := Userinfo{ userinfo := Userinfo{
Username: account.Username, Username: account.Username,
AccountID: account.ID, AccountID: account.ID,
Rights: make(map[string]string, 0), Rights: make(map[auxuuid.UUID]string, 0),
} }
for _, grant := range account.Grants { for _, grant := range account.Grants {
userinfo.Rights[grant.ID] = grant.Right userinfo.Rights[grant.ID] = grant.Right
+11 -10
View File
@@ -18,6 +18,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/viper" "github.com/spf13/viper"
"mstore/pkg/auxuuid"
"mstore/pkg/client" "mstore/pkg/client"
"mstore/pkg/descr" "mstore/pkg/descr"
) )
@@ -115,7 +116,7 @@ type CreateGrantParams struct {
Pattern string Pattern string
} }
type CreateGrantResult struct { type CreateGrantResult struct {
GrantID string `yaml:"grantId"` GrantID auxuuid.UUID `yaml:"grantId"`
} }
func (util *GrantUtil) CreateGrant(cmd *cobra.Command, args []string) { func (util *GrantUtil) CreateGrant(cmd *cobra.Command, args []string) {
@@ -138,9 +139,9 @@ func (util *GrantUtil) createGrant(common *CommonGrantParams, params *CreateGran
ctx, _ := context.WithTimeout(context.Background(), timeout) ctx, _ := context.WithTimeout(context.Background(), timeout)
re := regexp.MustCompile(uuidRegex) re := regexp.MustCompile(uuidRegex)
id := strings.ToLower(params.AccountID) id := strings.ToLower(params.AccountID)
var operRes string var operRes auxuuid.UUID
if re.MatchString(id) { if re.MatchString(id) {
operRes, err = client.NewClient().CreateGrantByAccountID(ctx, hostname, params.AccountID, params.Right, params.Pattern) operRes, err = client.NewClient().CreateGrantByAccountID(ctx, hostname, auxuuid.UUID(id), params.Right, params.Pattern)
} else { } else {
operRes, err = client.NewClient().CreateGrantByUsername(ctx, hostname, params.AccountID, params.Right, params.Pattern) operRes, err = client.NewClient().CreateGrantByUsername(ctx, hostname, params.AccountID, params.Right, params.Pattern)
} }
@@ -176,7 +177,7 @@ func (util *GrantUtil) updateGrant(common *CommonGrantParams, params *UpdateGran
timeout := time.Duration(common.Timeout) * time.Second timeout := time.Duration(common.Timeout) * time.Second
ctx, _ := context.WithTimeout(context.Background(), timeout) ctx, _ := context.WithTimeout(context.Background(), timeout)
id := strings.ToLower(params.GrantID) id := strings.ToLower(params.GrantID)
err = client.NewClient().UpdateGrant(ctx, hostname, id, params.Pattern) err = client.NewClient().UpdateGrant(ctx, hostname, auxuuid.UUID(id), params.Pattern)
if err != nil { if err != nil {
return res, err return res, err
} }
@@ -212,7 +213,7 @@ func (util *GrantUtil) getGrant(common *CommonGrantParams, params *GetGrantParam
opRes := &descr.Grant{} opRes := &descr.Grant{}
id := strings.ToLower(params.GrantID) id := strings.ToLower(params.GrantID)
opRes, err = client.NewClient().GetGrant(ctx, hostname, id) opRes, err = client.NewClient().GetGrant(ctx, hostname, auxuuid.UUID(id))
if err != nil { if err != nil {
return res, err return res, err
} }
@@ -243,7 +244,7 @@ func (util *GrantUtil) deleteGrant(common *CommonGrantParams, params *DeleteGran
timeout := time.Duration(common.Timeout) * time.Second timeout := time.Duration(common.Timeout) * time.Second
ctx, _ := context.WithTimeout(context.Background(), timeout) ctx, _ := context.WithTimeout(context.Background(), timeout)
id := strings.ToLower(params.GrantID) id := strings.ToLower(params.GrantID)
err = client.NewClient().DeleteGrant(ctx, hostname, id) err = client.NewClient().DeleteGrant(ctx, hostname, auxuuid.UUID(id))
if err != nil { if err != nil {
return res, err return res, err
} }
@@ -257,8 +258,8 @@ type ListGrantsParams struct {
} }
type ListGrantsResult struct { type ListGrantsResult struct {
Grants []descr.Grant `yaml:"grants,omitempty"` Grants []descr.Grant `yaml:"grants,omitempty"`
Rights map[string]string `yaml:"rights,omitempty"` Rights map[auxuuid.UUID]string `yaml:"rights,omitempty"`
} }
func (util *GrantUtil) ListGrants(cmd *cobra.Command, args []string) { func (util *GrantUtil) ListGrants(cmd *cobra.Command, args []string) {
@@ -280,7 +281,7 @@ func (util *GrantUtil) listGrants(common *CommonGrantParams, params *ListGrantsP
re := regexp.MustCompile(uuidRegex) re := regexp.MustCompile(uuidRegex)
id := strings.ToLower(params.AccountID) id := strings.ToLower(params.AccountID)
if re.MatchString(id) { if re.MatchString(id) {
grants, err = client.NewClient().ListGrantsByAccountID(ctx, hostname, params.AccountID) grants, err = client.NewClient().ListGrantsByAccountID(ctx, hostname, auxuuid.UUID(id))
} else { } else {
grants, err = client.NewClient().ListGrantsByUsername(ctx, hostname, params.AccountID) grants, err = client.NewClient().ListGrantsByUsername(ctx, hostname, params.AccountID)
} }
@@ -290,7 +291,7 @@ func (util *GrantUtil) listGrants(common *CommonGrantParams, params *ListGrantsP
if params.Detail { if params.Detail {
res.Grants = grants res.Grants = grants
} else { } else {
res.Rights = make(map[string]string, 0) res.Rights = make(map[auxuuid.UUID]string, 0)
for _, item := range grants { for _, item := range grants {
res.Rights[item.ID] = item.Right res.Rights[item.ID] = item.Right
} }
+4 -2
View File
@@ -13,8 +13,10 @@ import (
"github.com/google/uuid" "github.com/google/uuid"
) )
type UUID string
const ZeroUUID = "00000000-0000-0000-0000-000000000000" const ZeroUUID = "00000000-0000-0000-0000-000000000000"
func NewUUID() string { func NewUUID() UUID {
return uuid.New().String() return UUID(uuid.New().String())
} }
+6 -6
View File
@@ -16,12 +16,13 @@ import (
"mstore/app/handler" "mstore/app/handler"
"mstore/app/operator" "mstore/app/operator"
"mstore/pkg/auxuuid"
"mstore/pkg/descr" "mstore/pkg/descr"
) )
func (cli *Client) CreateAccount(ctx context.Context, hosturi, username, password string) (string, error) { func (cli *Client) CreateAccount(ctx context.Context, hosturi, username, password string) (auxuuid.UUID, error) {
var err error var err error
var res string var res auxuuid.UUID
apiuri, err := setApiPath(hosturi, "/v3/api/account/create") apiuri, err := setApiPath(hosturi, "/v3/api/account/create")
if err != nil { if err != nil {
@@ -53,7 +54,7 @@ func (cli *Client) CreateAccount(ctx context.Context, hosturi, username, passwor
return res, err return res, err
} }
func (cli *Client) GetAccountByID(ctx context.Context, hosturi, id string) (*descr.AccountShort, error) { func (cli *Client) GetAccountByID(ctx context.Context, hosturi string, id auxuuid.UUID) (*descr.AccountShort, error) {
var err error var err error
res := &descr.AccountShort{} res := &descr.AccountShort{}
@@ -120,7 +121,7 @@ func (cli *Client) GetAccountByName(ctx context.Context, hosturi, username strin
return res, err return res, err
} }
func (cli *Client) UpdateAccountByID(ctx context.Context, hosturi, id, newUsername, newPassword string) error { func (cli *Client) UpdateAccountByID(ctx context.Context, hosturi string, id auxuuid.UUID, newUsername, newPassword string) error {
var err error var err error
apipath, err := setApiPath(hosturi, "/v3/api/account/update") apipath, err := setApiPath(hosturi, "/v3/api/account/update")
@@ -128,7 +129,6 @@ func (cli *Client) UpdateAccountByID(ctx context.Context, hosturi, id, newUserna
return err return err
} }
operParams := operator.UpdateAccountParams{ operParams := operator.UpdateAccountParams{
//Username: username,
AccountID: id, AccountID: id,
NewUsername: newUsername, NewUsername: newUsername,
NewPassword: newPassword, NewPassword: newPassword,
@@ -215,7 +215,7 @@ func (cli *Client) DeleteAccountByName(ctx context.Context, hosturi, username st
return err return err
} }
func (cli *Client) DeleteAccountByID(ctx context.Context, hosturi, id string) error { func (cli *Client) DeleteAccountByID(ctx context.Context, hosturi string, id auxuuid.UUID) error {
var err error var err error
apipath, err := setApiPath(hosturi, "/v3/api/account/delete") apipath, err := setApiPath(hosturi, "/v3/api/account/delete")
+9 -8
View File
@@ -16,12 +16,13 @@ import (
"mstore/app/handler" "mstore/app/handler"
"mstore/app/operator" "mstore/app/operator"
"mstore/pkg/auxuuid"
"mstore/pkg/descr" "mstore/pkg/descr"
) )
func (cli *Client) CreateGrantByAccountID(ctx context.Context, hosturi, accountID, right, pattern string) (string, error) { func (cli *Client) CreateGrantByAccountID(ctx context.Context, hosturi string, accountID auxuuid.UUID, right, pattern string) (auxuuid.UUID, error) {
var err error var err error
var res string var res auxuuid.UUID
apiuri, err := setApiPath(hosturi, "/v3/api/grant/create") apiuri, err := setApiPath(hosturi, "/v3/api/grant/create")
if err != nil { if err != nil {
@@ -54,9 +55,9 @@ func (cli *Client) CreateGrantByAccountID(ctx context.Context, hosturi, accountI
return res, err return res, err
} }
func (cli *Client) CreateGrantByUsername(ctx context.Context, hosturi, username, right, pattern string) (string, error) { func (cli *Client) CreateGrantByUsername(ctx context.Context, hosturi, username, right, pattern string) (auxuuid.UUID, error) {
var err error var err error
var res string var res auxuuid.UUID
apiuri, err := setApiPath(hosturi, "/v3/api/grant/create") apiuri, err := setApiPath(hosturi, "/v3/api/grant/create")
if err != nil { if err != nil {
@@ -89,7 +90,7 @@ func (cli *Client) CreateGrantByUsername(ctx context.Context, hosturi, username,
return res, err return res, err
} }
func (cli *Client) GetGrant(ctx context.Context, hosturi, id string) (*descr.Grant, error) { func (cli *Client) GetGrant(ctx context.Context, hosturi string, id auxuuid.UUID) (*descr.Grant, error) {
var err error var err error
res := &descr.Grant{} res := &descr.Grant{}
@@ -122,7 +123,7 @@ func (cli *Client) GetGrant(ctx context.Context, hosturi, id string) (*descr.Gra
return res, err return res, err
} }
func (cli *Client) UpdateGrant(ctx context.Context, hosturi, grantID, newPattern string) error { func (cli *Client) UpdateGrant(ctx context.Context, hosturi string, grantID auxuuid.UUID, newPattern string) error {
var err error var err error
apipath, err := setApiPath(hosturi, "/v3/api/grant/update") apipath, err := setApiPath(hosturi, "/v3/api/grant/update")
@@ -153,7 +154,7 @@ func (cli *Client) UpdateGrant(ctx context.Context, hosturi, grantID, newPattern
return err return err
} }
func (cli *Client) DeleteGrant(ctx context.Context, hosturi, grantID string) error { func (cli *Client) DeleteGrant(ctx context.Context, hosturi string, grantID auxuuid.UUID) error {
var err error var err error
apipath, err := setApiPath(hosturi, "/v3/api/grant/delete") apipath, err := setApiPath(hosturi, "/v3/api/grant/delete")
@@ -184,7 +185,7 @@ func (cli *Client) DeleteGrant(ctx context.Context, hosturi, grantID string) err
return err return err
} }
func (cli *Client) ListGrantsByAccountID(ctx context.Context, hosturi, accountID string) ([]descr.Grant, error) { func (cli *Client) ListGrantsByAccountID(ctx context.Context, hosturi string, accountID auxuuid.UUID) ([]descr.Grant, error) {
var err error var err error
res := make([]descr.Grant, 0) res := make([]descr.Grant, 0)
+20 -17
View File
@@ -7,27 +7,30 @@
* Distribution of this work is permitted, but commercial use and * Distribution of this work is permitted, but commercial use and
* modifications are strictly prohibited. * modifications are strictly prohibited.
*/ */
package descr package descr
import (
"mstore/pkg/auxuuid"
)
type Account struct { type Account struct {
ID string `json:"id" db:"id"` ID auxuuid.UUID `json:"id" db:"id"`
Username string `json:"username" db:"username"` Username string `json:"username" db:"username"`
Passhash string `json:"passhash" db:"passhash"` Passhash string `json:"passhash" db:"passhash"`
Disabled bool `json:"disabled" db:"disabled"` Disabled bool `json:"disabled" db:"disabled"`
CreatedAt string `json:"createdAt" db:"created_at"` CreatedAt string `json:"createdAt" db:"created_at"`
UpdatedAt string `json:"updatedAt" db:"updated_at"` UpdatedAt string `json:"updatedAt" db:"updated_at"`
CreatedBy string `json:"createdBy" db:"created_by"` CreatedBy auxuuid.UUID `json:"createdBy" db:"created_by"`
UpdatedBy string `json:"updatedBy" db:"updated_by"` UpdatedBy auxuuid.UUID `json:"updatedBy" db:"updated_by"`
} }
type AccountShort struct { type AccountShort struct {
ID string `json:"id"` ID auxuuid.UUID `json:"id"`
Username string `json:"username"` Username string `json:"username"`
Disabled bool `json:"disabled"` Disabled bool `json:"disabled"`
CreatedAt string `json:"createdAt"` CreatedAt string `json:"createdAt"`
UpdatedAt string `json:"updatedAt"` UpdatedAt string `json:"updatedAt"`
CreatedBy string `json:"createdBy"` CreatedBy auxuuid.UUID `json:"createdBy"`
UpdatedBy string `json:"updatedBy"` UpdatedBy auxuuid.UUID `json:"updatedBy"`
Grants []Grant `json:"grants"` Grants []Grant `json:"grants"`
} }
+14 -10
View File
@@ -9,15 +9,19 @@
*/ */
package descr package descr
import (
"mstore/pkg/auxuuid"
)
type Blob struct { type Blob struct {
ID string `db:"id" json:"id"` ID auxuuid.UUID `db:"id" json:"id"`
Name string `db:"name" json:"name"` Name string `db:"name" json:"name"`
Reference string `db:"reference" json:"reference"` Reference string `db:"reference" json:"reference"`
MediaType string `db:"mediaType" json:"mediaType"` MediaType string `db:"mediaType" json:"mediaType"`
Digest string `db:"digest" json:"digest"` Digest string `db:"digest" json:"digest"`
Size int64 `db:"size" json:"size"` Size int64 `db:"size" json:"size"`
CreatedAt string `db:"created_at" json:"createdAt"` CreatedAt string `db:"created_at" json:"createdAt"`
UpdatedAt string `db:"updated_at" json:"updatedAt"` UpdatedAt string `db:"updated_at" json:"updatedAt"`
CreatedBy string `db:"created_by" json:"createdBy,omitempty"` CreatedBy auxuuid.UUID `db:"created_by" json:"createdBy,omitempty"`
UpdatedBy string `db:"updated_by" json:"updatedBy,omitempty"` UpdatedBy auxuuid.UUID `db:"updated_by" json:"updatedBy,omitempty"`
} }
+14 -10
View File
@@ -9,15 +9,19 @@
*/ */
package descr package descr
import (
"mstore/pkg/auxuuid"
)
type File struct { type File struct {
ID string `db:"id" json:"id,omitempty" yaml:"id,omitempty"` ID auxuuid.UUID `db:"id" json:"id,omitempty" yaml:"id,omitempty"`
Collection string `db:"collection" json:"collection,omitempty" yaml:"collection,omitempty"` Collection string `db:"collection" json:"collection,omitempty" yaml:"collection,omitempty"`
Name string `db:"name" json:"name,omitempty" yaml:"name,omitempty"` Name string `db:"name" json:"name,omitempty" yaml:"name,omitempty"`
Type string `db:"type" json:"type,omitempty" yaml:"type,omitempty"` Type string `db:"type" json:"type,omitempty" yaml:"type,omitempty"`
Checksum string `db:"checksum" json:"checksum,omitempty" yaml:"checksum,omitempty"` Checksum string `db:"checksum" json:"checksum,omitempty" yaml:"checksum,omitempty"`
Size int64 `db:"size" json:"size,omitempty" yaml:"size,omitempty"` Size int64 `db:"size" json:"size,omitempty" yaml:"size,omitempty"`
CreatedAt string `db:"created_at" json:"createdAt,omitempty" yaml:"createdAt,omitempty"` CreatedAt string `db:"created_at" json:"createdAt,omitempty" yaml:"createdAt,omitempty"`
UpdatedAt string `db:"updated_at" json:"updatedAt,omitempty" yaml:"updatedAt,omitempty"` UpdatedAt string `db:"updated_at" json:"updatedAt,omitempty" yaml:"updatedAt,omitempty"`
CreatedBy string `db:"created_by" json:"createdBy,omitempty" yaml:"createdBy,omitempty"` CreatedBy auxuuid.UUID `db:"created_by" json:"createdBy,omitempty" yaml:"createdBy,omitempty"`
UpdatedBy string `db:"updated_by" json:"updatedBy,omitempty" yaml:"updatedBy,omitempty"` UpdatedBy auxuuid.UUID `db:"updated_by" json:"updatedBy,omitempty" yaml:"updatedBy,omitempty"`
} }
+12 -8
View File
@@ -10,13 +10,17 @@
package descr package descr
import (
"mstore/pkg/auxuuid"
)
type Grant struct { type Grant struct {
ID string `json:"id" db:"id"` ID auxuuid.UUID `json:"id" db:"id"`
AccountID string `json:"accountID" db:"account_id"` AccountID auxuuid.UUID `json:"accountID" db:"account_id"`
Right string `json:"right" db:"right"` Right string `json:"right" db:"right"`
Pattern string `json:"pattern" db:"pattern"` Pattern string `json:"pattern" db:"pattern"`
CreatedAt string `json:"createdAt" db:"created_at"` CreatedAt string `json:"createdAt" db:"created_at"`
UpdatedAt string `json:"updatedAt" db:"updated_at"` UpdatedAt string `json:"updatedAt" db:"updated_at"`
CreatedBy string `json:"createdBy" db:"created_by"` CreatedBy auxuuid.UUID `json:"createdBy" db:"created_by"`
UpdatedBy string `json:"updatedBy" db:"updated_by"` UpdatedBy auxuuid.UUID `json:"updatedBy" db:"updated_by"`
} }
+14 -10
View File
@@ -9,17 +9,21 @@
*/ */
package descr package descr
import (
"mstore/pkg/auxuuid"
)
type Manifest struct { type Manifest struct {
ID string `db:"id" json:"id"` ID auxuuid.UUID `db:"id" json:"id"`
Name string `db:"name" json:"name"` Name string `db:"name" json:"name"`
Reference string `db:"reference" json:"reference"` Reference string `db:"reference" json:"reference"`
ContentType string `db:"contentType" json:"contentType"` ContentType string `db:"contentType" json:"contentType"`
Payload string `db:"payload" json:"-"` Payload string `db:"payload" json:"-"`
Digest string `db:"digest" json:"digest"` Digest string `db:"digest" json:"digest"`
CreatedAt string `db:"created_at" json:"createdAt"` CreatedAt string `db:"created_at" json:"createdAt"`
UpdatedAt string `db:"updated_at" json:"updatedAt"` UpdatedAt string `db:"updated_at" json:"updatedAt"`
CreatedBy string `db:"created_by" json:"createdBy,omitempty"` CreatedBy auxuuid.UUID `db:"created_by" json:"createdBy,omitempty"`
UpdatedBy string `db:"updated_by" json:"updatedBy,omitempty"` UpdatedBy auxuuid.UUID `db:"updated_by" json:"updatedBy,omitempty"`
} }
type Tags struct { type Tags struct {
-10
View File
@@ -1,10 +0,0 @@
/*
* Copyright 2026 Oleg Borodin <onborodin@gmail.com>
*
* This work is published and licensed under a Creative Commons
* Attribution-NonCommercial-NoDerivatives 4.0 International License.
*
* Distribution of this work is permitted, but commercial use and
* modifications are strictly prohibited.
*/
package descr
+10 -7
View File
@@ -10,6 +10,10 @@
package terms package terms
import (
"mstore/pkg/auxuuid"
)
type PathUsage string type PathUsage string
const ( const (
@@ -19,13 +23,12 @@ const (
) )
const ( const (
AnonimousUsername = "anonymous" AnonimousUsername string = "anonymous"
AnonymousID = "10000000-0000-0000-0000-000000000001" AnonymousID auxuuid.UUID = "10000000-0000-0000-0000-000000000001"
ServerUsername = "server" ServerUsername string = "server"
ServerID = "10000000-0000-0000-0000-000000000002" ServerID auxuuid.UUID = "10000000-0000-0000-0000-000000000002"
InitUsername string = "mstore"
InitUsername = "mstore" InitID auxuuid.UUID = "10000000-0000-0000-0000-000000000005"
InitID = "10000000-0000-0000-0000-000000000005"
) )
const ( const (
+3 -2
View File
@@ -17,6 +17,7 @@ import (
"time" "time"
"mstore/app/server" "mstore/app/server"
"mstore/pkg/auxuuid"
"mstore/pkg/client" "mstore/pkg/client"
"mstore/pkg/terms" "mstore/pkg/terms"
@@ -80,7 +81,7 @@ func TestAccountLife(t *testing.T) {
username := "testuser" username := "testuser"
password := "testpass" password := "testpass"
var accountID string var accountID auxuuid.UUID
{ {
// CreateAccount // CreateAccount
fmt.Printf("=== CreateAccount ===\n") fmt.Printf("=== CreateAccount ===\n")
@@ -91,7 +92,7 @@ func TestAccountLife(t *testing.T) {
accountID, err = cli.CreateAccount(ctx, srvaddr, username, password) accountID, err = cli.CreateAccount(ctx, srvaddr, username, password)
require.NoError(t, err) require.NoError(t, err)
} }
var grantID string var grantID auxuuid.UUID
{ {
// CreateGrant // CreateGrant
fmt.Printf("=== CreateGrant ===\n") fmt.Printf("=== CreateGrant ===\n")