feat(server): introduce ValidUniqueTemplateVariables

pull/5760/head
Pavel Zavora 2021-06-02 10:38:58 +02:00
parent fc2f2adc01
commit 97ed58bcbe
1 changed files with 15 additions and 0 deletions

View File

@ -37,6 +37,21 @@ func ValidTemplateRequest(template *chronograf.Template) error {
return nil return nil
} }
// ValidUniqueTemplateVariables validates that a template defines variable at most once
func ValidUniqueTemplateVariables(dashboard *chronograf.Dashboard) error {
variableNames := map[string]struct{}{}
for _, t := range dashboard.Templates {
if _, duplicate := variableNames[t.Var]; duplicate {
return fmt.Errorf("duplicate variable name %s", t.Var)
}
variableNames[t.Var] = struct{}{}
if err := ValidTemplateRequest(&t); err != nil {
return err
}
}
return nil
}
type templateLinks struct { type templateLinks struct {
Self string `json:"self"` // Self link mapping to this resource Self string `json:"self"` // Self link mapping to this resource
} }