Skip to content

Commit

Permalink
Merge pull request #11 from chkp-alonshev/master
Browse files Browse the repository at this point in the history
add login payload support
  • Loading branch information
chkp-alonshev authored May 23, 2022
2 parents 3d5831d + 68987bd commit 3d603c9
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions APIFiles/APIClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,23 @@ func (c *ApiClient) GetSessionID() string {
return c.sid
}

// Deprecated: Do not use.
func (c *ApiClient) Login(username string, password string, continueLastSession bool, domain string, readOnly bool, payload string) (APIResponse, error) {
credentials := map[string]interface{}{
"user": username,
"password": password,
}
return c.commonLoginLogic(credentials, continueLastSession, domain, readOnly, make(map[string]interface{}))
}

// Deprecated: Do not use.
func (c *ApiClient) LoginWithApiKey(apiKey string, continueLastSession bool, domain string, readOnly bool, payload string) (APIResponse, error) {
credentials := map[string]interface{}{
"api-key": apiKey,
}
return c.commonLoginLogic(credentials, continueLastSession, domain, readOnly, make(map[string]interface{}))
}

/*
Performs a 'login' API call to management server
Expand All @@ -185,7 +202,7 @@ returns: APIResponse, error
side-effects: updates the class's uid and server variables
*/
func (c *ApiClient) Login(username string, password string, continueLastSession bool, domain string, readOnly bool, payload string) (APIResponse, error) {
func (c *ApiClient) ApiLogin(username string, password string, continueLastSession bool, domain string, readOnly bool, payload map[string]interface{}) (APIResponse, error) {
credentials := map[string]interface{}{
"user": username,
"password": password,
Expand All @@ -206,14 +223,14 @@ payload: [optional] More settings for the login command
returns: APIResponse object
side-effects: updates the class's uid and server variables
*/
func (c *ApiClient) LoginWithApiKey(apiKey string, continueLastSession bool, domain string, readOnly bool, payload string) (APIResponse, error) {
func (c *ApiClient) ApiLoginWithApiKey(apiKey string, continueLastSession bool, domain string, readOnly bool, payload map[string]interface{}) (APIResponse, error) {
credentials := map[string]interface{}{
"api-key": apiKey,
}
return c.commonLoginLogic(credentials, continueLastSession, domain, readOnly, payload)
}

func (c *ApiClient) commonLoginLogic(credentials map[string]interface{}, continueLastSession bool, domain string, readOnly bool, payload string) (APIResponse, error) {
func (c *ApiClient) commonLoginLogic(credentials map[string]interface{}, continueLastSession bool, domain string, readOnly bool, payload map[string]interface{}) (APIResponse, error) {

if c.context == WebContext {
credentials["continue-last-session"] = continueLastSession
Expand All @@ -224,6 +241,10 @@ func (c *ApiClient) commonLoginLogic(credentials map[string]interface{}, continu
credentials["domain"] = domain
}

for k, v := range payload {
credentials[k] = v
}

loginRes, errCall := c.ApiCall("login", credentials, "", false, false)
if errCall != nil {
return loginRes, errCall
Expand Down

0 comments on commit 3d603c9

Please sign in to comment.