MCPcopy Create free account
hub / github.com/cortexlabs/cortex / DurationParser

Function DurationParser

pkg/lib/configreader/validators.go:79–122  ·  view source on GitHub ↗
(v *DurationValidation)

Source from the content-addressed store, hash-verified

77}
78
79func DurationParser(v *DurationValidation) func(string) (interface{}, error) {
80 return func(str string) (interface{}, error) {
81 d, err := time.ParseDuration(str)
82 if err != nil {
83 return nil, err
84 }
85
86 if v == nil {
87 return d, nil
88 }
89
90 if v.GreaterThan != nil {
91 if d <= *v.GreaterThan {
92 return nil, ErrorMustBeGreaterThan(str, *v.GreaterThan)
93 }
94 }
95
96 if v.GreaterThanOrEqualTo != nil {
97 if d < *v.GreaterThanOrEqualTo {
98 return nil, ErrorMustBeGreaterThanOrEqualTo(str, *v.GreaterThanOrEqualTo)
99 }
100 }
101
102 if v.LessThan != nil {
103 if d >= *v.LessThan {
104 return nil, ErrorMustBeLessThan(str, *v.LessThan)
105 }
106 }
107
108 if v.LessThanOrEqualTo != nil {
109 if d > *v.LessThanOrEqualTo {
110 return nil, ErrorMustBeLessThanOrEqualTo(str, *v.LessThanOrEqualTo)
111 }
112 }
113
114 if v.MultipleOf != nil {
115 if d.Nanoseconds()%(*v.MultipleOf).Nanoseconds() != 0 {
116 return nil, ErrorIsNotMultiple(d, *v.MultipleOf)
117 }
118 }
119
120 return d, nil
121 }
122}
123
124func ValidateImageVersion(image, cortexVersion string) (string, error) {
125 if !strings.HasPrefix(image, "quay.io/cortexlabs/") && !strings.HasPrefix(image, "quay.io/cortexlabsdev/") && !strings.HasPrefix(image, "docker.io/cortexlabs/") && !strings.HasPrefix(image, "docker.io/cortexlabsdev/") && !strings.HasPrefix(image, "cortexlabs/") && !strings.HasPrefix(image, "cortexlabsdev/") {

Callers

nothing calls this directly

Calls 5

ErrorMustBeGreaterThanFunction · 0.85
ErrorMustBeLessThanFunction · 0.85
ErrorIsNotMultipleFunction · 0.85

Tested by

no test coverage detected