chore: 纳入本地 Dify 1.19.0 源码及品牌与免登改动
演示目录只保留可重建的源码。运行密钥、数据卷、依赖和带口令的本地配置不进入仓库。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
60158935f4
commit
6519682885
15831 files changed
+3063428
No files matched your search
@@ -0,0 +1,52 @@
|
||||
"""Application service for the self-hosted initialization gate."""
|
||||
|
||||
import hmac
|
||||
from typing import Protocol
|
||||
|
||||
|
||||
class InitValidationState(Protocol):
|
||||
def has_tenants(self) -> bool: ...
|
||||
|
||||
def is_setup(self) -> bool: ...
|
||||
|
||||
|
||||
class AlreadyInitializedError(Exception):
|
||||
"""Raised when initialization has already created a tenant."""
|
||||
|
||||
|
||||
class InvalidInitializationPasswordError(Exception):
|
||||
"""Raised when the supplied initialization password does not match."""
|
||||
|
||||
|
||||
class InitValidationService:
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
state: InitValidationState,
|
||||
validation_required: bool,
|
||||
expected_password: str,
|
||||
) -> None:
|
||||
self._state = state
|
||||
self._validation_required = validation_required
|
||||
self._expected_password = expected_password
|
||||
|
||||
def is_validated(self, *, session_validated: bool) -> bool:
|
||||
if not self._validation_required or session_validated:
|
||||
return True
|
||||
|
||||
return self._state.is_setup()
|
||||
|
||||
def validate_password(self, password: str) -> None:
|
||||
if self._state.has_tenants():
|
||||
raise AlreadyInitializedError
|
||||
|
||||
expected_password = self._expected_password
|
||||
if (
|
||||
not password
|
||||
or not expected_password
|
||||
or not hmac.compare_digest(
|
||||
password.encode("utf-8"),
|
||||
expected_password.encode("utf-8"),
|
||||
)
|
||||
):
|
||||
raise InvalidInitializationPasswordError
|
||||
Reference in new issue
Block a user