Alerting: replace usage of simplejson to json.RawMessage in NotificationChannelConfig (#60423)
* introduce alias for json.RawMessage with name RawMessage. This is needed to keep raw JSON and implement a marshaler for YAML, which does not seem to be used but there are tests that fail. * replace usage of simplejson with RawMessage in NotificationChannelConfig * remove usage of simplejson in tests * change migration code to convert simplejson to raw message
This commit is contained in:
@@ -17,7 +17,6 @@ import (
|
||||
"github.com/prometheus/common/model"
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/models"
|
||||
"github.com/grafana/grafana/pkg/services/secrets"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
@@ -964,12 +963,54 @@ func AllReceivers(route *config.Route) (res []string) {
|
||||
return res
|
||||
}
|
||||
|
||||
type RawMessage json.RawMessage // This type alias adds YAML marshaling to the json.RawMessage.
|
||||
|
||||
// MarshalJSON returns m as the JSON encoding of m.
|
||||
func (r RawMessage) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(json.RawMessage(r))
|
||||
}
|
||||
|
||||
func (r *RawMessage) UnmarshalJSON(data []byte) error {
|
||||
var raw json.RawMessage
|
||||
err := json.Unmarshal(data, &raw)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*r = RawMessage(raw)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *RawMessage) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
var data interface{}
|
||||
if err := unmarshal(&data); err != nil {
|
||||
return err
|
||||
}
|
||||
bytes, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*r = bytes
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r RawMessage) MarshalYAML() (interface{}, error) {
|
||||
if r == nil {
|
||||
return nil, nil
|
||||
}
|
||||
var d interface{}
|
||||
err := json.Unmarshal(r, &d)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return d, nil
|
||||
}
|
||||
|
||||
type GettableGrafanaReceiver struct {
|
||||
UID string `json:"uid"`
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
DisableResolveMessage bool `json:"disableResolveMessage"`
|
||||
Settings *simplejson.Json `json:"settings"`
|
||||
Settings RawMessage `json:"settings,omitempty"`
|
||||
SecureFields map[string]bool `json:"secureFields"`
|
||||
Provenance models.Provenance `json:"provenance,omitempty"`
|
||||
}
|
||||
@@ -979,7 +1020,7 @@ type PostableGrafanaReceiver struct {
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
DisableResolveMessage bool `json:"disableResolveMessage"`
|
||||
Settings *simplejson.Json `json:"settings"`
|
||||
Settings RawMessage `json:"settings,omitempty"`
|
||||
SecureSettings map[string]string `json:"secureSettings"`
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user