[docs]@settings_dataclassclassDashboardAuthBasicSetting(BaseSetting):type:str="basic"algorithm:str="pbkdf2_sha256"users:Optional[FromFileSetting|dict[str,str]]=Nonedef__post_init__(self):FromFileSetting.may_override(self,"users")@cached_propertydefalgorithm_impl(self):ifself.algorithm=="plain":return_plain# todo check we do not import anything else than a valid algorithm implementationimpl=__import__("passlib.hash",fromlist=[self.algorithm])returngetattr(impl,self.algorithm).verify
[docs]defcheck(self,username,password):ifnotself.users:returnFalseifisinstance(self.users,dict):user=self.users.get(username)ifnotuser:returnFalseif"password"notinuser:returnFalseifnotself.algorithm_impl(password,user["password"]):returnFalsereturnusernameelse:raiseNotImplementedError("Only dict is supported for now")
[docs]def__new__(cls,**kwargs):_type=kwargs.pop("type",None)available_types=("basic",)if_typeisNoneornot_type:iflen(kwargs)>0:raiseConfigurationValueError("Invalid configuration for dashboard auth. There should not be additional arguments if no auth "f"type is provided. Available types: {', '.join(available_types)}.")returnNoneif_type=="basic":returnDashboardAuthBasicSetting(**kwargs)raiseConfigurationValueError(f"Invalid dashboard auth type: {_type}. Available types: {', '.join(available_types)}.")
[docs]@settings_dataclassclassDashboardSettings(BaseSetting):"""Root settings for the dashboard."""port:int|str=4080auth:Optional[DashboardAuthSetting]=Nonedevserver:Optional[DashboardDevserverSettings]=Nonedef__post_init__(self):ifisinstance(self.auth,str):raiseConfigurationRemovedSettingError("Invalid configuration for dashboard auth: string configuration is not supported anymore.")ifisinstance(self.auth,dict):object.__setattr__(self,"auth",DashboardAuthSetting(**self.auth))ifself.devserverisNone:object.__setattr__(self,"devserver",DashboardDevserverSettings())ifisinstance(self.devserver,dict):object.__setattr__(self,"devserver",DashboardDevserverSettings(**self.devserver))