2022-09-30 12:35:16 -05:00
|
|
|
package storage
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
type StoreController struct {
|
|
|
|
DefaultStore ImageStore
|
|
|
|
SubStore map[string]ImageStore
|
|
|
|
}
|
|
|
|
|
|
|
|
// BlobUpload models and upload request.
|
|
|
|
type BlobUpload struct {
|
|
|
|
StoreName string
|
|
|
|
ID string
|
|
|
|
}
|
|
|
|
|
2023-04-18 13:07:47 -05:00
|
|
|
func GetRoutePrefix(name string) string {
|
2022-09-30 12:35:16 -05:00
|
|
|
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) 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
|
2023-04-18 13:07:47 -05:00
|
|
|
prefixName := GetRoutePrefix(name)
|
2022-09-30 12:35:16 -05:00
|
|
|
|
|
|
|
imgStore, ok := sc.SubStore[prefixName]
|
|
|
|
if !ok {
|
|
|
|
imgStore = sc.DefaultStore
|
|
|
|
}
|
|
|
|
|
|
|
|
return imgStore
|
|
|
|
}
|
|
|
|
|
|
|
|
return sc.DefaultStore
|
|
|
|
}
|