Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docstring rules to Ruff linting configuration #142

Merged
10 changes: 10 additions & 0 deletions Backend/app/__main__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
"""
FastAPI App entrypoint

- Handles startup and shutdown app events
- Load middlewares
- Creates the app object
- Configure Uvicorn server

"""

from contextlib import asynccontextmanager

import uvicorn
Expand Down
8 changes: 6 additions & 2 deletions Backend/app/common/PropertiesManager.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
"""
Manages APP global state variables and manages initialization of enviroment variables and .ini files

Declares PropertiesManager global object to be accessed from across the app
"""

import configparser
import os

Expand All @@ -14,7 +20,6 @@
ARCHITECTURE_ENV_NAME,
DEFAULT_ARCHITECTURE,
DEV,
DISTRIBUTION_ID_ENV_NAME,
ENV_VALUE_ENV_NAME,
MONGO_URI_ENV_NAME,
PROD,
Expand All @@ -41,7 +46,6 @@ def __init__(self) -> None:
self.env_variables = [
MONGO_URI_ENV_NAME,
SECRET_KEY_SIGN_ENV_NAME,
DISTRIBUTION_ID_ENV_NAME,
SERVERLESS_FUNCTION_URL_ENV_NAME,
ENV_VALUE_ENV_NAME,
]
Expand Down
6 changes: 6 additions & 0 deletions Backend/app/common/PropertiesMessagesManager.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
"""
Manages APP global messages, storing and making them accesible across the app

Declares _PropertiesMessagesManager global object to be accessed from across the app
"""

import configparser
import os
import re
Expand Down
4 changes: 4 additions & 0 deletions Backend/app/common/config_constants.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
Constants for APP configuration
"""

RESOURCES_FOLDER = "resources"
CONFIG_FILENAME = "config.ini"
APP_CONFIG_SECTION = "app"
Expand Down
5 changes: 4 additions & 1 deletion Backend/app/common/set_up_constants.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
Constants for APP setup such as Architectures, launch mode and path for enviroment variables
"""

ARCH_STREAMING_SERVERLESS_FUNCTION = "STREAMING_SERVERLESS_FUNCTION"
ARCH_BLOB = "BLOB"

Expand All @@ -10,6 +14,5 @@

SECRET_KEY_SIGN_ENV_NAME = "SECRET_KEY_SIGN"
MONGO_URI_ENV_NAME = "MONGO_URI"
DISTRIBUTION_ID_ENV_NAME = "DISTRIBUTION_ID"
SERVERLESS_FUNCTION_URL_ENV_NAME = "SERVERLESS_FUNCTION_URL"
ENV_VALUE_ENV_NAME = "ENV_VALUE"
4 changes: 4 additions & 0 deletions Backend/app/database/Database.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
Manages the unique database connection across the app and provides the modules with the collections needed for persist data.
"""

import sys
from enum import StrEnum
from typing import Any
Expand Down
6 changes: 6 additions & 0 deletions Backend/app/exceptions/base_exceptions_schema.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
"""
Base common exceptions for the whole app
"""

from app.logging.logging_constants import LOGGING_EXCEPTION
from app.logging.logging_schema import SpotifyElectronLogger

exceptions_logger = SpotifyElectronLogger(LOGGING_EXCEPTION).getLogger()


class SpotifyElectronException(Exception):
"""Base app exception, all exceptions must inherit from it"""

def __init__(self, message):
super().__init__(message)

Expand Down
4 changes: 4 additions & 0 deletions Backend/app/logging/LogPropertiesManager.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
Loads and manages logging configurations
"""

import configparser
import os

Expand Down
4 changes: 4 additions & 0 deletions Backend/app/logging/logging_constants.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
Logging constants
"""

# Log Levels
DEBUG = "DEBUG"
INFO = "INFO"
Expand Down
21 changes: 19 additions & 2 deletions Backend/app/logging/logging_schema.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
Logging and Format schemas
"""

import logging
import logging.handlers
import sys
Expand Down Expand Up @@ -34,7 +38,15 @@ class SpotifyElectronFormatter(logging.Formatter):
),
}

def format(self, record):
def format(self, record: logging.LogRecord) -> str:
"""Format log output with the custom formatter structure

Args:
record (LogRecord): the output log record

Returns:
str: the result of formating the log record with the custom formatter
"""
log_format = self.FORMATS.get(
record.levelno, "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
)
Expand Down Expand Up @@ -106,5 +118,10 @@ def _get_log_level(self) -> int:
else:
return mapped_log_level

def getLogger(self):
def getLogger(self) -> logging.Logger:
"""Returns the global logger

Returns:
logging.Logger: the global logger
"""
return self.logger
19 changes: 16 additions & 3 deletions Backend/app/middleware/CheckJwtAuthMiddleware.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Middleware for authenticate incoming HTTP Requests using JWT Token"""

from fastapi import Request, Response
from starlette.middleware.base import BaseHTTPMiddleware
from starlette.status import HTTP_401_UNAUTHORIZED
Expand Down Expand Up @@ -62,6 +64,15 @@ def bypass_request(self, request: Request) -> bool:
return False

async def dispatch(self, request: Request, call_next):
"""Manages the incoming HTTP request and decides wheter or not it has to be blocked

Args:
request (Request): the incoming request
call_next (_type_): the method to call next

Returns:
_type_: the call next output if request was not blocked
"""
try:
if self.bypass_request(request):
check_jwt_auth_middleware_logger.debug(
Expand All @@ -77,14 +88,16 @@ async def dispatch(self, request: Request, call_next):
status_code=HTTP_401_UNAUTHORIZED,
)

async def _handle_jwt_validation(self, jwt, request, call_next) -> Response:
async def _handle_jwt_validation(
self, jwt: str, request: Request, call_next
) -> Response:
"""Handles JWT validation, sends HTTP_401_UNAUTHORIZED if jwt is not valid or\
continues the workflow

Args:
----
jwt (_type_): the jwt token
request (_type_): the incoming request
jwt (str): the jwt token
request (Request): the incoming request
call_next (_type_): the method for continuing the workflow

Returns:
Expand Down
4 changes: 4 additions & 0 deletions Backend/app/middleware/cors_middleware_config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
CORS Middleware configurations
"""

allowed_origins = [
"http://localhost/",
"http://localhost:1212",
Expand Down
4 changes: 4 additions & 0 deletions Backend/app/patterns/Factory.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
Song Service Factory Pattern
"""

from abc import ABC, abstractmethod


Expand Down
5 changes: 5 additions & 0 deletions Backend/app/patterns/Singleton.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
"""
Singleton Pattern
"""


class Singleton(type):
"""The Singleton class can be implemented in different ways in Python. Some
possible methods include: base class, decorator, metaclass. We will use the
Expand Down
4 changes: 4 additions & 0 deletions Backend/app/spotify_electron/genre/genre_controller.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
Genre controller for handling incoming HTTP Requests
"""

from fastapi import APIRouter
from fastapi.responses import Response
from starlette.status import HTTP_200_OK, HTTP_500_INTERNAL_SERVER_ERROR
Expand Down
4 changes: 4 additions & 0 deletions Backend/app/spotify_electron/genre/genre_schema.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
Genre schema for domain model
"""

from enum import StrEnum

from app.exceptions.base_exceptions_schema import SpotifyElectronException
Expand Down
4 changes: 4 additions & 0 deletions Backend/app/spotify_electron/genre/genre_service.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
Genre service for handling business logic
"""

import json

from app.logging.logging_constants import LOGGING_GENRE_SERVICE
Expand Down
6 changes: 5 additions & 1 deletion Backend/app/spotify_electron/health/health_controller.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
Health controller for handling incoming HTTP Requests
"""

from fastapi import APIRouter
from fastapi.responses import Response
from starlette.status import HTTP_200_OK
Expand All @@ -7,7 +11,7 @@

@router.get("/", summary="Health Check Endpoint")
def get_health():
"""Health endpoint allows us to determine if the app has launched correctly
"""Validates if the app has launched correctly

Returns
-------
Expand Down
4 changes: 4 additions & 0 deletions Backend/app/spotify_electron/login/login_controller.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
Login controller for handling incoming HTTP Requests
"""

from typing import Annotated

from fastapi import APIRouter, Depends
Expand Down
4 changes: 4 additions & 0 deletions Backend/app/spotify_electron/login/login_schema.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
Login schema for domain model
"""

from app.exceptions.base_exceptions_schema import SpotifyElectronException


Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
Playlist controller for handling incoming HTTP Requests
"""

from typing import Annotated

from fastapi import APIRouter, Body, Header
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
Playlist repository for managing persisted data
"""

from app.logging.logging_constants import LOGGING_PLAYLIST_REPOSITORY
from app.logging.logging_schema import SpotifyElectronLogger
from app.spotify_electron.playlist.playlist_schema import (
Expand Down
4 changes: 4 additions & 0 deletions Backend/app/spotify_electron/playlist/playlist_schema.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
Playlist schema for domain model
"""

from dataclasses import dataclass

from app.exceptions.base_exceptions_schema import SpotifyElectronException
Expand Down
4 changes: 4 additions & 0 deletions Backend/app/spotify_electron/playlist/playlist_service.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
Playlist service for handling business logic
"""

import app.spotify_electron.playlist.playlist_repository as playlist_repository
import app.spotify_electron.security.security_service as security_service
import app.spotify_electron.user.base_user_service as base_user_service
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
Provider class for supplying playlist collection connection with database
"""

from pymongo.collection import Collection

from app.database.Database import Database, DatabaseCollection
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
Validations for Playlist repository
"""

from pymongo.results import DeleteResult, InsertOneResult, UpdateResult

from app.spotify_electron.playlist.playlist_schema import (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
Validations for Playlist service
"""

from app.exceptions.base_exceptions_schema import BadParameterException
from app.spotify_electron.playlist.playlist_repository import check_playlist_exists
from app.spotify_electron.playlist.playlist_schema import (
Expand Down
4 changes: 4 additions & 0 deletions Backend/app/spotify_electron/search/search_controller.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
Search controller for handling incoming HTTP Requests
"""

from fastapi import APIRouter
from fastapi.responses import Response
from starlette.status import (
Expand Down
4 changes: 4 additions & 0 deletions Backend/app/spotify_electron/search/search_schema.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
Search schema for domain model
"""

from dataclasses import dataclass

from app.exceptions.base_exceptions_schema import SpotifyElectronException
Expand Down
4 changes: 4 additions & 0 deletions Backend/app/spotify_electron/search/search_service.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
Search service for handling business logic
"""

import app.spotify_electron.playlist.playlist_service as playlist_service
import app.spotify_electron.song.base_song_service as base_song_service
import app.spotify_electron.user.artist.artist_service as artist_service
Expand Down
8 changes: 4 additions & 4 deletions Backend/app/spotify_electron/security/security_schema.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import json
"""
Security schema for domain model
"""

from dataclasses import dataclass

from app.exceptions.base_exceptions_schema import SpotifyElectronException
Expand All @@ -13,9 +16,6 @@ class TokenData:
role: UserType
token_type: str

def get_json(self) -> str:
return json.dumps(self.__dict__)


class BadJWTTokenProvidedException(SpotifyElectronException):
"""Exception for bad JWT Token provided"""
Expand Down
Loading
Loading