Skip to content

Commit 5cb6c00

Browse files
tamyyalomanandkunal
authored andcommitted
add logs_account_id to read and update methods of account and site
1 parent 4798eff commit 5cb6c00

File tree

6 files changed

+33
-21
lines changed

6 files changed

+33
-21
lines changed

incapsula/client_log_level.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,25 @@ import (
1111
const endpointSiteLogLevel = "sites/setlog"
1212

1313
// UpdateLogLevel will update the site log level
14-
func (c *Client) UpdateLogLevel(siteID, logLevel string) error {
14+
func (c *Client) UpdateLogLevel(siteID, logLevel, logsAccountId string) error {
1515
type LogLevelResponse struct {
1616
Res int `json:"res"`
1717
ResMessage string `json:"res_message"`
1818
DebugInfo struct {
19-
LogLevel string `json:"log_level"`
19+
LogLevel string `json:"log_level,omitempty"`
20+
LogsAccountId string `json:"logs_account_id,omitempty"`
2021
} `json:"debug_info"`
2122
}
2223

2324
log.Printf("[INFO] Updating Incapsula log level (%s) for siteID: %s\n", logLevel, siteID)
2425

2526
// Post form to Incapsula
2627
resp, err := c.httpClient.PostForm(fmt.Sprintf("%s/%s", c.config.BaseURL, endpointSiteLogLevel), url.Values{
27-
"api_id": {c.config.APIID},
28-
"api_key": {c.config.APIKey},
29-
"site_id": {siteID},
30-
"log_level": {logLevel},
28+
"api_id": {c.config.APIID},
29+
"api_key": {c.config.APIKey},
30+
"site_id": {siteID},
31+
"log_level": {logLevel},
32+
"logs_account_id": {logsAccountId},
3133
})
3234
if err != nil {
3335
return fmt.Errorf("Error updating log level (%s) on site_id: %s: %s", logLevel, siteID, err)

incapsula/client_log_level_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ func TestClientUpdateLogLevelBadConnection(t *testing.T) {
1818
client := &Client{config: config, httpClient: &http.Client{Timeout: time.Millisecond * 1}}
1919
siteID := "42"
2020
logLevel := "full"
21-
err := client.UpdateLogLevel(siteID, logLevel)
21+
logsAccountId := "123"
22+
err := client.UpdateLogLevel(siteID, logLevel, logsAccountId)
2223
if err == nil {
2324
t.Errorf("Should have received an error")
2425
}
@@ -40,7 +41,8 @@ func TestClientUpdateLogLevelBadJSON(t *testing.T) {
4041
client := &Client{config: config, httpClient: &http.Client{}}
4142
siteID := "42"
4243
logLevel := "full"
43-
err := client.UpdateLogLevel(siteID, logLevel)
44+
logsAccountId := "123"
45+
err := client.UpdateLogLevel(siteID, logLevel, logsAccountId)
4446
if err == nil {
4547
t.Errorf("Should have received an error")
4648
}
@@ -62,7 +64,8 @@ func TestClientUpdateLogLevelInvalidSite(t *testing.T) {
6264
client := &Client{config: config, httpClient: &http.Client{}}
6365
siteID := "42"
6466
logLevel := "full"
65-
err := client.UpdateLogLevel(siteID, logLevel)
67+
logsAccountId := "123"
68+
err := client.UpdateLogLevel(siteID, logLevel, logsAccountId)
6669
if err == nil {
6770
t.Errorf("Should have received an error")
6871
}
@@ -84,7 +87,8 @@ func TestClientUpdateLogLevelValidSite(t *testing.T) {
8487
client := &Client{config: config, httpClient: &http.Client{}}
8588
siteID := "42"
8689
logLevel := "full"
87-
err := client.UpdateLogLevel(siteID, logLevel)
90+
logsAccountId := "123"
91+
err := client.UpdateLogLevel(siteID, logLevel, logsAccountId)
8892
if err != nil {
8993
t.Errorf("Should not have received an error")
9094
}

incapsula/client_site.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ type SiteStatusResponse struct {
207207
}
208208

209209
// AddSite adds a site to be managed by Incapsula
210-
func (c *Client) AddSite(domain, refID, sendSiteSetupEmails, siteIP, forceSSL string, accountID int, nakedDomainSan bool, wildcarSan bool) (*SiteAddResponse, error) {
210+
func (c *Client) AddSite(domain, refID, sendSiteSetupEmails, siteIP, forceSSL string, accountID int, nakedDomainSan bool, wildcarSan bool, logsAccountId string) (*SiteAddResponse, error) {
211211
log.Printf("[INFO] Adding Incapsula site for domain: %s (account ID %d)\n", domain, accountID)
212212

213213
values := url.Values{
@@ -220,6 +220,7 @@ func (c *Client) AddSite(domain, refID, sendSiteSetupEmails, siteIP, forceSSL st
220220
"force_ssl": {forceSSL},
221221
"naked_domain_san": {fmt.Sprintf("%t", nakedDomainSan)},
222222
"wildcard_san": {fmt.Sprintf("%t", wildcarSan)},
223+
"logs_account_id": {logsAccountId},
223224
}
224225
if accountID != 0 {
225226
values["account_id"] = make([]string, 1)

incapsula/client_site_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func TestClientAddSiteBadConnection(t *testing.T) {
1717
config := &Config{APIID: "foo", APIKey: "bar", BaseURL: "badness.incapsula.com"}
1818
client := &Client{config: config, httpClient: &http.Client{Timeout: time.Millisecond * 1}}
1919
domain := "foo.com"
20-
addSiteResponse, err := client.AddSite(domain, "", "", "", "", 0, false, false)
20+
addSiteResponse, err := client.AddSite(domain, "", "", "", "", 0, false, false, "")
2121
if err == nil {
2222
t.Errorf("Should have received an error")
2323
}
@@ -41,7 +41,7 @@ func TestClientAddSiteBadJSON(t *testing.T) {
4141
config := &Config{APIID: "foo", APIKey: "bar", BaseURL: server.URL}
4242
client := &Client{config: config, httpClient: &http.Client{}}
4343
domain := "foo.com"
44-
addSiteResponse, err := client.AddSite(domain, "", "", "", "", 0, false, false)
44+
addSiteResponse, err := client.AddSite(domain, "", "", "", "", 0, false, false, "")
4545
if err == nil {
4646
t.Errorf("Should have received an error")
4747
}
@@ -65,7 +65,7 @@ func TestClientAddSiteInvalidSite(t *testing.T) {
6565
config := &Config{APIID: "foo", APIKey: "bar", BaseURL: server.URL}
6666
client := &Client{config: config, httpClient: &http.Client{}}
6767
domain := "foo.com"
68-
addSiteResponse, err := client.AddSite(domain, "", "", "", "", 0, false, false)
68+
addSiteResponse, err := client.AddSite(domain, "", "", "", "", 0, false, false, "")
6969
if err == nil {
7070
t.Errorf("Should have received an error")
7171
}
@@ -89,7 +89,7 @@ func TestClientAddSiteValidSite(t *testing.T) {
8989
config := &Config{APIID: "foo", APIKey: "bar", BaseURL: server.URL}
9090
client := &Client{config: config, httpClient: &http.Client{}}
9191
domain := "foo.com"
92-
addSiteResponse, err := client.AddSite(domain, "", "", "", "", 0, false, false)
92+
addSiteResponse, err := client.AddSite(domain, "", "", "", "", 0, false, false, "")
9393
if err != nil {
9494
t.Errorf("Should not have received an error")
9595
}

incapsula/resource_account.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,13 @@ func updateAdditionalAccountProperties(client *Client, d *schema.ResourceData) e
287287
}
288288

289289
func updateAccountLogLevel(client *Client, d *schema.ResourceData) error {
290-
if d.HasChange("log_level") {
290+
if d.HasChange("log_level") ||
291+
d.HasChange("logs_account_id") {
291292
logLevel := d.Get("log_level").(string)
292-
err := client.UpdateLogLevel(d.Id(), logLevel)
293+
logsAccountId := d.Get("logs_account_id").(string)
294+
err := client.UpdateLogLevel(d.Id(), logLevel, logsAccountId)
293295
if err != nil {
294-
log.Printf("[ERROR] Could not update Incapsula account log level: %s for account_id: %s %s\n", logLevel, d.Id(), err)
296+
log.Printf("[ERROR] Could not update Incapsula account log level: %s and log account id: %s for account_id: %s %s\n", logLevel, logsAccountId, d.Id(), err)
295297
return err
296298
}
297299
}

incapsula/resource_site.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ func resourceSiteCreate(d *schema.ResourceData, m interface{}) error {
360360
d.Get("account_id").(int),
361361
d.Get("naked_domain_san").(bool),
362362
d.Get("wildcard_san").(bool),
363+
d.Get("logs_account_id").(string),
363364
)
364365

365366
if err != nil {
@@ -648,11 +649,13 @@ func updateMaskingSettings(client *Client, d *schema.ResourceData) error {
648649
}
649650

650651
func updateLogLevel(client *Client, d *schema.ResourceData) error {
651-
if d.HasChange("log_level") {
652+
if d.HasChange("log_level") ||
653+
d.HasChange("logs_account_id") {
652654
logLevel := d.Get("log_level").(string)
653-
err := client.UpdateLogLevel(d.Id(), logLevel)
655+
logsAccountId := d.Get("logs_account_id").(string)
656+
err := client.UpdateLogLevel(d.Id(), logLevel, logsAccountId)
654657
if err != nil {
655-
log.Printf("[ERROR] Could not update Incapsula site log level: %s for site_id: %s %s\n", logLevel, d.Id(), err)
658+
log.Printf("[ERROR] Could not update Incapsula site log level: %s and logs account id: %s for site_id: %s %s\n", logLevel, logsAccountId, d.Id(), err)
656659
return err
657660
}
658661
}

0 commit comments

Comments
 (0)