Skip to content

Commit

Permalink
fix: update pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
abusquets committed Aug 27, 2023
1 parent 074f0fc commit 23d7d3b
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 15 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,9 @@ jobs:
working-directory: ./src
run: |
poetry run pytest -c pytest.github.ini
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
13 changes: 9 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,25 @@ repos:


- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.280
rev: v0.0.286
hooks:
- id: ruff
args:
- --fix # Enables autofix
args: [--fix, --exit-non-zero-on-fix] # Enables autofix

- repo: https://github.com/psf/black # Refer to this repository for futher documentation about black hook
rev: 23.7.0
hooks:
- id: black


- repo: https://github.com/pycqa/bandit
rev: 1.7.5
hooks:
- id: bandit
args: [ "-iii", "-ll" ]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.4.1
rev: v1.5.1
hooks:
- id: mypy
args: [--config-file=mypy.ini, --ignore-missing-imports]
Expand Down
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,12 @@
"ruff.args": ["--config=${workspaceFolder}/pyproject.toml"],
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
},
"sonarlint.connectedMode.project": {
"connectionId": "alexandre-bussinero",
"projectKey": "alexandre-bussinero_abusquets-filmin"
},
"sonarlint.analyzerProperties": {

}
}
9 changes: 6 additions & 3 deletions src/app/session_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
from infra.cache.ports import AbstractCacheRepository


http_bearer = HTTPBearer()


def get_token_service() -> TokenService:
return AppContainer().token_service

Expand Down Expand Up @@ -46,23 +49,23 @@ async def _check_token(


async def check_access_token(
credentials: HTTPAuthorizationCredentials = Depends(HTTPBearer()),
credentials: HTTPAuthorizationCredentials = Depends(http_bearer),
cache_repository: AbstractCacheRepository = Depends(get_cache_repository),
token_service: TokenService = Depends(get_token_service),
) -> Session:
return await _check_token('a', credentials, cache_repository, token_service)


async def check_refresh_token(
credentials: HTTPAuthorizationCredentials = Depends(HTTPBearer()),
credentials: HTTPAuthorizationCredentials = Depends(http_bearer),
cache_repository: AbstractCacheRepository = Depends(get_cache_repository),
token_service: TokenService = Depends(get_token_service),
) -> Session:
return await _check_token('r', credentials, cache_repository, token_service)


async def is_admin_session(
credentials: HTTPAuthorizationCredentials = Depends(HTTPBearer()),
credentials: HTTPAuthorizationCredentials = Depends(http_bearer),
cache_repository: AbstractCacheRepository = Depends(get_cache_repository),
token_service: TokenService = Depends(get_token_service),
) -> Session:
Expand Down
3 changes: 2 additions & 1 deletion src/core/domain/entities/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ def encrypt_password(password: str) -> str:

@staticmethod
def verify_password(password: str, hashed: str) -> bool:
return bool(bcrypt.hashpw(password.encode(), hashed.encode()) == hashed.encode())
ret: bool = bcrypt.hashpw(password.encode(), hashed.encode()) == hashed.encode()
return ret


@dataclass(kw_only=True)
Expand Down
4 changes: 2 additions & 2 deletions src/infra/cache/memory_cache.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from threading import RLock
import time

from typing import Any, Dict, Union
from typing import Any, Dict, Optional

from infra.cache.ports import AbstractCacheRepository, EncodableT

Expand All @@ -27,7 +27,7 @@ async def get(self, key: str) -> Any:
self._data.pop(key, None)
return None

async def set(self, key: str, value: Union[EncodableT, None], expire: int) -> None:
async def set(self, key: str, value: Optional[EncodableT], expire: int) -> None:
with self.lock:
if value is None:
self._data.pop(key, None)
Expand Down
4 changes: 2 additions & 2 deletions src/infra/cache/ports.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import abc

from typing import Any, Union
from typing import Any, Optional, Union


EncodableT = Union[str, int, float, bytes]
Expand All @@ -12,7 +12,7 @@ async def get(self, key: str) -> Any:
...

@abc.abstractmethod
async def set(self, key: str, value: Union[EncodableT, None], expire: int) -> None:
async def set(self, key: str, value: Optional[EncodableT], expire: int) -> None:
...

@abc.abstractmethod
Expand Down
6 changes: 3 additions & 3 deletions src/infra/cache/redis_cache.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Union
from typing import Any, Optional

from redis import (
asyncio as aioredis,
Expand All @@ -11,7 +11,7 @@
@singleton
class RedisCache(AbstractCacheRepository):
def __init__(self, url: str, user: str, password: str) -> None:
self.redis: Union[aioredis.Redis, None] = None
self.redis: Optional[aioredis.Redis] = None
self.url = url
self.user = user
self.password = password
Expand All @@ -38,7 +38,7 @@ async def close(self) -> None:
async def get(self, key: str) -> Any:
return await (await self.get_redis()).get(key)

async def set(self, key: str, value: Union[EncodableT, None], expire: int) -> None:
async def set(self, key: str, value: Optional[EncodableT], expire: int) -> None:
"""expire: expiration in seconds"""
await self.get_redis()
if value is None:
Expand Down

0 comments on commit 23d7d3b

Please sign in to comment.