diff --git a/config/notifiers.go b/config/notifiers.go index 41735f3c..0f1271df 100644 --- a/config/notifiers.go +++ b/config/notifiers.go @@ -623,8 +623,5 @@ func (c *SNSConfig) UnmarshalYAML(unmarshal func(interface{}) error) error { if (c.TargetARN == "") != (c.TopicARN == "") != (c.PhoneNumber == "") { return fmt.Errorf("must provide either a Target ARN, Topic ARN, or Phone Number for SNS config") } - if (c.Sigv4.AccessKey == "") != (c.Sigv4.SecretKey == "") { - return fmt.Errorf("must provide a AWS SigV4 Access key and Secret Key if credentials are specified in the SNS config") - } return nil } diff --git a/config/notifiers_test.go b/config/notifiers_test.go index 2c4c8126..93b9dca2 100644 --- a/config/notifiers_test.go +++ b/config/notifiers_test.go @@ -590,6 +590,92 @@ func TestOpsgenieTypeMatcher(t *testing.T) { } } +func TestSNS(t *testing.T) { + for _, tc := range []struct { + in string + err bool + }{ + { + // Valid configuration without sigv4. + in: `target_arn: target`, + err: false, + }, + { + // Valid configuration without sigv4. + in: `topic_arn: topic`, + err: false, + }, + { + // Valid configuration with sigv4. + in: `phone_number: phone +sigv4: + access_key: abc + secret_key: abc +`, + err: false, + }, + { + // at most one of 'target_arn', 'topic_arn' or 'phone_number' must be provided without sigv4. + in: `topic_arn: topic +target_arn: target +`, + err: true, + }, + { + // at most one of 'target_arn', 'topic_arn' or 'phone_number' must be provided without sigv4. + in: `topic_arn: topic +phone_number: phone +`, + err: true, + }, + { + // one of 'target_arn', 'topic_arn' or 'phone_number' must be provided without sigv4. + in: "{}", + err: true, + }, + { + // one of 'target_arn', 'topic_arn' or 'phone_number' must be provided with sigv4. + in: `sigv4: + access_key: abc + secret_key: abc +`, + err: true, + }, + { + // 'secret_key' must be provided with 'access_key'. + in: `topic_arn: topic +sigv4: + access_key: abc +`, + err: true, + }, + { + // 'access_key' must be provided with 'secret_key'. + in: `topic_arn: topic +sigv4: + secret_key: abc +`, + err: true, + }, + } { + t.Run("", func(t *testing.T) { + var cfg SNSConfig + err := yaml.UnmarshalStrict([]byte(tc.in), &cfg) + if err != nil { + if !tc.err { + t.Errorf("expecting no error, got %q", err) + } + return + } + + if tc.err { + t.Logf("%#v", cfg) + t.Error("expecting error, got none") + } + }) + } +} + func TestWeChatTypeMatcher(t *testing.T) { good := []string{"text", "markdown"} for _, g := range good {