mirror of
https://github.com/project-zot/zot.git
synced 2024-12-16 21:56:37 -05:00
ba6f347d8d
Which could be imported independently. See more details: 1. "zotregistry.io/zot/pkg/test/common" - currently used as tcommon "zotregistry.io/zot/pkg/test/common" - inside pkg/test test "zotregistry.io/zot/pkg/test/common" - in tests . "zotregistry.io/zot/pkg/test/common" - in tests Decouple zb from code in test/pkg in order to keep the size small. 2. "zotregistry.io/zot/pkg/test/image-utils" - curently used as . "zotregistry.io/zot/pkg/test/image-utils" 3. "zotregistry.io/zot/pkg/test/deprecated" - curently used as "zotregistry.io/zot/pkg/test/deprecated" This one will bre replaced gradually by image-utils in the future. 4. "zotregistry.io/zot/pkg/test/signature" - (cosign + notation) use as "zotregistry.io/zot/pkg/test/signature" 5. "zotregistry.io/zot/pkg/test/auth" - (bearer + oidc) curently used as authutils "zotregistry.io/zot/pkg/test/auth" 6. "zotregistry.io/zot/pkg/test/oci-utils" - curently used as ociutils "zotregistry.io/zot/pkg/test/oci-utils" Some unused functions were removed, some were replaced, and in a few cases specific funtions were moved to the files they were used in. Added an interface for the StoreController, this reduces the number of imports of the entire image store, decreasing binary size for tests. If the zb code was still coupled with pkg/test, this would have reflected in zb size. Signed-off-by: Andrei Aaron <aaaron@luxoft.com>
55 lines
1.1 KiB
Go
55 lines
1.1 KiB
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
|
|
}
|
|
|
|
func (sc StoreController) GetDefaultImageStore() storageTypes.ImageStore {
|
|
return sc.DefaultStore
|
|
}
|
|
|
|
func (sc StoreController) GetImageSubStores() map[string]storageTypes.ImageStore {
|
|
return sc.SubStore
|
|
}
|