forked from hashicorp/otto
/
validate.go
65 lines (58 loc) · 1.5 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package appfile
import (
"fmt"
"github.com/hashicorp/go-multierror"
)
// Validate validates the Appfile
func (f *File) Validate() error {
var result error
// Basic checking for stanzas
if f.Application == nil {
result = multierror.Append(result, fmt.Errorf(
"'application' stanza required for Appfile"))
}
if f.Project == nil {
result = multierror.Append(result, fmt.Errorf(
"'project' stanza required for Appfile"))
}
if f.Infrastructure == nil {
result = multierror.Append(result, fmt.Errorf(
"'infrastructure' stanza required for Appfile"))
}
// Verify the application itself
if f.Application != nil {
if f.Application.Name == "" {
result = multierror.Append(result, fmt.Errorf(
"application: name is required"))
}
if f.Application.Type == "" {
result = multierror.Append(result, fmt.Errorf(
"application: type is required"))
}
}
// Validate the project
if f.Project != nil {
if f.Project.Name == "" {
result = multierror.Append(result, fmt.Errorf(
"project: name is required"))
}
if f.Project.Infrastructure == "" {
result = multierror.Append(result, fmt.Errorf(
"project: infrastructure is required"))
} else {
found := false
for _, i := range f.Infrastructure {
if i.Name == f.Project.Infrastructure {
found = true
break
}
}
if !found {
result = multierror.Append(result, fmt.Errorf(
"project: infra '%s' has no corresponding infrastruture stanza",
f.Project.Infrastructure))
}
}
}
return result
}