4.7.5.5. Setup environment variables

Tools for getting OS env vars.

axonius_api_client.setup_env.LOGGER = <Logger axonius_api_client.setup_env (DEBUG)>

Logger to use

axonius_api_client.setup_env.YES: List[str] = ['1', 'true', 't', 'yes', 'y', 'on']

Values that should be considered as truthy

axonius_api_client.setup_env.NO: List[str] = ['0', 'false', 'f', 'no', 'n', 'off']

Values that should be considered as falsey

axonius_api_client.setup_env.KEY_PRE: str = 'AX_'

Prefix for axonapi related OS env vars

axonius_api_client.setup_env.KEY_DEFAULT_PATH: str = 'AX_PATH'

OS env to use for DEFAULT_PATH instead of CWD

axonius_api_client.setup_env.KEY_ENV_FILE: str = 'AX_ENV_FILE'

OS env to use for .env file name

axonius_api_client.setup_env.KEY_ENV_PATH: str = 'AX_ENV'

OS env to use for path to ‘.env’ file

axonius_api_client.setup_env.KEY_OVERRIDE: str = 'AX_ENV_OVERRIDE'

OS env to control ignoring OS env when loading .env file

axonius_api_client.setup_env.KEY_URL: str = 'AX_URL'

OS env to get API URL from

axonius_api_client.setup_env.KEY_KEY: str = 'AX_KEY'

OS env to get API key from

axonius_api_client.setup_env.KEY_SECRET: str = 'AX_SECRET'

OS env to get API secret from

axonius_api_client.setup_env.KEY_CERTWARN: str = 'AX_CERTWARN'

OS env to get cert warning bool from

axonius_api_client.setup_env.KEY_DEBUG: str = 'AX_DEBUG'

OS env to enable debug logging

axonius_api_client.setup_env.KEY_DEBUG_PRINT: str = 'AX_DEBUG_PRINT'

OS env to use print() instead of LOGGER.debug()

axonius_api_client.setup_env.DEFAULT_DEBUG: str = 'no'

Default for KEY_DEBUG

axonius_api_client.setup_env.DEFAULT_DEBUG_PRINT: str = 'no'

Default for KEY_DEBUG_PRINT

axonius_api_client.setup_env.DEFAULT_OVERRIDE: str = 'yes'

Default for KEY_OVERRIDE

axonius_api_client.setup_env.DEFAULT_CERTWARN: str = 'yes'

Default for KEY_CERTWARN

axonius_api_client.setup_env.DEFAULT_ENV_FILE: str = '.env'

Default for KEY_ENV_FILE

axonius_api_client.setup_env.KEYS_HIDDEN: List[str] = ['AX_KEY', 'AX_SECRET']

List of keys to hide in get_env_ax()

axonius_api_client.setup_env.HIDDEN: str = '_HIDDEN_'

Value to use for hidden keys in get_env_ax()

axonius_api_client.setup_env.find_dotenv(ax_env=None, default='/home/docs/checkouts/readthedocs.org/user_builds/axonius-api-client/checkouts/develop/docs')[source]

Find a .env file.

Parameters

Notes

Order of operations:

  • Check for ax_env for .env (or dir with .env in it)

  • Check for OS env var KEY_ENV_PATH for .env (or dir with .env in it)

  • Check for OS env var KEY_DEFAULT_PATH as dir with .env in it

  • use dotenv.find_dotenv() to walk tree from CWD

  • use dotenv.find_dotenv() to walk tree from package root

Return type

typing.Tuple[str, str]

axonius_api_client.setup_env.load_dotenv(ax_env=None, **kwargs)[source]

Load a ‘.env’ file as environment variables accessible to this package.

Parameters
  • ax_env (typing.Union[str, pathlib.Path, None]) – path to .env file to load, if directory will look for ‘.env’ in that directory

  • **kwargs – passed to dotenv.load_dotenv()

Return type

str

axonius_api_client.setup_env.get_env_bool(key, default=None)[source]

Get an OS env var and turn convert it to a boolean.

Parameters
Raises

ValueError – OS env var value is not able to be converted to bool

Return type

bool

axonius_api_client.setup_env.get_env_str(key, default=None, empty_ok=False, lower=False)[source]

Get an OS env var.

Parameters
  • key (str) – OS env key

  • default (typing.Optional[str]) – default to use if not found

  • lower (bool) – lowercase the value

  • empty_ok (bool) –

Raises

ValueError – OS env var value is empty and empty_ok is False

Return type

str

axonius_api_client.setup_env.get_env_path(key, default=None, get_dir=True)[source]

Get a path from an OS env var.

Parameters
  • key (str) – OS env var to get path from

  • default (typing.Optional[str]) – default path to use if OS env var not set

  • get_dir (bool) – return directory containing file of path is file

Return type

typing.Union[pathlib.Path, str]

axonius_api_client.setup_env.get_env_connect(**kwargs)[source]

Get URL, API key, API secret, and certwarn from OS env vars.

Parameters

**kwargs – passed to load_dotenv()

Return type

dict

axonius_api_client.setup_env.get_env_ax()[source]

Get all axonapi related OS env vars.

axonius_api_client.setup_env.DEBUG_PRINT: bool = False

Use print() instead of LOGGER.debug().

axonius_api_client.setup_env.DEBUG_USE(msg, *args, **kwargs)

use print or LOGGER.debug()

axonius_api_client.setup_env.DEBUG: bool = False

Enable package wide debugging.

axonius_api_client.setup_env.DEBUG_LOG(x)

Function to use for debug logging

axonius_api_client.setup_env.DEFAULT_PATH: str = '/home/docs/checkouts/readthedocs.org/user_builds/axonius-api-client/checkouts/develop/docs'

Default path to use throughout this package