diff --git a/provider/lib.go b/provider/lib.go index 70510be..4f90486 100644 --- a/provider/lib.go +++ b/provider/lib.go @@ -522,18 +522,19 @@ var siteImporter = schema.ResourceImporter{ }, } -func validateConditionField(val interface{}, key string) ([]string, []error) { - knownFields := []string{ - "scheme", "method", "path", "useragent", "domain", "ip", "responseCode", "agentname", - "paramname", "paramvalue", "country", "name", "valueString", "valueIp", "signalType", - "signal", "requestHeader", "queryParameter", "postParameter", "requestCookie", "value", - } +var KnownConditionFields = []string{ + "scheme", "method", "path", "useragent", "domain", "ip", "responseCode", "agentname", + "paramname", "paramvalue", "country", "name", "valueString", "valueIp", "signalType", + "signal", "requestHeader", "queryParameter", "postParameter", "requestCookie", "value", + "responseHeader", +} - if existsInString(val.(string), knownFields...) { +func validateConditionField(val interface{}, key string) ([]string, []error) { + if existsInString(val.(string), KnownConditionFields...) { return nil, nil } - return []string{fmt.Sprintf("received %q for conditions.field. This is not necessarily an error, but we only know about the following values. If this is a new value, please open a PR to get it added.\n(%s)", val.(string), strings.Join(knownFields, ", "))}, nil + return []string{fmt.Sprintf("received %q for conditions.field. This is not necessarily an error, but we only know about the following values. If this is a new value, please open a PR to get it added.\n(%s)", val.(string), strings.Join(KnownConditionFields, ", "))}, nil } func validateActionResponseCode(val interface{}, key string) ([]string, []error) { diff --git a/provider/lib_test.go b/provider/lib_test.go index 9a4971b..db7c995 100644 --- a/provider/lib_test.go +++ b/provider/lib_test.go @@ -133,6 +133,7 @@ func TestValidateConditionField(t *testing.T) { {in: "scheme"}, {in: "queryParameter"}, {in: "value"}, + {in: "responseHeader"}, {in: "unknownconditionfield", wantErr: true}, } diff --git a/provider/resource_corp_rule.go b/provider/resource_corp_rule.go index 2fa11c8..356c0ab 100644 --- a/provider/resource_corp_rule.go +++ b/provider/resource_corp_rule.go @@ -2,6 +2,7 @@ package provider import ( "fmt" + "strings" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/signalsciences/go-sigsci" @@ -83,7 +84,7 @@ func resourceCorpRule() *schema.Resource { }, "field": { Type: schema.TypeString, - Description: "type: single - (scheme, method, path, useragent, domain, ip, responseCode, agentname, paramname, paramvalue, country, name, valueString, valueIp, signalType, signal, requestHeader, queryParameter, postParameter)", + Description: fmt.Sprintf("type: single - (%s)", strings.Join(KnownConditionFields, ", ")), Optional: true, ValidateFunc: validateConditionField, }, @@ -117,7 +118,7 @@ func resourceCorpRule() *schema.Resource { }, "field": { Type: schema.TypeString, - Description: "type: single - (scheme, method, path, useragent, domain, ip, responseCode, agentname, paramname, paramvalue, country, name, valueString, valueIp, signalType, signal, requestHeader, queryParameter, postParameter)", + Description: fmt.Sprintf("type: single - (%s)", strings.Join(KnownConditionFields, ", ")), Optional: true, ValidateFunc: validateConditionField, }, @@ -150,7 +151,7 @@ func resourceCorpRule() *schema.Resource { }, "field": { Type: schema.TypeString, - Description: "type: single - (scheme, method, path, useragent, domain, ip, responseCode, agentname, paramname, paramvalue, country, name, valueString, valueIp, signalType, signal, requestHeader, queryParameter, postParameter)", + Description: fmt.Sprintf("type: single - (%s)", strings.Join(KnownConditionFields, ", ")), Optional: true, ValidateFunc: validateConditionField, }, diff --git a/provider/resource_site_rule.go b/provider/resource_site_rule.go index ff8e638..6ebb7f7 100644 --- a/provider/resource_site_rule.go +++ b/provider/resource_site_rule.go @@ -3,6 +3,7 @@ package provider import ( "fmt" "net/http" + "strings" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/signalsciences/go-sigsci" @@ -100,7 +101,7 @@ func resourceSiteRule() *schema.Resource { }, "field": { Type: schema.TypeString, - Description: "type: single - (scheme, method, path, useragent, domain, ip, responseCode, agentname, paramname, paramvalue, country, name, valueString, valueIp, signalType, signal, requestHeader, queryParameter, postParameter)", + Description: fmt.Sprintf("type: single - (%s)", strings.Join(KnownConditionFields, ", ")), Optional: true, ValidateFunc: validateConditionField, }, @@ -133,7 +134,7 @@ func resourceSiteRule() *schema.Resource { }, "field": { Type: schema.TypeString, - Description: "type: single - (scheme, method, path, useragent, domain, ip, responseCode, agentname, paramname, paramvalue, country, name, valueString, valueIp, signalType, signal, requestHeader, queryParameter, postParameter)", + Description: fmt.Sprintf("type: single - (%s)", strings.Join(KnownConditionFields, ", ")), Optional: true, ValidateFunc: validateConditionField, }, @@ -166,7 +167,7 @@ func resourceSiteRule() *schema.Resource { }, "field": { Type: schema.TypeString, - Description: "type: single - (scheme, method, path, useragent, domain, ip, responseCode, agentname, paramname, paramvalue, country, name, valueString, valueIp, signalType, signal, requestHeader, queryParameter, postParameter)", + Description: fmt.Sprintf("type: single - (%s)", strings.Join(KnownConditionFields, ", ")), Optional: true, ValidateFunc: validateConditionField, },