From a2525ebe7f03db405fc2548dcb195e8455a9f40b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hallet?= Date: Fri, 19 Mar 2021 11:30:18 +0100 Subject: [PATCH] linter --- djangosaml2idp/conf.py | 1 - djangosaml2idp/idp.py | 9 +++++---- djangosaml2idp/views.py | 14 ++++++-------- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/djangosaml2idp/conf.py b/djangosaml2idp/conf.py index 1d93de6..e52d7a3 100644 --- a/djangosaml2idp/conf.py +++ b/djangosaml2idp/conf.py @@ -5,7 +5,6 @@ from django.core.exceptions import ImproperlyConfigured from django.http import HttpRequest from django.utils.module_loading import import_string -from saml2.config import IdPConfig def get_callable(path: Union[Callable, str]) -> Callable: diff --git a/djangosaml2idp/idp.py b/djangosaml2idp/idp.py index 81f3136..541f03c 100644 --- a/djangosaml2idp/idp.py +++ b/djangosaml2idp/idp.py @@ -5,15 +5,16 @@ from saml2.config import IdPConfig from saml2.metadata import entity_descriptor from saml2.server import Server -from typing import Callable, Dict, Optional, TypeVar, Union +from typing import Callable, Dict, Optional, Union from .conf import get_callable, get_config + class IDP: """ Access point for the IDP Server instance """ _server_instances: Dict[str, Server] = {} - + @classmethod def construct_metadata(cls, idp_conf: dict, request: Optional[HttpRequest] = None, with_local_sp: bool = True) -> IdPConfig: """ Get the config including the metadata for all the configured service providers. """ @@ -42,7 +43,7 @@ def construct_metadata(cls, idp_conf: dict, request: Optional[HttpRequest] = Non def load(cls, request: Optional[HttpRequest] = None, config_loader_path: Optional[Union[Callable, str]] = None) -> Server: idp_conf = get_config(config_loader_path, request) if "entityid" not in idp_conf: - raise ImproperlyConfigured(f'The configuration must contain an entityid') + raise ImproperlyConfigured('The configuration must contain an entityid') entity_id = idp_conf["entityid"] if entity_id not in cls._server_instances: @@ -55,7 +56,7 @@ def load(cls, request: Optional[HttpRequest] = None, config_loader_path: Optiona @classmethod def flush(cls): cls._server_instances = {} - + @classmethod def metadata(cls, request: Optional[HttpRequest] = None, config_loader_path: Optional[Union[Callable, str]] = None) -> str: """ Get the IDP metadata as a string. """ diff --git a/djangosaml2idp/views.py b/djangosaml2idp/views.py index 5829364..41274f8 100644 --- a/djangosaml2idp/views.py +++ b/djangosaml2idp/views.py @@ -23,11 +23,9 @@ from django.views.decorators.http import require_http_methods from saml2 import BINDING_HTTP_POST, BINDING_HTTP_REDIRECT from saml2.authn_context import PASSWORD, AuthnBroker, authn_context_class_ref -from saml2.config import IdPConfig from saml2.ident import NameID from saml2.saml import NAMEID_FORMAT_UNSPECIFIED from saml2.server import Server -from saml2.s_utils import UnknownSystemEntity from .error_views import error_cbv from .idp import IDP @@ -86,7 +84,7 @@ def check_access(processor: BaseProcessor, request: HttpRequest) -> None: raise PermissionDenied(_("You do not have access to this resource")) -def get_sp_config(sp_entity_id: str, idp_server: IDP) -> ServiceProvider: +def get_sp_config(sp_entity_id: str, idp_server: Server) -> ServiceProvider: """ Get a dict with the configuration for a SP according to the SAML_IDP_SPCONFIG settings and the SP model. Raises an exception if no SP matching the given entity id can be found. """ @@ -111,7 +109,7 @@ def get_authn(req_info=None): return broker.get_authn_by_accr(req_authn_context) -def build_authn_response(user: User, authn, resp_args, service_provider: ServiceProvider, idp_server: IDP) -> list: # type: ignore +def build_authn_response(user: User, authn, resp_args, service_provider: ServiceProvider, idp_server: Server) -> list: # type: ignore """ pysaml2 server.Server.create_authn_response wrapper """ policy = resp_args.get('name_id_policy', None) @@ -149,16 +147,16 @@ def build_authn_response(user: User, authn, resp_args, service_provider: Service class IdPHandlerViewMixin: config_loader_path = getattr(settings, 'SAML_IDP_CONFIG_LOADER', None) - + def get_config_loader_path(self, request: HttpRequest): return self.config_loader_path - + def get_idp_server(self, request: HttpRequest) -> Server: return IDP.load(request, self.get_config_loader_path(request)) - + def get_idp_metadata(self, request: HttpRequest) -> str: return IDP.metadata(request, self.get_config_loader_path(request)) - + """ Contains some methods used by multiple views """ def render_login_html_to_string(self, context=None, request=None, using=None): """ Render the html response for the login action. Can be using a custom html template if set on the view. """