// 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-go/plugin/registry" "github.com/drone/drone/core" ) // EndpointSource returns a registry credential provider // that sources registry credentials from an http endpoint. func EndpointSource(endpoint, secret string, skipVerify bool) core.RegistryService { return &service{ endpoint: endpoint, secret: secret, skipVerify: skipVerify, } } type service struct { endpoint string secret string skipVerify bool } func (c *service) List(ctx context.Context, in *core.RegistryArgs) ([]*core.Registry, error) { if c.endpoint == "" { return nil, nil } req := ®istry.Request{ Repo: toRepo(in.Repo), Build: toBuild(in.Build), } client := registry.Client(c.endpoint, c.secret, c.skipVerify) res, err := client.List(ctx, req) if err != nil { return nil, err } var registries []*core.Registry for _, registry := range res { registries = append(registries, &core.Registry{ Address: registry.Address, Username: registry.Username, Password: registry.Password, }) } return registries, nil }