sts-sponsors team mailing list archive
-
sts-sponsors team
-
Mailing list archive
-
Message #05738
Re: [Merge] ~ack/maas:session-timeout-update-existing-sessions into maas:master
Review: Needs Information
Diff comments:
> diff --git a/src/maasserver/sessiontimeout.py b/src/maasserver/sessiontimeout.py
> index 6564b4d..42af51f 100644
> --- a/src/maasserver/sessiontimeout.py
> +++ b/src/maasserver/sessiontimeout.py
> @@ -1,15 +1,31 @@
> """ Custom sessionstore for a user-configurable session timeout. """
>
> -from django.contrib.sessions.backends.db import SessionStore as DBStore
> -
> -from maasserver.models import Config
> +from datetime import datetime, timedelta
>
> +from django.contrib.sessions.backends.db import SessionStore as DBStore
> +from django.db.models import F
> +from django.db.models.functions import Least
>
> -def _get_timeout() -> int:
> - timeout = Config.objects.get_config("session_length")
> - return timeout
> +from maasserver.models.config import Config, DEFAULT_CONFIG
>
>
> class SessionStore(DBStore):
> def get_session_cookie_age(self) -> int:
> - return _get_timeout()
> + return _get_session_length()
> +
> +
> +def update_sessions_expiration():
> + """Update sessions expiration date to match the session length"""
This docstring is incorrect. The expiration date will most likely not match the session length.
It's unfortunate that it's expire_date, and not session_start, so it's hard to know how long the session has been active.
How about instead calculating the difference of the session length and add/subtract from the expiration date accordingly?
> + expiry_date = datetime.utcnow() + timedelta(seconds=_get_session_length())
> + SessionStore.get_model_class().objects.update(
> + expire_date=Least(F("expire_date"), expiry_date)
> + )
> + SessionStore.clear_expired()
> +
> +
> +def _get_session_length() -> int:
> + """Return the session duration."""
> + return (
> + Config.objects.get_config("session_length")
> + or DEFAULT_CONFIG["session_length"]
> + )
--
https://code.launchpad.net/~ack/maas/+git/maas/+merge/438471
Your team MAAS Committers is subscribed to branch maas:master.
References