Alerting: allow custom UID for contact points through API (#50089)
* Alerting: allow custom UID for contact points through API * fix auth
This commit is contained in:
@@ -132,7 +132,9 @@ func (ecp *ContactPointService) CreateContactPoint(ctx context.Context, orgID in
|
||||
extractedSecrets[k] = encryptedValue
|
||||
}
|
||||
|
||||
contactPoint.UID = util.GenerateShortUID()
|
||||
if contactPoint.UID == "" {
|
||||
contactPoint.UID = util.GenerateShortUID()
|
||||
}
|
||||
grafanaReceiver := &apimodels.PostableGrafanaReceiver{
|
||||
UID: contactPoint.UID,
|
||||
Name: contactPoint.Name,
|
||||
|
||||
@@ -42,6 +42,21 @@ func TestContactPointService(t *testing.T) {
|
||||
require.Equal(t, "slack", cps[1].Type)
|
||||
})
|
||||
|
||||
t.Run("it's possbile to use a custom uid", func(t *testing.T) {
|
||||
customUID := "1337"
|
||||
sut := createContactPointServiceSut(secretsService)
|
||||
newCp := createTestContactPoint()
|
||||
newCp.UID = customUID
|
||||
|
||||
_, err := sut.CreateContactPoint(context.Background(), 1, newCp, models.ProvenanceAPI)
|
||||
require.NoError(t, err)
|
||||
|
||||
cps, err := sut.GetContactPoints(context.Background(), 1)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, cps, 2)
|
||||
require.Equal(t, customUID, cps[1].UID)
|
||||
})
|
||||
|
||||
t.Run("default provenance of contact points is none", func(t *testing.T) {
|
||||
sut := createContactPointServiceSut(secretsService)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user