Source code for ska.contrib.django.ska.backends.constance_backend
import json
from typing import Dict, Optional, Union
from constance import config
from django.conf import settings
from django.http import HttpRequest
from rest_framework.request import Request
from .base import BaseSkaAuthenticationBackend
__author__ = "Artur Barseghyan <artur.barseghyan@gmail.com>"
__copyright__ = "2013-2023 Artur Barseghyan"
__license__ = "GPL-2.0-only OR LGPL-2.1-or-later"
__all__ = ("SkaAuthenticationConstanceBackend",)
[docs]
class SkaAuthenticationConstanceBackend(BaseSkaAuthenticationBackend):
"""Authentication backend."""
[docs]
def get_settings(
self,
request_data: Optional[Dict[str, Union[bytes, str, float, int]]] = None,
request: Optional[Union[Request, HttpRequest]] = None,
**kwargs,
) -> Dict[str, Dict[str, str]]:
"""Get settings.
:return:
"""
parse_from_json = getattr(
settings, "SKA_CONSTANCE_SETTINGS_PARSE_FROM_JSON", False
)
if parse_from_json:
try:
_settings = json.loads(config.SKA_PROVIDERS)
return _settings
except ValueError as err:
pass
return config.SKA_PROVIDERS
[docs]
def get_secret_key(
self,
request_data: Optional[Dict[str, Union[bytes, str, float, int]]] = None,
request: Optional[Union[Request, HttpRequest]] = None,
**kwargs,
) -> str:
"""Get secret key.
:return:
"""
return config.SKA_SECRET_KEY