diff --git a/Makefile.am b/Makefile.am index a826107..5323605 100644 --- a/Makefile.am +++ b/Makefile.am @@ -34,7 +34,6 @@ EXTRA_mstored_SOURCES = \ pkg/descr/file.go \ pkg/descr/grant.go \ pkg/descr/manifest.go \ - pkg/descr/response.go \ pkg/descr/server.go \ \ app/handler/aaafunc.go \ @@ -107,6 +106,7 @@ EXTRA_mstored_SOURCES = \ pkg/client/service.go EXTRA_DIST = vendor/ \ + \ Containerfile \ go.mod \ go.sum \ @@ -171,7 +171,8 @@ EXTRA_DIST = vendor/ \ format: - @dirs=$$($(FIND) $(CWD) -name '*.go' | $(XARGS) -n1 dirname | $(SORT) | $(UNIQ)); \ + @dirs=$$($(FIND) $(CWD)/app $(CWD)/cmd $(CWD)/pkg $(CWD)/test \ + -name '*.go' | $(XARGS) -n1 dirname | $(SORT) | $(UNIQ)); \ for dir in $$dirs;do \ (echo "====$$dir===="; cd $$dir && $(GO) fmt .); \ done diff --git a/Makefile.in b/Makefile.in index 7783dae..b78ae09 100644 --- a/Makefile.in +++ b/Makefile.in @@ -329,7 +329,6 @@ EXTRA_mstored_SOURCES = \ pkg/descr/file.go \ pkg/descr/grant.go \ pkg/descr/manifest.go \ - pkg/descr/response.go \ pkg/descr/server.go \ \ app/handler/aaafunc.go \ @@ -402,6 +401,7 @@ EXTRA_mstored_SOURCES = \ pkg/client/service.go EXTRA_DIST = vendor/ \ + \ Containerfile \ go.mod \ go.sum \ @@ -987,7 +987,8 @@ run: $(mstored_SOURCES) cd cmd/mstored && env CGO_ENABLED=1 $(GO) run . -daemon=false format: - @dirs=$$($(FIND) $(CWD) -name '*.go' | $(XARGS) -n1 dirname | $(SORT) | $(UNIQ)); \ + @dirs=$$($(FIND) $(CWD)/app $(CWD)/cmd $(CWD)/pkg $(CWD)/test \ + -name '*.go' | $(XARGS) -n1 dirname | $(SORT) | $(UNIQ)); \ for dir in $$dirs;do \ (echo "====$$dir===="; cd $$dir && $(GO) fmt .); \ done diff --git a/app/handler/aaafunc.go b/app/handler/aaafunc.go index 4a33d0b..1cbc20e 100644 --- a/app/handler/aaafunc.go +++ b/app/handler/aaafunc.go @@ -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 } diff --git a/app/handler/account.go b/app/handler/account.go index 8114d84..20c32c9 100644 --- a/app/handler/account.go +++ b/app/handler/account.go @@ -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) diff --git a/app/handler/blob.go b/app/handler/blob.go index f71aae9..162a195 100644 --- a/app/handler/blob.go +++ b/app/handler/blob.go @@ -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 diff --git a/app/handler/file.go b/app/handler/file.go index 8444ae5..942253b 100644 --- a/app/handler/file.go +++ b/app/handler/file.go @@ -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) diff --git a/app/handler/grant.go b/app/handler/grant.go index 7445c0a..14c11f2 100644 --- a/app/handler/grant.go +++ b/app/handler/grant.go @@ -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) diff --git a/app/handler/manifest.go b/app/handler/manifest.go index 9ab899b..c04c061 100644 --- a/app/handler/manifest.go +++ b/app/handler/manifest.go @@ -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 diff --git a/app/maindb/account.go b/app/maindb/account.go index 56e613d..b9afc55 100644 --- a/app/maindb/account.go +++ b/app/maindb/account.go @@ -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` diff --git a/app/maindb/file.go b/app/maindb/file.go index 2ccb22d..2722b50 100644 --- a/app/maindb/file.go +++ b/app/maindb/file.go @@ -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 diff --git a/app/maindb/file_test.go b/app/maindb/file_test.go index a571ec4..30ff1a3 100644 --- a/app/maindb/file_test.go +++ b/app/maindb/file_test.go @@ -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, diff --git a/app/maindb/grant.go b/app/maindb/grant.go index 4df4c40..24849cd 100644 --- a/app/maindb/grant.go +++ b/app/maindb/grant.go @@ -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) diff --git a/app/maindb/grant_test.go b/app/maindb/grant_test.go index bdbd03d..884336c 100644 --- a/app/maindb/grant_test.go +++ b/app/maindb/grant_test.go @@ -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) + } diff --git a/app/operator/account.go b/app/operator/account.go index f6fc47d..3a34f9f 100644 --- a/app/operator/account.go +++ b/app/operator/account.go @@ -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{} diff --git a/app/operator/blob.go b/app/operator/blob.go index 68c9ef0..1f00ce4 100644 --- a/app/operator/blob.go +++ b/app/operator/blob.go @@ -73,7 +73,7 @@ type PostUploadParams struct { From string } type PostUploadResult struct { - DockerUploadUUID string + DockerUploadUUID auxuuid.UUID Location string ContentLength string } diff --git a/app/operator/file.go b/app/operator/file.go index 18af2c5..bee6231 100644 --- a/app/operator/file.go +++ b/app/operator/file.go @@ -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), diff --git a/app/operator/grant.go b/app/operator/grant.go index c217cd2..191900b 100644 --- a/app/operator/grant.go +++ b/app/operator/grant.go @@ -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{} diff --git a/app/storage/storage.go b/app/storage/storage.go index c5bb1c0..1626aed 100644 --- a/app/storage/storage.go +++ b/app/storage/storage.go @@ -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) diff --git a/cmd/mstorectl/accountcmd.go b/cmd/mstorectl/accountcmd.go index 8330c1f..b956107 100644 --- a/cmd/mstorectl/accountcmd.go +++ b/cmd/mstorectl/accountcmd.go @@ -18,6 +18,7 @@ import ( "github.com/spf13/cobra" "github.com/spf13/viper" + "mstore/pkg/auxuuid" "mstore/pkg/client" "mstore/pkg/descr" "mstore/pkg/terms" @@ -125,8 +126,8 @@ type CreateAccountParams struct { NewPassword string } type CreateAccountResult struct { - AccountID string `yaml:"accountId"` - Grants map[string]string `yaml:"grantsIds,omitempty"` + AccountID auxuuid.UUID `yaml:"accountId"` + Grants map[auxuuid.UUID]string `yaml:"grantsIds,omitempty"` } func (util *AccountUtil) CreateAccount(cmd *cobra.Command, args []string) { @@ -140,7 +141,7 @@ func (util *AccountUtil) CreateAccount(cmd *cobra.Command, args []string) { func (util *AccountUtil) createAccount(common *CommonAccountParams, params *CreateAccountParams) (*CreateAccountResult, error) { var err error res := &CreateAccountResult{ - Grants: make(map[string]string, 0), + Grants: make(map[auxuuid.UUID]string, 0), } hostname, err := packUserinfo(common.Hostname, common.Username, common.Password) if err != nil { @@ -202,7 +203,7 @@ func (util *AccountUtil) updateAccount(common *CommonAccountParams, params *Upda re := regexp.MustCompile(uuidRegex) id := strings.ToLower(params.AccountID) if re.MatchString(id) { - err = client.NewClient().UpdateAccountByID(ctx, hostname, id, params.NewUsername, params.NewPassword) + err = client.NewClient().UpdateAccountByID(ctx, hostname, auxuuid.UUID(id), params.NewUsername, params.NewPassword) } else { err = client.NewClient().UpdateAccountByName(ctx, hostname, params.AccountID, params.NewUsername, params.NewPassword) } @@ -243,7 +244,7 @@ func (util *AccountUtil) getAccount(common *CommonAccountParams, params *GetAcco re := regexp.MustCompile(uuidRegex) id := strings.ToLower(params.AccountID) if re.MatchString(id) { - opRes, err = client.NewClient().GetAccountByID(ctx, hostname, id) + opRes, err = client.NewClient().GetAccountByID(ctx, hostname, auxuuid.UUID(id)) } else { opRes, err = client.NewClient().GetAccountByName(ctx, hostname, params.AccountID) } @@ -280,7 +281,7 @@ func (util *AccountUtil) deleteAccount(common *CommonAccountParams, params *Dele re := regexp.MustCompile(uuidRegex) id := strings.ToLower(params.AccountID) if re.MatchString(id) { - err = client.NewClient().DeleteAccountByID(ctx, hostname, id) + err = client.NewClient().DeleteAccountByID(ctx, hostname, auxuuid.UUID(id)) } else { err = client.NewClient().DeleteAccountByName(ctx, hostname, params.AccountID) } @@ -298,9 +299,9 @@ type ListAccountsParams struct { } type Userinfo struct { - Username string `yaml:"username,omitempty"` - AccountID string `yaml:"accountId,omitempty"` - Rights map[string]string `yaml:"rights,omitempty"` + Username string `yaml:"username,omitempty"` + AccountID auxuuid.UUID `yaml:"accountId,omitempty"` + Rights map[auxuuid.UUID]string `yaml:"rights,omitempty"` } type ListAccountsResult struct { @@ -349,7 +350,7 @@ func (util *AccountUtil) listAccounts(common *CommonAccountParams, params *ListA userinfo := Userinfo{ Username: account.Username, AccountID: account.ID, - Rights: make(map[string]string, 0), + Rights: make(map[auxuuid.UUID]string, 0), } for _, grant := range account.Grants { userinfo.Rights[grant.ID] = grant.Right diff --git a/cmd/mstorectl/grantcmd.go b/cmd/mstorectl/grantcmd.go index febbed6..bfb14b9 100644 --- a/cmd/mstorectl/grantcmd.go +++ b/cmd/mstorectl/grantcmd.go @@ -18,6 +18,7 @@ import ( "github.com/spf13/cobra" "github.com/spf13/viper" + "mstore/pkg/auxuuid" "mstore/pkg/client" "mstore/pkg/descr" ) @@ -115,7 +116,7 @@ type CreateGrantParams struct { Pattern string } type CreateGrantResult struct { - GrantID string `yaml:"grantId"` + GrantID auxuuid.UUID `yaml:"grantId"` } func (util *GrantUtil) CreateGrant(cmd *cobra.Command, args []string) { @@ -138,9 +139,9 @@ func (util *GrantUtil) createGrant(common *CommonGrantParams, params *CreateGran ctx, _ := context.WithTimeout(context.Background(), timeout) re := regexp.MustCompile(uuidRegex) id := strings.ToLower(params.AccountID) - var operRes string + var operRes auxuuid.UUID if re.MatchString(id) { - operRes, err = client.NewClient().CreateGrantByAccountID(ctx, hostname, params.AccountID, params.Right, params.Pattern) + operRes, err = client.NewClient().CreateGrantByAccountID(ctx, hostname, auxuuid.UUID(id), params.Right, params.Pattern) } else { operRes, err = client.NewClient().CreateGrantByUsername(ctx, hostname, params.AccountID, params.Right, params.Pattern) } @@ -176,7 +177,7 @@ func (util *GrantUtil) updateGrant(common *CommonGrantParams, params *UpdateGran timeout := time.Duration(common.Timeout) * time.Second ctx, _ := context.WithTimeout(context.Background(), timeout) id := strings.ToLower(params.GrantID) - err = client.NewClient().UpdateGrant(ctx, hostname, id, params.Pattern) + err = client.NewClient().UpdateGrant(ctx, hostname, auxuuid.UUID(id), params.Pattern) if err != nil { return res, err } @@ -212,7 +213,7 @@ func (util *GrantUtil) getGrant(common *CommonGrantParams, params *GetGrantParam opRes := &descr.Grant{} id := strings.ToLower(params.GrantID) - opRes, err = client.NewClient().GetGrant(ctx, hostname, id) + opRes, err = client.NewClient().GetGrant(ctx, hostname, auxuuid.UUID(id)) if err != nil { return res, err } @@ -243,7 +244,7 @@ func (util *GrantUtil) deleteGrant(common *CommonGrantParams, params *DeleteGran timeout := time.Duration(common.Timeout) * time.Second ctx, _ := context.WithTimeout(context.Background(), timeout) id := strings.ToLower(params.GrantID) - err = client.NewClient().DeleteGrant(ctx, hostname, id) + err = client.NewClient().DeleteGrant(ctx, hostname, auxuuid.UUID(id)) if err != nil { return res, err } @@ -257,8 +258,8 @@ type ListGrantsParams struct { } type ListGrantsResult struct { - Grants []descr.Grant `yaml:"grants,omitempty"` - Rights map[string]string `yaml:"rights,omitempty"` + Grants []descr.Grant `yaml:"grants,omitempty"` + Rights map[auxuuid.UUID]string `yaml:"rights,omitempty"` } func (util *GrantUtil) ListGrants(cmd *cobra.Command, args []string) { @@ -280,7 +281,7 @@ func (util *GrantUtil) listGrants(common *CommonGrantParams, params *ListGrantsP re := regexp.MustCompile(uuidRegex) id := strings.ToLower(params.AccountID) if re.MatchString(id) { - grants, err = client.NewClient().ListGrantsByAccountID(ctx, hostname, params.AccountID) + grants, err = client.NewClient().ListGrantsByAccountID(ctx, hostname, auxuuid.UUID(id)) } else { grants, err = client.NewClient().ListGrantsByUsername(ctx, hostname, params.AccountID) } @@ -290,7 +291,7 @@ func (util *GrantUtil) listGrants(common *CommonGrantParams, params *ListGrantsP if params.Detail { res.Grants = grants } else { - res.Rights = make(map[string]string, 0) + res.Rights = make(map[auxuuid.UUID]string, 0) for _, item := range grants { res.Rights[item.ID] = item.Right } diff --git a/pkg/auxuuid/uuid.go b/pkg/auxuuid/uuid.go index c8baac3..e6b9b68 100644 --- a/pkg/auxuuid/uuid.go +++ b/pkg/auxuuid/uuid.go @@ -13,8 +13,10 @@ import ( "github.com/google/uuid" ) +type UUID string + const ZeroUUID = "00000000-0000-0000-0000-000000000000" -func NewUUID() string { - return uuid.New().String() +func NewUUID() UUID { + return UUID(uuid.New().String()) } diff --git a/pkg/client/account.go b/pkg/client/account.go index 97d0ede..3b2e53f 100644 --- a/pkg/client/account.go +++ b/pkg/client/account.go @@ -16,12 +16,13 @@ import ( "mstore/app/handler" "mstore/app/operator" + "mstore/pkg/auxuuid" "mstore/pkg/descr" ) -func (cli *Client) CreateAccount(ctx context.Context, hosturi, username, password string) (string, error) { +func (cli *Client) CreateAccount(ctx context.Context, hosturi, username, password string) (auxuuid.UUID, error) { var err error - var res string + var res auxuuid.UUID apiuri, err := setApiPath(hosturi, "/v3/api/account/create") if err != nil { @@ -53,7 +54,7 @@ func (cli *Client) CreateAccount(ctx context.Context, hosturi, username, passwor return res, err } -func (cli *Client) GetAccountByID(ctx context.Context, hosturi, id string) (*descr.AccountShort, error) { +func (cli *Client) GetAccountByID(ctx context.Context, hosturi string, id auxuuid.UUID) (*descr.AccountShort, error) { var err error res := &descr.AccountShort{} @@ -120,7 +121,7 @@ func (cli *Client) GetAccountByName(ctx context.Context, hosturi, username strin return res, err } -func (cli *Client) UpdateAccountByID(ctx context.Context, hosturi, id, newUsername, newPassword string) error { +func (cli *Client) UpdateAccountByID(ctx context.Context, hosturi string, id auxuuid.UUID, newUsername, newPassword string) error { var err error apipath, err := setApiPath(hosturi, "/v3/api/account/update") @@ -128,7 +129,6 @@ func (cli *Client) UpdateAccountByID(ctx context.Context, hosturi, id, newUserna return err } operParams := operator.UpdateAccountParams{ - //Username: username, AccountID: id, NewUsername: newUsername, NewPassword: newPassword, @@ -215,7 +215,7 @@ func (cli *Client) DeleteAccountByName(ctx context.Context, hosturi, username st return err } -func (cli *Client) DeleteAccountByID(ctx context.Context, hosturi, id string) error { +func (cli *Client) DeleteAccountByID(ctx context.Context, hosturi string, id auxuuid.UUID) error { var err error apipath, err := setApiPath(hosturi, "/v3/api/account/delete") diff --git a/pkg/client/grant.go b/pkg/client/grant.go index fcd8578..c8bbee8 100644 --- a/pkg/client/grant.go +++ b/pkg/client/grant.go @@ -16,12 +16,13 @@ import ( "mstore/app/handler" "mstore/app/operator" + "mstore/pkg/auxuuid" "mstore/pkg/descr" ) -func (cli *Client) CreateGrantByAccountID(ctx context.Context, hosturi, accountID, right, pattern string) (string, error) { +func (cli *Client) CreateGrantByAccountID(ctx context.Context, hosturi string, accountID auxuuid.UUID, right, pattern string) (auxuuid.UUID, error) { var err error - var res string + var res auxuuid.UUID apiuri, err := setApiPath(hosturi, "/v3/api/grant/create") if err != nil { @@ -54,9 +55,9 @@ func (cli *Client) CreateGrantByAccountID(ctx context.Context, hosturi, accountI return res, err } -func (cli *Client) CreateGrantByUsername(ctx context.Context, hosturi, username, right, pattern string) (string, error) { +func (cli *Client) CreateGrantByUsername(ctx context.Context, hosturi, username, right, pattern string) (auxuuid.UUID, error) { var err error - var res string + var res auxuuid.UUID apiuri, err := setApiPath(hosturi, "/v3/api/grant/create") if err != nil { @@ -89,7 +90,7 @@ func (cli *Client) CreateGrantByUsername(ctx context.Context, hosturi, username, return res, err } -func (cli *Client) GetGrant(ctx context.Context, hosturi, id string) (*descr.Grant, error) { +func (cli *Client) GetGrant(ctx context.Context, hosturi string, id auxuuid.UUID) (*descr.Grant, error) { var err error res := &descr.Grant{} @@ -122,7 +123,7 @@ func (cli *Client) GetGrant(ctx context.Context, hosturi, id string) (*descr.Gra return res, err } -func (cli *Client) UpdateGrant(ctx context.Context, hosturi, grantID, newPattern string) error { +func (cli *Client) UpdateGrant(ctx context.Context, hosturi string, grantID auxuuid.UUID, newPattern string) error { var err error apipath, err := setApiPath(hosturi, "/v3/api/grant/update") @@ -153,7 +154,7 @@ func (cli *Client) UpdateGrant(ctx context.Context, hosturi, grantID, newPattern return err } -func (cli *Client) DeleteGrant(ctx context.Context, hosturi, grantID string) error { +func (cli *Client) DeleteGrant(ctx context.Context, hosturi string, grantID auxuuid.UUID) error { var err error apipath, err := setApiPath(hosturi, "/v3/api/grant/delete") @@ -184,7 +185,7 @@ func (cli *Client) DeleteGrant(ctx context.Context, hosturi, grantID string) err return err } -func (cli *Client) ListGrantsByAccountID(ctx context.Context, hosturi, accountID string) ([]descr.Grant, error) { +func (cli *Client) ListGrantsByAccountID(ctx context.Context, hosturi string, accountID auxuuid.UUID) ([]descr.Grant, error) { var err error res := make([]descr.Grant, 0) diff --git a/pkg/descr/account.go b/pkg/descr/account.go index 09f0d58..5a22a5f 100644 --- a/pkg/descr/account.go +++ b/pkg/descr/account.go @@ -7,27 +7,30 @@ * Distribution of this work is permitted, but commercial use and * modifications are strictly prohibited. */ - package descr +import ( + "mstore/pkg/auxuuid" +) + type Account struct { - ID string `json:"id" db:"id"` - Username string `json:"username" db:"username"` - Passhash string `json:"passhash" db:"passhash"` - Disabled bool `json:"disabled" db:"disabled"` - CreatedAt string `json:"createdAt" db:"created_at"` - UpdatedAt string `json:"updatedAt" db:"updated_at"` - CreatedBy string `json:"createdBy" db:"created_by"` - UpdatedBy string `json:"updatedBy" db:"updated_by"` + ID auxuuid.UUID `json:"id" db:"id"` + Username string `json:"username" db:"username"` + Passhash string `json:"passhash" db:"passhash"` + Disabled bool `json:"disabled" db:"disabled"` + CreatedAt string `json:"createdAt" db:"created_at"` + UpdatedAt string `json:"updatedAt" db:"updated_at"` + CreatedBy auxuuid.UUID `json:"createdBy" db:"created_by"` + UpdatedBy auxuuid.UUID `json:"updatedBy" db:"updated_by"` } type AccountShort struct { - ID string `json:"id"` - Username string `json:"username"` - Disabled bool `json:"disabled"` - CreatedAt string `json:"createdAt"` - UpdatedAt string `json:"updatedAt"` - CreatedBy string `json:"createdBy"` - UpdatedBy string `json:"updatedBy"` - Grants []Grant `json:"grants"` + ID auxuuid.UUID `json:"id"` + Username string `json:"username"` + Disabled bool `json:"disabled"` + CreatedAt string `json:"createdAt"` + UpdatedAt string `json:"updatedAt"` + CreatedBy auxuuid.UUID `json:"createdBy"` + UpdatedBy auxuuid.UUID `json:"updatedBy"` + Grants []Grant `json:"grants"` } diff --git a/pkg/descr/blob.go b/pkg/descr/blob.go index 5e1c460..57bed67 100644 --- a/pkg/descr/blob.go +++ b/pkg/descr/blob.go @@ -9,15 +9,19 @@ */ package descr +import ( + "mstore/pkg/auxuuid" +) + type Blob struct { - ID string `db:"id" json:"id"` - Name string `db:"name" json:"name"` - Reference string `db:"reference" json:"reference"` - MediaType string `db:"mediaType" json:"mediaType"` - Digest string `db:"digest" json:"digest"` - Size int64 `db:"size" json:"size"` - CreatedAt string `db:"created_at" json:"createdAt"` - UpdatedAt string `db:"updated_at" json:"updatedAt"` - CreatedBy string `db:"created_by" json:"createdBy,omitempty"` - UpdatedBy string `db:"updated_by" json:"updatedBy,omitempty"` + ID auxuuid.UUID `db:"id" json:"id"` + Name string `db:"name" json:"name"` + Reference string `db:"reference" json:"reference"` + MediaType string `db:"mediaType" json:"mediaType"` + Digest string `db:"digest" json:"digest"` + Size int64 `db:"size" json:"size"` + CreatedAt string `db:"created_at" json:"createdAt"` + UpdatedAt string `db:"updated_at" json:"updatedAt"` + CreatedBy auxuuid.UUID `db:"created_by" json:"createdBy,omitempty"` + UpdatedBy auxuuid.UUID `db:"updated_by" json:"updatedBy,omitempty"` } diff --git a/pkg/descr/file.go b/pkg/descr/file.go index ef91832..3e0da27 100644 --- a/pkg/descr/file.go +++ b/pkg/descr/file.go @@ -9,15 +9,19 @@ */ package descr +import ( + "mstore/pkg/auxuuid" +) + type File struct { - ID string `db:"id" json:"id,omitempty" yaml:"id,omitempty"` - Collection string `db:"collection" json:"collection,omitempty" yaml:"collection,omitempty"` - Name string `db:"name" json:"name,omitempty" yaml:"name,omitempty"` - Type string `db:"type" json:"type,omitempty" yaml:"type,omitempty"` - Checksum string `db:"checksum" json:"checksum,omitempty" yaml:"checksum,omitempty"` - Size int64 `db:"size" json:"size,omitempty" yaml:"size,omitempty"` - CreatedAt string `db:"created_at" json:"createdAt,omitempty" yaml:"createdAt,omitempty"` - UpdatedAt string `db:"updated_at" json:"updatedAt,omitempty" yaml:"updatedAt,omitempty"` - CreatedBy string `db:"created_by" json:"createdBy,omitempty" yaml:"createdBy,omitempty"` - UpdatedBy string `db:"updated_by" json:"updatedBy,omitempty" yaml:"updatedBy,omitempty"` + ID auxuuid.UUID `db:"id" json:"id,omitempty" yaml:"id,omitempty"` + Collection string `db:"collection" json:"collection,omitempty" yaml:"collection,omitempty"` + Name string `db:"name" json:"name,omitempty" yaml:"name,omitempty"` + Type string `db:"type" json:"type,omitempty" yaml:"type,omitempty"` + Checksum string `db:"checksum" json:"checksum,omitempty" yaml:"checksum,omitempty"` + Size int64 `db:"size" json:"size,omitempty" yaml:"size,omitempty"` + CreatedAt string `db:"created_at" json:"createdAt,omitempty" yaml:"createdAt,omitempty"` + UpdatedAt string `db:"updated_at" json:"updatedAt,omitempty" yaml:"updatedAt,omitempty"` + CreatedBy auxuuid.UUID `db:"created_by" json:"createdBy,omitempty" yaml:"createdBy,omitempty"` + UpdatedBy auxuuid.UUID `db:"updated_by" json:"updatedBy,omitempty" yaml:"updatedBy,omitempty"` } diff --git a/pkg/descr/grant.go b/pkg/descr/grant.go index 8140be5..58f02da 100644 --- a/pkg/descr/grant.go +++ b/pkg/descr/grant.go @@ -10,13 +10,17 @@ package descr +import ( + "mstore/pkg/auxuuid" +) + type Grant struct { - ID string `json:"id" db:"id"` - AccountID string `json:"accountID" db:"account_id"` - Right string `json:"right" db:"right"` - Pattern string `json:"pattern" db:"pattern"` - CreatedAt string `json:"createdAt" db:"created_at"` - UpdatedAt string `json:"updatedAt" db:"updated_at"` - CreatedBy string `json:"createdBy" db:"created_by"` - UpdatedBy string `json:"updatedBy" db:"updated_by"` + ID auxuuid.UUID `json:"id" db:"id"` + AccountID auxuuid.UUID `json:"accountID" db:"account_id"` + Right string `json:"right" db:"right"` + Pattern string `json:"pattern" db:"pattern"` + CreatedAt string `json:"createdAt" db:"created_at"` + UpdatedAt string `json:"updatedAt" db:"updated_at"` + CreatedBy auxuuid.UUID `json:"createdBy" db:"created_by"` + UpdatedBy auxuuid.UUID `json:"updatedBy" db:"updated_by"` } diff --git a/pkg/descr/manifest.go b/pkg/descr/manifest.go index 6019645..0dea6ec 100644 --- a/pkg/descr/manifest.go +++ b/pkg/descr/manifest.go @@ -9,17 +9,21 @@ */ package descr +import ( + "mstore/pkg/auxuuid" +) + type Manifest struct { - ID string `db:"id" json:"id"` - Name string `db:"name" json:"name"` - Reference string `db:"reference" json:"reference"` - ContentType string `db:"contentType" json:"contentType"` - Payload string `db:"payload" json:"-"` - Digest string `db:"digest" json:"digest"` - CreatedAt string `db:"created_at" json:"createdAt"` - UpdatedAt string `db:"updated_at" json:"updatedAt"` - CreatedBy string `db:"created_by" json:"createdBy,omitempty"` - UpdatedBy string `db:"updated_by" json:"updatedBy,omitempty"` + ID auxuuid.UUID `db:"id" json:"id"` + Name string `db:"name" json:"name"` + Reference string `db:"reference" json:"reference"` + ContentType string `db:"contentType" json:"contentType"` + Payload string `db:"payload" json:"-"` + Digest string `db:"digest" json:"digest"` + CreatedAt string `db:"created_at" json:"createdAt"` + UpdatedAt string `db:"updated_at" json:"updatedAt"` + CreatedBy auxuuid.UUID `db:"created_by" json:"createdBy,omitempty"` + UpdatedBy auxuuid.UUID `db:"updated_by" json:"updatedBy,omitempty"` } type Tags struct { diff --git a/pkg/descr/response.go b/pkg/descr/response.go deleted file mode 100644 index 647adea..0000000 --- a/pkg/descr/response.go +++ /dev/null @@ -1,10 +0,0 @@ -/* - * Copyright 2026 Oleg Borodin - * - * This work is published and licensed under a Creative Commons - * Attribution-NonCommercial-NoDerivatives 4.0 International License. - * - * Distribution of this work is permitted, but commercial use and - * modifications are strictly prohibited. - */ -package descr diff --git a/pkg/terms/terms.go b/pkg/terms/terms.go index 2673be3..9807833 100644 --- a/pkg/terms/terms.go +++ b/pkg/terms/terms.go @@ -10,6 +10,10 @@ package terms +import ( + "mstore/pkg/auxuuid" +) + type PathUsage string const ( @@ -19,13 +23,12 @@ const ( ) const ( - AnonimousUsername = "anonymous" - AnonymousID = "10000000-0000-0000-0000-000000000001" - ServerUsername = "server" - ServerID = "10000000-0000-0000-0000-000000000002" - - InitUsername = "mstore" - InitID = "10000000-0000-0000-0000-000000000005" + AnonimousUsername string = "anonymous" + AnonymousID auxuuid.UUID = "10000000-0000-0000-0000-000000000001" + ServerUsername string = "server" + ServerID auxuuid.UUID = "10000000-0000-0000-0000-000000000002" + InitUsername string = "mstore" + InitID auxuuid.UUID = "10000000-0000-0000-0000-000000000005" ) const ( diff --git a/test/account_test.go b/test/account_test.go index 9f486f1..6a11979 100644 --- a/test/account_test.go +++ b/test/account_test.go @@ -17,6 +17,7 @@ import ( "time" "mstore/app/server" + "mstore/pkg/auxuuid" "mstore/pkg/client" "mstore/pkg/terms" @@ -80,7 +81,7 @@ func TestAccountLife(t *testing.T) { username := "testuser" password := "testpass" - var accountID string + var accountID auxuuid.UUID { // CreateAccount fmt.Printf("=== CreateAccount ===\n") @@ -91,7 +92,7 @@ func TestAccountLife(t *testing.T) { accountID, err = cli.CreateAccount(ctx, srvaddr, username, password) require.NoError(t, err) } - var grantID string + var grantID auxuuid.UUID { // CreateGrant fmt.Printf("=== CreateGrant ===\n")