Wrappers#

Note

We are planning to refactor the check_token function into the token_manager class as it is more suitable for that scope.

check_token(func: Callable) Any[source]#

Decorator that ensures the validity of an access token before executing a function.

The check_token decorator performs several key tasks before the decorated function is executed:

  1. It validates the configuration of the token manager’s client.

  2. It checks if the current access token is valid. If the token is invalid, it attempts to refresh the token.

  3. It ensures that the token has a sufficient remaining lifetime (at least 5 minutes). If the token’s lifetime is insufficient, it raises a TokenLifetimeError.

This decorator is intended for use with asynchronous methods that require a valid and sufficiently long-lived access token to interact with the Jamf API.

Parameters:

func (Callable) – The asynchronous function to be decorated.

Raises:
  • pydantic.ValidationError – If the configuration validation fails.

  • TokenFetchError – If token refresh fails or returns None.

  • TokenLifetimeError – If the token’s remaining lifetime is too short.

Returns:

The result of the decorated function.

Return type:

Any