Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WAFV2 add ACFP rule support #33915

Merged
merged 4 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 106 additions & 0 deletions internal/service/wafv2/flex.go
Original file line number Diff line number Diff line change
Expand Up @@ -1099,6 +1099,9 @@ func expandManagedRuleGroupConfigs(tfList []interface{}) []*wafv2.ManagedRuleGro
if v, ok := m["aws_managed_rules_bot_control_rule_set"].([]interface{}); ok && len(v) > 0 {
r.AWSManagedRulesBotControlRuleSet = expandManagedRulesBotControlRuleSet(v)
}
if v, ok := m["aws_managed_rules_acfp_rule_set"].([]interface{}); ok && len(v) > 0 {
r.AWSManagedRulesACFPRuleSet = expandManagedRulesACFPRuleSet(v)
}
if v, ok := m["aws_managed_rules_atp_rule_set"].([]interface{}); ok && len(v) > 0 {
r.AWSManagedRulesATPRuleSet = expandManagedRulesATPRuleSet(v)
}
Expand All @@ -1121,6 +1124,19 @@ func expandManagedRuleGroupConfigs(tfList []interface{}) []*wafv2.ManagedRuleGro
return out
}

func expandEmailField(tfList []interface{}) *wafv2.EmailField {
if len(tfList) == 0 || tfList[0] == nil {
return nil
}

m := tfList[0].(map[string]interface{})
out := wafv2.EmailField{
Identifier: aws.String(m["identifier"].(string)),
}

return &out
}

func expandPasswordField(tfList []interface{}) *wafv2.PasswordField {
if len(tfList) == 0 || tfList[0] == nil {
return nil
Expand Down Expand Up @@ -1160,6 +1176,30 @@ func expandManagedRulesBotControlRuleSet(tfList []interface{}) *wafv2.AWSManaged
return &out
}

func expandManagedRulesACFPRuleSet(tfList []interface{}) *wafv2.AWSManagedRulesACFPRuleSet {
if len(tfList) == 0 || tfList[0] == nil {
return nil
}

m := tfList[0].(map[string]interface{})
out := wafv2.AWSManagedRulesACFPRuleSet{
CreationPath: aws.String(m["creation_path"].(string)),
RegistrationPagePath: aws.String(m["registration_page_path"].(string)),
}

if v, ok := m["enable_regex_in_path"].(bool); ok {
out.EnableRegexInPath = aws.Bool(v)
}
if v, ok := m["request_inspection"].([]interface{}); ok && len(v) > 0 {
out.RequestInspection = expandRequestInspectionACFP(v)
}
if v, ok := m["response_inspection"].([]interface{}); ok && len(v) > 0 {
out.ResponseInspection = expandResponseInspection(v)
}

return &out
}

func expandManagedRulesATPRuleSet(tfList []interface{}) *wafv2.AWSManagedRulesATPRuleSet {
if len(tfList) == 0 || tfList[0] == nil {
return nil
Expand Down Expand Up @@ -1198,6 +1238,22 @@ func expandRequestInspection(tfList []interface{}) *wafv2.RequestInspection {
return &out
}

func expandRequestInspectionACFP(tfList []interface{}) *wafv2.RequestInspectionACFP {
if len(tfList) == 0 || tfList[0] == nil {
return nil
}

m := tfList[0].(map[string]interface{})
out := wafv2.RequestInspectionACFP{
EmailField: expandEmailField(m["email_field"].([]interface{})),
PasswordField: expandPasswordField(m["password_field"].([]interface{})),
PayloadType: aws.String(m["payload_type"].(string)),
UsernameField: expandUsernameField(m["username_field"].([]interface{})),
}

return &out
}

func expandResponseInspection(tfList []interface{}) *wafv2.ResponseInspection {
if len(tfList) == 0 || tfList[0] == nil {
return nil
Expand Down Expand Up @@ -2365,6 +2421,9 @@ func flattenManagedRuleGroupConfigs(c []*wafv2.ManagedRuleGroupConfig) []interfa

for _, config := range c {
m := make(map[string]interface{})
if config.AWSManagedRulesACFPRuleSet != nil {
m["aws_managed_rules_acfp_rule_set"] = flattenManagedRulesACFPRuleSet(config.AWSManagedRulesACFPRuleSet)
}
if config.AWSManagedRulesBotControlRuleSet != nil {
m["aws_managed_rules_bot_control_rule_set"] = flattenManagedRulesBotControlRuleSet(config.AWSManagedRulesBotControlRuleSet)
}
Expand All @@ -2390,6 +2449,18 @@ func flattenManagedRuleGroupConfigs(c []*wafv2.ManagedRuleGroupConfig) []interfa
return out
}

func flattenEmailField(apiObject *wafv2.EmailField) []interface{} {
if apiObject == nil {
return nil
}

m := map[string]interface{}{
"identifier": aws.StringValue(apiObject.Identifier),
}

return []interface{}{m}
}

func flattenPasswordField(apiObject *wafv2.PasswordField) []interface{} {
if apiObject == nil {
return nil
Expand Down Expand Up @@ -2426,6 +2497,26 @@ func flattenManagedRulesBotControlRuleSet(apiObject *wafv2.AWSManagedRulesBotCon
return []interface{}{m}
}

func flattenManagedRulesACFPRuleSet(apiObject *wafv2.AWSManagedRulesACFPRuleSet) []interface{} {
if apiObject == nil {
return nil
}

m := map[string]interface{}{
"enable_regex_in_path": aws.BoolValue(apiObject.EnableRegexInPath),
"creation_path": aws.StringValue(apiObject.CreationPath),
"registration_page_path": aws.StringValue(apiObject.RegistrationPagePath),
}
if apiObject.RequestInspection != nil {
m["request_inspection"] = flattenRequestInspectionACFP(apiObject.RequestInspection)
}
if apiObject.ResponseInspection != nil {
m["response_inspection"] = flattenResponseInspection(apiObject.ResponseInspection)
}

return []interface{}{m}
}

func flattenManagedRulesATPRuleSet(apiObject *wafv2.AWSManagedRulesATPRuleSet) []interface{} {
if apiObject == nil {
return nil
Expand All @@ -2445,6 +2536,21 @@ func flattenManagedRulesATPRuleSet(apiObject *wafv2.AWSManagedRulesATPRuleSet) [
return []interface{}{m}
}

func flattenRequestInspectionACFP(apiObject *wafv2.RequestInspectionACFP) []interface{} {
if apiObject == nil {
return nil
}

m := map[string]interface{}{
"email_field": flattenEmailField(apiObject.EmailField),
"password_field": flattenPasswordField(apiObject.PasswordField),
"payload_type": aws.StringValue(apiObject.PayloadType),
"username_field": flattenUsernameField(apiObject.UsernameField),
}

return []interface{}{m}
}

func flattenRequestInspection(apiObject *wafv2.RequestInspection) []interface{} {
if apiObject == nil {
return nil
Expand Down
99 changes: 99 additions & 0 deletions internal/service/wafv2/schemas.go
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,37 @@ func managedRuleGroupConfigSchema() *schema.Schema {
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"aws_managed_rules_acfp_rule_set": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"enable_regex_in_path": {
Type: schema.TypeBool,
Optional: true,
},
"creation_path": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.All(
validation.StringLenBetween(1, 256),
validation.StringMatch(regexache.MustCompile(`.*\S.*`), `must conform to pattern .*\S.* `),
),
},
"registration_page_path": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.All(
validation.StringLenBetween(1, 256),
validation.StringMatch(regexache.MustCompile(`.*\S.*`), `must conform to pattern .*\S.* `),
),
},
"request_inspection": managedRuleGroupConfigACFPRequestInspectionSchema(),
"response_inspection": managedRuleGroupConfigATPResponseInspectionSchema(),
},
},
},
"aws_managed_rules_atp_rule_set": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -1218,6 +1249,74 @@ func ruleGroupReferenceStatementSchema() *schema.Schema {
}
}

func managedRuleGroupConfigACFPRequestInspectionSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Required: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"email_field": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"identifier": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.All(
validation.StringLenBetween(1, 512),
validation.StringMatch(regexache.MustCompile(`.*\S.*`), `must conform to pattern .*\S.* `),
),
},
},
},
},
"password_field": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"identifier": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.All(
validation.StringLenBetween(1, 512),
validation.StringMatch(regexache.MustCompile(`.*\S.*`), `must conform to pattern .*\S.* `),
),
},
},
},
},
"payload_type": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice(wafv2.PayloadType_Values(), false),
},
"username_field": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"identifier": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.All(
validation.StringLenBetween(1, 512),
validation.StringMatch(regexache.MustCompile(`.*\S.*`), `must conform to pattern .*\S.* `),
),
},
},
},
},
},
},
}
}

func managedRuleGroupConfigATPRequestInspectionSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Expand Down
Loading
Loading