@@ -63,6 +63,7 @@ type ApiClient struct {
63
63
timeout time.Duration
64
64
sleep time.Duration
65
65
userAgent string
66
+ cloudMgmtId string
66
67
}
67
68
68
69
// Api Client constructor
@@ -95,6 +96,10 @@ func APIClient(apiCA ApiClientArgs) *ApiClient {
95
96
apiCA .Sleep = SleepTime
96
97
}
97
98
99
+ if apiCA .UserAgent == "" {
100
+ apiCA .UserAgent = "golang-api-wrapper"
101
+ }
102
+
98
103
return & ApiClient {
99
104
port : apiCA .Port ,
100
105
isPortDefault_ : isPortDefault ,
@@ -115,6 +120,7 @@ func APIClient(apiCA ApiClientArgs) *ApiClient {
115
120
timeout : apiCA .Timeout ,
116
121
sleep : apiCA .Sleep ,
117
122
userAgent : apiCA .UserAgent ,
123
+ cloudMgmtId : apiCA .CloudMgmtId ,
118
124
}
119
125
}
120
126
@@ -254,7 +260,9 @@ func (c *ApiClient) commonLoginLogic(credentials map[string]interface{}, continu
254
260
if loginRes .Success {
255
261
c .sid = loginRes .data ["sid" ].(string )
256
262
c .domain = domain
257
- c .apiVersion = loginRes .data ["api-server-version" ].(string )
263
+ if c .apiVersion == "" {
264
+ c .apiVersion = loginRes .data ["api-server-version" ].(string )
265
+ }
258
266
}
259
267
260
268
return loginRes , nil
@@ -285,7 +293,7 @@ func (c *ApiClient) ApiCall(command string, payload map[string]interface{}, sid
285
293
c .fingerprint = fp
286
294
fpAuthentication , err := c .CheckFingerprint ()
287
295
if ! fpAuthentication {
288
- return APIResponse {}, errors .New ("fingerprint Doesn 't match, someone might be trying to steal your information\n " )
296
+ return APIResponse {}, errors .New ("fingerprint doesn 't match, someone might be trying to steal your information\n " )
289
297
}
290
298
if err != nil {
291
299
return APIResponse {}, err
@@ -294,28 +302,14 @@ func (c *ApiClient) ApiCall(command string, payload map[string]interface{}, sid
294
302
if payload == nil {
295
303
payload = map [string ]interface {}{}
296
304
}
297
- if sid == "" {
298
- sid = c .sid
299
- }
300
305
301
306
_data , err := json .Marshal (payload )
302
307
if err != nil {
303
308
return APIResponse {}, err
304
309
}
305
310
306
- if c .userAgent == "" {
307
- c .userAgent = "golang-api-wrapper"
308
- }
309
-
310
- headers := map [string ]interface {}{
311
- "User-Agent" : c .userAgent ,
312
- "Accept" : "*/*" ,
313
- "Content-Type" : "application/json" ,
314
- "Content-Length" : len (_data ),
315
- }
316
-
317
- if sid != "" {
318
- headers ["X-chkp-sid" ] = sid
311
+ if sid == "" {
312
+ sid = c .sid
319
313
}
320
314
321
315
var client * Client
@@ -331,28 +325,36 @@ func (c *ApiClient) ApiCall(command string, payload map[string]interface{}, sid
331
325
}
332
326
}
333
327
334
- var url string
335
- if c .apiVersion == "" {
336
- url = "/" + c .context + "/" + command
337
- } else {
338
- url = "/" + c .context + "/" + "v" + c .apiVersion + "/" + command
328
+ url := "https://" + c .server + ":" + strconv .Itoa (c .port )
329
+
330
+ if c .cloudMgmtId != "" {
331
+ url += "/" + c .cloudMgmtId
339
332
}
340
333
334
+ url += "/" + c .context
335
+
336
+ if c .apiVersion != "" {
337
+ url += "/v" + c .apiVersion
338
+ }
339
+
340
+ url += "/" + command
341
+
341
342
client .fingerprint = c .fingerprint
342
343
343
344
client .SetDebugLevel (c .httpDebugLevel )
344
345
345
346
spotReader := bytes .NewReader (_data )
346
347
347
- req , err := http .NewRequest ("POST" , "https://" + c . server + ":" + strconv . Itoa ( c . port ) + url , spotReader )
348
+ req , err := http .NewRequest ("POST" , url , spotReader )
348
349
if err != nil {
349
350
return APIResponse {}, err
350
351
}
351
352
352
353
req .Header .Set ("Content-Type" , "application/json" )
353
- req .Header .Set ("User-Agent" , headers ["User-Agent" ].(string ))
354
+ req .Header .Set ("User-Agent" , c .userAgent )
355
+
354
356
if command != "login" {
355
- req .Header .Set ("X-chkp-sid" , c . sid )
357
+ req .Header .Set ("X-chkp-sid" , sid )
356
358
}
357
359
358
360
response , err := client .client .Do (req )
0 commit comments