qmenta.core.auth¶
- class qmenta.core.auth.Auth(base_url: str, token: str)¶
Class for authenticating to the platform. Do not use the constructor directly, but use the login() function to create a new authentication.
- base_url¶
The base URL of the platform. Example: ‘https://platform.qmenta.com’
- Type:
str
- token¶
The authentication token, returned by the platform when logging in.
- Type:
str
- classmethod from_env(dot_env: Path | None = None) Auth ¶
Create an Auth object using the QMENTA_URL and QMENTA_AUTH_TOKEN environment variables. If the variables are not set in the environment, but they exist in the file dot_env, then those values are used.
This function can be used to create an Auth object in scripts to communicate with QMENTA Platform, after the qmenta-auth command has been run to authenticate.
- Parameters:
dot_env (Path) – The location of the .env file to read the environment variables. If no value is supplied, qmenta_auth_env_file() is used as the default value. (Optional)
- Raises:
InvalidLoginError – When one of the needed environment variables was not found
- get_session() Session ¶
- classmethod login(username: str, password: str, code_2fa: str | None = None, ask_for_2fa_input: bool = False, base_url: str = 'https://platform.qmenta.com') Auth ¶
Authenticate to the platform using username and password.
- Parameters:
username (str) – The username to log in on the platform. For all new platform accounts, this is the e-mail address of the user. Example: ‘example@qmenta.com’
password (str) – The QMENTA platform password of the user.
code_2fa (str) – The 2FA code that was sent to your phone (optional).
ask_for_2fa_input (bool) – When set to True, the user is asked input the 2FA code in the command-line interface when it is needed. If the user does not have 2FA enabled, no input is requested. This is useful for scripts. When set to False, a Needs2FAError exception is raised when a 2FA code is needed. This is useful for GUIs. Default value: False
base_url (str) – The URL of the platform to connect to. Default value: ‘https://platform.qmenta.com’
- Returns:
The Auth object that was logged in with.
- Return type:
- Raises:
ConnectionError – If there was a problem setting up the network connection with the platform.
InvalidResponseError – If the platform returned an invalid response.
InvalidLoginError – If the login was invalid. This can happen when the username/password combination is incorrect, or when the account is not active or 2FA is required to be set up.
Needs2FAError – When a login attempt was done without a valid 2FA code. The 2FA code has been sent to your phone, and must be provided in the next call to the login function.
- static qmenta_auth_env_file() Path ¶
Return the path of the qmenta auth env file
- exception qmenta.core.auth.InvalidLoginError(*args: str)¶
When the provided credentials are incorrect, or when the used token is not valid.
- exception qmenta.core.auth.Needs2FAError(*args: str)¶
When a 2FA code must to be provided to log in.
- qmenta.core.auth.main() None ¶
- qmenta.core.auth.validate_url(url: str) None ¶
Validate the URL as a valid http or https URL.
- Raises:
ValueError – When the URL is not valid
- qmenta.core.auth.write_dot_env_file(token: str, url: str, filename: Path | None = None) None ¶
Write the token and URL to a .env file.
- Parameters:
token (str) – The token to write to the .env file
url (str) – The URL to write to the .env file
filename (Path) – The filename of the .env file to write to (optional). If no value is supplied, it will be written to the default location qmenta_auth_env_file().
- Raises:
OSError – When the output file could not be written