-
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
46 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from datetime import timedelta | ||
from typing import Callable, Optional | ||
from uuid import uuid4 | ||
|
||
from pydantic_settings import BaseSettings | ||
|
||
|
||
def genSessionId() -> str: | ||
return uuid4().hex | ||
|
||
|
||
settings = {"sessionIdGenerator": genSessionId} | ||
|
||
|
||
class Config(BaseSettings): | ||
redisURL: str = "redis://localhost:6379/0" | ||
settings: dict = settings | ||
sessionIdName: str = "ssid" | ||
expireTime: timedelta = timedelta(hours=6) | ||
|
||
def genSessionId(self) -> str: | ||
return self.settings["sessionIdGenerator"]() | ||
|
||
|
||
config = Config() | ||
|
||
|
||
def basicConfig( | ||
redisURL: Optional[str] = "", | ||
sessionIdName: Optional[str] = "", | ||
sessionIdGenerator: Optional[Callable[[], str]] = None, | ||
expireTime: Optional[timedelta] = None, | ||
): | ||
if redisURL: | ||
config.redisURL = redisURL | ||
if sessionIdName: | ||
config.sessionIdName = sessionIdName | ||
if sessionIdGenerator: | ||
config.settings["sessionIdGenerator"] = sessionIdGenerator | ||
if expireTime: | ||
config.expireTime = expireTime |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters