forked from harness/gitness
/
plugin.go
48 lines (41 loc) · 1.27 KB
/
plugin.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright 2018 Drone.IO Inc
// Use of this software is governed by the Drone Enterpise License
// that can be found in the LICENSE file.
package secrets
import (
"github.com/drone/drone/model"
"github.com/drone/drone/store"
)
// NewDefault returns the Store wrapped as a Service.
func NewDefault(store store.Store) model.SecretService {
return New(store)
}
// Plugin defines the required interface for implementing a remote
// secret plugin and sourcing secrets from an external source.
type Plugin interface {
SecretListBuild(*model.Repo, *model.Build) ([]*model.Secret, error)
}
// Extend exetends the base secret service with the plugin.
func Extend(base model.SecretService, with Plugin) model.SecretService {
return &extender{base, with}
}
type extender struct {
model.SecretService
plugin Plugin
}
// extends the base secret service and combines the secret list with the
// secret list returned by the plugin.
func (e *extender) SecretListBuild(repo *model.Repo, build *model.Build) ([]*model.Secret, error) {
base, err := e.SecretService.SecretListBuild(repo, build)
if err != nil {
return nil, err
}
with, err := e.plugin.SecretListBuild(repo, build)
if err != nil {
return nil, err
}
for _, secret := range base {
with = append(with, secret)
}
return with, nil
}