quartic_sdk.utilities.decorator
¶
Module Contents¶
Functions¶
|
Get a new access token and refresh token from the authentication endpoint and save them. |
|
Save a token to a file. |
|
Request a new access token using a refresh token. |
|
Decorator to handle token expiration and refresh for API authentication. |
Decorator to handle token expiration and refresh for API authentication. |
-
quartic_sdk.utilities.decorator.
TOKEN_FILE
¶
-
quartic_sdk.utilities.decorator.
get_and_save_token
(host, username, password, verify_ssl)¶ Get a new access token and refresh token from the authentication endpoint and save them. This method sends a POST request to the authentication endpoint with the provided username and password to obtain a new access token and refresh token. It then saves these tokens to a file. Args:
host username password verify_ssl
- Returns:
access_token
- Raises:
- PermissionError: If there is an error during the authentication process or if the response status
code indicates an issue.
-
quartic_sdk.utilities.decorator.
save_token
(token, user_identification_string)¶ Save a token to a file.
This function creates the necessary directory structure and saves the provided token to a file.
- Args:
token (str): The token to be saved.
- Returns:
None
- Raises:
None
-
quartic_sdk.utilities.decorator.
request_new_token
(refresh_token, host, user_identification_string)¶ Request a new access token using a refresh token.
This function sends a request to the specified host’s refresh token endpoint to obtain a new access token. It includes the provided refresh token in the request data.
- Args:
refresh_token (str): The refresh token used to obtain a new access token. If None, the request will fail. host (str): The base URL of the host where the refresh token request will be sent.
- Returns:
str: The new access token obtained from the response.
- Raises:
PermissionError: If the refresh token has expired or if any other error occurs during the token request.
-
quartic_sdk.utilities.decorator.
authenticate_with_tokens
(func)¶ Decorator to handle token expiration and refresh for API authentication.
This decorator checks for the existence of a token file, reads the stored access token, and attempts to refresh the token if it has expired. It updates the token file with the new access token and retries the original API call with the refreshed token if necessary.
- Args:
func (callable): The function to decorate.
- Returns:
callable: The decorated function.
- Raises:
Exception: If the token file does not exist or if any other error occurs during token management. PermissionError: If the access token is missing in the token file.
-
quartic_sdk.utilities.decorator.
async_authenticate_with_tokens
(func)¶ Decorator to handle token expiration and refresh for API authentication.
This decorator checks for the existence of a token file, reads the stored access token, and attempts to refresh the token if it has expired. It updates the token file with the new access token and retries the original API call with the refreshed token if necessary.
- Args:
func (callable): The function to decorate.
- Returns:
callable: The decorated function.
- Raises:
Exception: If the token file does not exist or if any other error occurs during token management. PermissionError: If the access token is missing in the token file.