-
Notifications
You must be signed in to change notification settings - Fork 6
/
validate.go
49 lines (41 loc) · 1.6 KB
/
validate.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package tweed
import (
"fmt"
"regexp"
)
func ValidInstanceID(id string) error {
if ok, _ := regexp.Match(`^[a-zA-Z0-9][a-zA-Z0-9-]{0,61}[a-zA-Z0-9]$`, []byte(id)); !ok {
return fmt.Errorf("instance IDs must include only alphanumeric characters or hyphens, be less than 64 characters long, must start with a letter, and not end with a hyphen")
}
return nil
}
func ValidInstancePrefix(s string) error {
if s == "" {
return nil
}
if ok, _ := regexp.Match(`^[a-zA-Z0-9][a-zA-Z0-9-]{0,15}$`, []byte(s)); !ok {
return fmt.Errorf("instance prefixes must include only alphanumeric characters or hyphens, be less than 16 characters long, and must start with a letter")
}
return nil
}
func (c *Core) ValidateCatalog() error {
errors := make([]error, 0)
for _, s := range c.Config.Catalog.Services {
for _, p := range s.Plans {
if p.Tweed.Infrastructure == "" {
errors = append(errors, fmt.Errorf("service '%s' / '%s' does not specify an infrastructure", s.Name, p.Name))
} else if !FileExists(c.path("etc/infrastructures/" + p.Tweed.Infrastructure)) {
errors = append(errors, fmt.Errorf("service '%s' / '%s' specifies unknown infrastructure: %s", s.Name, p.Name, p.Tweed.Infrastructure))
}
if p.Tweed.Stencil == "" {
errors = append(errors, fmt.Errorf("service '%s' / '%s' does not specify a stencil", s.Name, p.Name))
} else if !DirExists(c.path("etc/stencils/" + p.Tweed.Stencil)) {
errors = append(errors, fmt.Errorf("service '%s' / '%s' specifies unknown stencil: %s", s.Name, p.Name, p.Tweed.Stencil))
}
}
}
if len(errors) > 0 {
return Errors{all: errors}
}
return nil
}