Skip to content

Commit

Permalink
Bring back support for Authorization.CredentialsFile.
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Štibraný <[email protected]>
  • Loading branch information
pstibrany committed Apr 19, 2021
1 parent 38e4e82 commit a6b0ffc
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
3 changes: 3 additions & 0 deletions pkg/alertmanager/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,9 @@ func validateReceiverHTTPConfig(cfg commoncfg.HTTPClientConfig) error {
if cfg.BasicAuth != nil && cfg.BasicAuth.PasswordFile != "" {
return errPasswordFileNotAllowed
}
if cfg.Authorization != nil && cfg.Authorization.CredentialsFile != "" {
return errPasswordFileNotAllowed
}
if cfg.BearerTokenFile != "" {
return errPasswordFileNotAllowed
}
Expand Down
35 changes: 34 additions & 1 deletion pkg/alertmanager/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,22 @@ alertmanager_config: |
http_config:
bearer_token_file: /secrets
route:
receiver: 'default-receiver'
receivers:
- name: default-receiver
`,
err: errors.Wrap(errPasswordFileNotAllowed, "error validating Alertmanager config"),
},
{
name: "Should return error if global HTTP credentials_file is set",
cfg: `
alertmanager_config: |
global:
http_config:
authorization:
credentials_file: /secrets
route:
receiver: 'default-receiver'
receivers:
Expand Down Expand Up @@ -288,6 +304,23 @@ alertmanager_config: |
http_config:
bearer_token_file: /secrets
route:
receiver: 'default-receiver'
`,
err: errors.Wrap(errPasswordFileNotAllowed, "error validating Alertmanager config"),
},
{
name: "Should return error if receiver's HTTP credentials_file is set",
cfg: `
alertmanager_config: |
receivers:
- name: default-receiver
webhook_configs:
- url: http://localhost
http_config:
authorization:
credentials_file: /secrets
route:
receiver: 'default-receiver'
`,
Expand Down Expand Up @@ -480,7 +513,7 @@ func TestValidateAlertmanagerConfig(t *testing.T) {
for testName, testData := range tests {
t.Run(testName, func(t *testing.T) {
err := validateAlertmanagerConfig(testData.input)
assert.True(t, errors.Is(err, testData.expected))
assert.ErrorIs(t, err, testData.expected)
})
}
}

0 comments on commit a6b0ffc

Please sign in to comment.