We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 05e380a commit 5fecfdeCopy full SHA for 5fecfde
notify/opsgenie/api_key_file
@@ -0,0 +1,2 @@
1
+my_secret_api_key
2
+
notify/opsgenie/opsgenie.go
@@ -282,6 +282,7 @@ func (n *Notifier) createRequests(ctx context.Context, as ...*types.Alert) ([]*h
282
return nil, false, fmt.Errorf("read key_file error: %w", err)
283
}
284
apiKey = tmpl(string(content))
285
+ apiKey = strings.TrimSpace(string(apiKey))
286
287
288
if err != nil {
notify/opsgenie/opsgenie_test.go
@@ -321,6 +321,25 @@ func TestOpsGenieWithUpdate(t *testing.T) {
321
`, body2)
322
323
324
+func TestOpsGenieApiKeyFile(t *testing.T) {
325
+ u, err := url.Parse("https://test-opsgenie-url")
326
+ require.NoError(t, err)
327
+ tmpl := test.CreateTmpl(t)
328
+ ctx := context.Background()
329
+ ctx = notify.WithGroupKey(ctx, "1")
330
+ opsGenieConfigWithUpdate := config.OpsGenieConfig{
331
+ APIKeyFile: `./api_key_file`,
332
+ APIURL: &config.URL{URL: u},
333
+ HTTPConfig: &commoncfg.HTTPClientConfig{},
334
+ }
335
+ notifierWithUpdate, err := New(&opsGenieConfigWithUpdate, tmpl, promslog.NewNopLogger())
336
337
338
+ requests, _, err := notifierWithUpdate.createRequests(ctx)
339
340
+ require.Equal(t, "GenieKey my_secret_api_key", requests[0].Header.Get("Authorization"))
341
+}
342
343
func readBody(t *testing.T, r *http.Request) string {
344
t.Helper()
345
body, err := io.ReadAll(r.Body)
0 commit comments