Skip to content

Commit

Permalink
#13 More on typing
Browse files Browse the repository at this point in the history
  • Loading branch information
barseghyanartur committed Jun 12, 2021
1 parent 6c08e6e commit 3576509
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/ska/contrib/django/ska/backends/base.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import logging
from typing import Dict, Optional, Union

from django.core.exceptions import PermissionDenied
from django.contrib.auth.hashers import make_password
from django.contrib.auth.models import User
from django.db import IntegrityError
from django.http import HttpRequest
from rest_framework.request import Request

from ..... import Signature, extract_signed_request_data
from .....helpers import get_callback_func
Expand Down Expand Up @@ -38,7 +41,12 @@
class BaseSkaAuthenticationBackend(object):
"""Base authentication backend."""

def get_settings(self, request_data=None, request=None, **kwargs):
def get_settings(
self,
request_data: Dict[str, Union[bytes, str, float, int]] = None,
request: HttpRequest = None,
**kwargs,
):
"""Get settings.
:return:
Expand All @@ -47,7 +55,12 @@ def get_settings(self, request_data=None, request=None, **kwargs):
"You should implement this method in your authentication backend"
)

def get_secret_key(self, request_data=None, request=None, **kwargs):
def get_secret_key(
self,
request_data: Dict[str, Union[bytes, str, float, int]] = None,
request: HttpRequest = None,
**kwargs,
) -> str:
"""Get secret key.
:return:
Expand All @@ -56,10 +69,14 @@ def get_secret_key(self, request_data=None, request=None, **kwargs):
"You should implement this method in your authentication backend"
)

def get_request_data(self, request, **kwargs):
def get_request_data(
self, request: Union[HttpRequest, Request], **kwargs
) -> Dict[str, str]:
return request.GET.dict()

def authenticate(self, request, **kwargs):
def authenticate(
self, request: Union[HttpRequest, Request], **kwargs
) -> Optional[User]:
"""Authenticate.
:param django.http.HttpRequest request:
Expand Down Expand Up @@ -213,7 +230,7 @@ def authenticate(self, request, **kwargs):

return user

def get_user(self, user_id):
def get_user(self, user_id: int) -> User:
"""Get user in the ``django.contrib.auth.models.User`` if exists.
:param int user_id:
Expand Down

0 comments on commit 3576509

Please sign in to comment.