forked from forj-oss/forjj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
validate.go
59 lines (50 loc) · 1.54 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
package main
import (
"log"
"fmt"
"github.com/forj-oss/goforjj"
)
func (a *Forj) validateAction(string) {
if err := a.Validate(); err != nil {
log.Fatalf("Forjj validate issue. %s", err)
}
}
// Validate check forjfile rules and return an error is the Forjfile loaded is respecting those rules.
func (a *Forj) Validate() error {
return a.ValidateForjfile()
}
// FoundValidAppFlag return true if the flag checked has been defined by the plugin.
// if not an error is returned.
func (a *Forj) FoundValidAppFlag(key, driver, object string, required bool) (_ bool, err error) {
d, _ := a.drivers[driver]
if d == nil {
err = fmt.Errorf("Internal issue. Driver %s not found in memory", driver)
return
}
if o, found := d.Plugin.Yaml.Objects[object]; found {
return o.HasValidKey(key), nil
}
if required {
err = fmt.Errorf("Plugin %s issue. objects/'%s' has not been defined in the plugin. Contact Plugin maintainer", driver, object)
}
return
}
// ValidateForjfile read all object fields and check if they are recognized by forjj or plugins.
func (a *Forj) ValidateForjfile() (_ error) {
f := a.f.DeployForjfile()
if err := a.f.Validate() ; err != nil {
return fmt.Errorf("Validation error. %s", err)
}
// AppYamlStruct.More
for _, app := range f.Apps {
for key := range app.More {
if found, err := a.FoundValidAppFlag(key, app.Driver, goforjj.ObjectApp, true); err != nil {
return err
} else if !found {
return fmt.Errorf("'%s' has no effect. No drivers use it", key)
}
}
}
fmt.Print("Validated successfully.\n")
return
}