* 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>
21 lines
421 B
Go
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
|
|
}
|