Skip to content

Commit

Permalink
extract common validation
Browse files Browse the repository at this point in the history
  • Loading branch information
nieomylnieja committed Oct 4, 2023
1 parent cd68f03 commit 0bf8be2
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions manifest/v1alpha/validation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package v1alpha

import "github.com/nobl9/nobl9-go/validation"

func FieldRuleMetdataName(getter func() string) validation.FieldRules[string] {
return validation.RulesForField[string]("metadata.name", getter).
With(validation.StringRequired(), validation.StringIsDNSSubdomain())
}

func FieldRuleMetadataDisplayName(getter func() string) validation.FieldRules[string] {
return validation.RulesForField[string]("metadata.displayName", getter).
With(validation.StringLength(0, 63))
}

func FieldRuleMetdataProject(getter func() string) validation.FieldRules[string] {
return validation.RulesForField[string]("metadata.project", getter).
With(validation.StringRequired(), validation.StringIsDNSSubdomain())
}

func FieldRuleMetadataLabels(getter func() Labels) validation.FieldRules[Labels] {
return validation.RulesForField[Labels]("metadata.labels", getter).
With(ValidationRule())
}

func FieldRuleMetadataDescription(getter func() string) validation.FieldRules[string] {
return validation.RulesForField[string]("spec.description", getter).
With(validation.StringDescription())
}

0 comments on commit 0bf8be2

Please sign in to comment.