github.com/drone/runner-go@v1.12.0/secret/combine.go (about) 1 // Copyright 2019 Drone.IO Inc. All rights reserved. 2 // Use of this source code is governed by the Polyform License 3 // that can be found in the LICENSE file. 4 5 package secret 6 7 import ( 8 "context" 9 10 "github.com/drone/drone-go/drone" 11 ) 12 13 // Combine returns a new combined secret provider, capable of 14 // sourcing secrets from multiple providers. 15 func Combine(sources ...Provider) Provider { 16 return &combined{sources} 17 } 18 19 type combined struct { 20 sources []Provider 21 } 22 23 func (p *combined) Find(ctx context.Context, in *Request) (*drone.Secret, error) { 24 for _, source := range p.sources { 25 secret, err := source.Find(ctx, in) 26 if err != nil { 27 return nil, err 28 } 29 if secret == nil { 30 continue 31 } 32 // if the secret object is not nil, but is empty 33 // we should assume the secret service returned a 34 // 204 no content, and proceed to the next service 35 // in the chain. 36 if secret.Data == "" { 37 continue 38 } 39 return secret, nil 40 } 41 return nil, nil 42 }