mirror of
https://github.com/Garmelon/PFERD.git
synced 2026-04-12 15:35:05 +02:00
Implement switch from ShibbolethLogintype to Literal["shibboleth"]
This commit is contained in:
parent
d219dd6337
commit
27667822eb
2 changed files with 9 additions and 15 deletions
|
|
@ -28,10 +28,6 @@ from .shibboleth_login import ShibbolethLogin
|
||||||
TargetType = Union[str, int]
|
TargetType = Union[str, int]
|
||||||
|
|
||||||
|
|
||||||
class ShibbolethLoginType():
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class LoginTypeLocal:
|
class LoginTypeLocal:
|
||||||
def __init__(self, client_id: str):
|
def __init__(self, client_id: str):
|
||||||
self.client_id = client_id
|
self.client_id = client_id
|
||||||
|
|
@ -45,17 +41,17 @@ class IliasWebCrawlerSection(HttpCrawlerSection):
|
||||||
|
|
||||||
return base_url
|
return base_url
|
||||||
|
|
||||||
def login(self) -> Union[Literal["shibboleth"], LocalLoginType]:
|
def login(self) -> Union[Literal["shibboleth"], LoginTypeLocal]:
|
||||||
login_type = self.s.get("login_type")
|
login_type = self.s.get("login_type")
|
||||||
if not login_type:
|
if not login_type:
|
||||||
self.missing_value("login_type")
|
self.missing_value("login_type")
|
||||||
if login_type == "shibboleth":
|
if login_type == "shibboleth":
|
||||||
return ShibbolethLoginType()
|
return "shibboleth"
|
||||||
elif login_type == "local":
|
elif login_type == "local":
|
||||||
client_id = self.s.get("client_id")
|
client_id = self.s.get("client_id")
|
||||||
if not client_id:
|
if not client_id:
|
||||||
self.missing_value("client_id")
|
self.missing_value("client_id")
|
||||||
return LocalLoginType(client_id)
|
return LoginTypeLocal(client_id)
|
||||||
|
|
||||||
self.invalid_value("login_type", login_type,
|
self.invalid_value("login_type", login_type,
|
||||||
"Should be <shibboleth | local>")
|
"Should be <shibboleth | local>")
|
||||||
|
|
@ -190,7 +186,7 @@ instance's greatest bottleneck.
|
||||||
self._tfa_auth = section.tfa_auth(authenticators)
|
self._tfa_auth = section.tfa_auth(authenticators)
|
||||||
|
|
||||||
self._login_type = section.login()
|
self._login_type = section.login()
|
||||||
if isinstance(self._login_type, LocalLoginType):
|
if isinstance(self._login_type, LoginTypeLocal):
|
||||||
self._client_id = self._login_type.client_id
|
self._client_id = self._login_type.client_id
|
||||||
else:
|
else:
|
||||||
self._shibboleth_login = ShibbolethLogin(self._base_url, self._auth, self._tfa_auth)
|
self._shibboleth_login = ShibbolethLogin(self._base_url, self._auth, self._tfa_auth)
|
||||||
|
|
@ -999,7 +995,7 @@ instance's greatest bottleneck.
|
||||||
@_iorepeat(3, "Login", failure_is_error=True)
|
@_iorepeat(3, "Login", failure_is_error=True)
|
||||||
async def _authenticate(self) -> None:
|
async def _authenticate(self) -> None:
|
||||||
# fill the session with the correct cookies
|
# fill the session with the correct cookies
|
||||||
if isinstance(self._login_type, ShibbolethLoginType):
|
if self._login_type == "shibboleth":
|
||||||
await self._shibboleth_login.login(self.session)
|
await self._shibboleth_login.login(self.session)
|
||||||
else:
|
else:
|
||||||
params = {
|
params = {
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,11 @@
|
||||||
from typing import Dict, Union
|
from typing import Dict, Literal
|
||||||
|
|
||||||
from ...auth import Authenticator
|
from ...auth import Authenticator
|
||||||
from ...config import Config
|
from ...config import Config
|
||||||
from .async_helper import _iorepeat
|
from .async_helper import _iorepeat
|
||||||
from .ilias_web_crawler import IliasWebCrawler, IliasWebCrawlerSection, ShibbolethLoginType
|
from .ilias_web_crawler import IliasWebCrawler, IliasWebCrawlerSection
|
||||||
from .shibboleth_login import ShibbolethLogin
|
from .shibboleth_login import ShibbolethLogin
|
||||||
|
|
||||||
TargetType = Union[str, int]
|
|
||||||
|
|
||||||
_ILIAS_URL = "https://ilias.studium.kit.edu"
|
_ILIAS_URL = "https://ilias.studium.kit.edu"
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -19,8 +17,8 @@ class KitIliasWebCrawlerSection(IliasWebCrawlerSection):
|
||||||
def base_url(self) -> str:
|
def base_url(self) -> str:
|
||||||
return _ILIAS_URL
|
return _ILIAS_URL
|
||||||
|
|
||||||
def login(self) -> ShibbolethLoginType:
|
def login(self) -> Literal["shibboleth"]:
|
||||||
return ShibbolethLoginType()
|
return "shibboleth"
|
||||||
|
|
||||||
|
|
||||||
class KitIliasWebCrawler(IliasWebCrawler):
|
class KitIliasWebCrawler(IliasWebCrawler):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue