mirror of
https://github.com/project-zot/zot.git
synced 2024-12-16 21:56:37 -05:00
a3f355c278
Signed-off-by: Laurentiu Niculae <niculae.laurentiu1@gmail.com>
47 lines
959 B
Go
47 lines
959 B
Go
package storage
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
storageTypes "zotregistry.io/zot/pkg/storage/types"
|
|
)
|
|
|
|
const (
|
|
CosignType = "cosign"
|
|
NotationType = "notation"
|
|
)
|
|
|
|
type StoreController struct {
|
|
DefaultStore storageTypes.ImageStore
|
|
SubStore map[string]storageTypes.ImageStore
|
|
}
|
|
|
|
func GetRoutePrefix(name string) string {
|
|
names := strings.SplitN(name, "/", 2) //nolint:gomnd
|
|
|
|
if len(names) != 2 { //nolint:gomnd
|
|
// it means route is of global storage e.g "centos:latest"
|
|
if len(names) == 1 {
|
|
return "/"
|
|
}
|
|
}
|
|
|
|
return fmt.Sprintf("/%s", names[0])
|
|
}
|
|
|
|
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
|
|
}
|