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 URL of the platform to connect to. Default value: ‘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 | None = None, password: str | None = None, *, api_key: str | None = None, base_url: str = 'https://platform.qmenta.com') Auth¶
Authenticate to the platform using username and password, or an API key.
api_keyandbase_urlmust be passed as keyword arguments.Valid parameter combinations:
username,password: standard login.api_key: login using an API key.
base_urlcan be combined with any of the above to target a specific platform environment. Whenusername+passwordandapi_keyare all provided,username+passwordtakes precedence.Accounts with two-factor authentication (2FA) enabled can no longer log in with username and password: generate an API key in the platform (My profile -> Credentials) and log in with
api_keyinstead.- 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.
api_key (str) – A QMENTA API key. See the platform manual to learn how to generate one. When provided together with
usernameandpassword, the username/password credentials take precedence.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 and for 404 and 5xx response status code.
InvalidResponseError – If the platform returned an invalid response.
InvalidLoginError – If the login was invalid. This can happen when the username/password combination is incorrect, when the api_key is invalid, when the account is not active. Also raised when neither credentials nor api_key are provided.
Needs2FAError – When the account has two-factor authentication enabled. Generate an API key and log in with it instead.
- 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 the account has two-factor authentication enabled. Username/password login with a 2FA code is no longer supported; generate an API key instead and log in with it.
- qmenta.core.auth.main() None¶
Entry point of the
qmenta-authcommand-line tool.
- 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