Skip to content

Commit ae7d331

Browse files
committed
fix: Remove destination credentials from alert payload
1 parent 09db5e4 commit ae7d331

File tree

6 files changed

+26
-9
lines changed

6 files changed

+26
-9
lines changed

internal/alert/monitor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func WithLogger(logger *logging.Logger) AlertOption {
7777
type DeliveryAttempt struct {
7878
Success bool
7979
DeliveryEvent *models.DeliveryEvent
80-
Destination *models.Destination
80+
Destination *AlertDestination
8181
Timestamp time.Time
8282
Data map[string]interface{}
8383
}

internal/alert/monitor_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func TestAlertMonitor_ConsecutiveFailures_MaxFailures(t *testing.T) {
5151
alert.WithAlertThresholds([]int{50, 66, 90, 100}), // use 66% to test rounding logic
5252
)
5353

54-
dest := &models.Destination{ID: "dest_1", TenantID: "tenant_1"}
54+
dest := &alert.AlertDestination{ID: "dest_1", TenantID: "tenant_1"}
5555
event := &models.Event{Topic: "test.event"}
5656
deliveryEvent := &models.DeliveryEvent{Event: *event}
5757
attempt := alert.DeliveryAttempt{
@@ -118,7 +118,7 @@ func TestAlertMonitor_ConsecutiveFailures_Reset(t *testing.T) {
118118
alert.WithAlertThresholds([]int{50, 66, 90, 100}),
119119
)
120120

121-
dest := &models.Destination{ID: "dest_1", TenantID: "tenant_1"}
121+
dest := &alert.AlertDestination{ID: "dest_1", TenantID: "tenant_1"}
122122
event := &models.Event{Topic: "test.event"}
123123
deliveryEvent := &models.DeliveryEvent{Event: *event}
124124
failedAttempt := alert.DeliveryAttempt{

internal/alert/notifier.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,22 @@ func NotifierWithBearerToken(token string) NotifierOption {
4242
}
4343
}
4444

45+
type AlertDestination struct {
46+
ID string `json:"id" redis:"id"`
47+
TenantID string `json:"tenant_id" redis:"-"`
48+
Type string `json:"type" redis:"type"`
49+
Topics models.Topics `json:"topics" redis:"-"`
50+
Config models.Config `json:"config" redis:"-"`
51+
CreatedAt time.Time `json:"created_at" redis:"created_at"`
52+
DisabledAt *time.Time `json:"disabled_at" redis:"disabled_at"`
53+
}
54+
4555
// ConsecutiveFailureData represents the data needed for a consecutive failure alert
4656
type ConsecutiveFailureData struct {
4757
MaxConsecutiveFailures int `json:"max_consecutive_failures"`
4858
ConsecutiveFailures int `json:"consecutive_failures"`
4959
WillDisable bool `json:"will_disable"`
50-
Destination *models.Destination `json:"destination"`
60+
Destination *AlertDestination `json:"destination"`
5161
Data map[string]interface{} `json:"data"`
5262
}
5363

internal/alert/notifier_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"time"
1010

1111
"github.com/hookdeck/outpost/internal/alert"
12-
"github.com/hookdeck/outpost/internal/models"
1312
"github.com/stretchr/testify/assert"
1413
"github.com/stretchr/testify/require"
1514
)
@@ -97,7 +96,7 @@ func TestAlertNotifier_Notify(t *testing.T) {
9796
notifier := alert.NewHTTPAlertNotifier(ts.URL, tt.notifierOpts...)
9897

9998
// Create test alert
100-
dest := &models.Destination{ID: "dest_123", TenantID: "tenant_123"}
99+
dest := &alert.AlertDestination{ID: "dest_123", TenantID: "tenant_123"}
101100
testAlert := alert.NewConsecutiveFailureAlert(alert.ConsecutiveFailureData{
102101
MaxConsecutiveFailures: 10,
103102
ConsecutiveFailures: 5,

internal/deliverymq/messagehandler.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,16 @@ func (h *messageHandler) handleAlertAttempt(ctx context.Context, deliveryEvent *
284284
attempt := alert.DeliveryAttempt{
285285
Success: deliveryEvent.Delivery.Status == models.DeliveryStatusSuccess,
286286
DeliveryEvent: deliveryEvent,
287-
Destination: destination,
288-
Timestamp: deliveryEvent.Delivery.Time,
287+
Destination: &alert.AlertDestination{
288+
ID: destination.ID,
289+
TenantID: destination.TenantID,
290+
Type: destination.Type,
291+
Topics: destination.Topics,
292+
Config: destination.Config,
293+
CreatedAt: destination.CreatedAt,
294+
DisabledAt: destination.DisabledAt,
295+
},
296+
Timestamp: deliveryEvent.Delivery.Time,
289297
}
290298

291299
if !attempt.Success && err != nil {

internal/deliverymq/messagehandler_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,7 @@ func TestMessageHandler_PublishSuccess(t *testing.T) {
11231123
// Setup alert monitor expectations
11241124
alertMonitor.On("HandleAttempt", mock.Anything, mock.MatchedBy(func(attempt alert.DeliveryAttempt) bool {
11251125
return attempt.Success && // Should be a successful attempt
1126-
attempt.Destination == &destination && // Should have correct destination
1126+
attempt.Destination.ID == destination.ID && // Should have correct destination
11271127
attempt.DeliveryEvent != nil && // Should have delivery event
11281128
attempt.Data == nil // No error data for success
11291129
})).Return(nil)

0 commit comments

Comments
 (0)