@@ -14,7 +14,7 @@ class WafRegexLogic:
14
14
def __init__ (self , resource_properties ):
15
15
self .regex_patterns = resource_properties ['RegexPatterns' ]
16
16
self .match_type = resource_properties ['Type' ]
17
- self .match_data = resource_properties [ 'Data' ]
17
+ self .match_data = resource_properties . get ( 'Data' , '' )
18
18
self .transform = resource_properties ['Transform' ]
19
19
self .match_name = resource_properties ['Name' ]
20
20
self .pattern_name = f"{ resource_properties ['Name' ]} -pattern"
@@ -99,22 +99,26 @@ def new_match_set(self):
99
99
return response_create_match_set ['RegexMatchSet' ]['RegexMatchSetId' ]
100
100
101
101
def insert_match_set (self , match_set_id , pattern_set_id ):
102
+ update = {
103
+ 'Action' : 'INSERT' ,
104
+ 'RegexMatchTuple' : {
105
+ 'FieldToMatch' : {
106
+ 'Type' : self .match_type
107
+ },
108
+ 'TextTransformation' : self .transform ,
109
+ 'RegexPatternSetId' : pattern_set_id
110
+ }
111
+ }
112
+
113
+ # This applies when `match_type` is 'HEADER' or 'SINGLE_QUERY_ARG'
114
+ if (self .match_data != '' ) {
115
+ update ['RegexMatchTuple' ]['FieldToMatch' ]['Data' ] = self .match_data
116
+ }
117
+
102
118
changeToken = self .client .get_change_token ()
103
119
update_regex_matchset = self .client .update_regex_match_set (
104
120
RegexMatchSetId = match_set_id ,
105
- Updates = [
106
- {
107
- 'Action' : 'INSERT' ,
108
- 'RegexMatchTuple' : {
109
- 'FieldToMatch' : {
110
- 'Type' : self .match_type ,
111
- 'Data' : self .match_data
112
- },
113
- 'TextTransformation' : self .transform ,
114
- 'RegexPatternSetId' : pattern_set_id
115
- }
116
- },
117
- ],
121
+ Updates = [update ],
118
122
ChangeToken = changeToken ['ChangeToken' ]
119
123
)
120
124
0 commit comments