Skip to content

Commit 64f99d8

Browse files
authored
Revert "Extend site ssl settings resource with inbound tls settings (#360)" (#386)
This reverts commit f8af4b8.
1 parent 98fbdef commit 64f99d8

File tree

4 files changed

+45
-249
lines changed

4 files changed

+45
-249
lines changed

incapsula/client_site_ssl_settings.go

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,38 +15,27 @@ type HSTSConfiguration struct {
1515
PreLoaded bool `json:"preLoaded"`
1616
}
1717

18-
type InboundTLSSettingsConfiguration struct {
19-
ConfigurationProfile string `json:"configurationProfile"`
20-
TLSConfigurations []TLSConfiguration `json:"tlsConfiguration"`
21-
}
22-
23-
type TLSConfiguration struct {
24-
TLSVersion string `json:"tlsVersion"`
25-
CiphersSupport []string `json:"ciphersSupport"`
18+
type Data struct {
19+
HstsConfiguration HSTSConfiguration `json:"hstsConfiguration"`
2620
}
2721

2822
type SSLSettingsDTO struct {
29-
HstsConfiguration HSTSConfiguration `json:"hstsConfiguration"`
30-
InboundTLSSettingsConfiguration *InboundTLSSettingsConfiguration `json:"inboundTlsSettings,omitempty"`
31-
}
32-
33-
type SSLSettingsResponse struct {
34-
Data []SSLSettingsDTO `json:"data"`
23+
Data []Data `json:"data"`
3524
}
3625

37-
func (c *Client) UpdateSiteSSLSettings(siteID int, mySSLSettings SSLSettingsResponse) (*SSLSettingsResponse, error) {
26+
func (c *Client) UpdateSiteSSLSettings(siteID int, mySSLSettings SSLSettingsDTO) (*SSLSettingsDTO, error) {
3827
log.Printf("[INFO] Updating Incapsula Site SSL settings for Site ID %d\n", siteID)
3928

4029
requestJSON, err := json.Marshal(mySSLSettings)
4130
if err != nil {
42-
return nil, fmt.Errorf("failed to JSON marshal SSLSettings: %s", err)
31+
return nil, fmt.Errorf("failed to JSON marshal HSTSConfiguration: %s", err)
4332
}
4433

45-
// Patch request to Incapsula
46-
reqURL := fmt.Sprintf("%s/sites-mgmt/v3/sites/%d/settings/TLSConfiguration", c.config.BaseURLAPI, siteID)
47-
log.Printf("[INFO] SSL Settings request json looks like this %s\n", requestJSON)
48-
log.Printf("[INFO] SSL Settings request URL looks like this %s\n", reqURL)
49-
resp, err := c.DoJsonRequestWithHeaders(http.MethodPatch, reqURL, requestJSON, UpdateSiteSSLSettings)
34+
// Put request to Incapsula
35+
reqURL := fmt.Sprintf("%s/sites/%d/settings/TLSConfiguration", c.config.BaseURLRev3, siteID)
36+
log.Printf("[INFO] HSTS request json looks like this %s\n", requestJSON)
37+
log.Printf("[INFO] HSTS request URL looks like this %s\n", reqURL)
38+
resp, err := c.DoJsonRequestWithHeaders(http.MethodPost, reqURL, requestJSON, UpdateSiteSSLSettings)
5039
if err != nil {
5140
return nil, fmt.Errorf("error from Incapsula service when updating Site SSL settings %s for Site ID %d: %s", requestJSON, siteID, err)
5241
}
@@ -64,20 +53,20 @@ func (c *Client) UpdateSiteSSLSettings(siteID int, mySSLSettings SSLSettingsResp
6453
}
6554

6655
// Parse the JSON
67-
var sslSettingsResponse SSLSettingsResponse
68-
err = json.Unmarshal([]byte(responseBody), &sslSettingsResponse)
56+
var sslSettingsDTO SSLSettingsDTO
57+
err = json.Unmarshal([]byte(responseBody), &sslSettingsDTO)
6958
if err != nil {
7059
return nil, fmt.Errorf("Error parsing Incap Site settings JSON response for Site ID %d: %s\nresponse: %s", siteID, err, string(responseBody))
7160
}
7261

73-
return &sslSettingsResponse, nil
62+
return &sslSettingsDTO, nil
7463
}
7564

76-
func (c *Client) ReadSiteSSLSettings(siteID int) (*SSLSettingsResponse, int, error) {
65+
func (c *Client) ReadSiteSSLSettings(siteID int) (*SSLSettingsDTO, int, error) {
7766
log.Printf("[INFO] Getting Incapsula Incap SSL settings for Site ID %d\n", siteID)
7867

79-
// Get form to Incapsula
80-
reqURL := fmt.Sprintf("%s/sites-mgmt/v3/sites/%d/settings/TLSConfiguration", c.config.BaseURLAPI, siteID)
68+
// Post form to Incapsula
69+
reqURL := fmt.Sprintf("%s/sites/%d/settings/TLSConfiguration", c.config.BaseURLRev3, siteID)
8170
resp, err := c.DoJsonRequestWithHeaders(http.MethodGet, reqURL, nil, ReadSiteSSLSettings)
8271
if err != nil {
8372
return nil, 0, fmt.Errorf("error from Incapsula service when reading SSL Settings for Site ID %d: %s", siteID, err)
@@ -96,11 +85,11 @@ func (c *Client) ReadSiteSSLSettings(siteID int) (*SSLSettingsResponse, int, err
9685
}
9786

9887
// Parse the JSON
99-
var sslSettingsResponse SSLSettingsResponse
100-
err = json.Unmarshal([]byte(responseBody), &sslSettingsResponse)
88+
var sslSettingsDTO SSLSettingsDTO
89+
err = json.Unmarshal([]byte(responseBody), &sslSettingsDTO)
10190
if err != nil {
10291
return nil, resp.StatusCode, fmt.Errorf("error parsing Site SSL settings JSON response for Site ID %d: %s\nresponse: %s", siteID, err, string(responseBody))
10392
}
10493

105-
return &sslSettingsResponse, resp.StatusCode, nil
94+
return &sslSettingsDTO, resp.StatusCode, nil
10695
}

incapsula/client_site_ssl_settings_test.go

Lines changed: 13 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
func TestUpdateSiteSSLSettingsHandleBadConnection(t *testing.T) {
1313
// arrange
14-
config := &Config{APIID: "foo", APIKey: "bar", BaseURLRev3: "badness.incapsula.com", BaseURLAPI: "badness.incapsula.com"}
14+
config := &Config{APIID: "foo", APIKey: "bar", BaseURLRev3: "badness.incapsula.com"}
1515
client := &Client{config: config, httpClient: &http.Client{Timeout: time.Millisecond * 1}}
1616
sslSettingsDTO := getUpdateSiteSSLSettingsDTO()
1717

@@ -34,7 +34,7 @@ func TestUpdateSiteSSLSettingsHandleResponseCodeNotSuccess(t *testing.T) {
3434
apiKey := "bar"
3535
siteID := 42
3636

37-
endpoint := fmt.Sprintf("/sites-mgmt/v3/sites/%d/settings/TLSConfiguration", siteID)
37+
endpoint := fmt.Sprintf("/sites/%d/settings/TLSConfiguration", siteID)
3838

3939
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
4040
rw.WriteHeader(406)
@@ -71,7 +71,7 @@ func TestUpdateSiteSSLSettingsHandleInvalidResponseBody(t *testing.T) {
7171
apiKey := "bar"
7272
siteID := 42
7373

74-
endpoint := fmt.Sprintf("/sites-mgmt/v3/sites/%d/settings/TLSConfiguration", siteID)
74+
endpoint := fmt.Sprintf("/sites/%d/settings/TLSConfiguration", siteID)
7575
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
7676
rw.WriteHeader(200)
7777

@@ -110,7 +110,7 @@ func TestUpdateSiteSSLSettingsSuccess(t *testing.T) {
110110

111111
validResponse := getValidJSONResponse()
112112

113-
endpoint := fmt.Sprintf("/sites-mgmt/v3/sites/%d/settings/TLSConfiguration", siteID)
113+
endpoint := fmt.Sprintf("/sites/%d/settings/TLSConfiguration", siteID)
114114
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
115115
rw.WriteHeader(200)
116116

@@ -163,7 +163,7 @@ func TestReadSiteSSLSettingsHandleResponseCodeNotSuccess(t *testing.T) {
163163
apiKey := "bar"
164164
siteID := 42
165165

166-
endpoint := fmt.Sprintf("/sites-mgmt/v3/sites/%d/settings/TLSConfiguration", siteID)
166+
endpoint := fmt.Sprintf("/sites/%d/settings/TLSConfiguration", siteID)
167167

168168
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
169169
rw.WriteHeader(406)
@@ -199,7 +199,7 @@ func TestReadSiteSSLSettingsHandleInvalidResponseBody(t *testing.T) {
199199
apiKey := "bar"
200200
siteID := 42
201201

202-
endpoint := fmt.Sprintf("/sites-mgmt/v3/sites/%d/settings/TLSConfiguration", siteID)
202+
endpoint := fmt.Sprintf("/sites/%d/settings/TLSConfiguration", siteID)
203203
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
204204
rw.WriteHeader(200)
205205

@@ -237,7 +237,7 @@ func TestReadSiteSSLSettingsSuccess(t *testing.T) {
237237

238238
var validResponse = getValidJSONResponse()
239239

240-
endpoint := fmt.Sprintf("/sites-mgmt/v3/sites/%d/settings/TLSConfiguration", siteID)
240+
endpoint := fmt.Sprintf("/sites/%d/settings/TLSConfiguration", siteID)
241241
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
242242
rw.WriteHeader(200)
243243

@@ -265,40 +265,20 @@ func TestReadSiteSSLSettingsSuccess(t *testing.T) {
265265
}
266266
}
267267

268-
func getUpdateSiteSSLSettingsDTO() SSLSettingsResponse {
269-
var sslSettingsDTO = SSLSettingsResponse{
270-
Data: []SSLSettingsDTO{
268+
func getUpdateSiteSSLSettingsDTO() SSLSettingsDTO {
269+
var sslSettingsDTO = SSLSettingsDTO{
270+
Data: []Data{
271271
{
272272
HstsConfiguration: HSTSConfiguration{
273273
PreLoaded: true,
274274
MaxAge: 1237,
275275
SubDomainsIncluded: true,
276276
IsEnabled: true,
277277
},
278-
InboundTLSSettingsConfiguration: &InboundTLSSettingsConfiguration{
279-
ConfigurationProfile: "CUSTOM",
280-
TLSConfigurations: []TLSConfiguration{
281-
{
282-
TLSVersion: "TLS 1.1",
283-
CiphersSupport: []string{
284-
"TLS_AES_128_GCM_SHA256",
285-
"TLS_AES_128_GCM_SHA256",
286-
},
287-
},
288-
{
289-
TLSVersion: "TLS 1.2",
290-
CiphersSupport: []string{
291-
"TLS_AES_128_GCM_SHA256",
292-
"TLS_AES_128_GCM_SHA256",
293-
},
294-
},
295-
},
296-
},
297278
// add more setting types here
298279
},
299280
},
300281
}
301-
302282
return sslSettingsDTO
303283
}
304284

@@ -315,29 +295,17 @@ func getClientTestConfig(apiID string, apiKey string, server *httptest.Server) *
315295
}
316296

317297
func getValidJSONResponse() string {
318-
var validResponse = `{
298+
var invalidResponse = `{
319299
"data":[
320300
{
321301
"hstsConfiguration":{
322302
"isEnabled":true,
323303
"maxAge":31536000,
324304
"subDomainsIncluded":true,
325305
"preLoaded":false
326-
},
327-
"inboundTlsSettings": {
328-
"configurationProfile": "CUSTOM",
329-
"tlsConfiguration": [
330-
{
331-
"tlsVersion": "TLS 1.1",
332-
"ciphersSupport": [
333-
"TLS_AES_128_GCM_SHA256",
334-
"TLS_AES_128_GCM_SHA256"
335-
]
336-
}
337-
]
338-
}
306+
}
339307
}
340308
]
341309
}`
342-
return validResponse
310+
return invalidResponse
343311
}

0 commit comments

Comments
 (0)