harbor/models/replication_job.go

141 lines
4.7 KiB
Go
Raw Normal View History

2016-05-10 13:38:50 +02:00
package models
import (
"time"
"github.com/astaxie/beego/validation"
2016-05-10 13:38:50 +02:00
)
const (
//JobPending ...
JobPending string = "pending"
//JobRunning ...
JobRunning string = "running"
//JobError ...
JobError string = "error"
//JobStopped ...
JobStopped string = "stopped"
//JobFinished ...
2016-05-10 13:38:50 +02:00
JobFinished string = "finished"
//JobCanceled ...
2016-05-10 13:38:50 +02:00
JobCanceled string = "canceled"
//JobContinue is the status returned by statehandler to tell statemachine to move to next possible state based on trasition table.
JobContinue string = "_continue"
//RepOpTransfer represents the operation of a job to transfer repository to a remote registry/harbor instance.
2016-05-10 13:38:50 +02:00
RepOpTransfer string = "transfer"
//RepOpDelete represents the operation of a job to remove repository from a remote registry/harbor instance.
RepOpDelete string = "delete"
//UISecretCookie is the cookie name to contain the UI secret
UISecretCookie string = "uisecret"
2016-05-10 13:38:50 +02:00
)
// RepPolicy is the model for a replication policy, which associate to a project and a target (destination)
2016-05-10 13:38:50 +02:00
type RepPolicy struct {
2016-06-13 10:49:46 +02:00
ID int64 `orm:"column(id)" json:"id"`
ProjectID int64 `orm:"column(project_id)" json:"project_id"`
ProjectName string `json:"project_name,omitempty"`
TargetID int64 `orm:"column(target_id)" json:"target_id"`
TargetName string `json:"target_name,omitempty"`
Name string `orm:"column(name)" json:"name"`
2016-05-17 12:49:02 +02:00
// Target RepTarget `orm:"-" json:"target"`
2016-05-10 13:38:50 +02:00
Enabled int `orm:"column(enabled)" json:"enabled"`
Description string `orm:"column(description)" json:"description"`
CronStr string `orm:"column(cron_str)" json:"cron_str"`
StartTime time.Time `orm:"column(start_time)" json:"start_time"`
CreationTime time.Time `orm:"column(creation_time);auto_now_add" json:"creation_time"`
UpdateTime time.Time `orm:"column(update_time);auto_now" json:"update_time"`
}
2016-06-06 11:36:48 +02:00
// Valid ...
func (r *RepPolicy) Valid(v *validation.Validation) {
if len(r.Name) == 0 {
v.SetError("name", "can not be empty")
}
if len(r.Name) > 256 {
v.SetError("name", "max length is 256")
}
if r.ProjectID <= 0 {
v.SetError("project_id", "invalid")
}
if r.TargetID <= 0 {
v.SetError("target_id", "invalid")
}
if r.Enabled != 0 && r.Enabled != 1 {
v.SetError("enabled", "must be 0 or 1")
}
if len(r.CronStr) > 256 {
v.SetError("cron_str", "max length is 256")
}
}
// RepJob is the model for a replication job, which is the execution unit on job service, currently it is used to transfer/remove
// a repository to/from a remote registry instance.
2016-05-10 13:38:50 +02:00
type RepJob struct {
ID int64 `orm:"column(id)" json:"id"`
Status string `orm:"column(status)" json:"status"`
Repository string `orm:"column(repository)" json:"repository"`
PolicyID int64 `orm:"column(policy_id)" json:"policy_id"`
Operation string `orm:"column(operation)" json:"operation"`
Tags string `orm:"column(tags)" json:"-"`
TagList []string `orm:"-" json:"tags"`
2016-05-17 12:49:02 +02:00
// Policy RepPolicy `orm:"-" json:"policy"`
2016-05-10 13:38:50 +02:00
CreationTime time.Time `orm:"column(creation_time);auto_now_add" json:"creation_time"`
UpdateTime time.Time `orm:"column(update_time);auto_now" json:"update_time"`
}
// RepTarget is the model for a replication targe, i.e. destination, which wraps the endpoint URL and username/password of a remote registry.
2016-05-10 13:38:50 +02:00
type RepTarget struct {
ID int64 `orm:"column(id)" json:"id"`
2016-06-03 10:16:31 +02:00
URL string `orm:"column(url)" json:"endpoint"`
2016-05-10 13:38:50 +02:00
Name string `orm:"column(name)" json:"name"`
Username string `orm:"column(username)" json:"username"`
Password string `orm:"column(password)" json:"password"`
CreationTime time.Time `orm:"column(creation_time);auto_now_add" json:"creation_time"`
UpdateTime time.Time `orm:"column(update_time);auto_now" json:"update_time"`
}
// Valid ...
func (r *RepTarget) Valid(v *validation.Validation) {
if len(r.Name) == 0 {
v.SetError("name", "can not be empty")
}
if len(r.Name) > 64 {
v.SetError("name", "max length is 64")
}
if len(r.URL) == 0 {
v.SetError("endpoint", "can not be empty")
}
if len(r.URL) > 64 {
v.SetError("endpoint", "max length is 64")
}
// password is encoded using base64, the length of this field
// in DB is 64, so the max length in request is 48
if len(r.Password) > 48 {
v.SetError("password", "max length is 48")
}
}
//TableName is required by by beego orm to map RepTarget to table replication_target
2016-06-06 11:36:48 +02:00
func (r *RepTarget) TableName() string {
2016-05-10 13:38:50 +02:00
return "replication_target"
}
//TableName is required by by beego orm to map RepJob to table replication_job
2016-06-06 11:36:48 +02:00
func (r *RepJob) TableName() string {
2016-05-10 13:38:50 +02:00
return "replication_job"
}
//TableName is required by by beego orm to map RepPolicy to table replication_policy
2016-06-06 11:36:48 +02:00
func (r *RepPolicy) TableName() string {
2016-05-10 13:38:50 +02:00
return "replication_policy"
}