working commit
This commit is contained in:
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Copyright 2026 Oleg Borodin <onborodin@gmail.com>
|
||||
*
|
||||
* This work is published and licensed under a Creative Commons
|
||||
* Attribution-NonCommercial-NoDerivatives 4.0 International License.
|
||||
*
|
||||
* Distribution of this work is permitted, but commercial use and
|
||||
* modifications are strictly prohibited.
|
||||
*/
|
||||
|
||||
package descr
|
||||
|
||||
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"`
|
||||
}
|
||||
|
||||
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"`
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
/*
|
||||
* Copyright 2026 Oleg Borodin <onborodin@gmail.com>
|
||||
*
|
||||
* This work is published and licensed under a Creative Commons
|
||||
* Attribution-NonCommercial-NoDerivatives 4.0 International License.
|
||||
*
|
||||
* Distribution of this work is permitted, but commercial use and
|
||||
* modifications are strictly prohibited.
|
||||
*/
|
||||
package descr
|
||||
|
||||
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"`
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
/*
|
||||
* Copyright 2026 Oleg Borodin <onborodin@gmail.com>
|
||||
*
|
||||
* This work is published and licensed under a Creative Commons
|
||||
* Attribution-NonCommercial-NoDerivatives 4.0 International License.
|
||||
*
|
||||
* Distribution of this work is permitted, but commercial use and
|
||||
* modifications are strictly prohibited.
|
||||
*/
|
||||
package descr
|
||||
|
||||
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"`
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* Copyright 2026 Oleg Borodin <onborodin@gmail.com>
|
||||
*
|
||||
* This work is published and licensed under a Creative Commons
|
||||
* Attribution-NonCommercial-NoDerivatives 4.0 International License.
|
||||
*
|
||||
* Distribution of this work is permitted, but commercial use and
|
||||
* modifications are strictly prohibited.
|
||||
*/
|
||||
|
||||
package descr
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
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"`
|
||||
}
|
||||
|
||||
const (
|
||||
// Accounts, grants
|
||||
RightReadAccounts = "readAccounts" // GetAccount, ListAccounts
|
||||
RightWriteAccounts = "writeAccounts" // CreateAccount, UpdateAccount, DeleteAccount
|
||||
// Files
|
||||
RightWriteFiles = "writeFiles" // FileInfo, GetFile, ListFiles
|
||||
RightReadFiles = "readFiles" // PutFile, DeleteFile
|
||||
// Images: manifests, layers
|
||||
RightReadImages = "readImages" // ManifestInfo, GetManifest, BlobInfo, GetBlob
|
||||
RightWriteImages = "writeImages" // other opearion
|
||||
)
|
||||
@@ -1,28 +0,0 @@
|
||||
/*
|
||||
* Copyright 2026 Oleg Borodin <onborodin@gmail.com>
|
||||
*
|
||||
* This work is published and licensed under a Creative Commons
|
||||
* Attribution-NonCommercial-NoDerivatives 4.0 International License.
|
||||
*
|
||||
* Distribution of this work is permitted, but commercial use and
|
||||
* modifications are strictly prohibited.
|
||||
*/
|
||||
package descr
|
||||
|
||||
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"`
|
||||
}
|
||||
|
||||
type Tags struct {
|
||||
Name string `json:"name" yaml:"name"`
|
||||
Tags []string `json:"tags" yaml:"tags"`
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
/*
|
||||
* Copyright 2026 Oleg Borodin <onborodin@gmail.com>
|
||||
*
|
||||
* This work is published and licensed under a Creative Commons
|
||||
* Attribution-NonCommercial-NoDerivatives 4.0 International License.
|
||||
*
|
||||
* Distribution of this work is permitted, but commercial use and
|
||||
* modifications are strictly prohibited.
|
||||
*/
|
||||
package descr
|
||||
@@ -1,20 +0,0 @@
|
||||
/*
|
||||
* Copyright 2026 Oleg Borodin <onborodin@gmail.com>
|
||||
*
|
||||
* This work is published and licensed under a Creative Commons
|
||||
* Attribution-NonCommercial-NoDerivatives 4.0 International License.
|
||||
*
|
||||
* Distribution of this work is permitted, but commercial use and
|
||||
* modifications are strictly prohibited.
|
||||
*/
|
||||
package descr
|
||||
|
||||
type Server struct {
|
||||
SchemeCreated bool `yaml:"schemeCreated"`
|
||||
AnonymousCreated bool `yaml:"anonymousCreated"`
|
||||
InituserCreated bool `yaml:"inituserCreated"`
|
||||
|
||||
SchemeCreatedAt string `yaml:"schemeCreatedAt"`
|
||||
AnonymousCreatedAt string `yaml:"anonymousCreatedAt"`
|
||||
InituserCreatedAt string `yaml:"inituserCreatedAt"`
|
||||
}
|
||||
@@ -14,10 +14,10 @@ import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
|
||||
"mstore/app/descr"
|
||||
"mstore/app/router"
|
||||
"mstore/pkg/auxhttp"
|
||||
"mstore/pkg/auxpwd"
|
||||
"mstore/pkg/terms"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -53,7 +53,7 @@ func (hand *Handler) CheckAccess(rctx *router.Context) (bool, string, error) {
|
||||
var password string
|
||||
var accountID string
|
||||
|
||||
accountID = descr.AnonymousID
|
||||
accountID = terms.AnonymousID
|
||||
|
||||
authHeader := rctx.GetHeader("Authorization")
|
||||
if authHeader != "" {
|
||||
@@ -80,7 +80,7 @@ func (hand *Handler) CheckAccess(rctx *router.Context) (bool, string, error) {
|
||||
}
|
||||
anonymous:
|
||||
success = true
|
||||
accountID = descr.AnonymousID
|
||||
accountID = terms.AnonymousID
|
||||
return success, accountID, err
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ func (hand *Handler) CheckRight(ctx context.Context, accountID, reqRight, subjec
|
||||
return res, err
|
||||
}
|
||||
switch reqRight {
|
||||
case descr.RightReadFiles, descr.RightWriteFiles:
|
||||
case terms.RightReadFiles, terms.RightWriteFiles:
|
||||
for _, grant := range grants {
|
||||
re, err := regexp.Compile(grant.Pattern)
|
||||
if err != nil {
|
||||
|
||||
@@ -12,9 +12,9 @@ package handler
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"mstore/app/descr"
|
||||
"mstore/app/operator"
|
||||
"mstore/app/router"
|
||||
"mstore/pkg/terms"
|
||||
)
|
||||
|
||||
// POST /v3/account/create 200 200
|
||||
@@ -29,7 +29,7 @@ func (hand *Handler) CreateAccount(rctx *router.Context) {
|
||||
}
|
||||
// Rigth checking
|
||||
operatorID, _ := rctx.GetString(userTag)
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightWriteAccounts, "")
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightWriteAccounts, "")
|
||||
if err != nil {
|
||||
err := fmt.Errorf("Operation error: %v", err)
|
||||
hand.SendError(rctx, err)
|
||||
@@ -62,7 +62,7 @@ func (hand *Handler) GetAccount(rctx *router.Context) {
|
||||
}
|
||||
// Rigth checking
|
||||
operatorID, _ := rctx.GetString(userTag)
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightWriteAccounts, "")
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightWriteAccounts, "")
|
||||
if err != nil {
|
||||
err := fmt.Errorf("Operation error: %v", err)
|
||||
hand.SendError(rctx, err)
|
||||
@@ -95,7 +95,7 @@ func (hand *Handler) ListAccounts(rctx *router.Context) {
|
||||
}
|
||||
// Rigth checking
|
||||
operatorID, _ := rctx.GetString(userTag)
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightWriteAccounts, "")
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightWriteAccounts, "")
|
||||
if err != nil {
|
||||
err := fmt.Errorf("Operation error: %v", err)
|
||||
hand.SendError(rctx, err)
|
||||
@@ -128,7 +128,7 @@ func (hand *Handler) UpdateAccount(rctx *router.Context) {
|
||||
}
|
||||
// Rigth checking
|
||||
operatorID, _ := rctx.GetString(userTag)
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightWriteAccounts, "")
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightWriteAccounts, "")
|
||||
if err != nil {
|
||||
err := fmt.Errorf("Operation error: %v", err)
|
||||
hand.SendError(rctx, err)
|
||||
@@ -161,7 +161,7 @@ func (hand *Handler) DeleteAccount(rctx *router.Context) {
|
||||
}
|
||||
// Rigth checking
|
||||
operatorID, _ := rctx.GetString(userTag)
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightWriteAccounts, params.Username)
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightWriteAccounts, params.Username)
|
||||
if err != nil {
|
||||
err := fmt.Errorf("Operation error: %v", err)
|
||||
hand.SendError(rctx, err)
|
||||
|
||||
+7
-7
@@ -14,9 +14,9 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"mstore/app/descr"
|
||||
"mstore/app/operator"
|
||||
"mstore/app/router"
|
||||
"mstore/pkg/terms"
|
||||
)
|
||||
|
||||
// HEAD /v2/<name>/blobs/<digest> 200 404
|
||||
@@ -32,7 +32,7 @@ func (hand *Handler) BlobExists(rctx *router.Context) {
|
||||
}
|
||||
// Rigth checking
|
||||
operatorID, _ := rctx.GetString(userTag)
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightReadImages, "")
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightReadImages, "")
|
||||
if err != nil {
|
||||
rctx.SetStatus(http.StatusInternalServerError)
|
||||
return
|
||||
@@ -72,7 +72,7 @@ func (hand *Handler) PostUpload(rctx *router.Context) {
|
||||
}
|
||||
// Rigth checking
|
||||
operatorID, _ := rctx.GetString(userTag)
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightWriteImages, "")
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightWriteImages, "")
|
||||
if err != nil {
|
||||
rctx.SetStatus(http.StatusInternalServerError)
|
||||
return
|
||||
@@ -117,7 +117,7 @@ func (hand *Handler) PatchUpload(rctx *router.Context) {
|
||||
}
|
||||
// Rigth checking
|
||||
operatorID, _ := rctx.GetString(userTag)
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightWriteImages, "")
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightWriteImages, "")
|
||||
if err != nil {
|
||||
rctx.SetStatus(http.StatusInternalServerError)
|
||||
return
|
||||
@@ -161,7 +161,7 @@ func (hand *Handler) PutUpload(rctx *router.Context) {
|
||||
}
|
||||
// Rigth checking
|
||||
operatorID, _ := rctx.GetString(userTag)
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightWriteImages, "")
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightWriteImages, "")
|
||||
if err != nil {
|
||||
rctx.SetStatus(http.StatusInternalServerError)
|
||||
return
|
||||
@@ -191,7 +191,7 @@ func (hand *Handler) GetBlob(rctx *router.Context) {
|
||||
}
|
||||
// Rigth checking
|
||||
operatorID, _ := rctx.GetString(userTag)
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightReadImages, "")
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightReadImages, "")
|
||||
if err != nil {
|
||||
rctx.SetStatus(http.StatusInternalServerError)
|
||||
return
|
||||
@@ -237,7 +237,7 @@ func (hand *Handler) DeleteBlob(rctx *router.Context) {
|
||||
}
|
||||
// Rigth checking
|
||||
operatorID, _ := rctx.GetString(userTag)
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightWriteImages, "")
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightWriteImages, "")
|
||||
if err != nil {
|
||||
rctx.SetStatus(http.StatusInternalServerError)
|
||||
return
|
||||
|
||||
+8
-8
@@ -13,9 +13,9 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"mstore/app/descr"
|
||||
"mstore/app/operator"
|
||||
"mstore/app/router"
|
||||
"mstore/pkg/terms"
|
||||
)
|
||||
|
||||
const zeroContentLength = "0"
|
||||
@@ -28,7 +28,7 @@ func (hand *Handler) FileInfo(rctx *router.Context) {
|
||||
}
|
||||
// Rigth checking
|
||||
operatorID, _ := rctx.GetString(userTag)
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightReadFiles, "")
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightReadFiles, "")
|
||||
if err != nil {
|
||||
rctx.SetStatus(http.StatusInternalServerError)
|
||||
return
|
||||
@@ -73,7 +73,7 @@ func (hand *Handler) PutFile(rctx *router.Context) {
|
||||
}
|
||||
// Rigth checking
|
||||
operatorID, _ := rctx.GetString(userTag)
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightWriteFiles, "")
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightWriteFiles, "")
|
||||
if err != nil {
|
||||
rctx.SetStatus(http.StatusInternalServerError)
|
||||
return
|
||||
@@ -101,7 +101,7 @@ func (hand *Handler) GetFile(rctx *router.Context) {
|
||||
}
|
||||
// Rigth checking
|
||||
operatorID, _ := rctx.GetString(userTag)
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightReadFiles, "")
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightReadFiles, "")
|
||||
if err != nil {
|
||||
rctx.SetStatus(http.StatusInternalServerError)
|
||||
return
|
||||
@@ -149,7 +149,7 @@ func (hand *Handler) DeleteFile(rctx *router.Context) {
|
||||
}
|
||||
// Rigth checking
|
||||
operatorID, _ := rctx.GetString(userTag)
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightWriteFiles, "")
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightWriteFiles, "")
|
||||
if err != nil {
|
||||
rctx.SetStatus(http.StatusInternalServerError)
|
||||
return
|
||||
@@ -179,7 +179,7 @@ func (hand *Handler) ListFiles(rctx *router.Context) {
|
||||
}
|
||||
// Rigth checking
|
||||
operatorID, _ := rctx.GetString(userTag)
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightReadFiles, "")
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightReadFiles, "")
|
||||
if err != nil {
|
||||
rctx.SetStatus(http.StatusInternalServerError)
|
||||
return
|
||||
@@ -210,7 +210,7 @@ func (hand *Handler) ListCollections(rctx *router.Context) {
|
||||
}
|
||||
// Rigth checking
|
||||
operatorID, _ := rctx.GetString(userTag)
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightReadFiles, "")
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightReadFiles, "")
|
||||
if err != nil {
|
||||
rctx.SetStatus(http.StatusInternalServerError)
|
||||
return
|
||||
@@ -248,7 +248,7 @@ func (hand *Handler) DeleteCollection(rctx *router.Context) {
|
||||
|
||||
// Rigth checking
|
||||
operatorID, _ := rctx.GetString(userTag)
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightReadFiles, "")
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightReadFiles, "")
|
||||
if err != nil {
|
||||
rctx.SetStatus(http.StatusInternalServerError)
|
||||
return
|
||||
|
||||
@@ -12,9 +12,9 @@ package handler
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"mstore/app/descr"
|
||||
"mstore/app/operator"
|
||||
"mstore/app/router"
|
||||
"mstore/pkg/terms"
|
||||
)
|
||||
|
||||
// POST /v3/grant/create 200 200
|
||||
@@ -29,7 +29,7 @@ func (hand *Handler) CreateGrant(rctx *router.Context) {
|
||||
}
|
||||
// Rigth checking
|
||||
operatorID, _ := rctx.GetString(userTag)
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightWriteAccounts, "")
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightWriteAccounts, "")
|
||||
if err != nil {
|
||||
err := fmt.Errorf("Operation error: %v", err)
|
||||
hand.SendError(rctx, err)
|
||||
@@ -62,7 +62,7 @@ func (hand *Handler) GetGrant(rctx *router.Context) {
|
||||
}
|
||||
// Rigth checking
|
||||
operatorID, _ := rctx.GetString(userTag)
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightReadAccounts, "")
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightReadAccounts, "")
|
||||
if err != nil {
|
||||
err := fmt.Errorf("Operation error: %v", err)
|
||||
hand.SendError(rctx, err)
|
||||
@@ -95,7 +95,7 @@ func (hand *Handler) ListGrants(rctx *router.Context) {
|
||||
}
|
||||
// Rigth checking
|
||||
operatorID, _ := rctx.GetString(userTag)
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightReadAccounts, "")
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightReadAccounts, "")
|
||||
if err != nil {
|
||||
err := fmt.Errorf("Operation error: %v", err)
|
||||
hand.SendError(rctx, err)
|
||||
@@ -128,7 +128,7 @@ func (hand *Handler) UpdateGrant(rctx *router.Context) {
|
||||
}
|
||||
// Rigth checking
|
||||
operatorID, _ := rctx.GetString(userTag)
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightWriteAccounts, "")
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightWriteAccounts, "")
|
||||
if err != nil {
|
||||
err := fmt.Errorf("Operation error: %v", err)
|
||||
hand.SendError(rctx, err)
|
||||
@@ -161,7 +161,7 @@ func (hand *Handler) DeleteGrant(rctx *router.Context) {
|
||||
}
|
||||
// Rigth checking
|
||||
operatorID, _ := rctx.GetString(userTag)
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightWriteAccounts, "")
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightWriteAccounts, "")
|
||||
if err != nil {
|
||||
err := fmt.Errorf("Operation error: %v", err)
|
||||
hand.SendError(rctx, err)
|
||||
|
||||
@@ -12,9 +12,9 @@ package handler
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"mstore/app/descr"
|
||||
"mstore/app/operator"
|
||||
"mstore/app/router"
|
||||
"mstore/pkg/terms"
|
||||
)
|
||||
|
||||
func (hand *Handler) ManifestExists(rctx *router.Context) {
|
||||
@@ -29,7 +29,7 @@ func (hand *Handler) ManifestExists(rctx *router.Context) {
|
||||
}
|
||||
// Rigth checking
|
||||
operatorID, _ := rctx.GetString(userTag)
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightReadImages, "")
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightReadImages, "")
|
||||
if err != nil {
|
||||
rctx.SetStatus(http.StatusInternalServerError)
|
||||
return
|
||||
@@ -71,7 +71,7 @@ func (hand *Handler) PutManifest(rctx *router.Context) {
|
||||
}
|
||||
// Rigth checking
|
||||
operatorID, _ := rctx.GetString(userTag)
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightWriteImages, "")
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightWriteImages, "")
|
||||
if err != nil {
|
||||
rctx.SetStatus(http.StatusInternalServerError)
|
||||
return
|
||||
@@ -104,7 +104,7 @@ func (hand *Handler) GetManifest(rctx *router.Context) {
|
||||
}
|
||||
// Rigth checking
|
||||
operatorID, _ := rctx.GetString(userTag)
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightReadImages, "")
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightReadImages, "")
|
||||
if err != nil {
|
||||
rctx.SetStatus(http.StatusInternalServerError)
|
||||
return
|
||||
@@ -144,7 +144,7 @@ func (hand *Handler) DeleteManifest(rctx *router.Context) {
|
||||
}
|
||||
// Rigth checking
|
||||
operatorID, _ := rctx.GetString(userTag)
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightWriteImages, "")
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightWriteImages, "")
|
||||
if err != nil {
|
||||
rctx.SetStatus(http.StatusInternalServerError)
|
||||
return
|
||||
@@ -173,7 +173,7 @@ func (hand *Handler) GetReferer(rctx *router.Context) {
|
||||
}
|
||||
// Rigth checking
|
||||
operatorID, _ := rctx.GetString(userTag)
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightReadImages, "")
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightReadImages, "")
|
||||
if err != nil {
|
||||
rctx.SetStatus(http.StatusInternalServerError)
|
||||
return
|
||||
@@ -199,7 +199,7 @@ func (hand *Handler) GetTags(rctx *router.Context) {
|
||||
}
|
||||
// Rigth checking
|
||||
operatorID, _ := rctx.GetString(userTag)
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightReadImages, "")
|
||||
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightReadImages, "")
|
||||
if err != nil {
|
||||
rctx.SetStatus(http.StatusInternalServerError)
|
||||
return
|
||||
|
||||
@@ -3,7 +3,7 @@ package maindb
|
||||
import (
|
||||
"context"
|
||||
|
||||
"mstore/app/descr"
|
||||
"mstore/pkg/descr"
|
||||
)
|
||||
|
||||
func (db *Database) InsertAccount(ctx context.Context, account *descr.Account) error {
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ package maindb
|
||||
import (
|
||||
"context"
|
||||
|
||||
"mstore/app/descr"
|
||||
"mstore/pkg/descr"
|
||||
)
|
||||
|
||||
func (db *Database) InsertBlob(ctx context.Context, layer *descr.Blob) error {
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ package maindb
|
||||
import (
|
||||
"context"
|
||||
|
||||
"mstore/app/descr"
|
||||
"mstore/pkg/descr"
|
||||
)
|
||||
|
||||
func (db *Database) InsertFile(ctx context.Context, file *descr.File) error {
|
||||
|
||||
@@ -14,9 +14,9 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"mstore/app/descr"
|
||||
"mstore/pkg/auxtool"
|
||||
"mstore/pkg/auxuuid"
|
||||
"mstore/pkg/descr"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ package maindb
|
||||
import (
|
||||
"context"
|
||||
|
||||
"mstore/app/descr"
|
||||
"mstore/pkg/descr"
|
||||
)
|
||||
|
||||
func (db *Database) InsertGrant(ctx context.Context, grant *descr.Grant) error {
|
||||
|
||||
@@ -14,9 +14,9 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"mstore/app/descr"
|
||||
"mstore/pkg/auxtool"
|
||||
"mstore/pkg/auxuuid"
|
||||
"mstore/pkg/descr"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
+35
-34
@@ -13,10 +13,11 @@ package maindb
|
||||
import (
|
||||
"context"
|
||||
|
||||
"mstore/app/descr"
|
||||
"mstore/pkg/auxpwd"
|
||||
"mstore/pkg/auxtool"
|
||||
"mstore/pkg/auxuuid"
|
||||
"mstore/pkg/descr"
|
||||
"mstore/pkg/terms"
|
||||
)
|
||||
|
||||
func (db *Database) WriteAnonymous(ctx context.Context) error {
|
||||
@@ -26,14 +27,14 @@ func (db *Database) WriteAnonymous(ctx context.Context) error {
|
||||
password := auxtool.RandomString(64)
|
||||
passhash := auxpwd.MakeSHA256Hash([]byte(password))
|
||||
accountDescr := &descr.Account{
|
||||
ID: descr.AnonymousID,
|
||||
Username: descr.AnonimousUsername,
|
||||
ID: terms.AnonymousID,
|
||||
Username: terms.AnonimousUsername,
|
||||
Passhash: passhash,
|
||||
Disabled: false,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
CreatedBy: descr.ServerID,
|
||||
UpdatedBy: descr.ServerID,
|
||||
CreatedBy: terms.ServerID,
|
||||
UpdatedBy: terms.ServerID,
|
||||
}
|
||||
err = db.InsertAccount(ctx, accountDescr)
|
||||
if err != nil {
|
||||
@@ -42,12 +43,12 @@ func (db *Database) WriteAnonymous(ctx context.Context) error {
|
||||
grantDescr := &descr.Grant{
|
||||
ID: auxuuid.NewUUID(),
|
||||
AccountID: accountDescr.ID,
|
||||
Right: descr.RightReadFiles,
|
||||
Right: terms.RightReadFiles,
|
||||
Pattern: ".*",
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
CreatedBy: descr.ServerID,
|
||||
UpdatedBy: descr.ServerID,
|
||||
CreatedBy: terms.ServerID,
|
||||
UpdatedBy: terms.ServerID,
|
||||
}
|
||||
err = db.InsertGrant(ctx, grantDescr)
|
||||
if err != nil {
|
||||
@@ -56,12 +57,12 @@ func (db *Database) WriteAnonymous(ctx context.Context) error {
|
||||
grantDescr = &descr.Grant{
|
||||
ID: auxuuid.NewUUID(),
|
||||
AccountID: accountDescr.ID,
|
||||
Right: descr.RightReadImages,
|
||||
Right: terms.RightReadImages,
|
||||
Pattern: ".*",
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
CreatedBy: descr.ServerID,
|
||||
UpdatedBy: descr.ServerID,
|
||||
CreatedBy: terms.ServerID,
|
||||
UpdatedBy: terms.ServerID,
|
||||
}
|
||||
err = db.InsertGrant(ctx, grantDescr)
|
||||
if err != nil {
|
||||
@@ -75,16 +76,16 @@ func (db *Database) WriteAnonymous(ctx context.Context) error {
|
||||
func (db *Database) WriteInituser(ctx context.Context) error {
|
||||
var err error
|
||||
now := auxtool.TimeNow()
|
||||
passhash := auxpwd.MakeSHA256Hash([]byte(descr.InitUsername))
|
||||
passhash := auxpwd.MakeSHA256Hash([]byte(terms.InitUsername))
|
||||
accountDescr := &descr.Account{
|
||||
ID: descr.InitID,
|
||||
Username: descr.InitUsername,
|
||||
ID: terms.InitID,
|
||||
Username: terms.InitUsername,
|
||||
Passhash: passhash,
|
||||
Disabled: false,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
CreatedBy: descr.ServerID,
|
||||
UpdatedBy: descr.ServerID,
|
||||
CreatedBy: terms.ServerID,
|
||||
UpdatedBy: terms.ServerID,
|
||||
}
|
||||
err = db.InsertAccount(ctx, accountDescr)
|
||||
if err != nil {
|
||||
@@ -94,12 +95,12 @@ func (db *Database) WriteInituser(ctx context.Context) error {
|
||||
grantDescr := &descr.Grant{
|
||||
ID: auxuuid.NewUUID(),
|
||||
AccountID: accountDescr.ID,
|
||||
Right: descr.RightReadFiles,
|
||||
Right: terms.RightReadFiles,
|
||||
Pattern: ".*",
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
CreatedBy: descr.ServerID,
|
||||
UpdatedBy: descr.ServerID,
|
||||
CreatedBy: terms.ServerID,
|
||||
UpdatedBy: terms.ServerID,
|
||||
}
|
||||
err = db.InsertGrant(ctx, grantDescr)
|
||||
if err != nil {
|
||||
@@ -108,12 +109,12 @@ func (db *Database) WriteInituser(ctx context.Context) error {
|
||||
grantDescr = &descr.Grant{
|
||||
ID: auxuuid.NewUUID(),
|
||||
AccountID: accountDescr.ID,
|
||||
Right: descr.RightWriteFiles,
|
||||
Right: terms.RightWriteFiles,
|
||||
Pattern: ".*",
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
CreatedBy: descr.ServerID,
|
||||
UpdatedBy: descr.ServerID,
|
||||
CreatedBy: terms.ServerID,
|
||||
UpdatedBy: terms.ServerID,
|
||||
}
|
||||
err = db.InsertGrant(ctx, grantDescr)
|
||||
if err != nil {
|
||||
@@ -123,12 +124,12 @@ func (db *Database) WriteInituser(ctx context.Context) error {
|
||||
grantDescr = &descr.Grant{
|
||||
ID: auxuuid.NewUUID(),
|
||||
AccountID: accountDescr.ID,
|
||||
Right: descr.RightReadAccounts,
|
||||
Right: terms.RightReadAccounts,
|
||||
Pattern: ".*",
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
CreatedBy: descr.ServerID,
|
||||
UpdatedBy: descr.ServerID,
|
||||
CreatedBy: terms.ServerID,
|
||||
UpdatedBy: terms.ServerID,
|
||||
}
|
||||
err = db.InsertGrant(ctx, grantDescr)
|
||||
if err != nil {
|
||||
@@ -137,12 +138,12 @@ func (db *Database) WriteInituser(ctx context.Context) error {
|
||||
grantDescr = &descr.Grant{
|
||||
ID: auxuuid.NewUUID(),
|
||||
AccountID: accountDescr.ID,
|
||||
Right: descr.RightWriteAccounts,
|
||||
Right: terms.RightWriteAccounts,
|
||||
Pattern: ".*",
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
CreatedBy: descr.ServerID,
|
||||
UpdatedBy: descr.ServerID,
|
||||
CreatedBy: terms.ServerID,
|
||||
UpdatedBy: terms.ServerID,
|
||||
}
|
||||
err = db.InsertGrant(ctx, grantDescr)
|
||||
if err != nil {
|
||||
@@ -152,12 +153,12 @@ func (db *Database) WriteInituser(ctx context.Context) error {
|
||||
grantDescr = &descr.Grant{
|
||||
ID: auxuuid.NewUUID(),
|
||||
AccountID: accountDescr.ID,
|
||||
Right: descr.RightReadImages,
|
||||
Right: terms.RightReadImages,
|
||||
Pattern: ".*",
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
CreatedBy: descr.ServerID,
|
||||
UpdatedBy: descr.ServerID,
|
||||
CreatedBy: terms.ServerID,
|
||||
UpdatedBy: terms.ServerID,
|
||||
}
|
||||
err = db.InsertGrant(ctx, grantDescr)
|
||||
if err != nil {
|
||||
@@ -166,12 +167,12 @@ func (db *Database) WriteInituser(ctx context.Context) error {
|
||||
grantDescr = &descr.Grant{
|
||||
ID: auxuuid.NewUUID(),
|
||||
AccountID: accountDescr.ID,
|
||||
Right: descr.RightWriteImages,
|
||||
Right: terms.RightWriteImages,
|
||||
Pattern: ".*",
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
CreatedBy: descr.ServerID,
|
||||
UpdatedBy: descr.ServerID,
|
||||
CreatedBy: terms.ServerID,
|
||||
UpdatedBy: terms.ServerID,
|
||||
}
|
||||
err = db.InsertGrant(ctx, grantDescr)
|
||||
if err != nil {
|
||||
|
||||
@@ -12,7 +12,7 @@ package maindb
|
||||
import (
|
||||
"context"
|
||||
|
||||
"mstore/app/descr"
|
||||
"mstore/pkg/descr"
|
||||
)
|
||||
|
||||
func (db *Database) InsertManifest(ctx context.Context, manifest *descr.Manifest) error {
|
||||
|
||||
@@ -4,10 +4,10 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"mstore/app/descr"
|
||||
"mstore/pkg/auxpwd"
|
||||
"mstore/pkg/auxtool"
|
||||
"mstore/pkg/auxuuid"
|
||||
"mstore/pkg/descr"
|
||||
)
|
||||
|
||||
type CreateAccountParams struct {
|
||||
|
||||
+65
-17
@@ -20,9 +20,10 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"mstore/app/descr"
|
||||
"mstore/pkg/auxtool"
|
||||
"mstore/pkg/auxuuid"
|
||||
"mstore/pkg/descr"
|
||||
"mstore/pkg/terms"
|
||||
)
|
||||
|
||||
// FileInfo
|
||||
@@ -358,8 +359,8 @@ func (oper *Operator) ListCollections(ctx context.Context, operID string, param
|
||||
|
||||
// DeleteColletion
|
||||
type DeleteColletionParams struct {
|
||||
Path string
|
||||
IsPattern bool `params:"isPattern"`
|
||||
Path string
|
||||
PathAs string `param:"pathAs"`
|
||||
}
|
||||
type DeleteColletionResult struct {
|
||||
Files []descr.File `json:"collection,omitempty"`
|
||||
@@ -375,24 +376,71 @@ func (oper *Operator) DeleteColletion(ctx context.Context, operID string, param
|
||||
code := http.StatusInternalServerError
|
||||
return code, res, err
|
||||
}
|
||||
fileDescrs, err := oper.mdb.ListFilesByCollection(ctx, param.Path)
|
||||
if err != nil {
|
||||
code := http.StatusInternalServerError
|
||||
return code, res, err
|
||||
}
|
||||
// TODO: transaction
|
||||
for _, file := range fileDescrs {
|
||||
err = oper.store.DeleteFile(file.Collection, file.Name)
|
||||
if err != nil {
|
||||
oper.logg.Warningf("%v", err)
|
||||
err = nil
|
||||
}
|
||||
err = oper.mdb.DeleteFileByCollectionName(ctx, file.Collection, file.Name)
|
||||
oper.logg.Debugf("=== Use path as %s", param.PathAs)
|
||||
switch terms.PathAs(param.PathAs) {
|
||||
case terms.AsPrefix:
|
||||
fileDescrs, err := oper.mdb.ListAllFiles(ctx)
|
||||
if err != nil {
|
||||
code := http.StatusInternalServerError
|
||||
return code, res, err
|
||||
}
|
||||
res.Files = append(res.Files, file)
|
||||
|
||||
collMap := make(map[string]bool)
|
||||
for _, item := range fileDescrs {
|
||||
_, exists := collMap[item.Collection]
|
||||
if !exists {
|
||||
collMap[item.Collection] = true
|
||||
}
|
||||
}
|
||||
collections := make([]string, len(collMap))
|
||||
for key, _ := range collMap {
|
||||
collections = append(collections, key)
|
||||
}
|
||||
for _, collection := range collections {
|
||||
if strings.HasPrefix(collection, param.Path) {
|
||||
|
||||
fileDescrs, err := oper.mdb.ListFilesByCollection(ctx, collection)
|
||||
if err != nil {
|
||||
code := http.StatusInternalServerError
|
||||
return code, res, err
|
||||
}
|
||||
// TODO: transaction
|
||||
for _, file := range fileDescrs {
|
||||
err = oper.store.DeleteFile(file.Collection, file.Name)
|
||||
if err != nil {
|
||||
oper.logg.Warningf("%v", err)
|
||||
err = nil
|
||||
}
|
||||
err = oper.mdb.DeleteFileByCollectionName(ctx, file.Collection, file.Name)
|
||||
if err != nil {
|
||||
code := http.StatusInternalServerError
|
||||
return code, res, err
|
||||
}
|
||||
res.Files = append(res.Files, file)
|
||||
}
|
||||
}
|
||||
}
|
||||
default:
|
||||
fileDescrs, err := oper.mdb.ListFilesByCollection(ctx, param.Path)
|
||||
if err != nil {
|
||||
code := http.StatusInternalServerError
|
||||
return code, res, err
|
||||
}
|
||||
|
||||
// TODO: transaction
|
||||
for _, file := range fileDescrs {
|
||||
err = oper.store.DeleteFile(file.Collection, file.Name)
|
||||
if err != nil {
|
||||
oper.logg.Warningf("%v", err)
|
||||
err = nil
|
||||
}
|
||||
err = oper.mdb.DeleteFileByCollectionName(ctx, file.Collection, file.Name)
|
||||
if err != nil {
|
||||
code := http.StatusInternalServerError
|
||||
return code, res, err
|
||||
}
|
||||
res.Files = append(res.Files, file)
|
||||
}
|
||||
}
|
||||
code := http.StatusOK
|
||||
return code, res, err
|
||||
|
||||
@@ -5,9 +5,9 @@ import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
|
||||
"mstore/app/descr"
|
||||
"mstore/pkg/auxtool"
|
||||
"mstore/pkg/auxuuid"
|
||||
"mstore/pkg/descr"
|
||||
)
|
||||
|
||||
// CreateGrant
|
||||
|
||||
@@ -18,8 +18,8 @@ import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"mstore/app/descr"
|
||||
"mstore/pkg/auxoci"
|
||||
"mstore/pkg/descr"
|
||||
)
|
||||
|
||||
type ManifestExistsParams struct {
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
package operator
|
||||
|
||||
import (
|
||||
"mstore/app/descr"
|
||||
"mstore/pkg/auxtool"
|
||||
"mstore/pkg/auxuuid"
|
||||
"mstore/pkg/descr"
|
||||
|
||||
ocidigest "github.com/opencontainers/go-digest"
|
||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
|
||||
@@ -22,7 +22,6 @@ import (
|
||||
"time"
|
||||
|
||||
"mstore/app/config"
|
||||
"mstore/app/descr"
|
||||
"mstore/app/handler"
|
||||
"mstore/app/logger"
|
||||
"mstore/app/maindb"
|
||||
@@ -30,6 +29,7 @@ import (
|
||||
"mstore/app/service"
|
||||
"mstore/app/storage"
|
||||
"mstore/pkg/auxtool"
|
||||
"mstore/pkg/descr"
|
||||
|
||||
yaml "go.yaml.in/yaml/v4"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user