api_go_sdk

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 26, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InProgress           string        = "in progress"
	DefaultPort          int           = 443
	Limit                int           = 50
	Filename             string        = "fingerprints.json"
	TimeOut              time.Duration = time.Second * 10
	SleepTime            time.Duration = time.Second * 2
	GaiaContext          string        = "gaia_api"
	WebContext           string        = "web_api"
	DefaultProxyPort                   = -1
	DefaultProxyHost                   = ""
	AutoPublishBatchSize int           = 100
)
View Source
const OkResponseCode string = "200 OK"

Variables

This section is empty.

Functions

This section is empty.

Types

type APIResponse

type APIResponse struct {
	StatusCode string

	Success  bool
	ErrorMsg string
	// contains filtered or unexported fields
}

API Response struct represent http response (Created from httpResponse struct)

func (*APIResponse) GetData

func (r *APIResponse) GetData() map[string]interface{}

Get response data (payload)

func (*APIResponse) GetResTmp

func (r *APIResponse) GetResTmp() map[string]interface{}

Get response data (payload)

type ApiClient

type ApiClient struct {
	// contains filtered or unexported fields
}

Check Point API Client (Management/GAIA)

func APIClient

func APIClient(apiCA ApiClientArgs) *ApiClient

Api Client constructor Input ApiClientArgs Returns new client instance

func (*ApiClient) ApiCall

func (c *ApiClient) ApiCall(command string, payload map[string]interface{}, sid string, waitForTask bool, useProxy bool, method ...string) (APIResponse, error)

Performs a web-service API request to the management server

command: the command is placed in the URL field payload: a JSON object (or a string representing a JSON object) with the command arguments sid: The Check Point session-id. when omitted use self.sid. waitForTask: determines the behavior when the API server responds with a "task-id".

by default, the function will periodically check the status of the task
and will not return until the task is completed.
when wait_for_task=False, it is up to the user to call the "show-task" API and check
the status of the command.

useProxy: Determines if the user wants to use the proxy server and port provider. method: HTTP request method - POST by default return: APIResponse object side-effects: updates the class's uid and server variables

func (*ApiClient) ApiCallSimple

func (c *ApiClient) ApiCallSimple(command string, payload map[string]interface{}) (APIResponse, error)

func (*ApiClient) ApiLogin

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

Performs a 'login' API call to management server

username: Check Point admin name password: Check Point admin password continue_last_session: [optional] It is possible to continue the last Check Point session or to create a new one domain: [optional] The name, UID or IP-Address of the domain to login. read_only: [optional] Login with Read Only permissions. This parameter is not considered in case continue-last-session is true. payload: [optional] More settings for the login command returns: APIResponse, error side-effects: updates the class's uid and server variables

func (*ApiClient) ApiLoginWithApiKey

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

performs a 'login' API call to the management server

api_key: Check Point api-key continue_last_session: [optional] It is possible to continue the last Check Point session or to create a new one domain: [optional] The name, UID or IP-Address of the domain to login. read_only: [optional] Login with Read Only permissions. This parameter is not considered in case continue-last-session is true. payload: [optional] More settings for the login command returns: APIResponse object side-effects: updates the class's uid and server variables

func (*ApiClient) ApiQuery

func (c *ApiClient) ApiQuery(command string, detailsLevel string, containerKey string, includeContainerKey bool, payload map[string]interface{}) (APIResponse, error)

* The APIs that return a list of objects are limited by the number of objects that they return. To get the full list of objects, there's a need to make repeated API calls each time using a different offset until all the objects are returned. This API makes such repeated API calls and return the full list objects. note: this function calls gen_api_query and iterates over the generator until it gets all the objects, then returns.

command: name of API command. This command should be an API that returns an array of

objects (for example: show-hosts, show networks, ...)

details_level: query APIs always take a details-level argument.

possible values are "standard", "full", "uid"

container_key: name of the key that holds the objects in the JSON response (usually "objects"). include_container_key: If set to False the 'data' field of the APIResponse object

will be a list of the wanted objects. Otherwise, the date field of the APIResponse will be a dictionary in the following

format: { container_key: [ List of the wanted objects], "total": size of the list} payload: a JSON object (or a string representing a JSON object) with the command arguments return: if include-container-key is False:

an APIResponse object whose .data member contains a list of the objects requested: [ , , , ...]
if include-container-key is True:
an APIResponse object whose .data member contains a dict: { container_key: [...], "total": n }

func (*ApiClient) CheckFingerprint

func (c *ApiClient) CheckFingerprint() (bool, error)

* This function checks if the server's certificate is stored in the local fingerprints file. If the server's fingerprint is not found, an HTTPS connection is made to the server and the user is asked if he or she accepts the server's fingerprint. If the fingerprint is trusted, it is stored in the fingerprint file.

return: False if the user does not accept the server certificate, True in all other cases.

func (*ApiClient) DisableAutoPublish

func (c *ApiClient) DisableAutoPublish()

func (*ApiClient) GetAutoPublishBatchSize

func (c *ApiClient) GetAutoPublishBatchSize() int

Returns number of batch size

func (*ApiClient) GetContext

func (c *ApiClient) GetContext() string

Returns the context of API client

func (*ApiClient) GetPort

func (c *ApiClient) GetPort() int

Returns the port of API client

func (*ApiClient) GetSessionID

func (c *ApiClient) GetSessionID() string

Returns session id

func (*ApiClient) IsPortDefault

func (c *ApiClient) IsPortDefault() bool

Returns true if API port is set to default

func (*ApiClient) IsProxyUsed

func (c *ApiClient) IsProxyUsed() bool

Returns true if client use proxy

func (*ApiClient) Login deprecated

func (c *ApiClient) Login(username string, password string, continueLastSession bool, domain string, readOnly bool, payload string) (APIResponse, error)

Deprecated: Do not use.

func (*ApiClient) LoginWithApiKey deprecated

func (c *ApiClient) LoginWithApiKey(apiKey string, continueLastSession bool, domain string, readOnly bool, payload string) (APIResponse, error)

Deprecated: Do not use.

func (*ApiClient) ResetTotalCallsCounter

func (c *ApiClient) ResetTotalCallsCounter()

func (*ApiClient) SetAutoPublishBatchSize

func (c *ApiClient) SetAutoPublishBatchSize(autoPublishBatchSize int)

func (*ApiClient) SetPort

func (c *ApiClient) SetPort(portToSet int)

Set API port

func (*ApiClient) SetSleepTime

func (c *ApiClient) SetSleepTime(sleepTime time.Duration)

Set API sleep time

func (*ApiClient) SetTimeout

func (c *ApiClient) SetTimeout(timeout time.Duration)

Set API client timeout

type ApiClientArgs

type ApiClientArgs struct {
	Port                    int
	Fingerprint             string
	Sid                     string
	Server                  string
	HttpDebugLevel          string
	ProxyHost               string
	ProxyPort               int
	ApiVersion              string
	IgnoreServerCertificate bool
	AcceptServerCertificate bool
	DebugFile               string
	Context                 string
	Timeout                 time.Duration
	Sleep                   time.Duration
	UserAgent               string
	CloudMgmtId             string
	AutoPublishBatchSize    int
}

Api Client arguments to init a new instance

func APIClientArgs

func APIClientArgs(port int, fingerprint string, sid string, server string, proxyHost string, proxyPort int, apiVersion string, ignoreServerCertificate bool, acceptServerCertificate bool, debugFile string, context string, timeout time.Duration, sleep time.Duration, userAgent string, cloudMgmtId string, autoPublishBatchSize int) ApiClientArgs

Init a new APIClientArgs Construct a new ApiClientArgs instance with the given parameters.

Port: the port that is being used Fingerprint: server's fingerprint Sid: session id Server: server's ip ProxyHost: proxy's ip ProxyPort: proxy port ApiVersion: the version of the api IgnoreServerCertificate: indicates that the client should not check the server's certificate AcceptServerCertificate: indicates that the client should automatically accept and save the server's certificate DebugFile: name of debug file Context: which API to use - Management API = web_api (default) or GAIA API = gaia_api Timeout: HTTP Client timeout value Sleep: Interval size in seconds of the task update UserAgent: User agent will be use in api call request header CloudMgmtId: Smart-1 Cloud management UID AutoPublishBatchSize: Number of batch size for auto publish

type Client

type Client struct {
	// contains filtered or unexported fields
}

HTTP Client wrapper

func CreateClient

func CreateClient(server string, sid string, timeout time.Duration) (*Client, error)

Init and returns new instance of HTTP client wrapper

func CreateProxyClient

func CreateProxyClient(server string, serverProxy string, sid string, portProxy int, timeout time.Duration) (*Client, error)

Init and returns new instance of HTTP proxy client

func (*Client) GetClient

func (c *Client) GetClient() *http.Client

Returns pointer to HTTP client

func (*Client) GetServer

func (c *Client) GetServer() string

Returns client server

func (*Client) SetDebugLevel

func (c *Client) SetDebugLevel(level string)

Set debug level for client

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL