Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update master #1

Merged
merged 91 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
7088fb9
use 3.10 instead of 3.10.0 (#2030)
LeoQuote Jan 12, 2023
6fd73e9
update coverage upload (#2035)
LeoQuote Jan 12, 2023
eba3e33
Bump django from 4.1.1 to 4.1.2 (#1979)
dependabot[bot] Jan 13, 2023
c0f41a4
mongo engine优化 (#2018)
nick2wang Jan 14, 2023
4fdf73c
:sparkles: 增加OIDC登入功能 (#2028)
shing6326 Jan 17, 2023
b3a08ef
变更dockerfile-base (#2021)
peng19832 Jan 17, 2023
1d47bd2
更新dockerfile (#2037)
peng19832 Jan 20, 2023
fefb8fc
do not use tsinghua source (#2041)
LeoQuote Jan 30, 2023
cef6e68
add config for ban_self_audit (#2040)
delphid Jan 31, 2023
4246273
fix black check (#2046)
LeoQuote Feb 8, 2023
0eee241
upgrade ace.js==1.15.0 (#2045)
Yebolin Feb 9, 2023
0b0167f
feat(mysql): 添加ddl_dml不能同时提交的逻辑 (#2060)
summingyu Feb 25, 2023
b18de11
Bump django from 4.1.2 to 4.1.7 (#2054)
dependabot[bot] Feb 25, 2023
96094b4
fix: 支持使用create or replace创建函数、存储过程、视图以及包等语句 (#2066)
songtao12 Mar 11, 2023
69c78c0
add parameters in clickhouse and mysql engine to avoid sql injection …
LeoQuote Mar 13, 2023
38d7a19
Revert "add parameters in clickhouse and mysql engine to avoid sql in…
hhyo Mar 13, 2023
db971d1
修复mongo会话管理报错 (#2079)
nick2wang Mar 16, 2023
c873c38
自动识别Oracle SQL上线文本中的PLSQL程序块 (#2071)
songtao12 Mar 22, 2023
17bca47
修复表格服务端分页导出数据不全问题 (#2093)
nick2wang Mar 27, 2023
f275b56
修复开启2fa登录后无法更新ding_user_id的问题 (#2104)
nick2wang Mar 31, 2023
e2573b7
engine增加escape_string用于处理字符串参数转义 (#2107)
hhyo Apr 1, 2023
f611f03
Revert "engine增加escape_string用于处理字符串参数转义" (#2109)
hhyo Apr 1, 2023
efbaa81
数据库管理和账号管理支持MongoDB (#2108)
quanbisen Apr 5, 2023
bc8a1e3
更新功能清单
hhyo Apr 5, 2023
7921044
engine查询增加参数化选项,修改sql参数化方式 (#2112)
hhyo Apr 9, 2023
7632b3d
解决会话管理表格可能加载错误的问题 (#2113)
hhyo Apr 9, 2023
5484ebd
解决平台报错:'NoneType' object is not subscriptable (#2132)
songtao12 Apr 24, 2023
09231d3
Bump django from 4.1.7 to 4.1.9 (#2152)
dependabot[bot] May 14, 2023
73cd611
增加sql变更语句 (#2116)
hhyo May 14, 2023
f8f1a8e
新增钉钉认证登录 Feature/dingding login (#2171)
quanbisen May 29, 2023
7f4b413
Bump requests from 2.28.0 to 2.31.0 (#2166)
dependabot[bot] May 29, 2023
4bca447
fixed thirdparty auth priority (#2180)
quanbisen Jun 2, 2023
59c89bc
allow client customize their own filename (#2188)
te87037 Jun 16, 2023
07ef383
调整instance_account唯一索引 (#2179)
nick2wang Jun 18, 2023
a794389
查询超时也要记录日志 (#2110)
woshiyanghai Jun 18, 2023
1ef4374
将阿里云RDS的功能抽到单独engine (#2087)
weideguo Jun 18, 2023
cdbd12e
修复之前的commit带入的bug (#2197)
weideguo Jul 7, 2023
cedc1f3
add ssl conn support to redis (#2215)
bobfantansy Jul 17, 2023
6c0d15a
add numberlong type support to mongo (#2224)
cyqxyy Aug 2, 2023
4afe3e6
sql advisor sql 注入修复 (#2229)
LeoQuote Aug 10, 2023
6018ae8
Bump django from 4.1.9 to 4.1.10 (#2203)
dependabot[bot] Aug 15, 2023
d503b55
add cassandra support (#2230)
LeoQuote Aug 16, 2023
aecd90b
fix cassandra frontend bug (#2240)
LeoQuote Aug 16, 2023
293e26e
默认不显示传统登录 (#2241)
LeoQuote Aug 16, 2023
a2c9c3e
delete unused dependency (#2243)
LeoQuote Aug 17, 2023
11176ae
Update docker-compose.yml,hhyo/archery更改为v1.10.0 (#2245)
ivan-lol Aug 18, 2023
eabb990
修复mongo执行sql语句超过4000工单失败的问题 (#2250)
woshiyanghai Aug 21, 2023
5e5c0f8
fix typo pgsql (#2254)
LeoQuote Aug 22, 2023
9d01416
修复钉钉认证登录失败 (#2269)
quanbisen Aug 25, 2023
61f493e
fix #2252 (#2266)
tonyhu214 Aug 28, 2023
6ae3355
Mongo check (#2292)
woshiyanghai Sep 12, 2023
9915cd6
redis没有密码配置的情况 (#2293)
woshiyanghai Sep 13, 2023
2f977b3
Add schemasync with charset args (#2296)
te87037 Sep 18, 2023
df48b0f
Bump pillow from 9.3.0 to 10.0.1 (#2309)
dependabot[bot] Oct 6, 2023
d69227c
fix: 手动更新 redis 依赖至 4.1.0 (#2311)
Maxcj Oct 6, 2023
c1f3a37
修复sql查询页面,数据库类型为PgSQL, schema下拉列表不显示的问题 (#2283)
CrusM Oct 8, 2023
929ef03
fix sign up button (#2315)
LeoQuote Oct 8, 2023
faf8f98
escape on js variables (#2318)
LeoQuote Oct 9, 2023
d4b5ea9
Fix favicon and opt nav (#2316)
finovy Oct 10, 2023
815cbd5
opt login form & support OIDC_BTN_NAME (#2329)
finovy Oct 13, 2023
c8fac7e
add generic webhook (#2333)
LeoQuote Oct 19, 2023
1fbf6ed
新增cas登录认证 (#2340)
lanheader Oct 20, 2023
fa2bb13
用 WorkflowType 和 WorkflowStatus 两个 enum 替换WorkflowDict (#2344)
LeoQuote Oct 23, 2023
2411ca0
脱敏规则不区分大小写 (#2347)
woshiyanghai Oct 25, 2023
785d317
针对性修复 sql_analyze 读取文件的 bug (#2349)
LeoQuote Oct 25, 2023
3cdfba0
删除redis帮助文档中多余的字符 (#2343)
Maxcj Oct 30, 2023
ba985e9
重构 audit 相关代码, 改为面向对象实现 (#2348)
LeoQuote Nov 3, 2023
f959849
初始化 notify 时自动根据 workflow audit 取 workflow (#2363)
LeoQuote Nov 6, 2023
d32d7bc
新增sql执行行数限制 (#2366)
lanheader Nov 6, 2023
9183bcc
正常设置自动通过的工单 (#2369)
LeoQuote Nov 7, 2023
3af3588
修复sql query 审核回调 (#2370)
LeoQuote Nov 7, 2023
e25bd54
Bump django from 4.1.10 to 4.1.13 (#2362)
dependabot[bot] Nov 7, 2023
2a42d5c
示例建表语句优化 (#2194)
weideguo Nov 7, 2023
ff69c39
修复无法展现SQL历史趋势图 (#2380)
Grain-Yu Nov 14, 2023
5597911
Revert "新增sql执行行数限制" (#2388)
LeoQuote Nov 16, 2023
86f1bf6
docker-compose 增加注释, 提醒用户自行更改版本 (#2399)
LeoQuote Nov 21, 2023
594b146
修复审批流创建时的若干bug (#2400)
LeoQuote Nov 21, 2023
3625b33
待审批的查询和上线工单, 都显示审批人用户名 (#2394)
LeoQuote Nov 21, 2023
7f5e9bd
在不启用 oidc, dingding 认证时, 不include 对应的路由 (#2401)
LeoQuote Nov 21, 2023
1e06868
用 python 镜像替代 centos, 升级 python 到 3.11 (#2389)
LeoQuote Nov 22, 2023
e44bd9f
use debian as base (#2391)
LeoQuote Nov 23, 2023
45d7129
实例账号管理功能兼容 mariadb (#2404)
LeoQuote Nov 23, 2023
64e5dbe
feat:support mongodb commit sql with comments (#2403)
linhuih Nov 23, 2023
5fd57db
修复 notify 的bug (#2405)
LeoQuote Nov 23, 2023
527eb30
修复表结构显示不正确的 bug (#2406)
LeoQuote Nov 23, 2023
280f28d
修复页面实例选项空白问题 (#2411)
lanheader Nov 24, 2023
90fc156
修复最新基础镜像mssql连接问题 (#2407)
hhyo Nov 25, 2023
828e1d7
补充遗漏的企业微信自建应用的通知 (#2409)
LeoQuote Nov 25, 2023
d8159f4
移除dockerize,使用原生healthcheck (#2413)
hhyo Nov 25, 2023
73c93e6
更新base为sha-d8159f4 (#2414)
hhyo Nov 25, 2023
f483213
修复查询 tab 随意跳转的 bug (#2412)
LeoQuote Nov 26, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions .coveragerc

This file was deleted.

10 changes: 8 additions & 2 deletions .env.list
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ AUTH_LDAP_USER_ATTR_MAP=username=cn,display=displayname,email=email
CSRF_TRUSTED_ORIGINS=http://127.0.0.1:9123

# https://django-q.readthedocs.io/en/latest/configure.html#
Q_CLUISTER_WORKERS=4
Q_CLUISTER_TIMEOUT=60
Q_CLUSTER_WORKERS=4
Q_CLUSTER_TIMEOUT=60
Q_CLUISTER_SYNC=false

# https://djangocas.dev/docs/latest/
ENABLE_CAS=true
CAS_SERVER_URL=https://127.0.0.1
CAS_VERSION=2
SECURE_SSL_REDIRECT=false
15 changes: 7 additions & 8 deletions .github/workflows/django.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
strategy:
max-parallel: 4
matrix:
python-version: [3.8, 3.9, 3.10.0]
python-version: ["3.8", "3.9", "3.10", "3.11"]

# https://github.com/actions/example-services/tree/master/.github/workflows
services:
Expand Down Expand Up @@ -70,25 +70,24 @@ jobs:

- name: Install Dependencies
run: |
sudo apt-get update && sudo apt-get install libsasl2-dev python-dev libldap2-dev libssl-dev unixodbc unixodbc-dev
sudo apt-get update && sudo apt-get install libsasl2-dev libkrb5-dev libldap2-dev libssl-dev unixodbc unixodbc-dev
python -m pip install --upgrade pip
pip install codecov coverage flake8 -r requirements.txt
pip install -r requirements.txt
pip install -r dev-requirements.txt

- name: Init Table
run: |
mysql -h127.0.0.1 -uroot -e "CREATE DATABASE archery CHARSET UTF8MB4;"
mysql -h127.0.0.1 -uroot -e "DROP DATABASE IF EXISTS test_archery;CREATE DATABASE test_archery CHARSET UTF8MB4;"
mysql -h127.0.0.1 -uroot test_archery<src/init_sql/mysql_slow_query_review.sql


- name: Run Tests
run: |
python manage.py makemigrations
python manage.py makemigrations sql
coverage run manage.py test -v 3 --keepdb
coverage xml
pytest --cov --cov-report xml

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.xml
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ env
sonar-project.properties
.scannerwork
.env
local_settings.py
local_settings.py
src/docker-compose-dev
.coverage
archery_custom
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,18 @@
功能清单
====

| 数据库 | 查询 | 审核 | 执行 | 备份 | 数据字典 | 慢日志 | 会话管理 | 账号管理 | 参数管理 | 数据归档 |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| MySQL | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ |
| MsSQL | √ | × | √ | × | √ | × | × | × | × | × |
| Redis | √ | × | √ | × | × | × | × | × | × | × |
| PgSQL | √ | × | √ | × | × | × | × | × | × | × |
| Oracle | √ | √ | √ | √ | √ | × | × | × | × | × |
| MongoDB | √ | √ | √ | × | × | × | × | × | × | × |
| Phoenix | √ | × | √ | × | × | × | × | × | × | × |
| ODPS | √ | × | × | × | × | × | × | × | × | × |
| 数据库 | 查询 | 审核 | 执行 | 备份 | 数据字典 | 慢日志 | 会话管理 | 账号管理 | 参数管理 | 数据归档 |
|------------| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| MySQL | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ |
| MsSQL | √ | × | √ | × | √ | × | × | × | × | × |
| Redis | √ | × | √ | × | × | × | × | × | × | × |
| PgSQL | √ | × | √ | × | × | × | × | × | × | × |
| Oracle | √ | √ | √ | √ | √ | × | | × | × | × |
| MongoDB | √ | √ | √ | × | × | × | √ | √ | × | × |
| Phoenix | √ | × | √ | × | × | × | × | × | × | × |
| ODPS | √ | × | × | × | × | × | × | × | × | × |
| ClickHouse | √ | √ | √ | × | × | × | × | × | × | × |
| Cassandra | √ | × | √ | × | × | × | × | × | × | × |



Expand Down
2 changes: 1 addition & 1 deletion archery/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version = (1, 9, 1)
version = (1, 10, 0)
display_version = ".".join(str(i) for i in version)
165 changes: 164 additions & 1 deletion archery/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,30 @@
from typing import List
from datetime import timedelta
import environ
import requests
import logging

logging.basicConfig(
level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
)
logger = logging.getLogger(__name__)

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

environ.Env.read_env(os.path.join(BASE_DIR, ".env"))
env = environ.Env(
DEBUG=(bool, False),
ALLOWED_HOSTS=(List[str], ["*"]),
ALLOWED_HOSTS=(list, ["*"]),
SECRET_KEY=(str, "hfusaf2m4ot#7)fkw#di2bu6(cv0@opwmafx5n#6=3d%x^hpl6"),
DATABASE_URL=(str, "mysql://root:@127.0.0.1:3306/archery"),
CACHE_URL=(str, "redis://127.0.0.1:6379/0"),
# 系统外部认证目前支持LDAP、OIDC、DINGDING三种,认证方式只能启用其中一种,如果启用多个,实际生效的只有一个,优先级LDAP > DINGDING > OIDC
ENABLE_LDAP=(bool, False),
ENABLE_OIDC=(bool, False),
ENABLE_DINGDING=(
bool,
False,
), # 钉钉认证方式参考文档:https://open.dingtalk.com/document/orgapp/tutorial-obtaining-user-personal-information
AUTH_LDAP_ALWAYS_UPDATE_USER=(bool, True),
AUTH_LDAP_USER_ATTR_MAP=(
dict,
Expand All @@ -25,6 +38,36 @@
Q_CLUISTER_SYNC=(bool, False), # qcluster 同步模式, debug 时可以调整为 True
# CSRF_TRUSTED_ORIGINS=subdomain.example.com,subdomain.example2.com subdomain.example.com
CSRF_TRUSTED_ORIGINS=(list, []),
ENABLED_ENGINES=(
list,
[
"mysql",
"clickhouse",
"goinception",
"mssql",
"redis",
"pgsql",
"oracle",
"mongo",
"phoenix",
"odps",
"cassandra",
],
),
ENABLED_NOTIFIERS=(
list,
[
"sql.notify:DingdingWebhookNotifier",
"sql.notify:DingdingPersonNotifier",
"sql.notify:FeishuWebhookNotifier",
"sql.notify:FeishuPersonNotifier",
"sql.notify:QywxWebhookNotifier",
"sql.notify:QywxToUserNotifier",
"sql.notify:MailNotifier",
"sql.notify:GenericWebhookNotifier",
],
),
CURRENT_AUDITOR=(str, "sql.utils.workflow_audit:AuditV2"),
)

# SECURITY WARNING: keep the secret key used in production secret!
Expand All @@ -44,6 +87,26 @@
# 请求限制
DATA_UPLOAD_MAX_MEMORY_SIZE = 15728640

AVAILABLE_ENGINES = {
"mysql": {"path": "sql.engines.mysql:MysqlEngine"},
"cassandra": {"path": "sql.engines.cassandra:CassandraEngine"},
"clickhouse": {"path": "sql.engines.clickhouse:ClickHouseEngine"},
"goinception": {"path": "sql.engines.goinception:GoInceptionEngine"},
"mssql": {"path": "sql.engines.mssql:MssqlEngine"},
"redis": {"path": "sql.engines.redis:RedisEngine"},
"pgsql": {"path": "sql.engines.pgsql:PgSQLEngine"},
"oracle": {"path": "sql.engines.oracle:OracleEngine"},
"mongo": {"path": "sql.engines.mongo:MongoEngine"},
"phoenix": {"path": "sql.engines.phoenix:PhoenixEngine"},
"odps": {"path": "sql.engines.odps:ODPSEngine"},
}

ENABLED_NOTIFIERS = env("ENABLED_NOTIFIERS")

ENABLED_ENGINES = env("ENABLED_ENGINES")

CURRENT_AUDITOR = env("CURRENT_AUDITOR")

# Application definition
INSTALLED_APPS = (
"django.contrib.admin",
Expand Down Expand Up @@ -228,6 +291,49 @@
"AUTH_HEADER_TYPES": ("Bearer",),
}

# OIDC
ENABLE_OIDC = env("ENABLE_OIDC", False)
if ENABLE_OIDC:
INSTALLED_APPS += ("mozilla_django_oidc",)
AUTHENTICATION_BACKENDS = (
"common.authenticate.oidc_auth.OIDCAuthenticationBackend",
"django.contrib.auth.backends.ModelBackend",
)

OIDC_RP_WELLKNOWN_URL = env(
"OIDC_RP_WELLKNOWN_URL"
) # 例如 https://keycloak.example.com/realms/<your realm>/.well-known/openid-configuration
OIDC_RP_CLIENT_ID = env("OIDC_RP_CLIENT_ID")
OIDC_RP_CLIENT_SECRET = env("OIDC_RP_CLIENT_SECRET")

response = requests.get(OIDC_RP_WELLKNOWN_URL)
response.raise_for_status()
config = response.json()
OIDC_OP_AUTHORIZATION_ENDPOINT = config["authorization_endpoint"]
OIDC_OP_TOKEN_ENDPOINT = config["token_endpoint"]
OIDC_OP_USER_ENDPOINT = config["userinfo_endpoint"]
OIDC_OP_JWKS_ENDPOINT = config["jwks_uri"]
OIDC_OP_LOGOUT_ENDPOINT = config["end_session_endpoint"]

OIDC_RP_SCOPES = env("OIDC_RP_SCOPES", default="openid profile email")
OIDC_RP_SIGN_ALGO = env("OIDC_RP_SIGN_ALGO", default="RS256")

LOGIN_REDIRECT_URL = "/"

# Dingding
ENABLE_DINGDING = env("ENABLE_DINGDING", False)
if ENABLE_DINGDING:
INSTALLED_APPS += ("django_auth_dingding",)
AUTHENTICATION_BACKENDS = (
"common.authenticate.dingding_auth.DingdingAuthenticationBackend",
"django.contrib.auth.backends.ModelBackend",
)
AUTH_DINGDING_AUTHENTICATION_CALLBACK_URL = env(
"AUTH_DINGDING_AUTHENTICATION_CALLBACK_URL"
)
AUTH_DINGDING_APP_KEY = env("AUTH_DINGDING_APP_KEY")
AUTH_DINGDING_APP_SECRET = env("AUTH_DINGDING_APP_SECRET")

# LDAP
ENABLE_LDAP = env("ENABLE_LDAP", False)
if ENABLE_LDAP:
Expand Down Expand Up @@ -261,6 +367,58 @@
) # 每次登录从ldap同步用户信息
AUTH_LDAP_USER_ATTR_MAP = env("AUTH_LDAP_USER_ATTR_MAP")

# CAS认证
ENABLE_CAS = env("ENABLE_CAS", default=False)
if ENABLE_CAS:
INSTALLED_APPS += ("django_cas_ng",)
MIDDLEWARE += ("django_cas_ng.middleware.CASMiddleware",)
AUTHENTICATION_BACKENDS = (
"django.contrib.auth.backends.ModelBackend",
"django_cas_ng.backends.CASBackend",
)

# CAS 的地址
CAS_SERVER_URL = env("CAS_SERVER_URL")
# CAS 版本
CAS_VERSION = env("CAS_VERSION")
# 存入所有 CAS 服务端返回的 User 数据。
CAS_APPLY_ATTRIBUTES_TO_USER = True
# 关闭浏览器退出登录
SESSION_EXPIRE_AT_BROWSER_CLOSE = True
# 忽略 SSL 证书校验
CAS_VERIFY_SSL_CERTIFICATE = env("CAS_VERIFY_SSL_CERTIFICATE", default=False)
# 忽略来源验证
CAS_IGNORE_REFERER = True
# https请求问题
CAS_FORCE_SSL_SERVICE_URL = env("CAS_FORCE_SSL_SERVICE_URL", default=False)
CAS_RETRY_TIMEOUT = 1
CAS_RETRY_LOGIN = True
CAS_EXTRA_LOGIN_PARAMS = {"renew": True}
CAS_LOGOUT_COMPLETELY = True

SUPPORTED_AUTHENTICATION = [
("LDAP", ENABLE_LDAP),
("DINGDING", ENABLE_DINGDING),
("OIDC", ENABLE_OIDC),
("CAS", ENABLE_CAS),
]
# 计算当前启用的外部认证方式数量
ENABLE_AUTHENTICATION_COUNT = len(
[enabled for (name, enabled) in SUPPORTED_AUTHENTICATION if enabled]
)
if ENABLE_AUTHENTICATION_COUNT > 0:
if ENABLE_AUTHENTICATION_COUNT > 1:
logger.warning(
"系统外部认证目前支持LDAP、DINGDING、OIDC、CAS四种,认证方式只能启用其中一种,如果启用多个,实际生效的只有一个,优先级LDAP > DINGDING > OIDC > CAS"
)
authentication = "" # 默认为空
for name, enabled in SUPPORTED_AUTHENTICATION:
if enabled:
authentication = name
break
logger.info("当前生效的外部认证方式:" + authentication)
logger.info("认证后端:" + AUTHENTICATION_BACKENDS.__str__())

# LOG配置
LOGGING = {
"version": 1,
Expand Down Expand Up @@ -308,6 +466,11 @@
"level": "WARNING",
"propagate": False,
},
"mozilla_django_oidc": {
"handlers": ["console", "default"],
"level": "WARNING",
"propagate": False,
},
# 'django.db': { # 打印SQL语句,方便开发
# 'handlers': ['console', 'default'],
# 'level': 'DEBUG',
Expand Down
22 changes: 22 additions & 0 deletions archery/urls.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
from django.urls import include, path
from django.contrib import admin
from common import views
from django.conf import settings

urlpatterns = [
path("admin/", admin.site.urls),
path("api/", include(("sql_api.urls", "sql_api"), namespace="sql_api")),
path("", include(("sql.urls", "sql"), namespace="sql")),
]

if settings.ENABLE_CAS: # pragma: no cover
import django_cas_ng.views

urlpatterns += [
path(
"cas/authenticate/",
django_cas_ng.views.LoginView.as_view(),
name="cas-login",
),
] # pragma: no cover

if settings.ENABLE_OIDC: # pragma: no cover
urlpatterns += [
path("oidc/", include("mozilla_django_oidc.urls")),
]

if settings.ENABLE_DINGDING: # pragma: no cover
urlpatterns += [
path("dingding/", include("django_auth_dingding.urls")),
]

handler400 = views.bad_request
handler403 = views.permission_denied
handler404 = views.page_not_found
Expand Down
7 changes: 7 additions & 0 deletions common/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from django.http import HttpResponse, HttpResponseRedirect
from django.urls import reverse

from django.conf import settings
from common.config import SysConfig
from common.utils.ding_api import get_ding_user_id
from sql.models import Users, ResourceGroup, TwoFactorAuthConfig
Expand Down Expand Up @@ -201,5 +202,11 @@ def sign_up(request):

# 退出登录
def sign_out(request):
user = request.user
logout(request)
# 如果开启了钉钉认证,重定向到钉钉退出登录页面
if user.ding_user_id and settings.ENABLE_DINGDING:
return HttpResponseRedirect(
redirect_to="https://login.dingtalk.com/oauth2/logout"
)
return HttpResponseRedirect(reverse("sql:login"))
Empty file added common/authenticate/__init__.py
Empty file.
10 changes: 10 additions & 0 deletions common/authenticate/dingding_auth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django_auth_dingding import auth
from common.auth import init_user


class DingdingAuthenticationBackend(auth.DingdingAuthenticationBackend):
def create_user(self, claims):
"""Return object for a newly created user account."""
user = super().create_user(claims)
init_user(user)
return user
Loading
Loading