web package

Submodules

web.web_door_opener module

class web.web_door_opener.WebDoorOpener(shutdown_event, config, loop, message_task_queue, camera_task_queue_async, door_open_task_queue)

Bases: object

Parameters:
  • shutdown_event (Event)

  • config (Configuration)

  • message_task_queue (Queue)

  • camera_task_queue_async (Queue)

  • door_open_task_queue (Queue)

static custom_auth_required(f)

A decorator for custom authentication required function.

run()

Runs the server in debug mode if the log level is set to “DEBUG”, otherwise runs the server in non-debug mode.

This function checks the value of self.str_log_level and sets self.app.debug accordingly. If the log level is “DEBUG”, the server is started in debug mode by setting self.app.debug to True. Otherwise, the server is started in non-debug mode by setting self.app.debug to False.

Parameters:

None

Returns:

None

shutdown()

A description of the entire function, its parameters, and its return types.

verify_password(username, password)

Verify the provided username and password for authentication.

Parameters:

username (str): The username to be verified. password (str): The password corresponding to the username.

Returns:

str or None: The authenticated username if successful, None otherwise.

log_request_info()

Logs information about the incoming HTTP request.

This function checks if the request is made from a browser session. If it is, and the user is ‘anonymous’ and the endpoint is not ‘login’, ‘favicon’, or ‘static’, it redirects to the ‘login’ endpoint. If the user is ‘anonymous’ and there is no browser session, it handles the 401 Unauthenticated error.

After that, it logs the user, method, path, and request headers to the logger. It also logs the request data.

Parameters:

self (WebDoorOpener): The instance of the WebDoorOpener class.

Returns:

None: If the request is redirected or if the user is ‘anonymous’ and there is no browser session. redirect: If the user is ‘anonymous’ and the endpoint is not ‘login’, ‘favicon’, or ‘static’. handle_401_unauthenticated: If the user is ‘anonymous’ and there is no browser session.

log_response_info(response)

Logs the response information including user, method, path, status, headers, and response data.

login()

Login method for interactive browser sessions :return: html login page as string :rtype: str

Return type:

str

favicon()

A function to serve the favicon file by sending it from the static directory.

index()

A function that returns the homepage HTML content as a string after ensuring custom authentication.

Return type:

str

open()

A function to open the door when a valid TOTP code is provided.

This function is decorated with @custom_auth_required, which ensures that the user is authenticated before accessing this endpoint.

Parameters:

None

Returns:
  • If the provided TOTP code is valid, the function sends a message to open the door and takes a photo, and returns a success response with status code 201 and a message “TOTP is valid! Opening!”.

  • If the provided TOTP code is invalid, the function sends a message indicating the invalid TOTP code and returns a bad request response with a message “Invalid TOTP. Retry again -> will notify owner.”.

handle_exception(e)

Default error exception handler for any error response. Results in http status code 500 - internal server error :param e: Error :return: http json response :rtype: json

handle_not_found(error)

A method to handle the not found error response. :param error: Error object describing the not found error :return: JSON response with status 404 and error details :rtype: json

Module contents