Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@
from fastapi_versioning import VersionedFastAPI
from bson import ObjectId, errors
from fastapi_users import FastAPIUsers
from beanie import PydanticObjectId
from pydantic import BaseModel
from typing import Any

Check warning on line 43 in api/main.py

View workflow job for this annotation

GitHub Actions / Lint

Unused Any imported from typing

Check warning on line 43 in api/main.py

View workflow job for this annotation

GitHub Actions / Lint

Imports from package typing are not grouped

Check warning on line 43 in api/main.py

View workflow job for this annotation

GitHub Actions / Lint

standard import "typing.Any" should be placed before third party imports "fastapi.Depends", "fastapi.encoders.jsonable_encoder", "fastapi.responses.JSONResponse" (...) "bson.ObjectId", "fastapi_users.FastAPIUsers", "pydantic.BaseModel"
from kernelci.api.models_base import PyObjectId

Check failure on line 44 in api/main.py

View workflow job for this annotation

GitHub Actions / Lint

Unable to import 'kernelci.api.models_base'
from kernelci.api.models import (

Check failure on line 45 in api/main.py

View workflow job for this annotation

GitHub Actions / Lint

Unable to import 'kernelci.api.models'
Node,
Hierarchy,
PublishEvent,
Expand Down Expand Up @@ -73,7 +74,9 @@
SUBSCRIPTION_CLEANUP_RETRY_MINUTES = 1 # Retry interval if cleanup fails




@asynccontextmanager

Check warning on line 79 in api/main.py

View workflow job for this annotation

GitHub Actions / Lint

too many blank lines (4)
async def lifespan(app: FastAPI): # pylint: disable=redefined-outer-name
"""Lifespan functions for startup and shutdown events"""
await pubsub_startup()
Expand All @@ -87,13 +90,16 @@
API_VERSIONS = ['v0']

metrics = Metrics()
app = FastAPI(lifespan=lifespan, debug=True, docs_url=None, redoc_url=None)
app = FastAPI(
lifespan=lifespan,
debug=True
)
db = Database(service=(os.getenv('MONGO_SERVICE') or 'mongodb://db:27017'))
auth = Authentication(token_url="user/login")
pubsub = None # pylint: disable=invalid-name

auth_backend = auth.get_user_authentication_backend()
fastapi_users_instance = FastAPIUsers[User, PydanticObjectId](
fastapi_users_instance = FastAPIUsers[User, PyObjectId](
get_user_manager,
[auth_backend],
)
Expand Down
5 changes: 2 additions & 3 deletions api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@
from beanie import (
Indexed,
Document,
PydanticObjectId,
)
from kernelci.api.models_base import DatabaseModel, ModelId
from kernelci.api.models_base import DatabaseModel, ModelId, PyObjectId

Check failure on line 30 in api/models.py

View workflow job for this annotation

GitHub Actions / Lint

Unable to import 'kernelci.api.models_base'


# PubSub model definitions
Expand Down Expand Up @@ -107,7 +106,7 @@
]


class UserRead(schemas.BaseUser[PydanticObjectId], ModelId):
class UserRead(schemas.BaseUser[PyObjectId], ModelId):
"""Schema for reading a user"""
username: Annotated[str, Indexed(unique=True)]
groups: List[UserGroup] = Field(default=[])
Expand Down
4 changes: 2 additions & 2 deletions api/user_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
BeanieUserDatabase,
ObjectIDIDMixin,
)
from beanie import PydanticObjectId
import jinja2
from .models import User
from kernelci.api.models_base import PyObjectId

Check warning on line 18 in api/user_manager.py

View workflow job for this annotation

GitHub Actions / Lint

third party import "kernelci.api.models_base.PyObjectId" should be placed before local import "models.User"

Check failure on line 18 in api/user_manager.py

View workflow job for this annotation

GitHub Actions / Lint

Unable to import 'kernelci.api.models_base'
from .config import AuthSettings
from .email_sender import EmailSender


class UserManager(ObjectIDIDMixin, BaseUserManager[User, PydanticObjectId]):
class UserManager(ObjectIDIDMixin, BaseUserManager[User, PyObjectId]):
"""User management logic"""
settings = AuthSettings()
reset_password_token_secret = settings.secret_key
Expand Down
Loading