Skip to main content

models

The code in models.py defines a set of classes used to represent authentication information and query management in an API-based system.

1. AuthUser

  • Attributes:
    • username: The username of the user.
    • password: The password of the user.
  • Methods:
    • toObject: Converts the user’s username and password into a dictionary ({"userName": username, "password": password}).
    • __str__: Returns the string representation of the user as a dictionary.

2. ApiKey

  • Attributes:
    • name: The name associated with the API key.
    • password: The password associated with the API key.
  • Methods:
    • getApiKey: Encodes the name:password combination in base64 format and returns it as a string.
    • getCompleteAuth: Prepares and returns the complete Basic <base64_encoded_api_key> authentication header.

3. Query

  • Attributes:
    • query: A string representing the query.
  • Methods:
    • toObject: Converts the query into a dictionary ({"query": query}).
    • __str__: Returns the string representation of the query as a dictionary.

4. User

  • Attributes:
    • name: The name of the user.
    • pin: A PIN associated with the user.
    • endDate, startDate, userId: These attributes are initialized to None: they will be used later for tracking when the user’s account is active, or for storing an unique user ID.

Key Functionality

  • The classes provide mechanisms to manage and represent authentication data (like usernames, passwords, and API keys), and prepare that information for API requests (such as generating base64-encoded API keys for authentication headers).

  • The ApiKey class is specifically designed to create an authentication string compatible with HTTP Basic Authentication, where the username and password are base64-encoded into the Authorization header.

  • The AuthUser and Query classes represent entities in a system that stores user credentials and query data, respectively. The User class is used to represent additional user information.