Files
grafana/pkg/services/provisioning/utils/utils.go
Maksim Nabokikh ba2524cd88 Provisioning: Add validation for missing organisations in datasource, dashboard, and notifier configurations (#26601)
* Provisioning: Check that org. from config exists

Signed-off-by: m.nabokikh <maksim.nabokikh@flant.com>

* Apply suggestions from code review

Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>

* Fix some code after applying suggestions

Signed-off-by: m.nabokikh <maksim.nabokikh@flant.com>

* Add negative test case

Signed-off-by: m.nabokikh <maksim.nabokikh@flant.com>

Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>
2020-07-30 12:59:12 +03:00

21 lines
421 B
Go

package utils
import (
"errors"
"fmt"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/models"
)
func CheckOrgExists(orgID int64) error {
query := models.GetOrgByIdQuery{Id: orgID}
if err := bus.Dispatch(&query); err != nil {
if errors.Is(err, models.ErrOrgNotFound) {
return err
}
return fmt.Errorf("failed to check whether org. with the given ID exists: %w", err)
}
return nil
}