2016-03-31 21:01:32 +02:00
|
|
|
package model
|
|
|
|
|
2016-07-31 22:29:56 +02:00
|
|
|
import (
|
|
|
|
"path/filepath"
|
|
|
|
)
|
2016-04-21 10:18:20 +02:00
|
|
|
|
2016-03-31 21:01:32 +02:00
|
|
|
type Secret struct {
|
2016-04-21 10:18:20 +02:00
|
|
|
// the name of the secret which will be used as the environment variable
|
|
|
|
// name at runtime.
|
2016-07-31 22:29:56 +02:00
|
|
|
Name string `json:"name"`
|
2016-03-31 21:01:32 +02:00
|
|
|
|
2016-04-21 10:18:20 +02:00
|
|
|
// the value of the secret which will be provided to the runtime environment
|
|
|
|
// as a named environment variable.
|
2016-07-31 22:29:56 +02:00
|
|
|
Value string `json:"value"`
|
2016-03-31 21:01:32 +02:00
|
|
|
|
|
|
|
// the secret is restricted to this list of images.
|
2016-07-31 22:29:56 +02:00
|
|
|
Images []string `json:"image,omitempty"`
|
2016-03-31 21:01:32 +02:00
|
|
|
|
|
|
|
// the secret is restricted to this list of events.
|
2016-07-31 22:29:56 +02:00
|
|
|
Events []string `json:"event,omitempty"`
|
2016-10-19 20:50:09 +02:00
|
|
|
|
|
|
|
// whether the secret requires verification
|
|
|
|
SkipVerify bool `json:"skip_verify"`
|
2016-11-16 21:28:36 +02:00
|
|
|
|
|
|
|
// whether the secret should be concealed in the build log
|
|
|
|
Conceal bool `json:"conceal"`
|
2016-03-31 21:01:32 +02:00
|
|
|
}
|
|
|
|
|
2016-04-21 09:25:30 +02:00
|
|
|
// Match returns true if an image and event match the restricted list.
|
|
|
|
func (s *Secret) Match(image, event string) bool {
|
|
|
|
return s.MatchImage(image) && s.MatchEvent(event)
|
|
|
|
}
|
|
|
|
|
|
|
|
// MatchImage returns true if an image matches the restricted list.
|
2016-04-21 10:18:20 +02:00
|
|
|
func (s *Secret) MatchImage(image string) bool {
|
|
|
|
for _, pattern := range s.Images {
|
|
|
|
if match, _ := filepath.Match(pattern, image); match {
|
2016-04-21 09:25:30 +02:00
|
|
|
return true
|
2016-04-23 22:51:12 +02:00
|
|
|
} else if pattern == "*" {
|
|
|
|
return true
|
2016-04-21 09:25:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// MatchEvent returns true if an event matches the restricted list.
|
2016-04-21 10:18:20 +02:00
|
|
|
func (s *Secret) MatchEvent(event string) bool {
|
|
|
|
for _, pattern := range s.Events {
|
|
|
|
if match, _ := filepath.Match(pattern, event); match {
|
2016-04-21 09:25:30 +02:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// Validate validates the required fields and formats.
|
2016-03-31 21:01:32 +02:00
|
|
|
func (s *Secret) Validate() error {
|
|
|
|
return nil
|
|
|
|
}
|