Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] authored and cmyui committed Feb 13, 2024
1 parent c64582a commit b675920
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 54 deletions.
3 changes: 1 addition & 2 deletions app/api/v2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from app.api.v2.common.oauth import OAuth2Scheme
from app.repositories import access_tokens as access_tokens_repo


oauth2_scheme = OAuth2Scheme(
authorizationUrl="/v2/oauth/authorize",
tokenUrl="/v2/oauth/token",
Expand Down Expand Up @@ -38,9 +37,9 @@ async def get_current_client(token: str = Depends(oauth2_scheme)) -> dict[str, A

from . import clans
from . import maps
from . import oauth
from . import players
from . import scores
from . import oauth

apiv2_router = APIRouter(tags=["API v2"], prefix="/v2")

Expand Down
12 changes: 6 additions & 6 deletions app/api/v2/common/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ def __init__(
self,
authorizationUrl: str,
tokenUrl: str,
refreshUrl: Optional[str] = None,
scheme_name: Optional[str] = None,
scopes: Optional[dict[str, str]] = None,
description: Optional[str] = None,
refreshUrl: str | None = None,
scheme_name: str | None = None,
scopes: dict[str, str] | None = None,
description: str | None = None,
auto_error: bool = True,
):
if not scopes:
Expand All @@ -45,7 +45,7 @@ def __init__(
auto_error=auto_error,
)

async def __call__(self, request: Request) -> Optional[str]:
async def __call__(self, request: Request) -> str | None:
authorization = request.headers.get("Authorization")
scheme, param = get_authorization_scheme_param(authorization)
if not authorization or scheme.lower() != "bearer":
Expand All @@ -63,7 +63,7 @@ async def __call__(self, request: Request) -> Optional[str]:
# https://developer.zendesk.com/api-reference/sales-crm/authentication/requests/#client-authentication
def get_credentials_from_basic_auth(
request: Request,
) -> Optional[dict[str, Union[str, int]]]:
) -> dict[str, str | int] | None:
authorization = request.headers.get("Authorization")
scheme, param = get_authorization_scheme_param(authorization)
if not authorization or scheme.lower() != "basic":
Expand Down
3 changes: 1 addition & 2 deletions app/api/v2/models/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from . import BaseModel


# input models


Expand All @@ -15,7 +14,7 @@

class Token(BaseModel):
access_token: str
refresh_token: Optional[str]
refresh_token: str | None
token_type: Literal["Bearer"]
expires_in: int
expires_at: str
Expand Down
5 changes: 3 additions & 2 deletions app/api/v2/oauth.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" bancho.py's v2 apis for interacting with clans """

from __future__ import annotations

import uuid
Expand Down Expand Up @@ -66,10 +67,10 @@ async def token(
grant_type: str = Form(),
client_id: int = Form(default=None),
client_secret: str = Form(default=None),
auth_credentials: Optional[dict[str, Any]] = Depends(
auth_credentials: dict[str, Any] | None = Depends(
get_credentials_from_basic_auth,
),
code: Optional[str] = Form(default=None),
code: str | None = Form(default=None),
scope: str = Form(default="", regex=r"\b\w+\b(?:,\s*\b\w+\b)*"),
) -> Token:
"""Get an access token for the API."""
Expand Down
22 changes: 11 additions & 11 deletions app/repositories/access_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@
from app.api.v2.common import json


def create_access_token_key(code: Union[UUID, str]) -> str:
def create_access_token_key(code: UUID | str) -> str:
return f"bancho:access_tokens:{code}"


async def create(
access_token: Union[UUID, str],
access_token: UUID | str,
client_id: int,
grant_type: str,
scope: str,
refresh_token: Optional[Union[UUID, str]] = "",
player_id: Optional[int] = "",
expires_in: Optional[int] = "",
refresh_token: UUID | str | None = "",
player_id: int | None = "",
expires_in: int | None = "",
) -> dict[str, Any]:
access_token_key = create_access_token_key(access_token)
now = datetime.now()
Expand All @@ -44,7 +44,7 @@ async def create(
return data


async def fetch_one(access_token: Union[UUID, str]) -> Optional[dict[str, Any]]:
async def fetch_one(access_token: UUID | str) -> dict[str, Any] | None:
data = await app.state.services.redis.hgetall(create_access_token_key(access_token))

if data is None:
Expand All @@ -54,10 +54,10 @@ async def fetch_one(access_token: Union[UUID, str]) -> Optional[dict[str, Any]]:


async def fetch_all(
client_id: Optional[int] = None,
scope: Optional[str] = None,
grant_type: Optional[str] = None,
player_id: Optional[int] = None,
client_id: int | None = None,
scope: str | None = None,
grant_type: str | None = None,
player_id: int | None = None,
page: int = 1,
page_size: int = 10,
) -> list[dict[str, Any]]:
Expand Down Expand Up @@ -101,7 +101,7 @@ async def fetch_all(
return access_tokens


async def delete(access_token: Union[UUID, str]) -> Optional[dict[str, Any]]:
async def delete(access_token: UUID | str) -> dict[str, Any] | None:
access_token_key = create_access_token_key(access_token)

data = await app.state.services.redis.hgetall(access_token_key)
Expand Down
12 changes: 6 additions & 6 deletions app/repositories/authorization_codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
from app.api.v2.common import json


def create_authorization_code_key(code: Union[UUID, str]) -> str:
def create_authorization_code_key(code: UUID | str) -> str:
return f"bancho:authorization_codes:{code}"


async def create(
code: Union[UUID, str],
code: UUID | str,
client_id: int,
scope: str,
player_id: int,
Expand All @@ -28,7 +28,7 @@ async def create(
)


async def fetch_one(code: Union[UUID, str]) -> Optional[dict[str, Any]]:
async def fetch_one(code: UUID | str) -> dict[str, Any] | None:
data = await app.state.services.redis.get(create_authorization_code_key(code))
if data is None:
return None
Expand All @@ -37,8 +37,8 @@ async def fetch_one(code: Union[UUID, str]) -> Optional[dict[str, Any]]:


async def fetch_all(
client_id: Optional[int] = None,
scope: Optional[str] = None,
client_id: int | None = None,
scope: str | None = None,
page: int = 1,
page_size: int = 10,
) -> list[dict[str, Any]]:
Expand Down Expand Up @@ -76,7 +76,7 @@ async def fetch_all(
return authorization_codes


async def delete(code: Union[UUID, str]) -> Optional[dict[str, Any]]:
async def delete(code: UUID | str) -> dict[str, Any] | None:
authorization_code_key = create_authorization_code_key(code)

data = await app.state.services.redis.get(authorization_code_key)
Expand Down
36 changes: 18 additions & 18 deletions app/repositories/ouath_clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
async def create(
secret: str,
owner: int,
name: Optional[str] = None,
redirect_uri: Optional[str] = None,
name: str | None = None,
redirect_uri: str | None = None,
) -> dict[str, Any]:
"""Create a new client in the database."""
query = """\
Expand Down Expand Up @@ -57,11 +57,11 @@ async def create(


async def fetch_one(
id: Optional[int] = None,
owner: Optional[int] = None,
secret: Optional[str] = None,
name: Optional[str] = None,
) -> Optional[dict[str, Any]]:
id: int | None = None,
owner: int | None = None,
secret: str | None = None,
name: str | None = None,
) -> dict[str, Any] | None:
"""Fetch a signle client from the database."""
if id is None and owner is None and secret is None:
raise ValueError("Must provide at least one parameter.")
Expand All @@ -85,12 +85,12 @@ async def fetch_one(


async def fetch_many(
id: Optional[int] = None,
owner: Optional[int] = None,
secret: Optional[str] = None,
page: Optional[int] = None,
page_size: Optional[int] = None,
) -> Optional[list[dict[str, Any]]]:
id: int | None = None,
owner: int | None = None,
secret: str | None = None,
page: int | None = None,
page_size: int | None = None,
) -> list[dict[str, Any]] | None:
"""Fetch all clients from the database."""
query = f"""\
SELECT {READ_PARAMS}
Expand Down Expand Up @@ -119,11 +119,11 @@ async def fetch_many(

async def update(
id: int,
secret: Optional[str] = None,
owner: Optional[int] = None,
name: Optional[str] = None,
redirect_uri: Optional[str] = None,
) -> Optional[dict[str, Any]]:
secret: str | None = None,
owner: int | None = None,
name: str | None = None,
redirect_uri: str | None = None,
) -> dict[str, Any] | None:
"""Update an existing client in the database."""
query = """\
UPDATE oauth_clients
Expand Down
14 changes: 7 additions & 7 deletions app/repositories/refresh_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
from app.api.v2.common import json


def create_refresh_token_key(code: Union[UUID, str]) -> str:
def create_refresh_token_key(code: UUID | str) -> str:
return f"bancho:refresh_tokens:{code}"


async def create(
refresh_token: Union[UUID, str],
access_token: Union[UUID, str],
refresh_token: UUID | str,
access_token: UUID | str,
client_id: int,
scope: str,
) -> dict[str, Any]:
Expand All @@ -39,7 +39,7 @@ async def create(
return data


async def fetch_one(refresh_token: Union[UUID, str]) -> Optional[dict[str, Any]]:
async def fetch_one(refresh_token: UUID | str) -> dict[str, Any] | None:
data = await app.state.services.redis.hgetall(
create_refresh_token_key(refresh_token),
)
Expand All @@ -50,8 +50,8 @@ async def fetch_one(refresh_token: Union[UUID, str]) -> Optional[dict[str, Any]]


async def fetch_all(
client_id: Optional[int] = None,
scope: Optional[str] = None,
client_id: int | None = None,
scope: str | None = None,
page: int = 1,
page_size: int = 10,
) -> list[dict[str, Any]]:
Expand Down Expand Up @@ -89,7 +89,7 @@ async def fetch_all(
return refresh_tokens


async def delete(refresh_token: Union[UUID, str]) -> Optional[dict[str, Any]]:
async def delete(refresh_token: UUID | str) -> dict[str, Any] | None:
refresh_token_key = create_refresh_token_key(refresh_token)

data = await app.state.services.redis.hgetall(refresh_token_key)
Expand Down

0 comments on commit b675920

Please sign in to comment.