32f06c6d9c
* Replace global authz abstraction with one compatible with uid scope * Replace GettableApiReceiver with models.Receiver in receiver_svc * GrafanaIntegrationConfig -> models.Integration * Implement Create/Update methods * Add optimistic concurrency to receiver API * Add scope to ReceiversRead & ReceiversReadSecrets migrates existing permissions to include implicit global scope * Add receiver create, update, delete actions * Check if receiver is used by rules before delete * On receiver name change update in routes and notification settings * Improve errors * Linting * Include read permissions are requirements for create/update/delete * Alias ngalert/models to ngmodels to differentiate from v0alpha1 model * Ensure integration UIDs are valid, unique, and generated if empty * Validate integration settings on create/update * Leverage UidToName to GetReceiver instead of GetReceivers * Remove some unnecessary uses of simplejson * alerting.notifications.receiver -> alerting.notifications.receivers * validator -> provenanceValidator * Only validate the modified receiver stops existing invalid receivers from preventing modification of a valid receiver. * Improve error in Integration.Encrypt * Remove scope from alert.notifications.receivers:create * Add todos for receiver renaming * Use receiverAC precondition checks in k8s api * Linting * Optional optimistic concurrency for delete * make update-workspace * More specific auth checks in k8s authorize.go * Add debug log when delete optimistic concurrency is skipped * Improve error message on authorizer.DecisionDeny * Keep error for non-forbidden errutil errors
68 lines
2.4 KiB
Go
68 lines
2.4 KiB
Go
package provisioning
|
|
|
|
import (
|
|
alertingNotify "github.com/grafana/alerting/notify"
|
|
|
|
"github.com/grafana/grafana/pkg/components/simplejson"
|
|
"github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
|
"github.com/grafana/grafana/pkg/services/ngalert/models"
|
|
)
|
|
|
|
func EmbeddedContactPointToGrafanaIntegrationConfig(e definitions.EmbeddedContactPoint) (alertingNotify.GrafanaIntegrationConfig, error) {
|
|
data, err := e.Settings.MarshalJSON()
|
|
if err != nil {
|
|
return alertingNotify.GrafanaIntegrationConfig{}, err
|
|
}
|
|
return alertingNotify.GrafanaIntegrationConfig{
|
|
UID: e.UID,
|
|
Name: e.Name,
|
|
Type: e.Type,
|
|
DisableResolveMessage: e.DisableResolveMessage,
|
|
Settings: data,
|
|
SecureSettings: nil,
|
|
}, nil
|
|
}
|
|
|
|
func PostableGrafanaReceiverToEmbeddedContactPoint(contactPoint *definitions.PostableGrafanaReceiver, provenance models.Provenance, decryptValue func(string) string) (definitions.EmbeddedContactPoint, error) {
|
|
simpleJson, err := simplejson.NewJson(contactPoint.Settings)
|
|
if err != nil {
|
|
return definitions.EmbeddedContactPoint{}, err
|
|
}
|
|
embeddedContactPoint := definitions.EmbeddedContactPoint{
|
|
UID: contactPoint.UID,
|
|
Type: contactPoint.Type,
|
|
Name: contactPoint.Name,
|
|
DisableResolveMessage: contactPoint.DisableResolveMessage,
|
|
Settings: simpleJson,
|
|
Provenance: string(provenance),
|
|
}
|
|
for k, v := range contactPoint.SecureSettings {
|
|
decryptedValue := decryptValue(v)
|
|
if decryptedValue == "" {
|
|
continue
|
|
}
|
|
embeddedContactPoint.Settings.Set(k, decryptedValue)
|
|
}
|
|
return embeddedContactPoint, nil
|
|
}
|
|
|
|
func GrafanaIntegrationConfigToEmbeddedContactPoint(r *models.Integration, provenance models.Provenance) definitions.EmbeddedContactPoint {
|
|
settingJson := simplejson.New()
|
|
if r.Settings != nil {
|
|
settingJson = simplejson.NewFromAny(r.Settings)
|
|
}
|
|
|
|
// We explicitly do not copy the secure settings to the settings field. This is because the provisioning API
|
|
// never returns decrypted or encrypted values, only redacted values. Redacted values should already exist in the
|
|
// settings field.
|
|
|
|
return definitions.EmbeddedContactPoint{
|
|
UID: r.UID,
|
|
Name: r.Name,
|
|
Type: r.Config.Type,
|
|
DisableResolveMessage: r.DisableResolveMessage,
|
|
Settings: settingJson,
|
|
Provenance: string(provenance),
|
|
}
|
|
}
|