right type used

This commit is contained in:
2026-02-20 15:28:26 +02:00
parent 8546ad496f
commit 1c8f6f142c
18 changed files with 146 additions and 144 deletions
+6 -6
View File
@@ -17,8 +17,8 @@ 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"
"mstore/pkg/uuid"
) )
const ( const (
@@ -44,12 +44,12 @@ func (hand *Handler) AuthMiddleware(next router.Handler) router.Handler {
} }
// Authentification // Authentification
func (hand *Handler) CheckAccess(rctx *router.Context) (bool, auxuuid.UUID, error) { func (hand *Handler) CheckAccess(rctx *router.Context) (bool, uuid.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 auxuuid.UUID var accountID uuid.UUID
accountID = terms.AnonymousID accountID = terms.AnonymousID
@@ -80,9 +80,9 @@ anonymous:
return success, accountID, err return success, accountID, err
} }
func (hand *Handler) ValidatePassword(ctx context.Context, username, password string) (bool, auxuuid.UUID, error) { func (hand *Handler) ValidatePassword(ctx context.Context, username, password string) (bool, uuid.UUID, error) {
var err error var err error
var accountID auxuuid.UUID var accountID uuid.UUID
valid := false valid := false
accountExists, accountDescr, err := hand.mdb.GetAccountByUsername(ctx, username) accountExists, accountDescr, err := hand.mdb.GetAccountByUsername(ctx, username)
@@ -102,7 +102,7 @@ func (hand *Handler) ValidatePassword(ctx context.Context, username, password st
// Authorization // Authorization
func (hand *Handler) CheckRight(ctx context.Context, accountID auxuuid.UUID, reqRight, subject string) (bool, error) { func (hand *Handler) CheckRight(ctx context.Context, accountID uuid.UUID, reqRight terms.Right, 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)
+10 -10
View File
@@ -14,8 +14,8 @@ import (
"mstore/app/operator" "mstore/app/operator"
"mstore/app/router" "mstore/app/router"
"mstore/pkg/auxuuid"
"mstore/pkg/terms" "mstore/pkg/terms"
"mstore/pkg/uuid"
) )
// POST /v3/account/create 200 200 // POST /v3/account/create 200 200
@@ -30,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, auxuuid.UUID(operatorID), terms.RightWriteAccounts, "") opEnable, err := hand.CheckRight(rctx.Ctx, uuid.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)
@@ -42,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, auxuuid.UUID(operatorID), params) res, err := hand.oper.CreateAccount(rctx.Ctx, uuid.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)
@@ -63,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, auxuuid.UUID(operatorID), terms.RightWriteAccounts, "") opEnable, err := hand.CheckRight(rctx.Ctx, uuid.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)
@@ -75,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, auxuuid.UUID(operatorID), params) res, err := hand.oper.GetAccount(rctx.Ctx, uuid.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)
@@ -96,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, auxuuid.UUID(operatorID), terms.RightWriteAccounts, "") opEnable, err := hand.CheckRight(rctx.Ctx, uuid.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)
@@ -129,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, auxuuid.UUID(operatorID), terms.RightWriteAccounts, "") opEnable, err := hand.CheckRight(rctx.Ctx, uuid.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)
@@ -141,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, auxuuid.UUID(operatorID), params) res, err := hand.oper.UpdateAccount(rctx.Ctx, uuid.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)
@@ -162,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, auxuuid.UUID(operatorID), terms.RightWriteAccounts, params.Username) opEnable, err := hand.CheckRight(rctx.Ctx, uuid.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)
@@ -174,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, auxuuid.UUID(operatorID), params) res, err := hand.oper.DeleteAccount(rctx.Ctx, uuid.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)
+7 -7
View File
@@ -16,8 +16,8 @@ import (
"mstore/app/operator" "mstore/app/operator"
"mstore/app/router" "mstore/app/router"
"mstore/pkg/auxuuid"
"mstore/pkg/terms" "mstore/pkg/terms"
"mstore/pkg/uuid"
) )
// HEAD /v2/<name>/blobs/<digest> 200 404 // HEAD /v2/<name>/blobs/<digest> 200 404
@@ -33,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, auxuuid.UUID(operatorID), terms.RightReadImages, "") opEnable, err := hand.CheckRight(rctx.Ctx, uuid.UUID(operatorID), terms.RightReadImages, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
@@ -73,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, auxuuid.UUID(operatorID), terms.RightWriteImages, "") opEnable, err := hand.CheckRight(rctx.Ctx, uuid.UUID(operatorID), terms.RightWriteImages, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
@@ -118,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, auxuuid.UUID(operatorID), terms.RightWriteImages, "") opEnable, err := hand.CheckRight(rctx.Ctx, uuid.UUID(operatorID), terms.RightWriteImages, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
@@ -162,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, auxuuid.UUID(operatorID), terms.RightWriteImages, "") opEnable, err := hand.CheckRight(rctx.Ctx, uuid.UUID(operatorID), terms.RightWriteImages, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
@@ -192,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, auxuuid.UUID(operatorID), terms.RightReadImages, "") opEnable, err := hand.CheckRight(rctx.Ctx, uuid.UUID(operatorID), terms.RightReadImages, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
@@ -238,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, auxuuid.UUID(operatorID), terms.RightWriteImages, "") opEnable, err := hand.CheckRight(rctx.Ctx, uuid.UUID(operatorID), terms.RightWriteImages, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
+15 -15
View File
@@ -15,8 +15,8 @@ import (
"mstore/app/operator" "mstore/app/operator"
"mstore/app/router" "mstore/app/router"
"mstore/pkg/auxuuid"
"mstore/pkg/terms" "mstore/pkg/terms"
"mstore/pkg/uuid"
) )
const zeroContentLength = "0" const zeroContentLength = "0"
@@ -29,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, auxuuid.UUID(operatorID), terms.RightReadFiles, "") opEnable, err := hand.CheckRight(rctx.Ctx, uuid.UUID(operatorID), terms.RightReadFiles, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
@@ -40,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, auxuuid.UUID(operatorID), params) code, res, err := hand.oper.FileInfo(ctx, uuid.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)
@@ -74,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, auxuuid.UUID(operatorID), terms.RightWriteFiles, "") opEnable, err := hand.CheckRight(rctx.Ctx, uuid.UUID(operatorID), terms.RightWriteFiles, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
@@ -85,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, auxuuid.UUID(operatorID), params) code, _, err := hand.oper.PutFile(ctx, uuid.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)
@@ -102,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, auxuuid.UUID(operatorID), terms.RightReadFiles, "") opEnable, err := hand.CheckRight(rctx.Ctx, uuid.UUID(operatorID), terms.RightReadFiles, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
@@ -113,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, auxuuid.UUID(operatorID), params) code, res, err := hand.oper.GetFile(ctx, uuid.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)
@@ -150,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, auxuuid.UUID(operatorID), terms.RightWriteFiles, "") opEnable, err := hand.CheckRight(rctx.Ctx, uuid.UUID(operatorID), terms.RightWriteFiles, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
@@ -161,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, auxuuid.UUID(operatorID), params) code, _, err := hand.oper.DeleteFile(ctx, uuid.UUID(operatorID), params)
if err != nil { if err != nil {
hand.logg.Errorf("DeleteFIle error: %v", err) hand.logg.Errorf("DeleteFIle error: %v", err)
} }
@@ -187,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, auxuuid.UUID(operatorID), terms.RightReadFiles, "") opEnable, err := hand.CheckRight(rctx.Ctx, uuid.UUID(operatorID), terms.RightReadFiles, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
@@ -198,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, auxuuid.UUID(operatorID), params) code, res, err := hand.oper.ListFiles(ctx, uuid.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)
@@ -224,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, auxuuid.UUID(operatorID), terms.RightReadFiles, "") opEnable, err := hand.CheckRight(rctx.Ctx, uuid.UUID(operatorID), terms.RightReadFiles, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
@@ -235,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, auxuuid.UUID(operatorID), params) code, res, err := hand.oper.ListCollections(ctx, uuid.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)
@@ -262,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, auxuuid.UUID(operatorID), terms.RightReadFiles, "") opEnable, err := hand.CheckRight(rctx.Ctx, uuid.UUID(operatorID), terms.RightReadFiles, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
@@ -273,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, auxuuid.UUID(operatorID), params) code, res, err := hand.oper.DeleteColletion(ctx, uuid.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 -11
View File
@@ -14,8 +14,8 @@ import (
"mstore/app/operator" "mstore/app/operator"
"mstore/app/router" "mstore/app/router"
"mstore/pkg/auxuuid"
"mstore/pkg/terms" "mstore/pkg/terms"
"mstore/pkg/uuid"
) )
// POST /v3/grant/create 200 200 // POST /v3/grant/create 200 200
@@ -30,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, auxuuid.UUID(operatorID), terms.RightWriteAccounts, "") opEnable, err := hand.CheckRight(rctx.Ctx, uuid.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)
@@ -42,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, auxuuid.UUID(operatorID), params) res, err := hand.oper.CreateGrant(rctx.Ctx, uuid.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)
@@ -63,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, auxuuid.UUID(operatorID), terms.RightReadAccounts, "") opEnable, err := hand.CheckRight(rctx.Ctx, uuid.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)
@@ -75,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, auxuuid.UUID(operatorID), params) res, err := hand.oper.GetGrant(rctx.Ctx, uuid.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)
@@ -96,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, auxuuid.UUID(operatorID), terms.RightReadAccounts, "") opEnable, err := hand.CheckRight(rctx.Ctx, uuid.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)
@@ -108,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, auxuuid.UUID(operatorID), params) res, err := hand.oper.ListGrants(rctx.Ctx, uuid.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)
@@ -129,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, auxuuid.UUID(operatorID), terms.RightWriteAccounts, "") opEnable, err := hand.CheckRight(rctx.Ctx, uuid.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)
@@ -141,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, auxuuid.UUID(operatorID), params) res, err := hand.oper.UpdateGrant(rctx.Ctx, uuid.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)
@@ -162,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, auxuuid.UUID(operatorID), terms.RightWriteAccounts, "") opEnable, err := hand.CheckRight(rctx.Ctx, uuid.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)
@@ -174,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, auxuuid.UUID(operatorID), params) res, err := hand.oper.DeleteGrant(rctx.Ctx, uuid.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 -7
View File
@@ -14,8 +14,8 @@ import (
"mstore/app/operator" "mstore/app/operator"
"mstore/app/router" "mstore/app/router"
"mstore/pkg/auxuuid"
"mstore/pkg/terms" "mstore/pkg/terms"
"mstore/pkg/uuid"
) )
func (hand *Handler) ManifestExists(rctx *router.Context) { func (hand *Handler) ManifestExists(rctx *router.Context) {
@@ -30,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, auxuuid.UUID(operatorID), terms.RightReadImages, "") opEnable, err := hand.CheckRight(rctx.Ctx, uuid.UUID(operatorID), terms.RightReadImages, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
@@ -72,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, auxuuid.UUID(operatorID), terms.RightWriteImages, "") opEnable, err := hand.CheckRight(rctx.Ctx, uuid.UUID(operatorID), terms.RightWriteImages, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
@@ -105,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, auxuuid.UUID(operatorID), terms.RightReadImages, "") opEnable, err := hand.CheckRight(rctx.Ctx, uuid.UUID(operatorID), terms.RightReadImages, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
@@ -145,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, auxuuid.UUID(operatorID), terms.RightWriteImages, "") opEnable, err := hand.CheckRight(rctx.Ctx, uuid.UUID(operatorID), terms.RightWriteImages, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
@@ -174,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, auxuuid.UUID(operatorID), terms.RightReadImages, "") opEnable, err := hand.CheckRight(rctx.Ctx, uuid.UUID(operatorID), terms.RightReadImages, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
@@ -200,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, auxuuid.UUID(operatorID), terms.RightReadImages, "") opEnable, err := hand.CheckRight(rctx.Ctx, uuid.UUID(operatorID), terms.RightReadImages, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
+4 -4
View File
@@ -3,8 +3,8 @@ package maindb
import ( import (
"context" "context"
"mstore/pkg/auxuuid"
"mstore/pkg/descr" "mstore/pkg/descr"
"mstore/pkg/uuid"
) )
func (db *Database) InsertAccount(ctx context.Context, account *descr.Account) error { func (db *Database) InsertAccount(ctx context.Context, account *descr.Account) error {
@@ -20,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 auxuuid.UUID, account *descr.Account) error { func (db *Database) UpdateAccountByID(ctx context.Context, accountID uuid.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)
@@ -52,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 auxuuid.UUID) (bool, *descr.Account, error) { func (db *Database) GetAccountByID(ctx context.Context, accountID uuid.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
@@ -91,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 auxuuid.UUID) error { func (db *Database) DeleteAccountByID(ctx context.Context, accountID uuid.UUID) error {
var err error var err error
request := `DELETE FROM accounts WHERE id = $1` request := `DELETE FROM accounts WHERE id = $1`
+2 -2
View File
@@ -12,8 +12,8 @@ package maindb
import ( import (
"context" "context"
"mstore/pkg/auxuuid"
"mstore/pkg/descr" "mstore/pkg/descr"
"mstore/pkg/uuid"
) )
func (db *Database) InsertFile(ctx context.Context, file *descr.File) error { func (db *Database) InsertFile(ctx context.Context, file *descr.File) error {
@@ -28,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 auxuuid.UUID, file *descr.File) error { func (db *Database) UpdateFileByID(ctx context.Context, fileID uuid.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
+3 -3
View File
@@ -15,8 +15,8 @@ import (
"time" "time"
"mstore/pkg/auxtool" "mstore/pkg/auxtool"
"mstore/pkg/auxuuid"
"mstore/pkg/descr" "mstore/pkg/descr"
"mstore/pkg/uuid"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@@ -33,9 +33,9 @@ func TestFile(t *testing.T) {
err = db.InitDatabase() err = db.InitDatabase()
require.NoError(t, err) require.NoError(t, err)
id := auxuuid.NewUUID() id := uuid.NewUUID()
timenow := auxtool.TimeNow() timenow := auxtool.TimeNow()
creator := auxuuid.NewUUID() creator := uuid.NewUUID()
collection := "foo" collection := "foo"
newFile := &descr.File{ newFile := &descr.File{
ID: id, ID: id,
+11 -10
View File
@@ -12,8 +12,9 @@ package maindb
import ( import (
"context" "context"
"mstore/pkg/auxuuid"
"mstore/pkg/descr" "mstore/pkg/descr"
"mstore/pkg/terms"
"mstore/pkg/uuid"
) )
func (db *Database) InsertGrant(ctx context.Context, grant *descr.Grant) error { func (db *Database) InsertGrant(ctx context.Context, grant *descr.Grant) error {
@@ -28,7 +29,7 @@ func (db *Database) InsertGrant(ctx context.Context, grant *descr.Grant) error {
return err return err
} }
func (db *Database) UpdateGrantByID(ctx context.Context, grantID auxuuid.UUID, grant *descr.Grant) error { func (db *Database) UpdateGrantByID(ctx context.Context, grantID uuid.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)
@@ -38,7 +39,7 @@ func (db *Database) UpdateGrantByID(ctx context.Context, grantID auxuuid.UUID, g
return err return err
} }
func (db *Database) ListGrantsByAccountID(ctx context.Context, accountID auxuuid.UUID) ([]descr.Grant, error) { func (db *Database) ListGrantsByAccountID(ctx context.Context, accountID uuid.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)
@@ -60,7 +61,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 auxuuid.UUID) (bool, *descr.Grant, error) { func (db *Database) GetGrantByID(ctx context.Context, id uuid.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`
@@ -77,7 +78,7 @@ func (db *Database) GetGrantByID(ctx context.Context, id auxuuid.UUID) (bool, *d
return true, res, err return true, res, err
} }
func (db *Database) GetGrantByAccoundIDRight(ctx context.Context, accountID auxuuid.UUID, right string) (bool, *descr.Grant, error) { func (db *Database) GetGrantByAccoundIDRight(ctx context.Context, accountID uuid.UUID, right terms.Right) (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`
@@ -94,7 +95,7 @@ func (db *Database) GetGrantByAccoundIDRight(ctx context.Context, accountID auxu
return true, res, err return true, res, err
} }
func (db *Database) ListGrantsByAccoundIDRight(ctx context.Context, accountID auxuuid.UUID, right string) (bool, []descr.Grant, error) { func (db *Database) ListGrantsByAccoundIDRight(ctx context.Context, accountID uuid.UUID, right terms.Right) (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)
@@ -108,7 +109,7 @@ func (db *Database) ListGrantsByAccoundIDRight(ctx context.Context, accountID au
return true, res, err return true, res, err
} }
func (db *Database) GetGrantByAccoundIDRightPattern(ctx context.Context, accountID auxuuid.UUID, right, pattern string) (bool, *descr.Grant, error) { func (db *Database) GetGrantByAccoundIDRightPattern(ctx context.Context, accountID uuid.UUID, right terms.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`
@@ -125,7 +126,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 auxuuid.UUID, right, pattern string) error { func (db *Database) DeleteGrantByAccountIDRightPattern(ctx context.Context, accountID uuid.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)
@@ -135,7 +136,7 @@ func (db *Database) DeleteGrantByAccountIDRightPattern(ctx context.Context, acco
return err return err
} }
func (db *Database) DeleteGrantByID(ctx context.Context, grantID auxuuid.UUID) error { func (db *Database) DeleteGrantByID(ctx context.Context, grantID uuid.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)
@@ -145,7 +146,7 @@ func (db *Database) DeleteGrantByID(ctx context.Context, grantID auxuuid.UUID) e
return err return err
} }
func (db *Database) DeleteAllGrantsForAccountID(ctx context.Context, grantID auxuuid.UUID) error { func (db *Database) DeleteAllGrantsForAccountID(ctx context.Context, grantID uuid.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)
+4 -4
View File
@@ -16,8 +16,8 @@ import (
"time" "time"
"mstore/pkg/auxtool" "mstore/pkg/auxtool"
"mstore/pkg/auxuuid"
"mstore/pkg/descr" "mstore/pkg/descr"
"mstore/pkg/uuid"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@@ -34,10 +34,10 @@ func TestGrant(t *testing.T) {
err = db.InitDatabase() err = db.InitDatabase()
require.NoError(t, err) require.NoError(t, err)
id := auxuuid.NewUUID() id := uuid.NewUUID()
accountID := auxuuid.NewUUID() accountID := uuid.NewUUID()
timenow := auxtool.TimeNow() timenow := auxtool.TimeNow()
creator := auxuuid.NewUUID() creator := uuid.NewUUID()
newGrant := &descr.Grant{ newGrant := &descr.Grant{
ID: id, ID: id,
AccountID: accountID, AccountID: accountID,
+9 -9
View File
@@ -15,9 +15,9 @@ import (
"mstore/pkg/auxpwd" "mstore/pkg/auxpwd"
"mstore/pkg/auxtool" "mstore/pkg/auxtool"
"mstore/pkg/auxuuid"
"mstore/pkg/descr" "mstore/pkg/descr"
"mstore/pkg/terms" "mstore/pkg/terms"
"mstore/pkg/uuid"
) )
func (db *Database) WriteAnonymous(ctx context.Context) error { func (db *Database) WriteAnonymous(ctx context.Context) error {
@@ -41,7 +41,7 @@ func (db *Database) WriteAnonymous(ctx context.Context) error {
return err return err
} }
grantDescr := &descr.Grant{ grantDescr := &descr.Grant{
ID: auxuuid.NewUUID(), ID: uuid.NewUUID(),
AccountID: accountDescr.ID, AccountID: accountDescr.ID,
Right: terms.RightReadFiles, Right: terms.RightReadFiles,
Pattern: ".*", Pattern: ".*",
@@ -55,7 +55,7 @@ func (db *Database) WriteAnonymous(ctx context.Context) error {
return err return err
} }
grantDescr = &descr.Grant{ grantDescr = &descr.Grant{
ID: auxuuid.NewUUID(), ID: uuid.NewUUID(),
AccountID: accountDescr.ID, AccountID: accountDescr.ID,
Right: terms.RightReadImages, Right: terms.RightReadImages,
Pattern: ".*", Pattern: ".*",
@@ -93,7 +93,7 @@ func (db *Database) WriteInituser(ctx context.Context) error {
} }
// Files // Files
grantDescr := &descr.Grant{ grantDescr := &descr.Grant{
ID: auxuuid.NewUUID(), ID: uuid.NewUUID(),
AccountID: accountDescr.ID, AccountID: accountDescr.ID,
Right: terms.RightReadFiles, Right: terms.RightReadFiles,
Pattern: ".*", Pattern: ".*",
@@ -107,7 +107,7 @@ func (db *Database) WriteInituser(ctx context.Context) error {
return err return err
} }
grantDescr = &descr.Grant{ grantDescr = &descr.Grant{
ID: auxuuid.NewUUID(), ID: uuid.NewUUID(),
AccountID: accountDescr.ID, AccountID: accountDescr.ID,
Right: terms.RightWriteFiles, Right: terms.RightWriteFiles,
Pattern: ".*", Pattern: ".*",
@@ -122,7 +122,7 @@ func (db *Database) WriteInituser(ctx context.Context) error {
} }
// Accounts // Accounts
grantDescr = &descr.Grant{ grantDescr = &descr.Grant{
ID: auxuuid.NewUUID(), ID: uuid.NewUUID(),
AccountID: accountDescr.ID, AccountID: accountDescr.ID,
Right: terms.RightReadAccounts, Right: terms.RightReadAccounts,
Pattern: ".*", Pattern: ".*",
@@ -136,7 +136,7 @@ func (db *Database) WriteInituser(ctx context.Context) error {
return err return err
} }
grantDescr = &descr.Grant{ grantDescr = &descr.Grant{
ID: auxuuid.NewUUID(), ID: uuid.NewUUID(),
AccountID: accountDescr.ID, AccountID: accountDescr.ID,
Right: terms.RightWriteAccounts, Right: terms.RightWriteAccounts,
Pattern: ".*", Pattern: ".*",
@@ -151,7 +151,7 @@ func (db *Database) WriteInituser(ctx context.Context) error {
} }
// Images // Images
grantDescr = &descr.Grant{ grantDescr = &descr.Grant{
ID: auxuuid.NewUUID(), ID: uuid.NewUUID(),
AccountID: accountDescr.ID, AccountID: accountDescr.ID,
Right: terms.RightReadImages, Right: terms.RightReadImages,
Pattern: ".*", Pattern: ".*",
@@ -165,7 +165,7 @@ func (db *Database) WriteInituser(ctx context.Context) error {
return err return err
} }
grantDescr = &descr.Grant{ grantDescr = &descr.Grant{
ID: auxuuid.NewUUID(), ID: uuid.NewUUID(),
AccountID: accountDescr.ID, AccountID: accountDescr.ID,
Right: terms.RightWriteImages, Right: terms.RightWriteImages,
Pattern: ".*", Pattern: ".*",
+16 -16
View File
@@ -6,8 +6,8 @@ import (
"mstore/pkg/auxpwd" "mstore/pkg/auxpwd"
"mstore/pkg/auxtool" "mstore/pkg/auxtool"
"mstore/pkg/auxuuid"
"mstore/pkg/descr" "mstore/pkg/descr"
"mstore/pkg/uuid"
) )
type CreateAccountParams struct { type CreateAccountParams struct {
@@ -15,10 +15,10 @@ type CreateAccountParams struct {
Password string `json:"password"` Password string `json:"password"`
} }
type CreateAccountResult struct { type CreateAccountResult struct {
AccountID auxuuid.UUID `json:"accountId"` AccountID uuid.UUID `json:"accountId"`
} }
func (oper *Operator) CreateAccount(ctx context.Context, operatorID auxuuid.UUID, params *CreateAccountParams) (*CreateAccountResult, error) { func (oper *Operator) CreateAccount(ctx context.Context, operatorID uuid.UUID, params *CreateAccountParams) (*CreateAccountResult, error) {
var err error var err error
res := &CreateAccountResult{} res := &CreateAccountResult{}
@@ -43,7 +43,7 @@ func (oper *Operator) CreateAccount(ctx context.Context, operatorID auxuuid.UUID
now := auxtool.TimeNow() now := auxtool.TimeNow()
passhash := auxpwd.MakeSHA256Hash([]byte(params.Password)) passhash := auxpwd.MakeSHA256Hash([]byte(params.Password))
accountDescr := &descr.Account{ accountDescr := &descr.Account{
ID: auxuuid.NewUUID(), ID: uuid.NewUUID(),
Username: params.Username, Username: params.Username,
Passhash: passhash, Passhash: passhash,
Disabled: false, Disabled: false,
@@ -62,14 +62,14 @@ func (oper *Operator) CreateAccount(ctx context.Context, operatorID auxuuid.UUID
// GetAccount // GetAccount
type GetAccountParams struct { type GetAccountParams struct {
Username string `json:"username"` Username string `json:"username"`
AccountID auxuuid.UUID `json:"accountId"` AccountID uuid.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, operatorID auxuuid.UUID, params *GetAccountParams) (*GetAccountResult, error) { func (oper *Operator) GetAccount(ctx context.Context, operatorID uuid.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, operatorID auxuuid.UUID, p
} }
type UpdateAccountParams struct { type UpdateAccountParams struct {
Username string `json:"username"` Username string `json:"username"`
AccountID auxuuid.UUID `json:"accountId"` AccountID uuid.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, operatorID auxuuid.UUID, params *UpdateAccountParams) (*UpdateAccountResult, error) { func (oper *Operator) UpdateAccount(ctx context.Context, operatorID uuid.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, operatorID auxuuid.UUID
} }
type DeleteAccountParams struct { type DeleteAccountParams struct {
Username string `json:"username"` Username string `json:"username"`
AccountID auxuuid.UUID `json:"accountId"` AccountID uuid.UUID `json:"accountId"`
} }
type DeleteAccountResult struct{} type DeleteAccountResult struct{}
func (oper *Operator) DeleteAccount(ctx context.Context, operatorID auxuuid.UUID, params *DeleteAccountParams) (*DeleteAccountResult, error) { func (oper *Operator) DeleteAccount(ctx context.Context, operatorID uuid.UUID, params *DeleteAccountParams) (*DeleteAccountResult, error) {
var err error var err error
res := &DeleteAccountResult{} res := &DeleteAccountResult{}
+3 -3
View File
@@ -16,7 +16,7 @@ import (
"net/http" "net/http"
"strconv" "strconv"
"mstore/pkg/auxuuid" "mstore/pkg/uuid"
) )
type BlobExistsParams struct { type BlobExistsParams struct {
@@ -73,7 +73,7 @@ type PostUploadParams struct {
From string From string
} }
type PostUploadResult struct { type PostUploadResult struct {
DockerUploadUUID auxuuid.UUID DockerUploadUUID uuid.UUID
Location string Location string
ContentLength string ContentLength string
} }
@@ -83,7 +83,7 @@ func (oper *Operator) PostUpload(ctx context.Context, params *PostUploadParams)
res := &PostUploadResult{} res := &PostUploadResult{}
if params.Digest == "" { if params.Digest == "" {
uuid := auxuuid.NewUUID() uuid := uuid.NewUUID()
location := fmt.Sprintf("/v2/%s/blobs/uploads/%s", params.Name, uuid) location := fmt.Sprintf("/v2/%s/blobs/uploads/%s", params.Name, uuid)
res.DockerUploadUUID = uuid res.DockerUploadUUID = uuid
res.Location = location res.Location = location
+13 -13
View File
@@ -22,9 +22,9 @@ import (
"strings" "strings"
"mstore/pkg/auxtool" "mstore/pkg/auxtool"
"mstore/pkg/auxuuid"
"mstore/pkg/descr" "mstore/pkg/descr"
"mstore/pkg/terms" "mstore/pkg/terms"
"mstore/pkg/uuid"
) )
// FileInfo // FileInfo
@@ -41,9 +41,9 @@ type FileInfoResult struct {
ContentDigest string ContentDigest string
ContentCreatedAt string ContentCreatedAt string
ContentCreatedBy auxuuid.UUID ContentCreatedBy uuid.UUID
ContentUpdatedAt string ContentUpdatedAt string
ContentUpdatedBy auxuuid.UUID ContentUpdatedBy uuid.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, operatorID auxuuid.UUID, param *FileInfoParams) (int, *FileInfoResult, error) { func (oper *Operator) FileInfo(ctx context.Context, operatorID uuid.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, operatorID auxuuid.UUID, param *PutFileParams) (int, *PutFileResult, error) { func (oper *Operator) PutFile(ctx context.Context, operatorID uuid.UUID, param *PutFileParams) (int, *PutFileResult, error) {
var err error var err error
res := &PutFileResult{} res := &PutFileResult{}
@@ -155,7 +155,7 @@ func (oper *Operator) PutFile(ctx context.Context, operatorID auxuuid.UUID, para
} }
} else { } else {
fileDescr = &descr.File{ fileDescr = &descr.File{
ID: auxuuid.NewUUID(), ID: uuid.NewUUID(),
Name: filename, Name: filename,
Collection: collection, Collection: collection,
Size: size, Size: size,
@@ -193,12 +193,12 @@ type GetFileResult struct {
Source io.ReadCloser Source io.ReadCloser
ContentCreatedAt string ContentCreatedAt string
ContentCreatedBy auxuuid.UUID ContentCreatedBy uuid.UUID
ContentUpdatedAt string ContentUpdatedAt string
ContentUpdatedBy auxuuid.UUID ContentUpdatedBy uuid.UUID
} }
func (oper *Operator) GetFile(ctx context.Context, operatorID auxuuid.UUID, param *GetFileParams) (int, *GetFileResult, error) { func (oper *Operator) GetFile(ctx context.Context, operatorID uuid.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, operatorID auxuuid.UUID, param *DeleteFileParams) (int, *DeleteFileResult, error) { func (oper *Operator) DeleteFile(ctx context.Context, operatorID uuid.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, operatorID auxuuid.UUID, params *ListFilesParams) (int, *ListFilesResult, error) { func (oper *Operator) ListFiles(ctx context.Context, operatorID uuid.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, operatorID auxuuid.UUID, param *ListCollectionsParams) (int, *ListCollectionsResult, error) { func (oper *Operator) ListCollections(ctx context.Context, operatorID uuid.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, operatorID auxuuid.UUID, param *DeleteColletionParams) (int, *DeleteColletionResult, error) { func (oper *Operator) DeleteColletion(ctx context.Context, operatorID uuid.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 -16
View File
@@ -6,22 +6,23 @@ import (
"regexp" "regexp"
"mstore/pkg/auxtool" "mstore/pkg/auxtool"
"mstore/pkg/auxuuid"
"mstore/pkg/descr" "mstore/pkg/descr"
"mstore/pkg/terms"
"mstore/pkg/uuid"
) )
// CreateGrant // CreateGrant
type CreateGrantParams struct { type CreateGrantParams struct {
AccountID auxuuid.UUID `json:"accountID"` AccountID uuid.UUID `json:"accountID"`
Username string `json:"username"` Username string `json:"username"`
Right string `json:"operation"` Right terms.Right `json:"operation"`
Pattern string `json:"pattern"` Pattern string `json:"pattern"`
} }
type CreateGrantResult struct { type CreateGrantResult struct {
GrantID auxuuid.UUID `json:"grantId"` GrantID uuid.UUID `json:"grantId"`
} }
func (oper *Operator) CreateGrant(ctx context.Context, operatorID auxuuid.UUID, params *CreateGrantParams) (*CreateGrantResult, error) { func (oper *Operator) CreateGrant(ctx context.Context, operatorID uuid.UUID, params *CreateGrantParams) (*CreateGrantResult, error) {
var err error var err error
res := &CreateGrantResult{} res := &CreateGrantResult{}
@@ -80,7 +81,7 @@ func (oper *Operator) CreateGrant(ctx context.Context, operatorID auxuuid.UUID,
oper.logg.Debugf("Call CreateGrant") oper.logg.Debugf("Call CreateGrant")
now := auxtool.TimeNow() now := auxtool.TimeNow()
grantDescr := &descr.Grant{ grantDescr := &descr.Grant{
ID: auxuuid.NewUUID(), ID: uuid.NewUUID(),
AccountID: accountDescr.ID, AccountID: accountDescr.ID,
Right: params.Right, Right: params.Right,
Pattern: params.Pattern, Pattern: params.Pattern,
@@ -99,12 +100,12 @@ func (oper *Operator) CreateGrant(ctx context.Context, operatorID auxuuid.UUID,
// UpdateGrant // UpdateGrant
type UpdateGrantParams struct { type UpdateGrantParams struct {
GrantID auxuuid.UUID GrantID uuid.UUID
NewPattern string NewPattern string
} }
type UpdateGrantResult struct{} type UpdateGrantResult struct{}
func (oper *Operator) UpdateGrant(ctx context.Context, operatorID auxuuid.UUID, params *UpdateGrantParams) (*UpdateGrantResult, error) { func (oper *Operator) UpdateGrant(ctx context.Context, operatorID uuid.UUID, params *UpdateGrantParams) (*UpdateGrantResult, error) {
var err error var err error
res := &UpdateGrantResult{} res := &UpdateGrantResult{}
@@ -142,11 +143,11 @@ func (oper *Operator) UpdateGrant(ctx context.Context, operatorID auxuuid.UUID,
// DeleteGrant // DeleteGrant
type DeleteGrantParams struct { type DeleteGrantParams struct {
GrantID auxuuid.UUID `json:"grantId"` GrantID uuid.UUID `json:"grantId"`
} }
type DeleteGrantResult struct{} type DeleteGrantResult struct{}
func (oper *Operator) DeleteGrant(ctx context.Context, operatorID auxuuid.UUID, params *DeleteGrantParams) (*DeleteGrantResult, error) { func (oper *Operator) DeleteGrant(ctx context.Context, operatorID uuid.UUID, params *DeleteGrantParams) (*DeleteGrantResult, error) {
var err error var err error
res := &DeleteGrantResult{} res := &DeleteGrantResult{}
@@ -176,13 +177,13 @@ func (oper *Operator) DeleteGrant(ctx context.Context, operatorID auxuuid.UUID,
// ListGrants // ListGrants
type ListGrantsParams struct { type ListGrantsParams struct {
Username string Username string
AccountID auxuuid.UUID AccountID uuid.UUID
} }
type ListGrantsResult struct { type ListGrantsResult struct {
Grants []descr.Grant `json:"grants"` Grants []descr.Grant `json:"grants"`
} }
func (oper *Operator) ListGrants(ctx context.Context, operatorID auxuuid.UUID, params *ListGrantsParams) (*ListGrantsResult, error) { func (oper *Operator) ListGrants(ctx context.Context, operatorID uuid.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 +224,13 @@ func (oper *Operator) ListGrants(ctx context.Context, operatorID auxuuid.UUID, p
// Get Grants // Get Grants
type GetGrantParams struct { type GetGrantParams struct {
GrantID auxuuid.UUID `json:"grantId"` GrantID uuid.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, operatorID auxuuid.UUID, params *GetGrantParams) (*GetGrantResult, error) { func (oper *Operator) GetGrant(ctx context.Context, operatorID uuid.UUID, params *GetGrantParams) (*GetGrantResult, error) {
var err error var err error
res := &GetGrantResult{} res := &GetGrantResult{}
+6 -6
View File
@@ -11,8 +11,8 @@ package operator
import ( import (
"mstore/pkg/auxtool" "mstore/pkg/auxtool"
"mstore/pkg/auxuuid"
"mstore/pkg/descr" "mstore/pkg/descr"
"mstore/pkg/uuid"
ocidigest "github.com/opencontainers/go-digest" ocidigest "github.com/opencontainers/go-digest"
ocispec "github.com/opencontainers/image-spec/specs-go/v1" ocispec "github.com/opencontainers/image-spec/specs-go/v1"
@@ -29,7 +29,7 @@ func descrsFromManifest(name, reference string, manifest *ocispec.Manifest, rawM
// Make manifest descriptor // Make manifest descriptor
manifestDigest := ocidigest.SHA256.FromBytes(rawManifest).String() manifestDigest := ocidigest.SHA256.FromBytes(rawManifest).String()
manifestDescr = descr.Manifest{ manifestDescr = descr.Manifest{
ID: auxuuid.NewUUID(), ID: uuid.NewUUID(),
Name: name, Name: name,
Reference: reference, Reference: reference,
Digest: manifestDigest, Digest: manifestDigest,
@@ -41,7 +41,7 @@ func descrsFromManifest(name, reference string, manifest *ocispec.Manifest, rawM
// Make config descriptor // Make config descriptor
ociConfig := manifest.Config ociConfig := manifest.Config
configDescr := descr.Blob{ configDescr := descr.Blob{
ID: auxuuid.NewUUID(), ID: uuid.NewUUID(),
Name: name, Name: name,
Reference: reference, Reference: reference,
MediaType: ociConfig.MediaType, MediaType: ociConfig.MediaType,
@@ -55,7 +55,7 @@ func descrsFromManifest(name, reference string, manifest *ocispec.Manifest, rawM
layerMap := make(map[string]bool) layerMap := make(map[string]bool)
for _, layer := range manifest.Layers { for _, layer := range manifest.Layers {
blobDescr := descr.Blob{ blobDescr := descr.Blob{
ID: auxuuid.NewUUID(), ID: uuid.NewUUID(),
Name: name, Name: name,
Reference: reference, Reference: reference,
MediaType: layer.MediaType, MediaType: layer.MediaType,
@@ -112,7 +112,7 @@ func layersDiff(name, reference string, existingManifest, incomingManifest *ocis
timestamp := auxtool.TimeNow() timestamp := auxtool.TimeNow()
for _, layer := range newLayers { for _, layer := range newLayers {
blobDescr := descr.Blob{ blobDescr := descr.Blob{
ID: auxuuid.NewUUID(), ID: uuid.NewUUID(),
Name: name, Name: name,
Reference: reference, Reference: reference,
MediaType: layer.MediaType, MediaType: layer.MediaType,
@@ -126,7 +126,7 @@ func layersDiff(name, reference string, existingManifest, incomingManifest *ocis
// Converting to old blobs // Converting to old blobs
for _, layer := range delLayers { for _, layer := range delLayers {
blobDescr := descr.Blob{ blobDescr := descr.Blob{
ID: auxuuid.NewUUID(), ID: uuid.NewUUID(),
Name: name, Name: name,
Reference: reference, Reference: reference,
MediaType: layer.MediaType, MediaType: layer.MediaType,
+2 -2
View File
@@ -20,7 +20,7 @@ import (
"path/filepath" "path/filepath"
"mstore/app/logger" "mstore/app/logger"
"mstore/pkg/auxuuid" "mstore/pkg/uuid"
) )
const ( const (
@@ -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 := string(auxuuid.NewUUID()) tmpname := string(uuid.NewUUID())
tmpname = fmt.Sprintf("file-%s.tmp", tmpname) tmpname = fmt.Sprintf("file-%s.tmp", tmpname)
tmppath := store.makeTmppath(tmpname) tmppath := store.makeTmppath(tmpname)