Skip to content

Commit 7571d28

Browse files
Eilon4 (#199)
* resource_account_ssl_settings - remove from doc tree * resource_account_ssl_settings - change account id to be string * resource_account_ssl_settings - change account id to be string * resource_account_ssl_settings - change account id to be string Co-authored-by: eilon.shai <eilon.shai@imperva.com>
1 parent 5dd4869 commit 7571d28

File tree

4 files changed

+58
-62
lines changed

4 files changed

+58
-62
lines changed

incapsula/client_account_ssl_settings.go

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ type AccountSSLSettingsDTOResponse struct {
3434
}
3535

3636
// UpdateAccountSSLSettings update account SSL settings
37-
func (c *Client) UpdateAccountSSLSettings(accountSSLSettingsDTO *AccountSSLSettingsDTO, accountId int) (*AccountSSLSettingsDTOResponse, diag.Diagnostics) {
37+
func (c *Client) UpdateAccountSSLSettings(accountSSLSettingsDTO *AccountSSLSettingsDTO, accountId string) (*AccountSSLSettingsDTOResponse, diag.Diagnostics) {
3838
var diags diag.Diagnostics
3939
log.Printf("[INFO] updating account SSL settings to: %v ", accountSSLSettingsDTO)
4040

@@ -44,7 +44,7 @@ func (c *Client) UpdateAccountSSLSettings(accountSSLSettingsDTO *AccountSSLSetti
4444
diags = append(diags, diag.Diagnostic{
4545
Severity: diag.Error,
4646
Summary: "Unable to parse update account SSL settings properties",
47-
Detail: fmt.Sprintf("Failed to parse update account SSL settings properties for account id %d, %s", accountId, err.Error()),
47+
Detail: fmt.Sprintf("Failed to parse update account SSL settings properties for account id %s, %s", accountId, err.Error()),
4848
})
4949
return nil, diags
5050
}
@@ -53,7 +53,7 @@ func (c *Client) UpdateAccountSSLSettings(accountSSLSettingsDTO *AccountSSLSetti
5353
diags = append(diags, diag.Diagnostic{
5454
Severity: diag.Error,
5555
Summary: "Error response from Imperva service on update account SSL settings",
56-
Detail: fmt.Sprintf("Failed to update account SSL settings for account id %d, %s", accountId, err.Error()),
56+
Detail: fmt.Sprintf("Failed to update account SSL settings for account id %s, %s", accountId, err.Error()),
5757
})
5858
return nil, diags
5959
}
@@ -63,7 +63,7 @@ func (c *Client) UpdateAccountSSLSettings(accountSSLSettingsDTO *AccountSSLSetti
6363
diags = append(diags, diag.Diagnostic{
6464
Severity: diag.Error,
6565
Summary: "Failed to read response from Imperva service on update account SSL settings",
66-
Detail: fmt.Sprintf("Failed to read response for account id %d, %s", accountId, err.Error()),
66+
Detail: fmt.Sprintf("Failed to read response for account id %s, %s", accountId, err.Error()),
6767
})
6868
return nil, diags
6969
}
@@ -72,7 +72,7 @@ func (c *Client) UpdateAccountSSLSettings(accountSSLSettingsDTO *AccountSSLSetti
7272
diags = append(diags, diag.Diagnostic{
7373
Severity: diag.Error,
7474
Summary: "Failed to read response from Imperva service on update account SSL settings",
75-
Detail: fmt.Sprintf("Failed to read response for account id %d, got response status %d, %s", accountId, resp.StatusCode, string(responseBody)),
75+
Detail: fmt.Sprintf("Failed to read response for account id %s, got response status %d, %s", accountId, resp.StatusCode, string(responseBody)),
7676
})
7777
return nil, diags
7878
}
@@ -82,28 +82,28 @@ func (c *Client) UpdateAccountSSLSettings(accountSSLSettingsDTO *AccountSSLSetti
8282
diags = append(diags, diag.Diagnostic{
8383
Severity: diag.Error,
8484
Summary: "Failed to parse update account SSL settings response",
85-
Detail: fmt.Sprintf("Failed to parse update account SSL settings JSON response for account %d, %s", accountId, err.Error()),
85+
Detail: fmt.Sprintf("Failed to parse update account SSL settings JSON response for account %s, %s", accountId, err.Error()),
8686
})
8787
return nil, diags
8888
}
8989

90-
log.Printf("[DEBUG] Imperva update account SSL settings ended successfully for account id: %d", accountId)
90+
log.Printf("[DEBUG] Imperva update account SSL settings ended successfully for account id: %s", accountId)
9191

9292
return &accountSSLSettingsDTOResponse, nil
9393
}
9494

9595
// GetAccountSSLSettings gets the Incapsula managed account's status
96-
func (c *Client) GetAccountSSLSettings(accountId int) (*AccountSSLSettingsDTOResponse, diag.Diagnostics) {
96+
func (c *Client) GetAccountSSLSettings(accountId string) (*AccountSSLSettingsDTOResponse, diag.Diagnostics) {
9797
var diags diag.Diagnostics
98-
log.Printf("[INFO] Getting account SSL settings of: %d ", accountId)
98+
log.Printf("[INFO] Getting account SSL settings of: %s ", accountId)
9999

100100
getUrl := getUrl(accountId, c.config.BaseURLAPI)
101101
resp, err := c.DoJsonAndQueryParamsRequestWithHeaders(http.MethodGet, getUrl, nil, nil, GetAccountSSLSettings)
102102
if err != nil {
103103
diags = append(diags, diag.Diagnostic{
104104
Severity: diag.Error,
105105
Summary: "Error response from Imperva service on getting account SSL settings",
106-
Detail: fmt.Sprintf("Failed to get account SSL settings for account id %d, %s", accountId, err.Error()),
106+
Detail: fmt.Sprintf("Failed to get account SSL settings for account id %s, %s", accountId, err.Error()),
107107
})
108108
return nil, diags
109109
}
@@ -114,17 +114,17 @@ func (c *Client) GetAccountSSLSettings(accountId int) (*AccountSSLSettingsDTORes
114114
diags = append(diags, diag.Diagnostic{
115115
Severity: diag.Error,
116116
Summary: "Failed to read response from Imperva service on getting account SSL settings",
117-
Detail: fmt.Sprintf("Failed to read response for account id %d, %s", accountId, err.Error()),
117+
Detail: fmt.Sprintf("Failed to read response for account id %s, %s", accountId, err.Error()),
118118
})
119119
return nil, diags
120120
}
121121

122-
log.Printf("[DEBUG] Imperva get account SSL settings for account %d response: %s\n", accountId, string(responseBody))
122+
log.Printf("[DEBUG] Imperva get account SSL settings for account %s response: %s\n", accountId, string(responseBody))
123123
if resp.StatusCode != 200 {
124124
diags = append(diags, diag.Diagnostic{
125125
Severity: diag.Error,
126126
Summary: "Failed to read response from Imperva service on getting account SSL settings",
127-
Detail: fmt.Sprintf("Failed to read response for account id %d, got response status %d, %s", accountId, resp.StatusCode, string(responseBody)),
127+
Detail: fmt.Sprintf("Failed to read response for account id %s, got response status %d, %s", accountId, resp.StatusCode, string(responseBody)),
128128
})
129129
return nil, diags
130130
}
@@ -134,49 +134,49 @@ func (c *Client) GetAccountSSLSettings(accountId int) (*AccountSSLSettingsDTORes
134134
diags = append(diags, diag.Diagnostic{
135135
Severity: diag.Error,
136136
Summary: "Failed to parse get account SSL settings response",
137-
Detail: fmt.Sprintf("Failed to parse get account SSL settings JSON response for account %d, %s", accountId, err.Error()),
137+
Detail: fmt.Sprintf("Failed to parse get account SSL settings JSON response for account %s, %s", accountId, err.Error()),
138138
})
139139
return nil, diags
140140
}
141-
log.Printf("[DEBUG] get account SSL settings ended successfully for account id: %d", accountId)
141+
log.Printf("[DEBUG] get account SSL settings ended successfully for account id: %s", accountId)
142142
return &accountSSLSettingsDTOResponse, nil
143143
}
144144

145145
// DeleteAccountSSLSettings gets the Incapsula managed account's status
146-
func (c *Client) DeleteAccountSSLSettings(accountId int) diag.Diagnostics {
146+
func (c *Client) DeleteAccountSSLSettings(accountId string) diag.Diagnostics {
147147
var diags diag.Diagnostics
148-
log.Printf("[INFO] Reseting account SSL settings of: %d ", accountId)
148+
log.Printf("[INFO] Reseting account SSL settings of: %s ", accountId)
149149

150150
getUrl := getUrl(accountId, c.config.BaseURLAPI)
151151
resp, err := c.DoJsonAndQueryParamsRequestWithHeaders(http.MethodDelete, getUrl, nil, nil, DeleteAccountSSLSettings)
152152
if err != nil {
153153
diags = append(diags, diag.Diagnostic{
154154
Severity: diag.Error,
155155
Summary: "Failed to delete account SSL settings",
156-
Detail: fmt.Sprintf("error from Imperva service when deleting Account SSL certificate for account_id %d: %s", accountId, err.Error()),
156+
Detail: fmt.Sprintf("error from Imperva service when deleting Account SSL certificate for account_id %s: %s", accountId, err.Error()),
157157
})
158158
return diags
159159
}
160160

161161
// Read the body
162162
defer resp.Body.Close()
163163

164-
log.Printf("[DEBUG] delete account SSL settings ended successfully for account id: %d", accountId)
164+
log.Printf("[DEBUG] delete account SSL settings ended successfully for account id: %s", accountId)
165165
if resp.StatusCode != 200 {
166166
diags = append(diags, diag.Diagnostic{
167167
Severity: diag.Error,
168168
Summary: "Failed to read response from Imperva service on update account SSL settings",
169-
Detail: fmt.Sprintf("Failed to read response for account id %d, got response status %d", accountId, resp.StatusCode),
169+
Detail: fmt.Sprintf("Failed to read response for account id %s, got response status %d", accountId, resp.StatusCode),
170170
})
171171
return diags
172172
}
173173
return nil
174174
}
175175

176-
func getUrl(accountId int, baseUrl string) string {
176+
func getUrl(accountId string, baseUrl string) string {
177177
url := fmt.Sprintf("%s%s", baseUrl, accountSSLSettingsUrl)
178-
if accountId > 0 {
179-
url = fmt.Sprintf("%s%s?caid=%d", baseUrl, accountSSLSettingsUrl, accountId)
178+
if accountId != "" {
179+
url = fmt.Sprintf("%s%s?caid=%s", baseUrl, accountSSLSettingsUrl, accountId)
180180
}
181181
return url
182182
}

incapsula/client_account_ssl_settings_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func TestClientUpdateAccountSSlSettingsBadConnection(t *testing.T) {
1313
config := &Config{APIID: "foo", APIKey: "bar", BaseURLAPI: "http://badness.incapsula.com"}
1414
client := &Client{config: config, httpClient: &http.Client{Timeout: time.Millisecond * 1}}
1515
dto := AccountSSLSettingsDTO{}
16-
updateAccountSSLSettingsResponse, diag := client.UpdateAccountSSLSettings(&dto, 0)
16+
updateAccountSSLSettingsResponse, diag := client.UpdateAccountSSLSettings(&dto, "")
1717
if diag == nil || !diag.HasError() || !strings.Contains(diag[0].Detail, "Timeout exceeded while awaiting") {
1818
t.Errorf("Should have received an time out error")
1919
}
@@ -40,7 +40,7 @@ func TestClientUpdateAccountSSlSettingsInternalError(t *testing.T) {
4040
dto := AccountSSLSettingsDTO{
4141
ImpervaCertificate: &imp,
4242
}
43-
_, diag := client.UpdateAccountSSLSettings(&dto, 0)
43+
_, diag := client.UpdateAccountSSLSettings(&dto, "")
4444
if diag == nil || !diag.HasError() || !strings.Contains(diag[0].Detail, "got response status 500, error") {
4545
t.Errorf("Should have received an error")
4646
}
@@ -64,7 +64,7 @@ func TestClientUpdateAccountSSlSettingsErrorsInBody(t *testing.T) {
6464
dto := AccountSSLSettingsDTO{
6565
ImpervaCertificate: &imp,
6666
}
67-
accountSSLSettingsResponse, diag := client.UpdateAccountSSLSettings(&dto, 0)
67+
accountSSLSettingsResponse, diag := client.UpdateAccountSSLSettings(&dto, "")
6868
if diag != nil {
6969
t.Errorf("Should not received an error")
7070
}
@@ -91,7 +91,7 @@ func TestClientUpdateAccountSSlSettingsDataInBody(t *testing.T) {
9191
dto := AccountSSLSettingsDTO{
9292
ImpervaCertificate: &imp,
9393
}
94-
accountSSLSettingsResponse, diag := client.UpdateAccountSSLSettings(&dto, 0)
94+
accountSSLSettingsResponse, diag := client.UpdateAccountSSLSettings(&dto, "")
9595
if diag != nil {
9696
t.Errorf("Should not received an error")
9797
}
@@ -111,7 +111,7 @@ func TestClientGetAccountSSlSettingsDataInBody(t *testing.T) {
111111
defer server.Close()
112112
config := &Config{APIID: "foo", APIKey: "bar", BaseURLAPI: server.URL}
113113
client := &Client{config: config, httpClient: &http.Client{}}
114-
accountSSLSettingsResponse, diag := client.GetAccountSSLSettings(0)
114+
accountSSLSettingsResponse, diag := client.GetAccountSSLSettings("")
115115
if diag != nil {
116116
t.Errorf("Should not received an error")
117117
}
@@ -132,7 +132,7 @@ func TestClientGetAccountSSlSettingsErrorsInBody(t *testing.T) {
132132
config := &Config{APIID: "foo", APIKey: "bar", BaseURLAPI: server.URL}
133133
client := &Client{config: config, httpClient: &http.Client{}}
134134

135-
accountSSLSettingsResponse, diag := client.GetAccountSSLSettings(0)
135+
accountSSLSettingsResponse, diag := client.GetAccountSSLSettings("")
136136
if diag != nil {
137137
t.Errorf("Should not received an error")
138138
}
@@ -152,7 +152,7 @@ func TestClientGetAccountSSlSettingsErrorFromMY(t *testing.T) {
152152
defer server.Close()
153153
config := &Config{APIID: "foo", APIKey: "bar", BaseURLAPI: server.URL}
154154
client := &Client{config: config, httpClient: &http.Client{}}
155-
_, diag := client.GetAccountSSLSettings(0)
155+
_, diag := client.GetAccountSSLSettings("")
156156
if diag == nil || !diag.HasError() || !strings.Contains(diag[0].Detail, "got response status 500, error") {
157157
t.Errorf("Should have received an error")
158158
}
@@ -161,7 +161,7 @@ func TestClientGetAccountSSlSettingsErrorFromMY(t *testing.T) {
161161
func TestClientGetAccountSSlSettingsBadConnection(t *testing.T) {
162162
config := &Config{APIID: "foo", APIKey: "bar", BaseURLAPI: "http://badness.incapsula.com"}
163163
client := &Client{config: config, httpClient: &http.Client{Timeout: time.Millisecond * 1}}
164-
updateAccountSSLSettingsResponse, diag := client.GetAccountSSLSettings(0)
164+
updateAccountSSLSettingsResponse, diag := client.GetAccountSSLSettings("")
165165
if diag == nil || !diag.HasError() || !strings.Contains(diag[0].Detail, "Timeout exceeded while awaiting") {
166166
t.Errorf("Should have received an time out error")
167167
}
@@ -173,7 +173,7 @@ func TestClientGetAccountSSlSettingsBadConnection(t *testing.T) {
173173
func TestClientDeleteAccountSSlSettingsBadConnection(t *testing.T) {
174174
config := &Config{APIID: "foo", APIKey: "bar", BaseURLAPI: "http://badness.incapsula.com"}
175175
client := &Client{config: config, httpClient: &http.Client{Timeout: time.Millisecond * 1}}
176-
diag := client.DeleteAccountSSLSettings(0)
176+
diag := client.DeleteAccountSSLSettings("")
177177
if diag == nil || !diag.HasError() || !strings.Contains(diag[0].Detail, "Timeout exceeded while awaiting") {
178178
t.Errorf("Should have received an time out error")
179179
}
@@ -190,7 +190,7 @@ func TestClientDeleteAccountSSlSettingsErrorFromMY(t *testing.T) {
190190
defer server.Close()
191191
config := &Config{APIID: "foo", APIKey: "bar", BaseURLAPI: server.URL}
192192
client := &Client{config: config, httpClient: &http.Client{}}
193-
diag := client.DeleteAccountSSLSettings(0)
193+
diag := client.DeleteAccountSSLSettings("")
194194
if diag == nil || !diag.HasError() || !strings.Contains(diag[0].Detail, "got response status 500") {
195195
t.Errorf("Should have received an error")
196196
}
@@ -206,7 +206,7 @@ func TestClientDeleteAccountSSlSettings200FromMY(t *testing.T) {
206206
defer server.Close()
207207
config := &Config{APIID: "foo", APIKey: "bar", BaseURLAPI: server.URL}
208208
client := &Client{config: config, httpClient: &http.Client{}}
209-
diag := client.DeleteAccountSSLSettings(0)
209+
diag := client.DeleteAccountSSLSettings("")
210210
if diag != nil || diag.HasError() {
211211
t.Errorf("Should not received an error")
212212
}

0 commit comments

Comments
 (0)