Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Added validation check to impose limits on stored, free-form strings #180

Merged
merged 13 commits into from
Aug 18, 2021
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ require (
github.com/pquerna/cachecontrol v0.0.0-20201205024021-ac21108117ac // indirect
github.com/prometheus/client_golang v1.9.0
github.com/prometheus/common v0.19.0 // indirect
github.com/qor/validations v0.0.0-20171228122639-f364bca61b46 // indirect
github.com/sirupsen/logrus v1.8.1
github.com/spf13/cobra v1.1.3
github.com/spf13/pflag v1.0.5
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmV
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
github.com/aryann/difflib v0.0.0-20170710044230-e206f873d14a/go.mod h1:DAHtR1m6lCRdSC2Tm3DSWRPvIPr6xNKyeHdqDQSQT+A=
github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a h1:idn718Q4B6AGu/h5Sxe66HYVdqdGu2l9Iebqhi/AEoA=
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
github.com/aws/amazon-sagemaker-operator-for-k8s v1.0.1-0.20210303003444-0fb33b1fd49d/go.mod h1:mZUP7GJmjiWtf8v3FD1X/QdK08BqyeH/1Ejt0qhNzCs=
github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU=
Expand Down Expand Up @@ -741,6 +742,8 @@ github.com/prometheus/procfs v0.3.0/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4O
github.com/prometheus/procfs v0.6.0 h1:mxy4L2jP6qMonqmq+aTtOx1ifVWUgG/TAmntgbh3xv4=
github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
github.com/qor/validations v0.0.0-20171228122639-f364bca61b46 h1:dRlsVUhwD1pwrasuVbNooGQITYjKzmXK5eYoEEvBGQI=
github.com/qor/validations v0.0.0-20171228122639-f364bca61b46/go.mod h1:UJsA0AuvrKNaWtrb1UzKai10mN3ZBbQkPjUHpxwahTc=
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
github.com/rcrowley/go-metrics v0.0.0-20190826022208-cac0b30c2563/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
Expand Down
2 changes: 2 additions & 0 deletions pkg/repositories/config/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/postgres" // Required to import database driver.
"github.com/qor/validations"
)

const Postgres = "postgres"
Expand Down Expand Up @@ -77,5 +78,6 @@ func OpenDbConnection(config DbConnectionConfigProvider) *gorm.DB {
panic(err)
}
db.LogMode(config.IsDebug())
validations.RegisterCallbacks(db)
return db
}
16 changes: 8 additions & 8 deletions pkg/repositories/models/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ type ExecutionKey struct {
type Execution struct {
BaseModel
ExecutionKey
LaunchPlanID uint `gorm:"index"`
WorkflowID uint `gorm:"index"`
TaskID uint `gorm:"index"`
Phase string
LaunchPlanID uint `gorm:"index"`
WorkflowID uint `gorm:"index"`
TaskID uint `gorm:"index"`
Phase string `valid:"length(3|50)"`
Closure []byte
Spec []byte `gorm:"not null"`
StartedAt *time.Time
Expand All @@ -37,7 +37,7 @@ type Execution struct {
ExecutionEvents []ExecutionEvent
// In the case of an aborted execution this string may be non-empty.
// It should be ignored for any other value of phase other than aborted.
AbortCause string
AbortCause string `valid:"length(3|50)"`
yindia marked this conversation as resolved.
Show resolved Hide resolved
// Corresponds to the execution mode used to trigger this execution
Mode int32
// The "parent" execution (if there is one) that is related to this execution.
Expand All @@ -47,16 +47,16 @@ type Execution struct {
// The parent node execution if this was launched by a node
ParentNodeExecutionID uint
// Cluster where execution was triggered
Cluster string
Cluster string `valid:"length(3|50)"`
// Offloaded location of inputs LiteralMap. These are the inputs evaluated and contain applied defaults.
InputsURI storage.DataReference
// User specified inputs. This map might be incomplete and not include defaults applied
UserInputsURI storage.DataReference
// Execution Error Kind. nullable
ErrorKind *string `gorm:"index"`
// Execution Error Code nullable
ErrorCode *string
ErrorCode *string `valid:"length(3|50)"`
// The user responsible for launching this execution.
// This is also stored in the spec but promoted as a column for filtering.
User string `gorm:"index"`
User string `gorm:"index" valid:"length(3|50)"`
}
4 changes: 2 additions & 2 deletions pkg/repositories/models/execution_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
type ExecutionEvent struct {
BaseModel
ExecutionKey
RequestID string
RequestID string `valid:"length(3|50)"`
OccurredAt time.Time
Phase string `gorm:"primary_key"`
Phase string `gorm:"primary_key" valid:"length(3|50)"`
}
8 changes: 4 additions & 4 deletions pkg/repositories/models/launch_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package models

// Launch plan primary key
type LaunchPlanKey struct {
Project string `gorm:"primary_key;index:lp_project_domain_name_idx,lp_project_domain_idx"`
Domain string `gorm:"primary_key;index:lp_project_domain_name_idx,lp_project_domain_idx"`
Name string `gorm:"primary_key;index:lp_project_domain_name_idx"`
Version string `gorm:"primary_key"`
Project string `gorm:"primary_key;index:lp_project_domain_name_idx,lp_project_domain_idx" valid:"length(3|50)"`
Domain string `gorm:"primary_key;index:lp_project_domain_name_idx,lp_project_domain_idx" valid:"length(3|50)"`
Name string `gorm:"primary_key;index:lp_project_domain_name_idx" valid:"length(3|50)"`
yindia marked this conversation as resolved.
Show resolved Hide resolved
Version string `gorm:"primary_key" valid:"length(3|50)"`
}

type LaunchPlanScheduleType string
Expand Down
14 changes: 7 additions & 7 deletions pkg/repositories/models/named_entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (

// NamedEntityMetadata primary key
type NamedEntityMetadataKey struct {
ResourceType core.ResourceType `gorm:"primary_key;index:named_entity_metadata_type_project_domain_name_idx"`
Project string `gorm:"primary_key;index:named_entity_metadata_type_project_domain_name_idx"`
Domain string `gorm:"primary_key;index:named_entity_metadata_type_project_domain_name_idx"`
Name string `gorm:"primary_key;index:named_entity_metadata_type_project_domain_name_idx"`
ResourceType core.ResourceType `gorm:"primary_key;index:named_entity_metadata_type_project_domain_name_idx" valid:"length(3|50)"`
Project string `gorm:"primary_key;index:named_entity_metadata_type_project_domain_name_idx" valid:"length(3|50)"`
Domain string `gorm:"primary_key;index:named_entity_metadata_type_project_domain_name_idx" valid:"length(3|50)"`
Name string `gorm:"primary_key;index:named_entity_metadata_type_project_domain_name_idx" valid:"length(3|50)"`
yindia marked this conversation as resolved.
Show resolved Hide resolved
}

// Fields to be composed into any named entity
Expand All @@ -30,9 +30,9 @@ type NamedEntityMetadata struct {
// fields here should match the ones in NamedEntityMetadataKey.
type NamedEntityKey struct {
ResourceType core.ResourceType
Project string
Domain string
Name string
Project string `valid:"length(3|50)"`
Domain string `valid:"length(3|50)"`
Name string `valid:"length(3|50)"`
}

// Composes an identifier (NamedEntity) and its associated metadata fields
Expand Down
2 changes: 1 addition & 1 deletion pkg/repositories/models/node_execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

type NodeExecutionKey struct {
ExecutionKey
NodeID string `gorm:"primary_key;index"`
NodeID string `gorm:"primary_key;index" valid:"length(3|50)"`
}

// By convention, gorm foreign key references are of the form {ModelName}ID
Expand Down
2 changes: 1 addition & 1 deletion pkg/repositories/models/node_execution_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ type NodeExecutionEvent struct {
NodeExecutionKey
RequestID string
OccurredAt time.Time
Phase string `gorm:"primary_key"`
Phase string `gorm:"primary_key" valid:"length(3|50)"`
}
4 changes: 2 additions & 2 deletions pkg/repositories/models/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package models

type Project struct {
BaseModel
Identifier string `gorm:"primary_key"`
Name string // Human-readable name, not a unique identifier.
Identifier string `gorm:"primary_key" valid:"length(3|50)"`
Name string `valid:"length(3|50)"` // Human-readable name, not a unique identifier.
yindia marked this conversation as resolved.
Show resolved Hide resolved
Description string `gorm:"type:varchar(300)"`
Labels []byte
// GORM doesn't save the zero value for ints, so we use a pointer for the State field
Expand Down
10 changes: 5 additions & 5 deletions pkg/repositories/models/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ type Resource struct {
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt *time.Time `sql:"index"`
Project string `gorm:"unique_index:resource_idx"`
Domain string `gorm:"unique_index:resource_idx"`
Workflow string `gorm:"unique_index:resource_idx"`
LaunchPlan string `gorm:"unique_index:resource_idx"`
ResourceType string `gorm:"unique_index:resource_idx"`
Project string `gorm:"unique_index:resource_idx" valid:"length(3|50)"`
Domain string `gorm:"unique_index:resource_idx" valid:"length(3|50)"`
Workflow string `gorm:"unique_index:resource_idx" valid:"length(3|50)"`
LaunchPlan string `gorm:"unique_index:resource_idx" valid:"length(3|50)"`
ResourceType string `gorm:"unique_index:resource_idx" valid:"length(3|50)"`
Priority ResourcePriority
// Serialized flyteidl.admin.MatchingAttributes.
Attributes []byte
Expand Down
10 changes: 5 additions & 5 deletions pkg/repositories/models/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ package models

// Task primary key
type TaskKey struct {
Project string `gorm:"primary_key;index:task_project_domain_name_idx,task_project_domain_idx"`
Domain string `gorm:"primary_key;index:task_project_domain_name_idx,task_project_domain_idx"`
Name string `gorm:"primary_key;index:task_project_domain_name_idx"`
Version string `gorm:"primary_key"`
Project string `gorm:"primary_key;index:task_project_domain_name_idx,task_project_domain_idx" valid:"length(3|50)"`
Domain string `gorm:"primary_key;index:task_project_domain_name_idx,task_project_domain_idx" valid:"length(3|50)"`
Name string `gorm:"primary_key;index:task_project_domain_name_idx" valid:"length(3|50)"`
yindia marked this conversation as resolved.
Show resolved Hide resolved
Version string `gorm:"primary_key" valid:"length(3|50)"`
}

// Database model to encapsulate a task.
Expand All @@ -19,5 +19,5 @@ type Task struct {
// Hash of the compiled task closure
Digest []byte
// Task type (also stored in the closure put promoted as a column for filtering).
Type string
Type string `valid:"length(3|50)"`
}
4 changes: 2 additions & 2 deletions pkg/repositories/models/task_execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ type TaskExecutionKey struct {
type TaskExecution struct {
BaseModel
TaskExecutionKey
Phase string
Phase string `valid:"length(3|50)"`
PhaseVersion uint32
InputURI string
InputURI string `valid:"length(3|50)"`
yindia marked this conversation as resolved.
Show resolved Hide resolved
Closure []byte
StartedAt *time.Time
// Corresponds to the CreatedAt field in the TaskExecution closure
Expand Down
2 changes: 1 addition & 1 deletion pkg/repositories/models/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type Workflow struct {
BaseModel
WorkflowKey
TypedInterface []byte
RemoteClosureIdentifier string `gorm:"not null"`
RemoteClosureIdentifier string `gorm:"not null" valid:"length(3|50)"`
yindia marked this conversation as resolved.
Show resolved Hide resolved
LaunchPlans []LaunchPlan
Executions []Execution
// Hash of the compiled workflow closure
Expand Down