Skip to content

Commit

Permalink
split validator
Browse files Browse the repository at this point in the history
  • Loading branch information
nieomylnieja committed Oct 11, 2023
1 parent f2a61f6 commit f273a41
Show file tree
Hide file tree
Showing 9 changed files with 3,440 additions and 2,475 deletions.
2 changes: 1 addition & 1 deletion manifest/v1alpha/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func AWSRegions() []AWSRegion {
}
}

func isValidRegion(code string, regions []AWSRegion) bool {
func IsValidRegion(code string, regions []AWSRegion) bool {
for _, region := range regions {
if region.Code == code {
return true
Expand Down
3 changes: 2 additions & 1 deletion manifest/v1alpha/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/nobl9/nobl9-go/manifest/v1alpha"
"github.com/nobl9/nobl9-go/manifest/v1alpha/project"
"github.com/nobl9/nobl9-go/manifest/v1alpha/service"
"github.com/nobl9/nobl9-go/manifest/v1alpha/slo"
)

type unmarshalFunc func(v interface{}) error
Expand Down Expand Up @@ -48,7 +49,7 @@ func parseObject(kind manifest.Kind, unmarshal unmarshalFunc) (manifest.Object,
case manifest.KindService:
return genericParseObject[service.Service](unmarshal)
case manifest.KindSLO:
return genericParseObject[v1alpha.SLO](unmarshal)
return genericParseObject[slo.SLO](unmarshal)
case manifest.KindProject:
return genericParseObject[project.Project](unmarshal)
case manifest.KindAgent:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v1alpha
package slo

import "fmt"

Expand Down
2 changes: 1 addition & 1 deletion manifest/v1alpha/slo/slo.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type Spec struct {
// Status holds dynamic fields returned when the Service is fetched from Nobl9 platform.
// Status is not part of the static object definition.
type Status struct {
ReplayStatus *v1alpha.ReplayStatus `json:"timeTravel,omitempty"`
ReplayStatus *ReplayStatus `json:"timeTravel,omitempty"`
}

type ReplayStatus struct {
Expand Down
15 changes: 8 additions & 7 deletions manifest/v1alpha/slo/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import (
"github.com/nobl9/nobl9-go/validation"
)

var sloValidation = validation.New[SLO](
v1alpha.FieldRuleMetadataName(func(s SLO) string { return s.Metadata.Name }),
v1alpha.FieldRuleMetadataDisplayName(func(s SLO) string { return s.Metadata.DisplayName }),
v1alpha.FieldRuleMetadataLabels(func(s SLO) v1alpha.Labels { return s.Metadata.Labels }),
v1alpha.FieldRuleSpecDescription(func(s SLO) string { return s.Spec.Description }),
)

func validate(s SLO) error {
v := validation.RulesForStruct(
v1alpha.FieldRuleMetadataName(func() string { return s.Metadata.Name }),
v1alpha.FieldRuleMetadataDisplayName(func() string { return s.Metadata.DisplayName }),
v1alpha.FieldRuleMetadataLabels(func() v1alpha.Labels { return s.Metadata.Labels }),
v1alpha.FieldRuleSpecDescription(func() string { return s.Spec.Description }),
)
if errs := v.Validate(); len(errs) > 0 {
if errs := sloValidation.Validate(s); len(errs) > 0 {
return v1alpha.NewObjectError(s, errs)
}
return nil
Expand Down
Loading

0 comments on commit f273a41

Please sign in to comment.