mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-09 03:09:34 +00:00
[Update] 优化 dynamic settings (#4107)
This commit is contained in:
@@ -1,12 +1,46 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
#
|
#
|
||||||
import os
|
import os
|
||||||
from .conf import ConfigManager
|
|
||||||
|
|
||||||
__all__ = ['BASE_DIR', 'PROJECT_DIR', 'VERSION', 'CONFIG', 'DYNAMIC']
|
from werkzeug.local import LocalProxy
|
||||||
|
|
||||||
|
from .conf import ConfigManager
|
||||||
|
from common.local import thread_local
|
||||||
|
|
||||||
|
__all__ = ['BASE_DIR', 'PROJECT_DIR', 'VERSION', 'CONFIG', 'DYNAMIC', 'LOCAL_DYNAMIC_SETTINGS']
|
||||||
|
|
||||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
PROJECT_DIR = os.path.dirname(BASE_DIR)
|
PROJECT_DIR = os.path.dirname(BASE_DIR)
|
||||||
VERSION = '2.0.0'
|
VERSION = '2.0.0'
|
||||||
CONFIG = ConfigManager.load_user_config()
|
CONFIG = ConfigManager.load_user_config()
|
||||||
DYNAMIC = ConfigManager.get_dynamic_config(CONFIG)
|
DYNAMIC = ConfigManager.get_dynamic_config(CONFIG)
|
||||||
|
|
||||||
|
|
||||||
|
class _Settings:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def get_dynamic_cfg_from_thread_local():
|
||||||
|
KEY = 'dynamic_config'
|
||||||
|
|
||||||
|
try:
|
||||||
|
cfg = getattr(thread_local, KEY)
|
||||||
|
except AttributeError:
|
||||||
|
cfg = _Settings()
|
||||||
|
setattr(thread_local, KEY, cfg)
|
||||||
|
|
||||||
|
return cfg
|
||||||
|
|
||||||
|
|
||||||
|
class DynamicDefaultLocalProxy(LocalProxy):
|
||||||
|
def __getattr__(self, item):
|
||||||
|
try:
|
||||||
|
value = super().__getattr__(item)
|
||||||
|
except AttributeError:
|
||||||
|
value = getattr(DYNAMIC, item)()
|
||||||
|
setattr(self, item, value)
|
||||||
|
|
||||||
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
LOCAL_DYNAMIC_SETTINGS = DynamicDefaultLocalProxy(get_dynamic_cfg_from_thread_local)
|
||||||
|
@@ -16,6 +16,7 @@ from django.utils.translation import ugettext_lazy as _
|
|||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.shortcuts import reverse
|
from django.shortcuts import reverse
|
||||||
|
|
||||||
|
from jumpserver.const import LOCAL_DYNAMIC_SETTINGS
|
||||||
from orgs.utils import current_org
|
from orgs.utils import current_org
|
||||||
from common.utils import signer, date_expired_default, get_logger, lazyproperty
|
from common.utils import signer, date_expired_default, get_logger, lazyproperty
|
||||||
from common import fields
|
from common import fields
|
||||||
@@ -394,7 +395,7 @@ class MFAMixin:
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def mfa_force_enabled(self):
|
def mfa_force_enabled(self):
|
||||||
if settings.SECURITY_MFA_AUTH:
|
if LOCAL_DYNAMIC_SETTINGS.SECURITY_MFA_AUTH:
|
||||||
return True
|
return True
|
||||||
return self.mfa_level == 2
|
return self.mfa_level == 2
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user