Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
build(deps-dev): bump ruff from 0.3.7 to 0.4.0 (#151)
Browse files Browse the repository at this point in the history
* build(deps-dev): bump ruff from 0.3.7 to 0.4.0

Bumps [ruff](https://github.com/astral-sh/ruff) from 0.3.7 to 0.4.0.
- [Release notes](https://github.com/astral-sh/ruff/releases)
- [Changelog](https://github.com/astral-sh/ruff/blob/main/CHANGELOG.md)
- [Commits](astral-sh/ruff@v0.3.7...v0.4.0)

---
updated-dependencies:
- dependency-name: ruff
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* style(pre-commit): bump ruff to 0.4.0

* style(ruff): remove legacy async

* style(mypy): remove legacy async

* test(pytest): remove legacy async

* test(pytest): remove unnecessary await & async

* style(mypy): remove legacy async & await

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: F-G Fernandez <[email protected]>
  • Loading branch information
dependabot[bot] and frgfm authored Apr 19, 2024
1 parent 86ad2b1 commit 3627ff9
Show file tree
Hide file tree
Showing 17 changed files with 84 additions and 104 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ repos:
- id: debug-statements
language_version: python3
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.3.7'
rev: 'v0.4.0'
hooks:
- id: ruff
args:
Expand Down
38 changes: 19 additions & 19 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ prometheus-fastapi-instrumentator = "^6.1.0"
optional = true

[tool.poetry.group.quality.dependencies]
ruff = "==0.3.7"
ruff = "==0.4.0"
mypy = "==1.9.0"
types-requests = ">=2.0.0"
types-passlib = ">=1.7.0"
Expand Down
16 changes: 6 additions & 10 deletions src/app/api/api_v1/endpoints/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@


@router.get("/authorize", summary="Request authorization code through GitHub OAuth app", include_in_schema=False)
async def authorize_github(
def authorize_github(
scope: str,
redirect_uri: HttpUrl,
) -> RedirectResponse:
Expand All @@ -40,7 +40,7 @@ async def authorize_github(
summary="Request a GitHub token from authorization code",
include_in_schema=False,
)
async def request_github_token_from_code(
def request_github_token_from_code(
payload: TokenRequest,
) -> GHToken:
return gh_client.get_token_from_code(payload.code, payload.redirect_uri)
Expand All @@ -59,16 +59,12 @@ async def login_with_creds(
"""
# Verify credentials
user = await users.get_by_login(form_data.username)
if (
user is None
or user.hashed_password is None
or not await verify_password(form_data.password, user.hashed_password)
):
if user is None or user.hashed_password is None or not verify_password(form_data.password, user.hashed_password):
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Invalid credentials.")
telemetry_client.capture(user.id, event="user-login", properties={"method": "credentials"})
# create access token using user user_id/user_scopes
token_data = {"sub": str(user.id), "scopes": user.scope.split()}
token = await create_access_token(token_data, settings.ACCESS_TOKEN_UNLIMITED_MINUTES)
token = create_access_token(token_data, settings.ACCESS_TOKEN_UNLIMITED_MINUTES)

return Token(access_token=token, token_type="bearer") # noqa S106

Expand All @@ -93,13 +89,13 @@ async def login_with_github_token(

# create access token using user user_id/user_scopes
token_data = {"sub": str(user.id), "scopes": user.scope.split()}
token = await create_access_token(token_data, settings.ACCESS_TOKEN_UNLIMITED_MINUTES)
token = create_access_token(token_data, settings.ACCESS_TOKEN_UNLIMITED_MINUTES)

return Token(access_token=token, token_type="bearer") # noqa S106


@router.get("/validate", status_code=status.HTTP_200_OK, summary="Check token validity")
async def check_token_validity(
def check_token_validity(
payload: TokenPayload = Security(get_token_payload, scopes=[UserScope.USER, UserScope.ADMIN]),
) -> TokenPayload:
return payload
4 changes: 2 additions & 2 deletions src/app/api/api_v1/endpoints/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ async def _create_user(payload: UserCreate, users: UserCRUD, requester_id: Union
if (await users.get_by_login(payload.login, strict=False)) is not None:
raise HTTPException(status.HTTP_409_CONFLICT, "Login already taken")
valid_creds = True
hashed_password = await hash_password(payload.password)
hashed_password = hash_password(payload.password)

if not valid_creds:
raise HTTPException(
Expand Down Expand Up @@ -135,7 +135,7 @@ async def update_user_password(
token_payload: TokenPayload = Security(get_token_payload, scopes=[UserScope.ADMIN]),
) -> User:
telemetry_client.capture(token_payload.user_id, event="user-pwd", properties={"user_id": user_id})
pwd = await hash_password(payload.password)
pwd = hash_password(payload.password)
return await users.update(user_id, CredHash(hashed_password=pwd))


Expand Down
10 changes: 5 additions & 5 deletions src/app/api/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@
)


async def get_user_crud(session: AsyncSession = Depends(get_session)) -> UserCRUD:
def get_user_crud(session: AsyncSession = Depends(get_session)) -> UserCRUD:
return UserCRUD(session=session)


async def get_repo_crud(session: AsyncSession = Depends(get_session)) -> RepositoryCRUD:
def get_repo_crud(session: AsyncSession = Depends(get_session)) -> RepositoryCRUD:
return RepositoryCRUD(session=session)


async def get_guideline_crud(session: AsyncSession = Depends(get_session)) -> GuidelineCRUD:
def get_guideline_crud(session: AsyncSession = Depends(get_session)) -> GuidelineCRUD:
return GuidelineCRUD(session=session)


async def get_token_payload(
def get_token_payload(
security_scopes: SecurityScopes,
token: str = Depends(oauth2_scheme),
) -> TokenPayload:
Expand Down Expand Up @@ -91,5 +91,5 @@ async def get_current_user(
users: UserCRUD = Depends(get_user_crud),
) -> User:
"""Dependency to use as fastapi.security.Security with scopes"""
token_payload = await get_token_payload(security_scopes, token)
token_payload = get_token_payload(security_scopes, token)
return cast(User, await users.get(token_payload.user_id, strict=True))
6 changes: 3 additions & 3 deletions src/app/core/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")


async def create_access_token(content: Dict[str, Any], expires_minutes: Optional[int] = None) -> str:
def create_access_token(content: Dict[str, Any], expires_minutes: Optional[int] = None) -> str:
"""Encode content dict using security algorithm, setting expiration."""
expire_delta = timedelta(minutes=expires_minutes or settings.ACCESS_TOKEN_EXPIRE_MINUTES)
expire = datetime.utcnow() + expire_delta
return jwt.encode({**content, "exp": expire}, settings.SECRET_KEY, algorithm=settings.JWT_ENCODING_ALGORITHM)


async def verify_password(plain_password: str, hashed_password: str) -> bool:
def verify_password(plain_password: str, hashed_password: str) -> bool:
return pwd_context.verify(plain_password, hashed_password)


async def hash_password(password: str) -> str:
def hash_password(password: str) -> str:
return pwd_context.hash(password)
2 changes: 1 addition & 1 deletion src/app/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async def init_db() -> None:
logger.info("Initializing PostgreSQL database...")
# Fetch authenticated GitHub User
gh_user = gh_client.get_my_user(settings.SUPERADMIN_GH_PAT)
pwd = await hash_password(settings.SUPERADMIN_PWD)
pwd = hash_password(settings.SUPERADMIN_PWD)
session.add(
User(
provider_user_id=gh_user["id"],
Expand Down
2 changes: 1 addition & 1 deletion src/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ async def add_process_time_header(request: Request, call_next):

# Overrides swagger to include favicon
@app.get("/docs", include_in_schema=False)
async def swagger_ui_html():
def swagger_ui_html():
return get_swagger_ui_html(
openapi_url=f"{settings.API_V1_STR}/openapi.json",
title=settings.PROJECT_NAME,
Expand Down
8 changes: 4 additions & 4 deletions src/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ async def async_session() -> AsyncSession:
await session.rollback()


async def mock_verify_password(plain_password, hashed_password):
def mock_verify_password(plain_password, hashed_password):
return hashed_password == f"hashed_{plain_password}"


async def mock_hash_password(password):
def mock_hash_password(password):
return f"hashed_{password}"


Expand Down Expand Up @@ -152,9 +152,9 @@ async def guideline_session(user_session: AsyncSession, monkeypatch):
yield user_session


async def get_token(access_id: int, scopes: str) -> Dict[str, str]:
def get_token(access_id: int, scopes: str) -> Dict[str, str]:
token_data = {"sub": str(access_id), "scopes": scopes}
token = await create_access_token(token_data)
token = create_access_token(token_data)
return {"Authorization": f"Bearer {token}", "Content-Type": "application/json"}


Expand Down
2 changes: 1 addition & 1 deletion src/tests/endpoints/test_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async def test_chat(
):
auth = None
if isinstance(user_idx, int):
auth = await pytest.get_token(pytest.user_table[user_idx]["id"], pytest.user_table[user_idx]["scope"].split())
auth = pytest.get_token(pytest.user_table[user_idx]["id"], pytest.user_table[user_idx]["scope"].split())

response = await async_client.post("/code/chat", json=payload, headers=auth)
assert response.status_code == status_code, print(response.__dict__)
Expand Down
10 changes: 5 additions & 5 deletions src/tests/endpoints/test_guidelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async def test_create_guideline(
):
auth = None
if isinstance(user_idx, int):
auth = await pytest.get_token(pytest.user_table[user_idx]["id"], pytest.user_table[user_idx]["scope"].split())
auth = pytest.get_token(pytest.user_table[user_idx]["id"], pytest.user_table[user_idx]["scope"].split())

response = await async_client.post("/guidelines", json=payload, headers=auth)
assert response.status_code == status_code, print(response.__dict__)
Expand Down Expand Up @@ -62,7 +62,7 @@ async def test_get_guideline(
):
auth = None
if isinstance(user_idx, int):
auth = await pytest.get_token(pytest.user_table[user_idx]["id"], pytest.user_table[user_idx]["scope"].split())
auth = pytest.get_token(pytest.user_table[user_idx]["id"], pytest.user_table[user_idx]["scope"].split())

response = await async_client.get(f"/guidelines/{guideline_id}", headers=auth)
assert response.status_code == status_code, print(response.__dict__)
Expand Down Expand Up @@ -91,7 +91,7 @@ async def test_fetch_guidelines(
):
auth = None
if isinstance(user_idx, int):
auth = await pytest.get_token(pytest.user_table[user_idx]["id"], pytest.user_table[user_idx]["scope"].split())
auth = pytest.get_token(pytest.user_table[user_idx]["id"], pytest.user_table[user_idx]["scope"].split())

response = await async_client.get("/guidelines", headers=auth)
assert response.status_code == status_code, print(response.__dict__)
Expand Down Expand Up @@ -124,7 +124,7 @@ async def test_delete_guideline(
):
auth = None
if isinstance(user_idx, int):
auth = await pytest.get_token(pytest.user_table[user_idx]["id"], pytest.user_table[user_idx]["scope"].split())
auth = pytest.get_token(pytest.user_table[user_idx]["id"], pytest.user_table[user_idx]["scope"].split())

response = await async_client.request("DELETE", f"/guidelines/{guideline_id}", json={}, headers=auth)
assert response.status_code == status_code, print(response.__dict__)
Expand Down Expand Up @@ -159,7 +159,7 @@ async def test_update_guideline_content(
):
auth = None
if isinstance(user_idx, int):
auth = await pytest.get_token(pytest.user_table[user_idx]["id"], pytest.user_table[user_idx]["scope"].split())
auth = pytest.get_token(pytest.user_table[user_idx]["id"], pytest.user_table[user_idx]["scope"].split())

response = await async_client.patch(f"/guidelines/{guideline_id}", json=payload, headers=auth)
assert response.status_code == status_code, print(response.__dict__)
Expand Down
8 changes: 4 additions & 4 deletions src/tests/endpoints/test_repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async def test_create_repo(
):
auth = None
if isinstance(user_idx, int):
auth = await pytest.get_token(pytest.user_table[user_idx]["id"], pytest.user_table[user_idx]["scope"].split())
auth = pytest.get_token(pytest.user_table[user_idx]["id"], pytest.user_table[user_idx]["scope"].split())

response = await async_client.post("/repos", json=payload, headers=auth)
assert response.status_code == status_code, print(response.__dict__)
Expand Down Expand Up @@ -76,7 +76,7 @@ async def test_get_repo(
):
auth = None
if isinstance(user_idx, int):
auth = await pytest.get_token(pytest.user_table[user_idx]["id"], pytest.user_table[user_idx]["scope"].split())
auth = pytest.get_token(pytest.user_table[user_idx]["id"], pytest.user_table[user_idx]["scope"].split())

response = await async_client.get(f"/repos/{repo_id}", headers=auth)
assert response.status_code == status_code, print(response.__dict__)
Expand Down Expand Up @@ -105,7 +105,7 @@ async def test_fetch_repos(
):
auth = None
if isinstance(user_idx, int):
auth = await pytest.get_token(pytest.user_table[user_idx]["id"], pytest.user_table[user_idx]["scope"].split())
auth = pytest.get_token(pytest.user_table[user_idx]["id"], pytest.user_table[user_idx]["scope"].split())

response = await async_client.get("/repos", headers=auth)
assert response.status_code == status_code, print(response.__dict__)
Expand Down Expand Up @@ -138,7 +138,7 @@ async def test_delete_repo(
):
auth = None
if isinstance(user_idx, int):
auth = await pytest.get_token(pytest.user_table[user_idx]["id"], pytest.user_table[user_idx]["scope"].split())
auth = pytest.get_token(pytest.user_table[user_idx]["id"], pytest.user_table[user_idx]["scope"].split())

response = await async_client.delete(f"/repos/{repo_id}", headers=auth)
assert response.status_code == status_code, print(response.__dict__)
Expand Down
Loading

0 comments on commit 3627ff9

Please sign in to comment.