grafana/pkg/services/ngalert/accesscontrol/models.go
Yuri Tseretyan 827860d459
Alerting: Alerting accesscontrol utilities (#84508)
* create fake for accesscontrol.RuleService
* make errAuthorizationGeneric public
2024-03-14 14:03:53 -04:00

29 lines
674 B
Go

package accesscontrol
import (
"fmt"
"github.com/grafana/grafana/pkg/services/accesscontrol"
"github.com/grafana/grafana/pkg/util/errutil"
)
var (
ErrAuthorizationBase = errutil.Forbidden("alerting.unauthorized")
)
func NewAuthorizationErrorWithPermissions(action string, eval accesscontrol.Evaluator) error {
msg := fmt.Sprintf("user is not authorized to %s", action)
err := ErrAuthorizationBase.Errorf(msg)
err.PublicMessage = msg
if eval != nil {
err.PublicPayload = map[string]any{
"permissions": eval.GoString(),
}
}
return err
}
func NewAuthorizationErrorGeneric(action string) error {
return NewAuthorizationErrorWithPermissions(action, nil)
}