mirror of
https://github.com/grafana/grafana.git
synced 2024-11-25 18:30:41 -06:00
a63ef42816
* use relaxed validation to not introduce breaking changes for now but to be able to use the service in non-provisioning APIs.
29 lines
1.2 KiB
Go
29 lines
1.2 KiB
Go
package provisioning
|
|
|
|
import (
|
|
"github.com/grafana/grafana/pkg/services/ngalert/models"
|
|
)
|
|
|
|
// canUpdateProvenanceInRuleGroup checks if a provenance can be updated for a rule group and its alerts.
|
|
// ReplaceRuleGroup function intends to replace an entire rule group: inserting, updating, and removing rules.
|
|
func canUpdateProvenanceInRuleGroup(storedProvenance, provenance models.Provenance) bool {
|
|
return storedProvenance == provenance ||
|
|
storedProvenance == models.ProvenanceNone ||
|
|
(storedProvenance == models.ProvenanceAPI && provenance == models.ProvenanceNone)
|
|
}
|
|
|
|
type ProvenanceStatusTransitionValidator = func(from, to models.Provenance) error
|
|
|
|
// ValidateProvenanceRelaxed checks if the transition of provenance status from `from` to `to` is allowed.
|
|
// Applies relaxed checks that prevents only transition from any status to `none`.
|
|
// Returns ErrProvenanceChangeNotAllowed if transition is not allowed
|
|
func ValidateProvenanceRelaxed(from, to models.Provenance) error {
|
|
if from == models.ProvenanceNone { // allow any transition from none
|
|
return nil
|
|
}
|
|
if to == models.ProvenanceNone { // allow any transition to none unless it's from "none" either
|
|
return MakeErrProvenanceChangeNotAllowed(from, to)
|
|
}
|
|
return nil
|
|
}
|