4.2. Connection Handler¶
Easy all-in-one connection handler.
- class axonius_api_client.connect.Connect(url, key, secret, log_console=False, log_file=False, log_file_rotate=False, certpath=None, certverify=False, certwarn=True, proxy=None, headers=None, cookies=None, credentials=False, **kwargs)[source]¶
Bases:
object
Easy all-in-one connection handler for using the API client.
Examples
>>> #!/usr/bin/env python >>> # -*- coding: utf-8 -*- >>> '''Base example for setting up the API client.''' >>> import axonius_api_client as axonapi >>> >>> # get the URL, API key, API secret, & certwarn from the default ".env" file >>> client_args = axonapi.get_env_connect() >>> >>> # OR override OS env vars with the values from a custom .env file >>> # client_args = axonapi.get_env_connect(ax_env="/path/to/envfile", override=True) >>> >>> # create a client using the url, key, and secret from OS env >>> client = axonapi.Connect(**client_args) >>> >>> j = client.jdump # json dump helper >>> >>> client.start() # connect to axonius >>> >>> # client.activity_logs # get audit logs >>> # client.adapters # get adapters and update adapter settings >>> # client.adapters.cnx # CRUD for adapter connections >>> # client.dashboard # get/start/stop discovery cycles >>> # client.devices # get device assets >>> # client.devices.fields # get field schemas for device assets >>> # client.devices.labels # add/remove/get tags for device assets >>> # client.devices.saved_queries # CRUD for saved queries for device assets >>> # client.enforcements # CRUD for enforcements >>> # client.instances # get instances and instance meta data >>> # client.meta # get product meta data >>> # client.remote_support # enable/disable remote support settings >>> # client.settings_global # get/update global system settings >>> # client.settings_gui # get/update gui system settings >>> # client.settings_ip # get/update identity provider system settings >>> # client.settings_lifecycle # get/update lifecycle system settings >>> # client.signup # perform initial signup and use password reset tokens >>> # client.system_roles # CRUD for system roles >>> # client.system_users # CRUD for system users >>> # client.users # get user assets >>> # client.users.fields # get field schemas for user assets >>> # client.users.labels # add/remove/get tags for user assets >>> # client.users.saved_queries # CRUD for saved queries for user assets
- Parameters
url (
str
) –key (
str
) –secret (
str
) –log_console (
bool
) –log_file (
bool
) –log_file_rotate (
bool
) –certpath (
typing.Union
[str
,pathlib.Path
,None
]) –certverify (
bool
) –certwarn (
bool
) –proxy (
typing.Optional
[str
]) –headers (
typing.Union
[dict
,requests.structures.CaseInsensitiveDict
,None
]) –cookies (
typing.Union
[dict
,requests.cookies.RequestsCookieJar
,None
]) –credentials (
bool
) –
- __init__(url, key, secret, log_console=False, log_file=False, log_file_rotate=False, certpath=None, certverify=False, certwarn=True, proxy=None, headers=None, cookies=None, credentials=False, **kwargs)[source]¶
Easy all-in-one connection handler.
- Parameters
url (
str
) – URL, hostname, or IP address of Axonius instancekey (
str
) – API Key from account page in Axonius instancesecret (
str
) – API Secret from account page in Axonius instancelog_console (
bool
) – enable logging to consolelog_file (
bool
) – enable logging to filecertpath (
typing.Union
[str
,pathlib.Path
,None
]) – path to CA bundle file to use when verifying certs offered byurl
certverify (
bool
) – raise exception if cert is self-signed or only if cert is invalidcertwarn (
bool
) – show insecure warning once or never show insecure warningproxy (
typing.Optional
[str
]) – proxy to use when making https requests tourl
headers (
typing.Union
[dict
,requests.structures.CaseInsensitiveDict
,None
]) – additional headers to supply with every requestcookies (
typing.Union
[dict
,requests.cookies.RequestsCookieJar
,None
]) – additional cookies to supply with every request**kwargs – documented as properties
log_file_rotate (
bool
) –credentials (
bool
) –
-
CERT_CLIENT_KEY:
typing.Union
[str
,pathlib.Path
,None
]¶ Private key file for cert_client_cert
kwargs=cert_client_key
-
CERT_CLIENT_CERT:
typing.Union
[str
,pathlib.Path
,None
]¶ cert file to offer to
url
kwargs=cert_client_cert
-
CERT_CLIENT_BOTH:
typing.Union
[str
,pathlib.Path
,None
]¶ cert file with both private key and cert to offer to
url
kwargs=cert_client_both
-
SAVE_HISTORY:
bool
¶ append responses to
axonius_api_client.http.Http.HISTORY
kwargs=save_history
-
LOG_LEVEL:
typing.Union
[str
,int
]¶ log level for this class
kwargs=log_level
-
LOG_REQUEST_ATTRS:
typing.Optional
[typing.List
[str
]]¶ request attrs to log
axonius_api_client.constants.logs.REQUEST_ATTR_MAP
kwargs=log_request_attrs
-
LOG_RESPONSE_ATTRS:
typing.Optional
[typing.List
[str
]]¶ response attrs to log
axonius_api_client.constants.logs.RESPONSE_ATTR_MAP
kwargs=log_response_attrs
-
LOG_LOGGER:
logging.Logger
¶ logger to use as package root logger
kwargs=log_logger
-
LOG_LEVEL_PACKAGE:
typing.Union
[str
,int
]¶ log level for entire package
kwargs=log_level_package
-
LOG_LEVEL_ENDPOINTS:
typing.Union
[str
,int
]¶ log level for entire package
kwargs=log_level_package
-
LOG_LEVEL_HTTP:
typing.Union
[str
,int
]¶ log level for
axonius_api_client.http.Http
kwargs=log_level_http
-
LOG_LEVEL_AUTH:
typing.Union
[str
,int
]¶ log level for
axonius_api_client.auth.models.Mixins
kwargs=log_level_auth
-
LOG_LEVEL_API:
typing.Union
[str
,int
]¶ log level for
axonius_api_client.api.mixins.ModelMixins
kwargs=log_level_api
-
LOG_LEVEL_CONSOLE:
typing.Union
[str
,int
]¶ log level for logs sent to console
kwargs=log_level_console
-
LOG_LEVEL_FILE:
typing.Union
[str
,int
]¶ log level for logs sent to file
kwargs=log_level_file
-
LOG_FILE_NAME:
typing.Union
[str
,pathlib.Path
]¶ name of file to write logs to under
LOG_FILE_PATH
kwargs=log_file_name
-
LOG_FILE_PATH:
typing.Union
[str
,pathlib.Path
]¶ path to write
LOG_FILE_NAME
tokwargs=log_file_path
-
LOG:
logging.Logger
¶ logger object to use
-
HANDLER_CON:
logging.StreamHandler
¶ console logging handler
-
HANDLER_FILE:
logging.handlers.RotatingFileHandler
¶ file logging handler
- HTTP¶
axonius_api_client.http.Http
client to use forAUTH
- AUTH¶
ApiKey
auth method to use for all API models
- SIGNUP¶
Easy access to signup.
- property activity_logs: ActivityLogs¶
Work with activity logs.
- property remote_support: RemoteSupport¶
Work with configuring remote support.
- property dashboard_spaces: DashboardSpaces¶
Work with dashboard spaces.
- property enforcements: Enforcements¶
Work with Enforcement Center.
- property system_users: SystemUsers¶
Work with system users.
- property system_roles: SystemRoles¶
Work with system roles.
- property settings_ip: SettingsIdentityProviders¶
Work with identity providers settings.
- property settings_global: SettingsGlobal¶
Work with core system settings.
- property settings_gui: SettingsGui¶
Work with gui system settings.
- property settings_lifecycle: SettingsLifecycle¶
Work with lifecycle system settings.
- property openapi: OpenAPISpec¶
Work with the OpenAPI specification file.
- property data_scopes: DataScopes¶
Work with data scopes.
- property folders: Folders¶
Work with data scopes.
- classmethod _get_exc_reason(exc)[source]¶
Trim exceptions down to a more user friendly display.
Uses
REASON_RES
to do regex substituions.
-
REASON_RES:
typing.List
[str
] = [re.compile('.*?object at.*?\\>\\: ([a-zA-Z0-9\\]\\[: ]+)'), re.compile('.*?\\] (.*) ')]¶ patterns to look for in exceptions that we can pretty up for user display.