diff --git a/config/notifiers.go b/config/notifiers.go index f3447561..8c87102d 100644 --- a/config/notifiers.go +++ b/config/notifiers.go @@ -18,6 +18,7 @@ import ( "net/textproto" "regexp" "strings" + "text/template" "time" "github.com/pkg/errors" @@ -541,9 +542,16 @@ func (c *OpsGenieConfig) UnmarshalYAML(unmarshal func(interface{}) error) error return errors.Errorf("opsGenieConfig responder %v has to have at least one of id, username or name specified", r) } - r.Type = strings.ToLower(r.Type) - if !opsgenieTypeMatcher.MatchString(r.Type) { - return errors.Errorf("opsGenieConfig responder %v type does not match valid options %s", r, opsgenieValidTypesRe) + if strings.Contains(r.Type, "{{") { + _, err := template.New("").Parse(r.Type) + if err != nil { + return errors.Errorf("opsGenieConfig responder %v type is not a valid template: %v", r, err) + } + } else { + r.Type = strings.ToLower(r.Type) + if !opsgenieTypeMatcher.MatchString(r.Type) { + return errors.Errorf("opsGenieConfig responder %v type does not match valid options %s", r, opsgenieValidTypesRe) + } } } diff --git a/config/notifiers_test.go b/config/notifiers_test.go index 602cd182..a22b0169 100644 --- a/config/notifiers_test.go +++ b/config/notifiers_test.go @@ -743,6 +743,25 @@ api_url: http://example.com responders: - type: schedule api_url: http://example.com +`, + err: true, + }, + { + name: "valid responder type template", + in: `api_key: xyz +responders: +- id: foo + type: "{{/* valid comment */}}team" +api_url: http://example.com +`, + }, + { + name: "invalid responder type template", + in: `api_key: xyz +responders: +- id: foo + type: "{{/* invalid comment }}team" +api_url: http://example.com `, err: true, },