0
Fork 0
mirror of https://github.com/project-zot/zot.git synced 2025-03-04 02:02:49 -05:00
zot/pkg/storage/storage_controller.go
peusebiu 772e90a6c5
Catalog content discovery (#2782)
fix(sync): use pagination when querying remote catalog

feat(api): added /v2/_catalog pagination, fixes #2715

Signed-off-by: Eusebiu Petu <petu.eusebiu@gmail.com>
2024-12-19 09:38:35 -08:00

70 lines
1.4 KiB
Go

package storage
import (
"strings"
storageTypes "zotregistry.dev/zot/pkg/storage/types"
)
const (
CosignType = "cosign"
NotationType = "notation"
DefaultStorePath = "/"
)
type StoreController struct {
DefaultStore storageTypes.ImageStore
SubStore map[string]storageTypes.ImageStore
}
func GetRoutePrefix(name string) string {
names := strings.SplitN(name, "/", 2) //nolint:mnd
if len(names) != 2 { //nolint:mnd
// it means route is of global storage e.g "centos:latest"
if len(names) == 1 {
return "/"
}
}
return "/" + names[0]
}
func (sc StoreController) GetStorePath(name string) string {
if sc.SubStore != nil && name != "" {
subStorePath := GetRoutePrefix(name)
_, ok := sc.SubStore[subStorePath]
if !ok {
return DefaultStorePath
}
return subStorePath
}
return DefaultStorePath
}
func (sc StoreController) GetImageStore(name string) storageTypes.ImageStore {
if sc.SubStore != nil {
// SubStore is being provided, now we need to find equivalent image store and this will be found by splitting name
prefixName := GetRoutePrefix(name)
imgStore, ok := sc.SubStore[prefixName]
if !ok {
imgStore = sc.DefaultStore
}
return imgStore
}
return sc.DefaultStore
}
func (sc StoreController) GetDefaultImageStore() storageTypes.ImageStore {
return sc.DefaultStore
}
func (sc StoreController) GetImageSubStores() map[string]storageTypes.ImageStore {
return sc.SubStore
}