-
Notifications
You must be signed in to change notification settings - Fork 14
/
plugin_validate.go
50 lines (40 loc) · 1.76 KB
/
plugin_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
package plugin
import (
"fmt"
"log"
"strings"
"github.com/turbot/go-kit/helpers"
)
func (p *Plugin) Validate() string {
// TODO KAI for dynamic schema we must validate all table maps in ConnectionMap
log.Printf("[TRACE] validate plugin %s, required columns %v", p.Name, p.RequiredColumns)
var validationErrors []string
for tableName, table := range p.TableMap {
validationErrors = append(validationErrors, table.validate(tableName, p.RequiredColumns)...)
}
if p.ConnectionConfigSchema != nil {
validationErrors = append(validationErrors, p.ConnectionConfigSchema.Validate()...)
}
// validate the schema mode
if !helpers.StringSliceContains(validSchemaModes, p.SchemaMode) {
validationErrors = append(validationErrors, fmt.Sprintf("schema mode must be either %s or %s (if not specified it defaults to %s)", SchemaModeStatic, SchemaModeDynamic, SchemaModeStatic))
}
log.Printf("[TRACE] validate DefaultRetryConfig")
validationErrors = append(validationErrors, p.DefaultRetryConfig.Validate(nil)...)
log.Printf("[TRACE] validate DefaultIgnoreConfig")
validationErrors = append(validationErrors, p.DefaultIgnoreConfig.Validate(nil)...)
log.Printf("[TRACE] validate table names")
validationErrors = append(validationErrors, p.validateTableNames()...)
log.Printf("[TRACE] plugin has %d validation errors", len(validationErrors))
return strings.Join(validationErrors, "\n")
}
// validate that table names are consistent with their key in the table map
func (p *Plugin) validateTableNames() []string {
var validationErrors []string
for tableName, table := range p.TableMap {
if table.Name != tableName {
validationErrors = append(validationErrors, fmt.Sprintf("table '%s' has inconsistent Name property: '%s'", tableName, table.Name))
}
}
return validationErrors
}