@@ -43,29 +43,36 @@ type Notifier struct {
43
43
44
44
// New returns a new incident.io notifier.
45
45
func New (conf * config.IncidentioConfig , t * template.Template , l * slog.Logger , httpOpts ... commoncfg.HTTPClientOption ) (* Notifier , error ) {
46
- // If alert source token is specified, set authorization in HTTP config
46
+ // Handle authentication configuration
47
47
if conf .HTTPConfig == nil {
48
48
conf .HTTPConfig = & commoncfg.HTTPClientConfig {}
49
49
}
50
50
51
+ // Ensure one of AlertSourceToken or AlertSourceTokenFile is provided
52
+ if conf .AlertSourceToken == "" && conf .AlertSourceTokenFile == "" {
53
+ return nil , errors .New ("one of alert_source_token or alert_source_token_file must be configured" )
54
+ }
55
+
56
+ // Error if authorization is already set in HTTPConfig
57
+ if conf .HTTPConfig .Authorization != nil {
58
+ return nil , errors .New ("cannot specify both alert_source_token/alert_source_token_file and http_config.authorization" )
59
+ }
60
+
61
+ // Set authorization from token or token file
51
62
if conf .AlertSourceToken != "" {
52
- if conf .HTTPConfig .Authorization == nil {
53
- conf .HTTPConfig .Authorization = & commoncfg.Authorization {
54
- Type : "Bearer" ,
55
- Credentials : commoncfg .Secret (conf .AlertSourceToken ),
56
- }
63
+ conf .HTTPConfig .Authorization = & commoncfg.Authorization {
64
+ Type : "Bearer" ,
65
+ Credentials : commoncfg .Secret (conf .AlertSourceToken ),
57
66
}
58
67
} else if conf .AlertSourceTokenFile != "" {
59
68
content , err := os .ReadFile (conf .AlertSourceTokenFile )
60
69
if err != nil {
61
70
return nil , fmt .Errorf ("failed to read alert_source_token_file: %w" , err )
62
71
}
63
72
64
- if conf .HTTPConfig .Authorization == nil {
65
- conf .HTTPConfig .Authorization = & commoncfg.Authorization {
66
- Type : "Bearer" ,
67
- Credentials : commoncfg .Secret (strings .TrimSpace (string (content ))),
68
- }
73
+ conf .HTTPConfig .Authorization = & commoncfg.Authorization {
74
+ Type : "Bearer" ,
75
+ Credentials : commoncfg .Secret (strings .TrimSpace (string (content ))),
69
76
}
70
77
}
71
78
@@ -83,10 +90,6 @@ func New(conf *config.IncidentioConfig, t *template.Template, l *slog.Logger, ht
83
90
retrier : & notify.Retrier {
84
91
RetryCodes : []int {
85
92
http .StatusTooManyRequests , // 429
86
- http .StatusInternalServerError ,
87
- http .StatusBadGateway ,
88
- http .StatusServiceUnavailable ,
89
- http .StatusGatewayTimeout ,
90
93
},
91
94
CustomDetailsFunc : errDetails ,
92
95
},
@@ -124,7 +127,7 @@ func (n *Notifier) Notify(ctx context.Context, alerts ...*types.Alert) (bool, er
124
127
n .logger .Debug ("incident.io notification" , "groupKey" , groupKey )
125
128
126
129
msg := & Message {
127
- Version : "4 " ,
130
+ Version : "1 " ,
128
131
Data : data ,
129
132
GroupKey : groupKey .String (),
130
133
TruncatedAlerts : numTruncated ,
@@ -197,8 +200,5 @@ func errDetails(status int, body io.Reader) string {
197
200
parts = append (parts , strings .Join (errorResponse .Errors , ", " ))
198
201
}
199
202
200
- if len (parts ) > 0 {
201
- return strings .Join (parts , ": " )
202
- }
203
- return ""
203
+ return strings .Join (parts , ": " )
204
204
}
0 commit comments