Token Manager#
- class TokenManager(config: ConfigManager)[source]#
The
TokenManagerclass handles all operations related to the token lifecycle, including fetching, saving, and validating the access token.It is initialized with a
ConfigManagerinstance, which provides the necessary credentials.- Parameters:
config (
ConfigManager) – AConfigManagerinstance for managing credentials and configurations.
- load_token() AccessToken[source]#
Loads the
AccessTokenand its expiration from the keyring.If either the AccessToken string or AccessToken expiration cannot be retrieved, a
CredentialErroris raised.- Returns:
An AccessToken object containing the token and its expiration date.
- Return type:
- attach_client() JamfClient[source]#
Creates and returns a
JamfClientobject using the stored credentials.- Returns:
The
JamfClientobject if validation is successful.- Return type:
- Raises:
PatcherError – If
JamfClientobject 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
AccessTokeninstance.- Return type:
- Raises:
TokenError – If a token cannot be retrieved from the Jamf API.
- save_token(token: AccessToken)[source]#
This method stores the access token and its expiration date in the keyring for later retrieval. It also updates the
JamfClientinstance with the new token.- Parameters:
token (
AccessToken) – TheAccessTokeninstance containing the token and its expiration date.- Raises:
TokenError – If either the token string or expiration could not be saved.
- 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
AccessTokenobject by way ofself.tokenproperty.- Return type: