Merge pull request #11062 from jumpserver/pr@dev@for_django4

perf: 修改写法
pull/11064/head
老广 2023-07-24 18:10:04 +08:00 committed by GitHub
commit 5b1ae46153
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 19 deletions

View File

@ -2,8 +2,12 @@
#
import datetime
import inspect
import sys
from collections.abc import Iterable
if sys.version_info.major == 3 and sys.version_info.minor >= 10:
from collections.abc import Iterable
else:
from collections import Iterable
from functools import reduce, partial
from itertools import groupby
from uuid import UUID
@ -19,7 +23,6 @@ from common.utils import get_logger
from common.utils.timezone import local_now_date_display
from common.exceptions import JMSException
logger = get_logger(__file__)

View File

@ -514,10 +514,9 @@ class Config(dict):
'TIME_ZONE': 'Asia/Shanghai',
'FORCE_SCRIPT_NAME': '',
'SESSION_COOKIE_SECURE': False,
'ALLOWED_HOSTS': '',
'DOMAINS': '',
'CSRF_COOKIE_SECURE': False,
'REFERER_CHECK_ENABLED': False,
'CSRF_TRUSTED_ORIGINS': '',
'SESSION_ENGINE': 'cache',
'SESSION_SAVE_EVERY_REQUEST': True,
'SESSION_EXPIRE_AT_BROWSER_CLOSE_FORCE': False,

View File

@ -67,21 +67,36 @@ SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
# LOG LEVEL
LOG_LEVEL = CONFIG.LOG_LEVEL
DOMAINS = CONFIG.DOMAINS or CONFIG.SITE_URL
ALLOWED_DOMAINS = DOMAINS.split(',') if DOMAINS else ['localhost:8080']
ALLOWED_DOMAINS = [host.strip() for host in ALLOWED_DOMAINS]
ALLOWED_DOMAINS = [host.replace('http://', '').replace('https://', '') for host in ALLOWED_DOMAINS if host]
ALLOWED_DOMAINS = [host.split('/')[0] for host in ALLOWED_DOMAINS if host]
ALLOWED_HOSTS = CONFIG.ALLOWED_HOSTS.split(',') if CONFIG.ALLOWED_HOSTS else ['localhost', '127.0.0.1']
DEBUG_HOSTS = ['127.0.0.1', 'localhost']
DEBUG_PORT = ['8080', '80', '443', '4200', '9528']
if DEBUG:
DEBUG_HOST_PORTS = ['{}:{}'.format(host, port) for host in DEBUG_HOSTS for port in DEBUG_PORT]
ALLOWED_DOMAINS.extend(DEBUG_HOST_PORTS)
ALLOWED_HOSTS = list(set(['.' + host.split(':')[0] for host in ALLOWED_DOMAINS]))
print("ALLOWED_HOSTS: ", ALLOWED_HOSTS)
# https://docs.djangoproject.com/en/4.1/ref/settings/#std-setting-CSRF_TRUSTED_ORIGINS
CSRF_TRUSTED_ORIGINS = []
for origin in ALLOWED_HOSTS:
# 避免错误 先判断一下吧
if origin.startswith('http'):
CSRF_TRUSTED_ORIGINS.append(origin)
continue
if origin.startswith('.'):
origin = '*.'
for schema in ['https', 'http']:
CSRF_TRUSTED_ORIGINS.append('{}://{}'.format(schema, origin))
for host in ALLOWED_DOMAINS:
host = host.strip('.')
if host.startswith('http'):
CSRF_TRUSTED_ORIGINS.append(host)
continue
for schema in ['https', 'http']:
# CSRF_TRUSTED_ORIGINS.append('{}://{}'.format(schema, host))
CSRF_TRUSTED_ORIGINS.append('{}://*.{}'.format(schema, host))
print("CSRF_TRUSTED_ORIGINS: ")
for origin in CSRF_TRUSTED_ORIGINS:
print(' - ' + origin)
# Max post update field num
DATA_UPLOAD_MAX_NUMBER_FIELDS = 10000

View File

@ -7,16 +7,14 @@ azure-mgmt-network==23.1.0
google-cloud-compute==1.13.0
grpcio==1.56.2
alibabacloud_dysmsapi20170525==2.0.24
python-novaclient==11.0.1
python-novaclient==18.3.0
python-keystoneclient==5.1.0
bce-python-sdk==0.8.87
tencentcloud-sdk-python==3.0.941
aliyun-python-sdk-core-v3==2.13.33
aliyun-python-sdk-ecs==4.24.64
huaweicloud-sdk-python==1.0.28
# python-keystoneclient need keystoneauth1>=3.4.0
# huaweicloud-sdk-python need keystoneauth1<=3.4.0
keystoneauth1==3.4.0
#huaweicloud-sdk-python==1.0.28
keystoneauth1==5.2.1
# DB requirements
oracledb==1.3.2
psycopg2-binary==2.9.6