2016-05-09 20:28:49 +02:00
|
|
|
package transform
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/drone/drone/model"
|
|
|
|
"github.com/drone/drone/yaml"
|
|
|
|
)
|
|
|
|
|
2017-01-20 09:16:15 +02:00
|
|
|
//
|
|
|
|
// TODO remove
|
|
|
|
//
|
|
|
|
|
2016-05-10 07:57:57 +02:00
|
|
|
func ImageSecrets(c *yaml.Config, secrets []*model.Secret, event string) error {
|
|
|
|
var images []*yaml.Container
|
|
|
|
images = append(images, c.Pipeline...)
|
|
|
|
images = append(images, c.Services...)
|
2016-05-09 20:28:49 +02:00
|
|
|
|
2016-05-10 07:57:57 +02:00
|
|
|
for _, image := range images {
|
|
|
|
imageSecrets(image, secrets, event)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2016-05-09 20:28:49 +02:00
|
|
|
|
2016-05-10 07:57:57 +02:00
|
|
|
func imageSecrets(c *yaml.Container, secrets []*model.Secret, event string) {
|
|
|
|
for _, secret := range secrets {
|
|
|
|
if !secret.Match(c.Image, event) {
|
|
|
|
continue
|
|
|
|
}
|
2016-05-09 20:28:49 +02:00
|
|
|
|
2016-05-10 07:57:57 +02:00
|
|
|
switch secret.Name {
|
|
|
|
case "REGISTRY_USERNAME":
|
|
|
|
c.AuthConfig.Username = secret.Value
|
|
|
|
case "REGISTRY_PASSWORD":
|
|
|
|
c.AuthConfig.Password = secret.Value
|
|
|
|
case "REGISTRY_EMAIL":
|
|
|
|
c.AuthConfig.Email = secret.Value
|
|
|
|
default:
|
|
|
|
if c.Environment == nil {
|
|
|
|
c.Environment = map[string]string{}
|
|
|
|
}
|
|
|
|
c.Environment[secret.Name] = secret.Value
|
2016-05-09 20:28:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|