2020-05-19 14:44:16 +02:00
|
|
|
package registry
|
|
|
|
|
|
|
|
import (
|
2021-09-27 19:51:55 +02:00
|
|
|
"github.com/woodpecker-ci/woodpecker/server/model"
|
2020-05-19 14:44:16 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type combined struct {
|
|
|
|
registries []model.ReadOnlyRegistryService
|
|
|
|
dbRegistry model.RegistryService
|
|
|
|
}
|
|
|
|
|
|
|
|
func Combined(dbRegistry model.RegistryService, registries ...model.ReadOnlyRegistryService) model.RegistryService {
|
|
|
|
registries = append(registries, dbRegistry)
|
|
|
|
return &combined{
|
|
|
|
registries: registries,
|
|
|
|
dbRegistry: dbRegistry,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c combined) RegistryFind(repo *model.Repo, name string) (*model.Registry, error) {
|
|
|
|
for _, registry := range c.registries {
|
|
|
|
res, err := registry.RegistryFind(repo, name)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if res != nil {
|
|
|
|
return res, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c combined) RegistryList(repo *model.Repo) ([]*model.Registry, error) {
|
2020-05-19 16:05:45 +02:00
|
|
|
var registries []*model.Registry
|
|
|
|
for _, registry := range c.registries {
|
|
|
|
list, err := registry.RegistryList(repo)
|
2020-05-19 14:44:16 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-05-19 16:05:45 +02:00
|
|
|
registries = append(registries, list...)
|
2020-05-19 14:44:16 +02:00
|
|
|
}
|
2020-05-19 16:05:45 +02:00
|
|
|
return registries, nil
|
2020-05-19 14:44:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c combined) RegistryCreate(repo *model.Repo, registry *model.Registry) error {
|
|
|
|
return c.dbRegistry.RegistryCreate(repo, registry)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c combined) RegistryUpdate(repo *model.Repo, registry *model.Registry) error {
|
|
|
|
return c.dbRegistry.RegistryUpdate(repo, registry)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c combined) RegistryDelete(repo *model.Repo, name string) error {
|
|
|
|
return c.dbRegistry.RegistryDelete(repo, name)
|
|
|
|
}
|