grafana/pkg/services/publicdashboards/validation/validation.go
Jeff Levin bf672f960a
public dashboards: rename api functions (#57789)
This PR imposes better naming conventions on public dashboards api

* rename api functions and remove use of _config_ noun

* fix tests

Co-authored-by: Ezequiel Victorero <ezequiel.victorero@grafana.com>
2022-10-27 17:08:11 -08:00

35 lines
808 B
Go

package validation
import (
"fmt"
"github.com/grafana/grafana/pkg/models"
. "github.com/grafana/grafana/pkg/services/publicdashboards/models"
)
func ValidateSavePublicDashboard(dto *SavePublicDashboardDTO, dashboard *models.Dashboard) error {
if hasTemplateVariables(dashboard) {
return ErrPublicDashboardHasTemplateVariables
}
return nil
}
func hasTemplateVariables(dashboard *models.Dashboard) bool {
templateVariables := dashboard.Data.Get("templating").Get("list").MustArray()
return len(templateVariables) > 0
}
func ValidateQueryPublicDashboardRequest(req PublicDashboardQueryDTO) error {
if req.IntervalMs < 0 {
return fmt.Errorf("intervalMS should be greater than 0")
}
if req.MaxDataPoints < 0 {
return fmt.Errorf("maxDataPoints should be greater than 0")
}
return nil
}