Skip to content

Commit cd0fca4

Browse files
authored
Merge pull request #8 from chkp-alonshev/master
add support for login with api key, with function LoginWithApiKey()
2 parents e28526b + e4cbaec commit cd0fca4

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

APIFiles/APIClient.go

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ version 1.0
55
A library for communicating with Check Point's management server using Golang
66
written by: Check Point software technologies inc.
77
June 2019
8-
tested with Check Point R80.20 (tested with take hero2 198)
8+
tested with Check Point R81.20
99
1010
-----------------------------------------------------------------------------
1111
@@ -70,14 +70,14 @@ type ApiClient struct {
7070
// Returns new client instance
7171
func APIClient(apiCA ApiClientArgs) *ApiClient {
7272
isPortDefault := false
73-
proxyUsed := true
73+
proxyUsed := false
7474

7575
if apiCA.Port == -1 || apiCA.Port == DefaultPort {
7676
apiCA.Port = DefaultPort
7777
isPortDefault = true
7878
}
79-
if apiCA.ProxyPort == DefaultProxyPort && apiCA.ProxyHost == DefaultProxyHost {
80-
proxyUsed = false
79+
if apiCA.ProxyPort != DefaultProxyPort && apiCA.ProxyHost != DefaultProxyHost {
80+
proxyUsed = true
8181
}
8282

8383
// The context of using the client - defaults to web api
@@ -190,6 +190,30 @@ func (c *ApiClient) Login(username string, password string, continueLastSession
190190
"user": username,
191191
"password": password,
192192
}
193+
return c.commonLoginLogic(credentials, continueLastSession, domain, readOnly, payload)
194+
}
195+
196+
/*
197+
performs a 'login' API call to the management server
198+
199+
api_key: Check Point api-key
200+
continue_last_session: [optional] It is possible to continue the last Check Point session
201+
or to create a new one
202+
domain: [optional] The name, UID or IP-Address of the domain to login.
203+
read_only: [optional] Login with Read Only permissions. This parameter is not considered in case
204+
continue-last-session is true.
205+
payload: [optional] More settings for the login command
206+
returns: APIResponse object
207+
side-effects: updates the class's uid and server variables
208+
*/
209+
func (c *ApiClient) LoginWithApiKey(apiKey string, continueLastSession bool, domain string, readOnly bool, payload string) (APIResponse, error) {
210+
credentials := map[string]interface{}{
211+
"api-key": apiKey,
212+
}
213+
return c.commonLoginLogic(credentials, continueLastSession, domain, readOnly, payload)
214+
}
215+
216+
func (c *ApiClient) commonLoginLogic(credentials map[string]interface{}, continueLastSession bool, domain string, readOnly bool, payload string) (APIResponse, error) {
193217

194218
if c.context == WebContext {
195219
credentials["continue-last-session"] = continueLastSession

0 commit comments

Comments
 (0)