Skip to content

Session

API_VERSION = '1.0.2' module-attribute

client_session Defines a global session, accessible by all classes. client_session is of type ClientSession.

log = logger.getLogger(__name__) module-attribute

API_VERSION The API version is not directly correlated with Iris version. Server has an endpoint /api/versions which should returns the API compatible versions it can handles.

ClientSession

Bases: object

Represents a client that can interacts with Iris. It is basic wrapper handling authentication and the requests to the server.

__init__(apikey, host=None, agent='iris-client', ssl_verify=True, proxy=None, timeout=120)

Version verification expects to fall into the following schema

Version(server_min_api_version) <= Version(client_api_version) <= Version(server_max_api_version)

Initialize the ClientSession. APIKey validity is verified as well as API compatibility between the client and the server. If the client does not find itself compatible, an exception is raised.

Once successfully initialized, the session become available through global var client_session.

Parameters:

Name Type Description Default
apikey

A valid API key. It can be fetched from My profile > API Key

required
host

Target IRIS server full URL eg https://iris.local:9443

None
agent

User agent to issue the requests with

'iris-client'
ssl_verify

Set or unset SSL verification

True
proxy

Proxy parameters - For future use only

None
timeout

Default timeout for requests

120

_check_api_compatibility()

Checks that the server and client can work together. The methods expects the following : Version(server_min_api_version) <= Version(client_api_version) <= Version(server_max_api_version)

If API is not compatible, an exception is raised.

Returns:

Type Description
bool

bool

_check_apikey_validity()

Checks the validity of the provided API key (emptiness, string and authorized). If the key is invalid, a ValueError exception is raised.

Returns:

Type Description
bool

bool

_pi_request(uri, type=None, data=None)

Make a request (GET or POST) and handle the errors. The authentication header is added.

Parameters:

Name Type Description Default
uri str

URI to request

required
type str

Type of the request [POST or GET]

None
data dict

dict to send if request type is POST

None

Returns:

Type Description
ApiResponse

ApiResponse object

_pi_uri(uri=None)

Wraps the provided uri around the URL.

Parameters:

Name Type Description Default
uri str

URI to request

None

Returns:

Type Description

Str - URL to request

pi_get(uri, cid=None)

Adds the CID information needed by the server when issuing GET requests and then issue the request itself.

Parameters:

Name Type Description Default
uri str

URI endpoint to request

required
cid int

Target case ID

None

Returns:

Type Description
ApiResponse

ApiResponse object

pi_post(uri, data)

Issues a POSt request with the provided data. Simple wrapper around _pi_request

Parameters:

Name Type Description Default
uri str

URI endpoint to request

required
data dict

data to be posted. Expect a dict

required

Returns:

Type Description
ApiResponse

ApiResponse object

preload_base_objects()

Preload the base objects most commonly used. This simply init the BaseObjects class, which in turns requests and build all the most common objects such as AnalysisStatus, EventCategory, EventType, etc.

For future use only


Last update: 2022-03-20
Back to top