MCPcopy Create free account
hub / github.com/coldbrewcloud/coldbrew-cli / Validate

Method Validate

config/validate.go:13–113  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

11)
12
13func (c *Config) Validate() error {
14 if !core.AppNameRE.MatchString(conv.S(c.Name)) {
15 return fmt.Errorf("Invalid app name [%s]", conv.S(c.Name))
16 }
17
18 if !core.ClusterNameRE.MatchString(conv.S(c.ClusterName)) {
19 return fmt.Errorf("Invalid cluster name [%s]", conv.S(c.ClusterName))
20 }
21
22 if conv.U16(c.Units) > core.MaxAppUnits {
23 return fmt.Errorf("Units cannot exceed %d", core.MaxAppUnits)
24 }
25
26 if conv.F64(c.CPU) == 0 {
27 return errors.New("CPU cannot be 0")
28 }
29 if conv.F64(c.CPU) > core.MaxAppCPU {
30 return fmt.Errorf("CPU cannot exceed %d", core.MaxAppCPU)
31 }
32
33 if !core.SizeExpressionRE.MatchString(conv.S(c.Memory)) {
34 return fmt.Errorf("Invalid app memory [%s] (1)", conv.S(c.Memory))
35 } else {
36 sizeInBytes, err := core.ParseSizeExpression((conv.S(c.Memory)))
37 if err != nil {
38 return fmt.Errorf("Invalid app memory: %s", err.Error())
39 }
40 if sizeInBytes > core.MaxAppMemoryInMB*1000*1000 {
41 return fmt.Errorf("App memory cannot exceed %dM", core.MaxAppMemoryInMB)
42 }
43 }
44
45 if conv.U16(c.LoadBalancer.HTTPSPort) == 0 &&
46 conv.U16(c.LoadBalancer.Port) == 0 {
47 return errors.New("Load balancer ort number is required.")
48 }
49
50 if !core.TimeExpressionRE.MatchString(conv.S(c.LoadBalancer.HealthCheck.Interval)) {
51 return fmt.Errorf("Invalid health check interval [%s]", conv.S(c.LoadBalancer.HealthCheck.Interval))
52 }
53
54 if !core.HealthCheckPathRE.MatchString(conv.S(c.LoadBalancer.HealthCheck.Path)) {
55 return fmt.Errorf("Invalid health check path [%s]", conv.S(c.LoadBalancer.HealthCheck.Path))
56 }
57
58 if !core.HealthCheckStatusRE.MatchString(conv.S(c.LoadBalancer.HealthCheck.Status)) {
59 return fmt.Errorf("Invalid health check status [%s]", conv.S(c.LoadBalancer.HealthCheck.Status))
60 }
61
62 if !core.TimeExpressionRE.MatchString(conv.S(c.LoadBalancer.HealthCheck.Timeout)) {
63 return fmt.Errorf("Invalid health check timeout [%s]", conv.S(c.LoadBalancer.HealthCheck.Timeout))
64 }
65
66 if conv.U16(c.LoadBalancer.HealthCheck.HealthyLimit) == 0 {
67 return errors.New("Health check healthy limit cannot be 0.")
68 }
69
70 if conv.U16(c.LoadBalancer.HealthCheck.UnhealthyLimit) == 0 {

Callers 4

RunMethod · 0.95
LoadFunction · 0.95
TestConfig_ValidateFunction · 0.95
TestDefaultConfigFunction · 0.80

Calls 1

ErrorMethod · 0.80

Tested by 2

TestConfig_ValidateFunction · 0.76
TestDefaultConfigFunction · 0.64