Token Manager#
- class TokenManager(config: ConfigManager)[source]#
The
TokenManager
class handles all operations related to the token lifecycle, including fetching, saving, and validating the access token.It is initialized with a
ConfigManager
instance, which provides the necessary credentials.- Parameters:
config (
ConfigManager
) – AConfigManager
instance for managing credentials and configurations.
- load_token() AccessToken [source]#
Loads the
AccessToken
and its expiration from the keyring.If either the AccessToken string or AccessToken expiration cannot be retrieved, a
CredentialError
is raised.- Returns:
An AccessToken object containing the token and its expiration date.
- Return type:
- attach_client() JamfClient [source]#
Creates and returns a
JamfClient
object using the stored credentials.- Returns:
The
JamfClient
object if validation is successful.- Return type:
- Raises:
PatcherError – If
JamfClient
object fails pydantic validation.
- async fetch_token() AccessToken [source]#
Asynchronously fetches a new access token from the Jamf API. The token is then saved and returned for use.
- Returns:
The fetched
AccessToken
instance.- Return type:
- Raises:
TokenError – If a token cannot be retrieved from the Jamf API.
- async ensure_valid_token() AccessToken [source]#
Verifies the current access token is valid (present and not expired). If the token is found to be invalid, a new token is requested and refreshed.
See also
The
check_token()
decorator leverages this method with thread locking to ensure tokens are valid before API calls.- Returns:
The
AccessToken
object by way ofself.token
property.- Return type: