Skip to content

ANTA Settings

anta.settings

Settings for ANTA.

DEFAULT_HTTPX_TRUST_ENV module-attribute

DEFAULT_HTTPX_TRUST_ENV = True

Default value for the trust_env parameter of the HTTPX client.

DEFAULT_MAX_CONCURRENCY module-attribute

DEFAULT_MAX_CONCURRENCY = 50000

Default value for the maximum number of concurrent tests in the event loop.

DEFAULT_NOFILE module-attribute

DEFAULT_NOFILE = 16384

Default value for the maximum number of open file descriptors for the ANTA process.

DEFAULT_SSL_CIPHERS module-attribute

DEFAULT_SSL_CIPHERS: str | None = None

Default value for the SSL cipher list.

AntaHttpxSettings

Bases: BaseSettings

Environment variables for configuring the ANTA HTTPX client.

When initialized, relevant environment variables are loaded. If not set, default values are used.

Attributes:

Name Type Description
trust_env bool

Environment variable: ANTA_HTTPX_TRUST_ENV

Set to False to disable the use of environment variables by the HTTPX client. Defaults to True.

AntaRunnerSettings

Bases: BaseSettings

Environment variables for configuring the ANTA runner.

When initialized, relevant environment variables are loaded. If not set, default values are used.

On POSIX systems, also adjusts the process soft limit based on the ANTA_NOFILE environment variable while respecting the system hard limit, meaning the new soft limit cannot exceed the system’s hard limit.

On non-POSIX systems (Windows), sets the limit to sys.maxsize.

The adjusted limit is available with the file_descriptor_limit property after initialization.

Attributes:

Name Type Description
nofile PositiveInt

Environment variable: ANTA_NOFILE

The maximum number of open file descriptors for the ANTA process. Defaults to 16384.

max_concurrency PositiveInt

Environment variable: ANTA_MAX_CONCURRENCY

The maximum number of concurrent tests that can run in the event loop. Defaults to 50000.

file_descriptor_limit property

file_descriptor_limit: PositiveInt

The maximum number of file descriptors available to the process.

set_and_compute_file_descriptor_limit

set_and_compute_file_descriptor_limit() -> AntaRunnerSettings

Execute the system call to set the file descriptor limit and computes the effective limit.

Source code in anta/settings.py
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
@model_validator(mode="after")
def set_and_compute_file_descriptor_limit(self) -> AntaRunnerSettings:
    """Execute the system call to set the file descriptor limit and computes the effective limit."""
    calculated_limit: int

    if os.name != "posix":
        logger.warning("Running on a non-POSIX system, cannot adjust the maximum number of file descriptors.")
        calculated_limit = sys.maxsize
    else:
        import resource  # noqa: PLC0415

        limits = resource.getrlimit(resource.RLIMIT_NOFILE)
        logger.debug("Initial file descriptor limits for the current ANTA process: Soft Limit: %s | Hard Limit: %s", limits[0], limits[1])

        # Set new soft limit to minimum of requested and hard limit
        new_soft_limit = min(limits[1], self.nofile)
        logger.debug("Setting file descriptor soft limit to %s", new_soft_limit)

        try:
            resource.setrlimit(resource.RLIMIT_NOFILE, (new_soft_limit, limits[1]))
        except ValueError as exception:
            logger.warning("Failed to set file descriptor soft limit for the current ANTA process: %s", exc_to_str(exception))

        calculated_limit = resource.getrlimit(resource.RLIMIT_NOFILE)[0]

    self._file_descriptor_limit = calculated_limit
    return self

AntaSslSettings

Bases: BaseSettings

Environment variables for configuring SSL connections.

Attributes:

Name Type Description
ciphers str | None

Environment variable: ANTA_SSL_CIPHERS

OpenSSL cipher list applied to HTTPS connections. None uses the Python defaults.

get_httpx_settings cached

get_httpx_settings() -> AntaHttpxSettings

Return the cached ANTA HTTPX settings loaded from environment variables.

Returns:

Type Description
AntaHttpxSettings

The HTTPX settings instance populated from ANTA_HTTPX_* environment variables.

Raises:

Type Description
ValueError

If any ANTA_HTTPX_* environment variable has an invalid value.

Source code in anta/settings.py
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
@cache
def get_httpx_settings() -> AntaHttpxSettings:
    """Return the cached ANTA HTTPX settings loaded from environment variables.

    Returns
    -------
    AntaHttpxSettings
        The HTTPX settings instance populated from `ANTA_HTTPX_*` environment variables.

    Raises
    ------
    ValueError
        If any `ANTA_HTTPX_*` environment variable has an invalid value.
    """
    try:
        return AntaHttpxSettings()
    except ValidationError as exc:
        msg = f"Failed to load ANTA HTTPX settings. Check ANTA_HTTPX_* environment variables: {exc_to_str(exc)}"
        raise ValueError(msg) from exc

get_ssl_settings cached

get_ssl_settings() -> AntaSslSettings

Return the cached ANTA SSL settings loaded from environment variables.

Returns:

Type Description
AntaSslSettings

The SSL settings instance populated from ANTA_SSL_* environment variables.

Raises:

Type Description
ValueError

If any ANTA_SSL_* environment variable has an invalid value.

Source code in anta/settings.py
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
@cache
def get_ssl_settings() -> AntaSslSettings:
    """Return the cached ANTA SSL settings loaded from environment variables.

    Returns
    -------
    AntaSslSettings
        The SSL settings instance populated from ``ANTA_SSL_*`` environment variables.

    Raises
    ------
    ValueError
        If any ``ANTA_SSL_*`` environment variable has an invalid value.
    """
    try:
        return AntaSslSettings()
    except ValidationError as exc:
        msg = f"Failed to load ANTA SSL settings. Check ANTA_SSL_* environment variables: {exc_to_str(exc)}"
        raise ValueError(msg) from exc