Skip to content

Commit 478d133

Browse files
committed
feat: WIP add WaaS support - starting convert
1 parent 76996ac commit 478d133

File tree

1 file changed

+57
-2
lines changed

1 file changed

+57
-2
lines changed

internal/convert/firewall.go

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ func SchemaToFirewallAppPolicy(d *schema.ResourceData) (policy.FirewallAppPolicy
1919

2020
if schemaRules, ok := d.GetOk("rules"); ok {
2121
iterRules := schemaRules.([]interface{})
22+
2223
for _, schemaRule := range iterRules {
2324
mapRule := schemaRule.(map[string]interface{})
2425
rule := waas.WaasRule{}
@@ -29,13 +30,16 @@ func SchemaToFirewallAppPolicy(d *schema.ResourceData) (policy.FirewallAppPolicy
2930

3031
if schemaApplications, ok := mapRule["applications"]; ok {
3132
iterApplications := schemaApplications.([]interface{})
33+
3234
for _, schemaApplication := range iterApplications {
3335
mapApplication := schemaApplication.(map[string]interface{})
36+
application := waas.WaasApplicationSpec{}
3437

3538
if schemaAPIs, ok := mapApplication["api"]; ok {
3639
iterAPIs := schemaAPIs.([]interface{})
37-
for _, schemaAPI := range iterAPIs {
38-
mapAPI := schemaAPI.(map[string]interface{})
40+
41+
if len(iterAPIs) == 1 {
42+
mapAPI := iterAPIs[0].(map[string]interface{})
3943
api := waas.WaasAPISpec{}
4044

4145
if val, ok := mapAPI["description"]; ok {
@@ -161,10 +165,61 @@ func SchemaToFirewallAppPolicy(d *schema.ResourceData) (policy.FirewallAppPolicy
161165
if val, ok := mapPath["path"]; ok {
162166
path.Path = val.(string)
163167
}
168+
169+
api.Paths = append(api.Paths, path)
170+
}
171+
}
172+
173+
if val, ok := mapAPI["query_param_effect"]; ok {
174+
api.QueryParamFallbackEffect = val.(string)
175+
}
176+
177+
application.APISpec = api
178+
}
179+
}
180+
181+
if val, ok := mapApplication["app_id"]; ok {
182+
application.AppID = val.(string)
183+
}
184+
185+
if schemaAttackTools, ok := mapApplication["attack_tools"]; ok {
186+
iterAttackTools := schemaAttackTools.([]interface{})
187+
188+
if len(iterAttackTools) == 1 {
189+
mapAttackTools := iterAttackTools[0].(map[string]interface{})
190+
attackTools := waas.WaasProtectionConfig{}
191+
192+
if val, ok := mapAttackTools["effect"]; ok {
193+
attackTools.Effect = val.(string)
194+
}
195+
196+
if schemaAttackToolsExceptions, ok := mapAttackTools["exceptions"]; ok {
197+
iterAttackToolsExceptions := schemaAttackToolsExceptions.([]interface{})
198+
199+
for _, schemaAttackException := range iterAttackToolsExceptions {
200+
mapAttackToolsException := schemaAttackException.(map[string]interface{})
201+
attackToolsException := waas.WaasExceptionField{}
202+
203+
if val, ok := mapAttackToolsException["key"]; ok {
204+
attackToolsException.Key = val.(string)
205+
}
206+
207+
if val, ok := mapAttackToolsException["location"]; ok {
208+
attackToolsException.Location = val.(string)
209+
}
210+
211+
attackTools.ExceptionFields = append(attackTools.ExceptionFields, attackToolsException)
164212
}
165213
}
214+
215+
application.AttackTools = attackTools
166216
}
167217
}
218+
219+
if val, ok := mapApplication["ban_duration"]; ok {
220+
application.BanDurationMinutes = val.(int)
221+
}
222+
168223
}
169224
}
170225
}

0 commit comments

Comments
 (0)