Skip to content

Commit

Permalink
Add validation for SiteStatusResponse Res filed in EditSecurityRuleEx…
Browse files Browse the repository at this point in the history
…ception (#375)
  • Loading branch information
Pavel-Koev authored Jan 3, 2024
1 parent f8af4b8 commit decdf01
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion incapsula/client_security_rule_exception.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,18 @@ func (c *Client) EditSecurityRuleException(siteID int, ruleID, clientAppTypes, c
return nil, fmt.Errorf("Error parsing configure security rule exception JSON response for rule_id (%s) and site_id (%d)", ruleID, siteID)
}

// Res can sometimes oscillate between a string and number
// We need to add safeguards for this inside the provider
var resString string

if resNumber, ok := siteStatusResponse.Res.(float64); ok {
resString = fmt.Sprintf("%d", int(resNumber))
} else {
resString = siteStatusResponse.Res.(string)
}

// Look at the response status code from Incapsula
if siteStatusResponse.Res != 0 {
if resString != "0" {
return nil, fmt.Errorf("Error from Incapsula service when adding security rule exception for rule_id (%s) and site_id (%d): %s", ruleID, siteID, string(responseBody))
}

Expand Down

0 comments on commit decdf01

Please sign in to comment.