Skip to content

Commit 56e6570

Browse files
authored
feat: disable ldap default (#215)
1 parent a842368 commit 56e6570

File tree

4 files changed

+167
-25
lines changed

4 files changed

+167
-25
lines changed

FasterRunner/settings/base.py

+28-25
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"rest_framework_swagger",
5656
"drf_yasg",
5757
"system",
58-
"django_auth_ldap",
58+
# "django_auth_ldap",
5959
"mock",
6060
]
6161

@@ -344,32 +344,35 @@
344344
EMAIL_HOST_PASSWORD = os.environ.get("EMAIL_HOST_PASSWORD") # 对应的授权码
345345
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
346346

347-
348-
# LDAP配置
349-
import ldap
350-
from django_auth_ldap.config import LDAPSearch
351-
352347
USE_LDAP = False # 如果需要开启LDAP认证,就设置位True
353348

354-
if USE_LDAP:
355-
AUTHENTICATION_BACKENDS = ("django_auth_ldap.backend.LDAPBackend",)
356-
357-
AUTH_LDAP_SERVER_URI = "ldap://localhost:389" # LDAP服务器地址,默认端口389
358-
359-
AUTH_LDAP_BIND_DN = "cn=admin,dc=myorg,dc=com" # LDAP管理员账号
360-
AUTH_LDAP_BIND_PASSWORD = "admin" # LDAP管理员密码
361-
AUTH_LDAP_USER_SEARCH = LDAPSearch(
362-
"ou=Tester,dc=myorg,dc=com",
363-
ldap.SCOPE_SUBTREE,
364-
"(uid=%(user)s)",
365-
) # LDAP搜索账号,ou可以理解为组织单位或者部门,不填写也是ok,dc可以理解为域名
366-
367-
AUTH_LDAP_USER_ATTR_MAP = {
368-
"username": "uid",
369-
"first_name": "givenName",
370-
"last_name": "sn",
371-
"email": "mail",
372-
}
349+
# LDAP配置
350+
try:
351+
import ldap
352+
from django_auth_ldap.config import LDAPSearch
353+
except (ModuleNotFoundError, NameError):
354+
pass
355+
else:
356+
357+
if USE_LDAP:
358+
AUTHENTICATION_BACKENDS = ("django_auth_ldap.backend.LDAPBackend",)
359+
360+
AUTH_LDAP_SERVER_URI = "ldap://localhost:389" # LDAP服务器地址,默认端口389
361+
362+
AUTH_LDAP_BIND_DN = "cn=admin,dc=myorg,dc=com" # LDAP管理员账号
363+
AUTH_LDAP_BIND_PASSWORD = "admin" # LDAP管理员密码
364+
AUTH_LDAP_USER_SEARCH = LDAPSearch(
365+
"ou=Tester,dc=myorg,dc=com",
366+
ldap.SCOPE_SUBTREE,
367+
"(uid=%(user)s)",
368+
) # LDAP搜索账号,ou可以理解为组织单位或者部门,不填写也是ok,dc可以理解为域名
369+
370+
AUTH_LDAP_USER_ATTR_MAP = {
371+
"username": "uid",
372+
"first_name": "givenName",
373+
"last_name": "sn",
374+
"email": "mail",
375+
}
373376

374377
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
375378
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"

requirements.txt

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
aiocontextvars==0.2.2
2+
amqp==5.2.0
3+
beautifulsoup4==4.6.3
4+
celery==5.2.7,<5.3.0
5+
certifi==2019.9.11
6+
chardet==3.0.4
7+
colorama==0.4.1
8+
colorlog==4.0.2
9+
contextvars==2.4
10+
coreapi==2.3.3
11+
coreschema==0.0.4
12+
dingtalkchatbot==1.3.0
13+
django==4.1.13
14+
django-celery-beat==2.5.0
15+
django-cors-headers==4.3.1
16+
django-jsonfield==1.4.0
17+
django-model-utils==4.0.0
18+
django-rest-swagger==2.2.0
19+
django-simpleui==2023.12.12
20+
django-utils-six==2.0
21+
djangorestframework==3.14.0
22+
djangorestframework-jwt==1.11.0
23+
drf-yasg==1.21.7
24+
packaging==23.2
25+
har2case==0.3.1
26+
idna==2.8
27+
inflection==0.5.0
28+
jinja2==2.10.3
29+
loguru==0.5.1
30+
markupsafe==1.1.1
31+
openapi-codec==1.3.2
32+
pyjwt==1.7.1
33+
pyparsing==2.4.7
34+
python-dotenv==0.10.3
35+
pytz==2022.2.1
36+
pyyaml==5.3.1,<5.4.0
37+
requests==2.22.0
38+
requests-toolbelt==0.9.1
39+
simplejson==3.17.0
40+
six==1.15.0
41+
sqlparse==0.3.1
42+
tornado==6.4
43+
uritemplate==3.0.1
44+
urllib3==1.25.7
45+
django-mysql==4.12.0
46+
json5==0.9.5
47+
django-bulk-update==2.2.0
48+
xmltodict==0.12.0,<0.13.0
49+
genson==1.2.2,<1.3.0
50+
faker==7.0.1,<7.1.0
51+
curlify==2.2.1,<2.3.0
52+
pydash==5.0.1,<5.1.0
53+
jsonpath==0.82,<1.0
54+
pydantic==1.9.0
55+
gunicorn==21.2.0
56+
sentry-sdk==1.5.8,<1.6.0
57+
croniter==1.3.5,<1.4.0
58+
django-log-request-id==2.0.0,<2.1.0
59+
gevent==22.10.2
60+
django-filter==2.4.0,<2.5.0
61+
#django-auth-ldap==2.3.0
62+
pymysql==1.1.0
63+
pytest==8.1.1
64+
pytest-django==4.8.0

start.bat

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@echo off
2+
set input=%1
3+
4+
if "%input%"=="app" (
5+
echo start app
6+
set DJANGO_SETTINGS_MODULE=FasterRunner.settings.dev
7+
python manage.py runserver localhost:8000
8+
)
9+

web/nginx_localhost.conf

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
2+
server {
3+
listen 80;
4+
#server_name 8.129.237.137; # 修改为docker服务宿主机的ip
5+
6+
proxy_set_header Host $host;
7+
proxy_set_header X-Real-IP $remote_addr;
8+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
9+
proxy_set_header X-Forwarded-Proto $scheme;
10+
11+
location / {
12+
root ./dist;
13+
index index.html index.htm;
14+
try_files $uri $uri/ /index.html =404;
15+
gzip on;
16+
gzip_comp_level 6;
17+
gzip_min_length 1k;
18+
gzip_buffers 4 16k;
19+
gzip_proxied any;
20+
gzip_vary on;
21+
gzip_types
22+
application/javascript
23+
application/x-javascript
24+
text/javascript
25+
text/css
26+
text/xml
27+
application/xhtml+xml
28+
application/xml
29+
application/atom+xml
30+
application/rdf+xml
31+
application/rss+xml
32+
application/geo+json
33+
application/json
34+
application/ld+json
35+
application/manifest+json
36+
application/x-web-app-manifest+json
37+
image/svg+xml
38+
image/jpeg
39+
image/gif
40+
image/png
41+
text/x-cross-domain-policy;
42+
gzip_static on;
43+
}
44+
45+
location /api {
46+
proxy_pass http://localhost:8000;
47+
}
48+
49+
location /mock {
50+
proxy_pass http://localhost:8000;
51+
}
52+
53+
# 测试报告接口
54+
location /api/fastrunner/reports {
55+
proxy_pass http://localhost:8000;
56+
}
57+
# 测试报告静态文件
58+
location /static/extent.js {
59+
proxy_pass http://localhost:8000;
60+
}
61+
62+
error_page 500 502 503 504 /50x.html;
63+
location = /50x.html {
64+
root html;
65+
}
66+
}

0 commit comments

Comments
 (0)