diff --git a/model/repo_secret.go b/model/repo_secret.go new file mode 100644 index 000000000..a450f434a --- /dev/null +++ b/model/repo_secret.go @@ -0,0 +1,48 @@ +package model + +type RepoSecret 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"` + + // the name of the secret which will be used as the environment variable + // name at runtime. + Name string `json:"name" meddler:"secret_name"` + + // the value of the secret which will be provided to the runtime environment + // as a named environment variable. + 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"` +} + +// Secret transforms a repo secret into a simple secret. +func (s *RepoSecret) Secret() *Secret { + return &Secret{ + Name: s.Name, + Value: s.Value, + Images: s.Images, + Events: s.Events, + } +} + +// Clone provides a repo secrets clone without the value. +func (s *RepoSecret) Clone() *RepoSecret { + return &RepoSecret{ + ID: s.ID, + Name: s.Name, + Images: s.Images, + Events: s.Events, + } +} + +// Validate validates the required fields and formats. +func (s *RepoSecret) Validate() error { + return nil +} diff --git a/model/secret.go b/model/secret.go index 9f1c2f798..b28a57e3b 100644 --- a/model/secret.go +++ b/model/secret.go @@ -1,27 +1,23 @@ package model -import "path/filepath" +import ( + "path/filepath" +) 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"` - // the name of the secret which will be used as the environment variable // name at runtime. - Name string `json:"name" meddler:"secret_name"` + Name string `json:"name"` // the value of the secret which will be provided to the runtime environment // as a named environment variable. - Value string `json:"value" meddler:"secret_value"` + Value string `json:"value"` // the secret is restricted to this list of images. - Images []string `json:"image,omitempty" meddler:"secret_images,json"` + Images []string `json:"image,omitempty"` // the secret is restricted to this list of events. - Events []string `json:"event,omitempty" meddler:"secret_events,json"` + Events []string `json:"event,omitempty"` } // Match returns true if an image and event match the restricted list. @@ -55,12 +51,3 @@ func (s *Secret) MatchEvent(event string) bool { func (s *Secret) Validate() error { return nil } - -func (s *Secret) Clone() *Secret { - return &Secret{ - ID: s.ID, - Name: s.Name, - Images: s.Images, - Events: s.Events, - } -} diff --git a/model/team_secret.go b/model/team_secret.go new file mode 100644 index 000000000..75108b454 --- /dev/null +++ b/model/team_secret.go @@ -0,0 +1,48 @@ +package model + +type TeamSecret struct { + // the id for this secret. + ID int64 `json:"id" meddler:"team_secret_id,pk"` + + // the foreign key for this secret. + Key string `json:"-" meddler:"team_secret_key"` + + // the name of the secret which will be used as the environment variable + // name at runtime. + Name string `json:"name" meddler:"team_secret_name"` + + // the value of the secret which will be provided to the runtime environment + // as a named environment variable. + Value string `json:"value" meddler:"team_secret_value"` + + // the secret is restricted to this list of images. + Images []string `json:"image,omitempty" meddler:"team_secret_images,json"` + + // the secret is restricted to this list of events. + Events []string `json:"event,omitempty" meddler:"team_secret_events,json"` +} + +// Secret transforms a repo secret into a simple secret. +func (s *TeamSecret) Secret() *Secret { + return &Secret{ + Name: s.Name, + Value: s.Value, + Images: s.Images, + Events: s.Events, + } +} + +// Clone provides a repo secrets clone without the value. +func (s *TeamSecret) Clone() *TeamSecret { + return &TeamSecret{ + ID: s.ID, + Name: s.Name, + Images: s.Images, + Events: s.Events, + } +} + +// Validate validates the required fields and formats. +func (s *TeamSecret) Validate() error { + return nil +}