Skip to content

Commit ed93283

Browse files
authored
Merge pull request #536 from Pavel-Koev/block_duration-fix
Fixing block duration fields
2 parents b0e127c + f2bdc94 commit ed93283

File tree

2 files changed

+39
-29
lines changed

2 files changed

+39
-29
lines changed

incapsula/client_incap_rule.go

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,29 @@ import (
1010

1111
// IncapRule is a struct that encompasses all the properties of an IncapRule
1212
type IncapRule struct {
13-
Name string `json:"name"`
14-
Action string `json:"action"`
15-
Filter string `json:"filter,omitempty"`
16-
ResponseCode int `json:"response_code,omitempty"`
17-
AddMissing bool `json:"add_missing,omitempty"`
18-
RewriteExisting *bool `json:"rewrite_existing,omitempty"`
19-
From string `json:"from,omitempty"`
20-
To string `json:"to,omitempty"`
21-
RewriteName string `json:"rewrite_name,omitempty"`
22-
DCID int `json:"dc_id,omitempty"`
23-
PortForwardingContext string `json:"port_forwarding_context,omitempty"`
24-
PortForwardingValue string `json:"port_forwarding_value,omitempty"`
25-
RateContext string `json:"rate_context,omitempty"`
26-
RateInterval int `json:"rate_interval,omitempty"`
27-
ErrorType string `json:"error_type,omitempty"`
28-
ErrorResponseFormat string `json:"error_response_format,omitempty"`
29-
ErrorResponseData string `json:"error_response_data,omitempty"`
30-
MultipleDeletions bool `json:"multiple_deletions,omitempty"`
31-
OverrideWafRule string `json:"overrideWafRule,omitempty"`
32-
OverrideWafAction string `json:"overrideWafAction,omitempty"`
33-
Enabled bool `json:"enabled"`
34-
SendNotifications *bool `json:"sendNotifications,omitempty"`
35-
BlockDurationDetails BlockDurationDetails `json:"blockDurationDetails,omitempty"`
13+
Name string `json:"name"`
14+
Action string `json:"action"`
15+
Filter string `json:"filter,omitempty"`
16+
ResponseCode int `json:"response_code,omitempty"`
17+
AddMissing bool `json:"add_missing,omitempty"`
18+
RewriteExisting *bool `json:"rewrite_existing,omitempty"`
19+
From string `json:"from,omitempty"`
20+
To string `json:"to,omitempty"`
21+
RewriteName string `json:"rewrite_name,omitempty"`
22+
DCID int `json:"dc_id,omitempty"`
23+
PortForwardingContext string `json:"port_forwarding_context,omitempty"`
24+
PortForwardingValue string `json:"port_forwarding_value,omitempty"`
25+
RateContext string `json:"rate_context,omitempty"`
26+
RateInterval int `json:"rate_interval,omitempty"`
27+
ErrorType string `json:"error_type,omitempty"`
28+
ErrorResponseFormat string `json:"error_response_format,omitempty"`
29+
ErrorResponseData string `json:"error_response_data,omitempty"`
30+
MultipleDeletions bool `json:"multiple_deletions,omitempty"`
31+
OverrideWafRule string `json:"overrideWafRule,omitempty"`
32+
OverrideWafAction string `json:"overrideWafAction,omitempty"`
33+
Enabled bool `json:"enabled"`
34+
SendNotifications *bool `json:"sendNotifications,omitempty"`
35+
BlockDurationDetails *BlockDurationDetails `json:"blockDurationDetails,omitempty"`
3636
}
3737

3838
type BlockDurationDetails struct {

incapsula/resource_incap_rule.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,13 +214,17 @@ func resourceIncapRuleCreate(d *schema.ResourceData, m interface{}) error {
214214
sendNotifications = &valBool
215215
}
216216

217-
blockDurationDetails := BlockDurationDetails{
217+
blockDurationDetails := &BlockDurationDetails{
218218
BlockDurationType: d.Get("block_duration_type").(string),
219219
BlockDuration: d.Get("block_duration").(int),
220220
BlockDurationMin: d.Get("block_duration_min").(int),
221221
BlockDurationMax: d.Get("block_duration_max").(int),
222222
}
223223

224+
if blockDurationDetails.BlockDurationType == "" {
225+
blockDurationDetails = nil
226+
}
227+
224228
rule := IncapRule{
225229
Name: d.Get("name").(string),
226230
Action: action,
@@ -303,10 +307,12 @@ func resourceIncapRuleRead(d *schema.ResourceData, m interface{}) error {
303307
if rule.SendNotifications != nil {
304308
d.Set("send_notifications", strconv.FormatBool(*rule.SendNotifications))
305309
}
306-
d.Set("block_duration_type", rule.BlockDurationDetails.BlockDurationType)
307-
d.Set("block_duration", rule.BlockDurationDetails.BlockDuration)
308-
d.Set("block_duration_min", rule.BlockDurationDetails.BlockDurationMin)
309-
d.Set("block_duration_max", rule.BlockDurationDetails.BlockDurationMax)
310+
if rule.BlockDurationDetails != nil {
311+
d.Set("block_duration_type", rule.BlockDurationDetails.BlockDurationType)
312+
d.Set("block_duration", rule.BlockDurationDetails.BlockDuration)
313+
d.Set("block_duration_min", rule.BlockDurationDetails.BlockDurationMin)
314+
d.Set("block_duration_max", rule.BlockDurationDetails.BlockDurationMax)
315+
}
310316

311317
action := d.Get("action").(string)
312318

@@ -344,13 +350,17 @@ func resourceIncapRuleUpdate(d *schema.ResourceData, m interface{}) error {
344350
sendNotifications = &valBool
345351
}
346352

347-
blockDurationDetails := BlockDurationDetails{
353+
blockDurationDetails := &BlockDurationDetails{
348354
BlockDurationType: d.Get("block_duration_type").(string),
349355
BlockDuration: d.Get("block_duration").(int),
350356
BlockDurationMin: d.Get("block_duration_min").(int),
351357
BlockDurationMax: d.Get("block_duration_max").(int),
352358
}
353359

360+
if blockDurationDetails.BlockDurationType == "" {
361+
blockDurationDetails = nil
362+
}
363+
354364
rule := IncapRule{
355365
Name: d.Get("name").(string),
356366
Action: action,

0 commit comments

Comments
 (0)