forked from harness/harness
-
Notifications
You must be signed in to change notification settings - Fork 0
/
secrets.go
45 lines (40 loc) · 1.06 KB
/
secrets.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
package builtin
import (
"github.com/drone/drone/engine/compiler/parse"
"github.com/drone/drone/model"
)
type secretOp struct {
visitor
event string
secrets []*model.Secret
}
// NewSecretOp returns a transformer that configures plugin secrets.
func NewSecretOp(event string, secrets []*model.Secret) Visitor {
return &secretOp{
event: event,
secrets: secrets,
}
}
func (v *secretOp) VisitContainer(node *parse.ContainerNode) error {
for _, secret := range v.secrets {
if !secret.Match(node.Container.Image, v.event) {
continue
}
switch secret.Name {
case "REGISTRY_USERNAME":
node.Container.AuthConfig.Username = secret.Value
case "REGISTRY_PASSWORD":
node.Container.AuthConfig.Password = secret.Value
case "REGISTRY_EMAIL":
node.Container.AuthConfig.Email = secret.Value
case "REGISTRY_TOKEN":
node.Container.AuthConfig.Token = secret.Value
default:
if node.Container.Environment == nil {
node.Container.Environment = map[string]string{}
}
node.Container.Environment[secret.Name] = secret.Value
}
}
return nil
}