// Copyright 2019 Drone.IO Inc. All rights reserved. // Use of this source code is governed by the Drone Non-Commercial License // that can be found in the LICENSE file. package registry import ( "context" "github.com/drone/drone/logger" "github.com/drone/drone/core" "github.com/sirupsen/logrus" ) // Combine combines the registry services, allowing the // system to source registry credential from multiple sources. func Combine(services ...core.RegistryService) core.RegistryService { return &combined{services} } type combined struct { sources []core.RegistryService } func (c *combined) List(ctx context.Context, req *core.RegistryArgs) ([]*core.Registry, error) { var all []*core.Registry for _, source := range c.sources { list, err := source.List(ctx, req) if err != nil { return all, err } all = append(all, list...) } // if trace level debugging is enabled we print // all registry credentials retrieved from the // various registy sources. logger := logger.FromContext(ctx) if logrus.IsLevelEnabled(logrus.TraceLevel) { if len(all) == 0 { logger.Traceln("registry: no registry credentials loaded") } for _, registry := range all { logger.WithField("address", registry.Address). Traceln("registry: registry credentials loaded") } } return all, nil }