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
+7 -12
View File
@@ -17,6 +17,7 @@ import (
"mstore/app/router"
"mstore/pkg/auxhttp"
"mstore/pkg/auxpwd"
"mstore/pkg/auxuuid"
"mstore/pkg/terms"
)
@@ -29,40 +30,35 @@ func (hand *Handler) AuthMiddleware(next router.Handler) router.Handler {
var handlerFunc router.HandlerFunc
handlerFunc = func(rctx *router.Context) {
//hand.logg.Debugf("Call authorization middleware")
success, accountID, err := hand.CheckAccess(rctx)
if success {
rctx.SetBool(authTag, true)
rctx.SetString(userTag, accountID)
//hand.logg.Debugf("Authorization for accountID [%s]", rctx.Strings[userTag])
rctx.SetString(userTag, string(accountID))
}
if err != nil {
hand.logg.Errorf("Authorization middleware error: %v", err)
}
next.ServeHTTP(rctx)
}
return handlerFunc
}
// 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 success bool
var username string
var password string
var accountID string
var accountID auxuuid.UUID
accountID = terms.AnonymousID
authHeader := rctx.GetHeader("Authorization")
if authHeader != "" {
//hand.logg.Debugf("Authorization header is %s", authHeader)
username, password, err = auxhttp.ParseBasicAuth(authHeader)
if err != nil {
return success, accountID, err
}
//hand.logg.Debugf("Authorization pair is %s:%s", username, password)
if username == "" || password == "" {
goto anonymous
}
@@ -84,9 +80,9 @@ anonymous:
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 accountID string
var accountID auxuuid.UUID
valid := false
accountExists, accountDescr, err := hand.mdb.GetAccountByUsername(ctx, username)
@@ -106,7 +102,7 @@ func (hand *Handler) ValidatePassword(ctx context.Context, username, password st
// 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 res bool
//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
}
res = true
//hand.logg.Debugf("Result of checking right %s for %s: %v", reqRight, accountID, res)
return res, err
}
+10 -9
View File
@@ -14,6 +14,7 @@ import (
"mstore/app/operator"
"mstore/app/router"
"mstore/pkg/auxuuid"
"mstore/pkg/terms"
)
@@ -29,7 +30,7 @@ func (hand *Handler) CreateAccount(rctx *router.Context) {
}
// Rigth checking
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 {
err := fmt.Errorf("Operation error: %v", err)
hand.SendError(rctx, err)
@@ -41,7 +42,7 @@ func (hand *Handler) CreateAccount(rctx *router.Context) {
return
}
// 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 {
hand.logg.Errorf("Operation error: %v", err)
hand.SendError(rctx, err)
@@ -62,7 +63,7 @@ func (hand *Handler) GetAccount(rctx *router.Context) {
}
// Rigth checking
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 {
err := fmt.Errorf("Operation error: %v", err)
hand.SendError(rctx, err)
@@ -74,7 +75,7 @@ func (hand *Handler) GetAccount(rctx *router.Context) {
return
}
// 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 {
hand.logg.Errorf("Operation error: %v", err)
hand.SendError(rctx, err)
@@ -95,7 +96,7 @@ func (hand *Handler) ListAccounts(rctx *router.Context) {
}
// Rigth checking
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 {
err := fmt.Errorf("Operation error: %v", err)
hand.SendError(rctx, err)
@@ -128,7 +129,7 @@ func (hand *Handler) UpdateAccount(rctx *router.Context) {
}
// Rigth checking
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 {
err := fmt.Errorf("Operation error: %v", err)
hand.SendError(rctx, err)
@@ -140,7 +141,7 @@ func (hand *Handler) UpdateAccount(rctx *router.Context) {
return
}
// 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 {
hand.logg.Errorf("UpdateAccount error: %v", err)
hand.SendError(rctx, err)
@@ -161,7 +162,7 @@ func (hand *Handler) DeleteAccount(rctx *router.Context) {
}
// Rigth checking
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 {
err := fmt.Errorf("Operation error: %v", err)
hand.SendError(rctx, err)
@@ -173,7 +174,7 @@ func (hand *Handler) DeleteAccount(rctx *router.Context) {
return
}
// 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 {
hand.logg.Errorf("DeleteAccount error: %v", err)
hand.SendError(rctx, err)
+8 -7
View File
@@ -16,6 +16,7 @@ import (
"mstore/app/operator"
"mstore/app/router"
"mstore/pkg/auxuuid"
"mstore/pkg/terms"
)
@@ -32,7 +33,7 @@ func (hand *Handler) BlobExists(rctx *router.Context) {
}
// Rigth checking
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 {
rctx.SetStatus(http.StatusInternalServerError)
return
@@ -72,7 +73,7 @@ func (hand *Handler) PostUpload(rctx *router.Context) {
}
// Rigth checking
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 {
rctx.SetStatus(http.StatusInternalServerError)
return
@@ -88,7 +89,7 @@ func (hand *Handler) PostUpload(rctx *router.Context) {
} else {
rctx.SetHeader("Location", res.Location)
rctx.SetHeader("Content-Length", res.ContentLength)
rctx.SetHeader("Docker-Upload-UUID", res.DockerUploadUUID)
rctx.SetHeader("Docker-Upload-UUID", string(res.DockerUploadUUID))
}
rctx.SetStatus(code)
}
@@ -117,7 +118,7 @@ func (hand *Handler) PatchUpload(rctx *router.Context) {
}
// Rigth checking
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 {
rctx.SetStatus(http.StatusInternalServerError)
return
@@ -161,7 +162,7 @@ func (hand *Handler) PutUpload(rctx *router.Context) {
}
// Rigth checking
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 {
rctx.SetStatus(http.StatusInternalServerError)
return
@@ -191,7 +192,7 @@ func (hand *Handler) GetBlob(rctx *router.Context) {
}
// Rigth checking
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 {
rctx.SetStatus(http.StatusInternalServerError)
return
@@ -237,7 +238,7 @@ func (hand *Handler) DeleteBlob(rctx *router.Context) {
}
// Rigth checking
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 {
rctx.SetStatus(http.StatusInternalServerError)
return
+19 -18
View File
@@ -15,6 +15,7 @@ import (
"mstore/app/operator"
"mstore/app/router"
"mstore/pkg/auxuuid"
"mstore/pkg/terms"
)
@@ -28,7 +29,7 @@ func (hand *Handler) FileInfo(rctx *router.Context) {
}
// Rigth checking
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 {
rctx.SetStatus(http.StatusInternalServerError)
return
@@ -39,7 +40,7 @@ func (hand *Handler) FileInfo(rctx *router.Context) {
}
// Execution of the operation
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 {
hand.logg.Errorf("FileInfo error: %v", err)
rctx.SetStatus(code)
@@ -52,9 +53,9 @@ func (hand *Handler) FileInfo(rctx *router.Context) {
rctx.SetHeader("Content-Digest", res.ContentDigest)
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-UpdatedBy", res.ContentUpdatedBy)
rctx.SetHeader("Content-UpdatedBy", string(res.ContentUpdatedBy))
rctx.SetHeader("Content-Length", zeroContentLength)
rctx.SetStatus(code)
@@ -73,7 +74,7 @@ func (hand *Handler) PutFile(rctx *router.Context) {
}
// Rigth checking
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 {
rctx.SetStatus(http.StatusInternalServerError)
return
@@ -84,7 +85,7 @@ func (hand *Handler) PutFile(rctx *router.Context) {
}
// Execution of the operation
ctx := rctx.GetContext()
code, _, err := hand.oper.PutFile(ctx, operatorID, params)
code, _, err := hand.oper.PutFile(ctx, auxuuid.UUID(operatorID), params)
if err != nil {
hand.logg.Errorf("PutFile error: %v", err)
rctx.SetStatus(code)
@@ -101,7 +102,7 @@ func (hand *Handler) GetFile(rctx *router.Context) {
}
// Rigth checking
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 {
rctx.SetStatus(http.StatusInternalServerError)
return
@@ -112,7 +113,7 @@ func (hand *Handler) GetFile(rctx *router.Context) {
}
// Execution of the operation
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 {
hand.logg.Errorf("PutFile error: %v", err)
rctx.SetStatus(code)
@@ -125,9 +126,9 @@ func (hand *Handler) GetFile(rctx *router.Context) {
rctx.SetHeader("Content-Length", res.ContentSize)
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-UpdatedBy", res.ContentUpdatedBy)
rctx.SetHeader("Content-UpdatedBy", string(res.ContentUpdatedBy))
rctx.SetStatus(code)
@@ -149,7 +150,7 @@ func (hand *Handler) DeleteFile(rctx *router.Context) {
}
// Rigth checking
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 {
rctx.SetStatus(http.StatusInternalServerError)
return
@@ -160,7 +161,7 @@ func (hand *Handler) DeleteFile(rctx *router.Context) {
}
// Execution of the operation
ctx := rctx.GetContext()
code, _, err := hand.oper.DeleteFile(ctx, operatorID, params)
code, _, err := hand.oper.DeleteFile(ctx, auxuuid.UUID(operatorID), params)
if err != nil {
hand.logg.Errorf("DeleteFIle error: %v", err)
}
@@ -186,7 +187,7 @@ func (hand *Handler) ListFiles(rctx *router.Context) {
// Rigth checking
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 {
rctx.SetStatus(http.StatusInternalServerError)
return
@@ -197,7 +198,7 @@ func (hand *Handler) ListFiles(rctx *router.Context) {
}
// Execution of the operation
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 {
hand.logg.Errorf("ListFiles error: %v", err)
rctx.SetStatus(code)
@@ -223,7 +224,7 @@ func (hand *Handler) ListCollections(rctx *router.Context) {
}
// Rigth checking
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 {
rctx.SetStatus(http.StatusInternalServerError)
return
@@ -234,7 +235,7 @@ func (hand *Handler) ListCollections(rctx *router.Context) {
}
// Execution of the operation
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 {
hand.logg.Errorf("ListCollections error: %v", err)
rctx.SetStatus(code)
@@ -261,7 +262,7 @@ func (hand *Handler) DeleteCollection(rctx *router.Context) {
// Rigth checking
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 {
rctx.SetStatus(http.StatusInternalServerError)
return
@@ -272,7 +273,7 @@ func (hand *Handler) DeleteCollection(rctx *router.Context) {
}
// Execution of the operation
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 {
hand.logg.Errorf("DeleteColletion error: %v", err)
rctx.SetStatus(code)
+11 -10
View File
@@ -14,6 +14,7 @@ import (
"mstore/app/operator"
"mstore/app/router"
"mstore/pkg/auxuuid"
"mstore/pkg/terms"
)
@@ -29,7 +30,7 @@ func (hand *Handler) CreateGrant(rctx *router.Context) {
}
// Rigth checking
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 {
err := fmt.Errorf("Operation error: %v", err)
hand.SendError(rctx, err)
@@ -41,7 +42,7 @@ func (hand *Handler) CreateGrant(rctx *router.Context) {
return
}
// 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 {
hand.logg.Errorf("CreateGrant error: %v", err)
hand.SendError(rctx, err)
@@ -62,7 +63,7 @@ func (hand *Handler) GetGrant(rctx *router.Context) {
}
// Rigth checking
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 {
err := fmt.Errorf("Operation error: %v", err)
hand.SendError(rctx, err)
@@ -74,7 +75,7 @@ func (hand *Handler) GetGrant(rctx *router.Context) {
return
}
// 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 {
hand.logg.Errorf("CreateGrant error: %v", err)
hand.SendError(rctx, err)
@@ -95,7 +96,7 @@ func (hand *Handler) ListGrants(rctx *router.Context) {
}
// Rigth checking
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 {
err := fmt.Errorf("Operation error: %v", err)
hand.SendError(rctx, err)
@@ -107,7 +108,7 @@ func (hand *Handler) ListGrants(rctx *router.Context) {
return
}
// 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 {
hand.logg.Errorf("ListGrants error: %v", err)
hand.SendError(rctx, err)
@@ -128,7 +129,7 @@ func (hand *Handler) UpdateGrant(rctx *router.Context) {
}
// Rigth checking
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 {
err := fmt.Errorf("Operation error: %v", err)
hand.SendError(rctx, err)
@@ -140,7 +141,7 @@ func (hand *Handler) UpdateGrant(rctx *router.Context) {
return
}
// 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 {
hand.logg.Errorf("UpdateGrant error: %v", err)
hand.SendError(rctx, err)
@@ -161,7 +162,7 @@ func (hand *Handler) DeleteGrant(rctx *router.Context) {
}
// Rigth checking
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 {
err := fmt.Errorf("Operation error: %v", err)
hand.SendError(rctx, err)
@@ -173,7 +174,7 @@ func (hand *Handler) DeleteGrant(rctx *router.Context) {
return
}
// 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 {
hand.logg.Errorf("DeleteGrant error: %v", err)
hand.SendError(rctx, err)
+7 -6
View File
@@ -14,6 +14,7 @@ import (
"mstore/app/operator"
"mstore/app/router"
"mstore/pkg/auxuuid"
"mstore/pkg/terms"
)
@@ -29,7 +30,7 @@ func (hand *Handler) ManifestExists(rctx *router.Context) {
}
// Rigth checking
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 {
rctx.SetStatus(http.StatusInternalServerError)
return
@@ -71,7 +72,7 @@ func (hand *Handler) PutManifest(rctx *router.Context) {
}
// Rigth checking
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 {
rctx.SetStatus(http.StatusInternalServerError)
return
@@ -104,7 +105,7 @@ func (hand *Handler) GetManifest(rctx *router.Context) {
}
// Rigth checking
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 {
rctx.SetStatus(http.StatusInternalServerError)
return
@@ -144,7 +145,7 @@ func (hand *Handler) DeleteManifest(rctx *router.Context) {
}
// Rigth checking
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 {
rctx.SetStatus(http.StatusInternalServerError)
return
@@ -173,7 +174,7 @@ func (hand *Handler) GetReferer(rctx *router.Context) {
}
// Rigth checking
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 {
rctx.SetStatus(http.StatusInternalServerError)
return
@@ -199,7 +200,7 @@ func (hand *Handler) GetTags(rctx *router.Context) {
}
// Rigth checking
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 {
rctx.SetStatus(http.StatusInternalServerError)
return
+4 -3
View File
@@ -3,6 +3,7 @@ package maindb
import (
"context"
"mstore/pkg/auxuuid"
"mstore/pkg/descr"
)
@@ -19,7 +20,7 @@ func (db *Database) InsertAccount(ctx context.Context, account *descr.Account) e
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
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)
@@ -51,7 +52,7 @@ func (db *Database) ListAccounts(ctx context.Context) ([]descr.Account, error) {
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 res *descr.Account
var exists bool = false
@@ -90,7 +91,7 @@ func (db *Database) GetAccountByUsername(ctx context.Context, username string) (
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
request := `DELETE FROM accounts WHERE id = $1`
+2 -1
View File
@@ -12,6 +12,7 @@ package maindb
import (
"context"
"mstore/pkg/auxuuid"
"mstore/pkg/descr"
)
@@ -27,7 +28,7 @@ func (db *Database) InsertFile(ctx context.Context, file *descr.File) error {
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
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
+1 -1
View File
@@ -35,7 +35,7 @@ func TestFile(t *testing.T) {
id := auxuuid.NewUUID()
timenow := auxtool.TimeNow()
creator := "some"
creator := auxuuid.NewUUID()
collection := "foo"
newFile := &descr.File{
ID: id,
+10 -9
View File
@@ -12,6 +12,7 @@ package maindb
import (
"context"
"mstore/pkg/auxuuid"
"mstore/pkg/descr"
)
@@ -27,7 +28,7 @@ func (db *Database) InsertGrant(ctx context.Context, grant *descr.Grant) error {
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
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)
@@ -37,7 +38,7 @@ func (db *Database) UpdateGrantByID(ctx context.Context, grantID string, grant *
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
request := `SELECT * FROM grants WHERE account_id = $1`
res := make([]descr.Grant, 0)
@@ -59,7 +60,7 @@ func (db *Database) ListGrants(ctx context.Context) ([]descr.Grant, error) {
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
res := &descr.Grant{}
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
}
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
res := &descr.Grant{}
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
}
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
request := `SELECT * FROM grants WHERE account_id = $1 AND right = $2`
res := make([]descr.Grant, 0)
@@ -107,7 +108,7 @@ func (db *Database) ListGrantsByAccoundIDRight(ctx context.Context, accountID, r
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
res := &descr.Grant{}
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
}
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
request := `DELETE FROM grants WHERE account_id = $1 AND right = $2 AND pattern = $3`
_, err = db.db.Exec(request, accountID, right, pattern)
@@ -134,7 +135,7 @@ func (db *Database) DeleteGrantByAccountIDRightPattern(ctx context.Context, acco
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
request := `DELETE FROM grants WHERE id = $1`
_, err = db.db.Exec(request, grantID)
@@ -144,7 +145,7 @@ func (db *Database) DeleteGrantByID(ctx context.Context, grantID string) error {
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
request := `DELETE FROM grants WHERE account_id = $1`
_, err = db.db.Exec(request, grantID)
+5 -1
View File
@@ -11,6 +11,7 @@ package maindb
import (
"context"
"fmt"
"testing"
"time"
@@ -36,7 +37,7 @@ func TestGrant(t *testing.T) {
id := auxuuid.NewUUID()
accountID := auxuuid.NewUUID()
timenow := auxtool.TimeNow()
creator := "some"
creator := auxuuid.NewUUID()
newGrant := &descr.Grant{
ID: id,
AccountID: accountID,
@@ -57,4 +58,7 @@ func TestGrant(t *testing.T) {
require.Equal(t, len(files), 1)
require.Equal(t, files[0].ID, id)
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"`
}
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
res := &CreateAccountResult{}
@@ -62,14 +62,14 @@ func (oper *Operator) CreateAccount(ctx context.Context, operatorID string, para
// GetAccount
type GetAccountParams struct {
Username string `json:"username"`
AccountID string `json:"accountId"`
Username string `json:"username"`
AccountID auxuuid.UUID `json:"accountId"`
}
type GetAccountResult struct {
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
res := &GetAccountResult{}
@@ -128,15 +128,15 @@ func (oper *Operator) GetAccount(ctx context.Context, params *GetAccountParams)
}
type UpdateAccountParams struct {
Username string `json:"username"`
AccountID string `json:"accountId"`
NewUsername string `json:"newUsername"`
NewPassword string `json:"newPassword"`
Disabled bool `json:"disabled"`
Username string `json:"username"`
AccountID auxuuid.UUID `json:"accountId"`
NewUsername string `json:"newUsername"`
NewPassword string `json:"newPassword"`
Disabled bool `json:"disabled"`
}
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
res := &UpdateAccountResult{}
if params.Username == "" && params.AccountID == "" {
@@ -195,12 +195,12 @@ func (oper *Operator) UpdateAccount(ctx context.Context, params *UpdateAccountPa
}
type DeleteAccountParams struct {
Username string `json:"username"`
AccountID string `json:"accountId"`
Username string `json:"username"`
AccountID auxuuid.UUID `json:"accountId"`
}
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
res := &DeleteAccountResult{}
+1 -1
View File
@@ -73,7 +73,7 @@ type PostUploadParams struct {
From string
}
type PostUploadResult struct {
DockerUploadUUID string
DockerUploadUUID auxuuid.UUID
Location string
ContentLength string
}
+14 -14
View File
@@ -41,9 +41,9 @@ type FileInfoResult struct {
ContentDigest string
ContentCreatedAt string
ContentCreatedBy string
ContentCreatedBy auxuuid.UUID
ContentUpdatedAt string
ContentUpdatedBy string
ContentUpdatedBy auxuuid.UUID
}
func cleanFilepath(filename string) (string, error) {
@@ -51,7 +51,7 @@ func cleanFilepath(filename string) (string, error) {
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
code := http.StatusOK
res := &FileInfoResult{}
@@ -101,7 +101,7 @@ type PutFileResult struct{}
const defaultContentType = "application/octet-stream"
// 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
res := &PutFileResult{}
@@ -147,7 +147,7 @@ func (oper *Operator) PutFile(ctx context.Context, operID string, param *PutFile
fileDescr.Checksum = checksum
fileDescr.UpdatedAt = now
fileDescr.Type = contentType
fileDescr.UpdatedBy = operID
fileDescr.UpdatedBy = operatorID
err = oper.mdb.UpdateFileByID(ctx, fileDescr.ID, fileDescr)
if err != nil {
code := http.StatusInternalServerError
@@ -163,8 +163,8 @@ func (oper *Operator) PutFile(ctx context.Context, operID string, param *PutFile
Checksum: checksum,
CreatedAt: now,
UpdatedAt: now,
CreatedBy: operID,
UpdatedBy: operID,
CreatedBy: operatorID,
UpdatedBy: operatorID,
}
err = oper.mdb.InsertFile(ctx, fileDescr)
if err != nil {
@@ -193,12 +193,12 @@ type GetFileResult struct {
Source io.ReadCloser
ContentCreatedAt string
ContentCreatedBy string
ContentCreatedBy auxuuid.UUID
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
res := &GetFileResult{}
@@ -247,7 +247,7 @@ type DeleteFileParams 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
res := &DeleteFileResult{}
code := http.StatusOK
@@ -294,7 +294,7 @@ type ListFilesResult struct {
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
res := &ListFilesResult{
Files: make([]descr.File, 0),
@@ -406,7 +406,7 @@ type ListCollectionsResult struct {
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
res := &ListCollectionsResult{
Collections: make([]string, 0),
@@ -539,7 +539,7 @@ type DeleteColletionResult struct {
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
res := &DeleteColletionResult{
Files: make([]descr.File, 0),
+17 -17
View File
@@ -12,16 +12,16 @@ import (
// CreateGrant
type CreateGrantParams struct {
AccountID string `json:"accountID"`
Username string `json:"username"`
Right string `json:"operation"`
Pattern string `json:"pattern"`
AccountID auxuuid.UUID `json:"accountID"`
Username string `json:"username"`
Right string `json:"operation"`
Pattern string `json:"pattern"`
}
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
res := &CreateGrantResult{}
@@ -86,8 +86,8 @@ func (oper *Operator) CreateGrant(ctx context.Context, operID string, params *Cr
Pattern: params.Pattern,
CreatedAt: now,
UpdatedAt: now,
CreatedBy: operID,
UpdatedBy: operID,
CreatedBy: operatorID,
UpdatedBy: operatorID,
}
err = oper.mdb.InsertGrant(ctx, grantDescr)
if err != nil {
@@ -99,12 +99,12 @@ func (oper *Operator) CreateGrant(ctx context.Context, operID string, params *Cr
// UpdateGrant
type UpdateGrantParams struct {
GrantID string
GrantID auxuuid.UUID
NewPattern string
}
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
res := &UpdateGrantResult{}
@@ -130,7 +130,7 @@ func (oper *Operator) UpdateGrant(ctx context.Context, operID string, params *Up
now := auxtool.TimeNow()
if params.NewPattern != "" {
grantDescr.UpdatedAt = now
grantDescr.UpdatedBy = operID
grantDescr.UpdatedBy = operatorID
grantDescr.Pattern = params.NewPattern
}
err = oper.mdb.UpdateGrantByID(ctx, grantDescr.ID, grantDescr)
@@ -142,11 +142,11 @@ func (oper *Operator) UpdateGrant(ctx context.Context, operID string, params *Up
// DeleteGrant
type DeleteGrantParams struct {
GrantID string `json:"grantId"`
GrantID auxuuid.UUID `json:"grantId"`
}
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
res := &DeleteGrantResult{}
@@ -176,13 +176,13 @@ func (oper *Operator) DeleteGrant(ctx context.Context, operID string, params *De
// ListGrants
type ListGrantsParams struct {
Username string
AccountID string
AccountID auxuuid.UUID
}
type ListGrantsResult struct {
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
res := &ListGrantsResult{
Grants: make([]descr.Grant, 0),
@@ -223,13 +223,13 @@ func (oper *Operator) ListGrants(ctx context.Context, operID string, params *Lis
// Get Grants
type GetGrantParams struct {
GrantID string `json:"grantId"`
GrantID auxuuid.UUID `json:"grantId"`
}
type GetGrantResult struct {
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
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 csum string
tmpname := auxuuid.NewUUID()
tmpname := string(auxuuid.NewUUID())
tmpname = fmt.Sprintf("file-%s.tmp", tmpname)
tmppath := store.makeTmppath(tmpname)