5.4. connect

Easy all-in-one connection handler.

class axonius_api_client.connect.Connect(url, key, secret, wraperror=True, timeout_connect=5, timeout_response=900, certpath=None, certverify=False, certwarn=True, cert_client_key=None, cert_client_cert=None, cert_client_both=None, proxy=None, save_history=False, log_request_attrs=None, log_response_attrs=None, log_request_body=False, log_response_body=False, log_logger=<Logger axonius_api_client (DEBUG)>, log_level_package='debug', log_level_http='debug', log_level_auth='debug', log_level_api='debug', log_level_console='debug', log_level_file='debug', log_console=False, log_file=False, log_file_name='axonius_api_client.log', log_file_path='/home/docs/checkouts/readthedocs.org/user_builds/axonius-api-client/checkouts/develop/docs', log_file_max_mb=5, log_file_max_files=5)[source]

Bases: object

Easy all-in-one connection handler.

REASON_RES = [re.compile('.*?object at.*?\\>\\: ([a-zA-Z0-9\\]\\[: ]+)'), re.compile('.*?\\] (.*) ')]

patterns to look for in exceptions that we can pretty up for user display.

Type:list of patterns`
__init__(url, key, secret, wraperror=True, timeout_connect=5, timeout_response=900, certpath=None, certverify=False, certwarn=True, cert_client_key=None, cert_client_cert=None, cert_client_both=None, proxy=None, save_history=False, log_request_attrs=None, log_response_attrs=None, log_request_body=False, log_response_body=False, log_logger=<Logger axonius_api_client (DEBUG)>, log_level_package='debug', log_level_http='debug', log_level_auth='debug', log_level_api='debug', log_level_console='debug', log_level_file='debug', log_console=False, log_file=False, log_file_name='axonius_api_client.log', log_file_path='/home/docs/checkouts/readthedocs.org/user_builds/axonius-api-client/checkouts/develop/docs', log_file_max_mb=5, log_file_max_files=5)[source]

Easy all-in-one connection handler.

Parameters:
  • url (str) – URL, hostname, or IP address of Axonius instance
  • key (str) – API Key from account page in Axonius instance
  • secret (str) – API Secret from account page in Axonius instance
  • timeout_connect (int, optional) – default TIMEOUT_CONNECT - seconds to wait for connections to open to url
  • timeout_response (int, optional) – default TIMEOUT_RESPONSE - seconds to wait for responses from url
  • wraperror (bool, optional) –

    default True

    • if True wrap exceptions so that they are more user friendly
    • if False print the original exception with the full traceback
  • certpath (str, optional) – default None - path to CA bundle file to use when verifing certs offered by url instead of the system CA bundle
  • certverify (bool, optional) –

    default False - control validation of certs offered by url:

    • if True raise exception if cert is invalid/self-signed
    • if False only raise exception if cert is invalid
  • certwarn (bool, optional) –

    default True - show warnings from requests about certs offered by url that are self signed:

    • if True show warning only the first time it happens
    • if False never show warning
    • if None show warning every time it happens
  • cert_client_key (str, optional) – default None - path to private key file for cert_client_cert to offer to url (must also supply cert_client_cert)
  • cert_client_cert (str, optional) – default None - path to cert file to offer to url (must also supply cert_client_key)
  • cert_client_both (str, optional) – default None - path to cert file containing both the private key and cert to offer to url
  • proxy (str, optional) – default None - proxy to use when making https requests to url
  • save_history (bool, optional) –

    default True -

  • log_request_attrs (bool) –

    default None - control logging of request attributes:

    • if True, log request attributes defined in axonius_api_client.LOG_REQUEST_ATTRS_VERBOSE
    • if False, log request attributes defined in axonius_api_client.LOG_REQUEST_ATTRS_BRIEF
    • if None, do not log any request attributes
  • log_response_attrs (bool) –

    default None - control logging of response attributes:

    • if True, log response attributes defined in axonius_api_client.LOG_RESPONSE_ATTRS_VERBOSE
    • if False, log response attributes defined in axonius_api_client.LOG_RESPONSE_ATTRS_BRIEF
    • if None, do not log any response attributes
  • log_request_body (bool) –

    default False - control logging of request bodies:

    • if True, log request bodies
    • if False, do not log request bodies
  • log_response_body (bool) –

    default False - control logging of response bodies:

    • if True, log response bodies
    • if False, do not log response bodies
  • log_logger (logging.Logger, optional) – default axonius_api_client.LOG logger to use as package root logger
  • log_level_package (str, optional) – default axonius_api_client.LOG_LEVEL_PACKAGE log level to use for log_logger
  • log_level_http (str, optional) – default axonius_api_client.LOG_LEVEL_HTTP log level to use for axonius_api_client.http.Http
  • log_level_auth (str, optional) – default axonius_api_client.LOG_LEVEL_AUTH log level to use for all subclasses of axonius_api_client.auth.Mixins
  • log_level_api (str, optional) – default axonius_api_client.LOG_LEVEL_API log level to use for all subclasses of axonius_api_client.mixins.Mixins
  • log_level_console (str, optional) – default axonius_api_client.LOG_LEVEL_CONSOLE log level to use for logs sent to console
  • log_level_file (str, optional) – default axonius_api_client.LOG_LEVEL_FILE log level to use for logs sent to file
  • log_console (bool, optional) –

    default False -

    • if True, enable logging to console
    • if False, do not log to console
  • log_file (bool, optional) –

    default False -

    • if True, enable logging to file
    • if False, do not log to console
  • log_file_name (str, optional) – default axonius_api_client.LOG_FILE_NAME name of file to write logs to under log_file_path
  • log_file_path (str, optional) – default axonius_api_client.LOG_FILE_PATH path to write log_file_name to
  • log_file_max_mb (str, optional) – default axonius_api_client.LOG_FILE_MAX_MB rollover file logs at this many MB
  • log_file_max_files (str, optional) – default axonius_api_client.LOG_FILE_MAX_FILES number of rollover file logs to keep
url = None

URL to connect to

Type:str
start()[source]

Connect to and authenticate with Axonius.

users

Get the object for user assets API.

Returns:axonius_api_client.api.assets.Users
devices

Get the object for user assets API.

Returns:axonius_api_client.assets.Devices
adapters

Get the object for adapters API.

Returns:axonius_api_client.adapters.Adapters
enforcements

Get the object for enforcements API.

Returns:axonius_api_client.enforcements.Enforcements
system

Get the object for system API.

Returns:axonius_api_client.system.System
classmethod _get_exc_reason(exc)[source]

Trim exceptions down to a more user friendly display.

Uses REASON_RES to do regex substituions.

Parameters:exc (Exception) – Exception to trim down.
Returns:prettied up str if match found, else original exception str
Return type:str