5.4. connect

Easy all-in-one connection handler.

class axonius_api_client.connect.Connect(url: str, key: str, secret: str, wraperror: bool = True, timeout_connect: int = 5, timeout_response: int = 900, certpath: Union[str, pathlib.Path, None] = None, certverify: bool = False, certwarn: bool = True, cert_client_key: Union[str, pathlib.Path, None] = None, cert_client_cert: Union[str, pathlib.Path, None] = None, cert_client_both: Union[str, pathlib.Path, None] = None, proxy: Optional[str] = None, save_history: bool = False, log_level: Union[str, int] = 'debug', log_request_attrs: Optional[List[str]] = None, log_response_attrs: Optional[List[str]] = None, log_request_body: bool = False, log_response_body: bool = False, log_logger: logging.Logger = <Logger axonius_api_client (DEBUG)>, log_level_package: Union[str, int] = 'debug', log_level_http: Union[str, int] = 'debug', log_level_auth: Union[str, int] = 'debug', log_level_api: Union[str, int] = 'debug', log_level_console: Union[str, int] = 'debug', log_level_file: Union[str, int] = 'debug', log_console: bool = False, log_file: bool = False, log_file_name: Union[str, pathlib.Path] = 'axonius_api_client.log', log_file_path: Union[str, pathlib.Path] = '/home/docs/checkouts/readthedocs.org/user_builds/axonius-api-client/checkouts/develop/docs', log_file_max_mb: int = 5, log_file_max_files: int = 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: str, key: str, secret: str, wraperror: bool = True, timeout_connect: int = 5, timeout_response: int = 900, certpath: Union[str, pathlib.Path, None] = None, certverify: bool = False, certwarn: bool = True, cert_client_key: Union[str, pathlib.Path, None] = None, cert_client_cert: Union[str, pathlib.Path, None] = None, cert_client_both: Union[str, pathlib.Path, None] = None, proxy: Optional[str] = None, save_history: bool = False, log_level: Union[str, int] = 'debug', log_request_attrs: Optional[List[str]] = None, log_response_attrs: Optional[List[str]] = None, log_request_body: bool = False, log_response_body: bool = False, log_logger: logging.Logger = <Logger axonius_api_client (DEBUG)>, log_level_package: Union[str, int] = 'debug', log_level_http: Union[str, int] = 'debug', log_level_auth: Union[str, int] = 'debug', log_level_api: Union[str, int] = 'debug', log_level_console: Union[str, int] = 'debug', log_level_file: Union[str, int] = 'debug', log_console: bool = False, log_file: bool = False, log_file_name: Union[str, pathlib.Path] = 'axonius_api_client.log', log_file_path: Union[str, pathlib.Path] = '/home/docs/checkouts/readthedocs.org/user_builds/axonius-api-client/checkouts/develop/docs', log_file_max_mb: int = 5, log_file_max_files: int = 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
run_actions

Get the object for run actions API.

Returns:axonius_api_client.actions.RunAction
system

Get the object for system API.

Returns:axonius_api_client.system.System
classmethod _get_exc_reason(exc: Exception) → str[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