@@ -11,7 +11,6 @@ import (
1111
1212// Endpoints (unexported consts)
1313const endpointSubAccountAdd = "subaccounts/add"
14- const endpointSubAccountList = "accounts/listSubAccounts"
1514const endpointSubAccountDelete = "subaccounts/delete"
1615const PAGE_SIZE = 50
1716
@@ -102,70 +101,6 @@ func (c *Client) AddSubAccount(subAccountPayload *SubAccountPayload) (*SubAccoun
102101 return & subAccountAddResponse , nil
103102}
104103
105- // GetSubAccount gets the Incapsula list of SubAccounts
106- func (c * Client ) GetSubAccount (parentAccountID int , subAccountID int ) (* SubAccount , error ) {
107-
108- log .Printf ("[INFO] Reading Incapsula subaccounts for id: %d" , subAccountID )
109-
110- var count = 0
111- var shouldFetch = true
112- // Pagination (default page size 50)
113- for shouldFetch {
114- log .Printf ("[DEBUG] looking for subaccount %d, fetching for page: %d" , subAccountID , count )
115- var subAccounts , error = c .sendListSubAccountsRequest (parentAccountID , count )
116- if error != nil {
117- return nil , error
118- }
119- for _ , subAccount := range subAccounts {
120- if subAccount .SubAccountID == subAccountID {
121- log .Printf ("[INFO] found subaccount : %v\n " , subAccount )
122- return & subAccount , nil
123- }
124- }
125- shouldFetch = len (subAccounts ) == PAGE_SIZE
126- count += 1
127- }
128- log .Printf ("[DEBUG] didn't find subaccount %d returning nil" , subAccountID )
129- return nil , nil
130- }
131-
132- func (c * Client ) sendListSubAccountsRequest (accountId int , pageNum int ) ([]SubAccount , error ) {
133- values := map [string ][]string {}
134-
135- if accountId != 0 {
136- values ["account_id" ] = make ([]string , 1 )
137- values ["account_id" ][0 ] = fmt .Sprint (accountId )
138- }
139- values ["page_num" ] = make ([]string , 1 )
140- values ["page_num" ][0 ] = fmt .Sprint (pageNum )
141- values ["page_size" ] = make ([]string , 1 )
142- values ["page_size" ][0 ] = fmt .Sprint (PAGE_SIZE )
143-
144- log .Printf ("[INFO] Pagination loop, page : %d)\n " , pageNum )
145-
146- // Post form to Incapsula
147- resp , err := c .PostFormWithHeaders (fmt .Sprintf ("%s/%s" , c .config .BaseURL , endpointSubAccountList ), values , ReadSubAccount )
148- if err != nil {
149- return nil , fmt .Errorf ("Error getting subaccounts for account %d: %s" , accountId , err )
150- }
151-
152- // Read the body
153- defer resp .Body .Close ()
154- responseBody , err := ioutil .ReadAll (resp .Body )
155-
156- // Dump JSON
157- log .Printf ("[DEBUG] Incapsula subaccounts JSON response: %s\n " , string (responseBody ))
158-
159- // Parse the JSON
160- var subAccountListResponse SubAccountListResponse
161- err = json .Unmarshal ([]byte (responseBody ), & subAccountListResponse )
162- if err != nil {
163- return nil , fmt .Errorf ("Error parsing subaccounts list JSON response for accountid: %d %s\n response: %s" , accountId , err , string (responseBody ))
164- }
165-
166- return subAccountListResponse .SubAccounts , nil
167- }
168-
169104// DeleteSubAccount deletes a SubAcccount currently managed by Incapsula
170105func (c * Client ) DeleteSubAccount (subAccountID int ) error {
171106 // Specifically shaded this struct, no need to share across funcs or export
0 commit comments