2016-03-31 19:01:32 +00:00
|
|
|
package model
|
|
|
|
|
2016-04-21 08:18:20 +00:00
|
|
|
import "path/filepath"
|
|
|
|
|
2016-03-31 19:01:32 +00:00
|
|
|
type Secret struct {
|
|
|
|
// the id for this secret.
|
|
|
|
ID int64 `json:"id" meddler:"secret_id,pk"`
|
|
|
|
|
|
|
|
// the foreign key for this secret.
|
|
|
|
RepoID int64 `json:"-" meddler:"secret_repo_id"`
|
|
|
|
|
2016-04-21 08:18:20 +00:00
|
|
|
// the name of the secret which will be used as the environment variable
|
|
|
|
// name at runtime.
|
2016-03-31 19:01:32 +00:00
|
|
|
Name string `json:"name" meddler:"secret_name"`
|
|
|
|
|
2016-04-21 08:18:20 +00:00
|
|
|
// the value of the secret which will be provided to the runtime environment
|
|
|
|
// as a named environment variable.
|
2016-03-31 19:01:32 +00:00
|
|
|
Value string `json:"value" meddler:"secret_value"`
|
|
|
|
|
|
|
|
// the secret is restricted to this list of images.
|
|
|
|
Images []string `json:"image,omitempty" meddler:"secret_images,json"`
|
|
|
|
|
|
|
|
// the secret is restricted to this list of events.
|
|
|
|
Events []string `json:"event,omitempty" meddler:"secret_events,json"`
|
|
|
|
}
|
|
|
|
|
2016-04-21 07:25:30 +00: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 08:18:20 +00:00
|
|
|
func (s *Secret) MatchImage(image string) bool {
|
|
|
|
for _, pattern := range s.Images {
|
|
|
|
if match, _ := filepath.Match(pattern, image); match {
|
2016-04-21 07:25:30 +00:00
|
|
|
return true
|
2016-04-23 20:51:12 +00:00
|
|
|
} else if pattern == "*" {
|
|
|
|
return true
|
2016-04-21 07:25:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// MatchEvent returns true if an event matches the restricted list.
|
2016-04-21 08:18:20 +00:00
|
|
|
func (s *Secret) MatchEvent(event string) bool {
|
|
|
|
for _, pattern := range s.Events {
|
|
|
|
if match, _ := filepath.Match(pattern, event); match {
|
2016-04-21 07:25:30 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// Validate validates the required fields and formats.
|
2016-03-31 19:01:32 +00:00
|
|
|
func (s *Secret) Validate() error {
|
|
|
|
return nil
|
|
|
|
}
|