Skip to content

Commit

Permalink
Validate table Name property matches key in plugin's TableMap. Closes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
kaidaguerre committed Jul 11, 2022
1 parent d1d2097 commit 097c8ee
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cache/query_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ func (c *QueryCache) getKeyColumnsForTable(table string) map[string]*proto.KeyCo
for _, k := range append(tableSchema.ListCallKeyColumnList, tableSchema.GetCallKeyColumnList...) {
res[k.Name] = k
}
} else {
log.Printf("[WARN] getKeyColumnsForTable found NO SCHEMA FOR %s", table)
}
return res
}
Expand Down
3 changes: 3 additions & 0 deletions plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,9 @@ func (p *Plugin) ensureCache() error {
}

func (p *Plugin) buildSchema() (map[string]*proto.TableSchema, error) {
log.Printf("[TRACE] buildSchema")
defer log.Printf("[TRACE] buildSchema complete")

// the connection property must be set already
if p.Connection == nil {
return nil, fmt.Errorf("plugin.GetSchema called before setting connection config")
Expand Down
14 changes: 14 additions & 0 deletions plugin/plugin_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ func (p *Plugin) Validate() string {
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
}

0 comments on commit 097c8ee

Please sign in to comment.