forked from wuranxu/pity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
executable file
·142 lines (105 loc) · 3.76 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# 基础配置类
import os
from typing import List
from pydantic import BaseSettings
ROOT = os.path.dirname(os.path.abspath(__file__))
class BaseConfig(BaseSettings):
LOG_DIR = os.path.join(ROOT, 'logs')
LOG_NAME = os.path.join(LOG_DIR, 'pity.log')
SERVER_HOST: str = "0.0.0.0"
SERVER_PORT: int
HEARTBEAT: int = 48
# mock server
MOCK_ON: bool
PROXY_ON: bool
PROXY_PORT: int
MYSQL_HOST: str
MYSQL_PORT: int
MYSQL_USER: str
MYSQL_PWD: str
DBNAME: str
# WARNING: close redis can make job run multiple times at the same time
REDIS_ON: bool
REDIS_HOST: str
REDIS_PORT: int
REDIS_DB: int
REDIS_PASSWORD: str
# Redis连接信息
REDIS_NODES: List[dict] = []
# sqlalchemy
SQLALCHEMY_DATABASE_URI: str = ''
# 异步URI
ASYNC_SQLALCHEMY_URI: str = ''
SQLALCHEMY_TRACK_MODIFICATIONS = False
# 权限 0 普通用户 1 组长 2 管理员
MEMBER = 0
MANAGER = 1
ADMIN = 2
# github access_token地址
GITHUB_ACCESS = "https://github.com/login/oauth/access_token"
# github获取用户信息
GITHUB_USER = "https://api.github.com/user"
# client_id
CLIENT_ID: str
# SECRET
SECRET_KEY: str
# 测试报告路径
REPORT_PATH = os.path.join(ROOT, "templates", "report.html")
# 重置密码路径
PASSWORD_HTML_PATH = os.path.join(ROOT, "templates", "reset_password.html")
# APP 路径
APP_PATH = os.path.join(ROOT, "app")
# dao路径
DAO_PATH = os.path.join(APP_PATH, 'crud')
# markdown地址
MARKDOWN_PATH = os.path.join(ROOT, 'templates', "markdown")
SERVER_REPORT = "http://localhost:8000/#/record/report/"
OSS_URL = "http://oss.pity.fun"
# 七牛云链接地址,如果采用七牛oss,需要自行替换
QINIU_URL = "https://static.pity.fun"
RELATION = "pity_relation"
ALIAS = "__alias__"
TABLE_TAG = "__tag__"
# 数据库表展示的变更字段
FIELD = "__fields__"
SHOW_FIELD = "__show__"
IGNORE_FIELDS = ('created_at', "updated_at", "deleted_at", "create_user", "update_user")
# 测试计划中,case默认重试次数
RETRY_TIMES = 1
# 日志名
PITY_ERROR = "pity_error"
PITY_INFO = "pity_info"
class DevConfig(BaseConfig):
class Config:
env_file = os.path.join(ROOT, "conf", "dev.env")
class ProConfig(BaseConfig):
class Config:
env_file = os.path.join(ROOT, "conf", "pro.env")
SERVER_REPORT = "https://pity.fun/#/record/report/"
SERVER_HOST = "127.0.0.1"
# 获取pity环境变量
PITY_ENV = os.environ.get("pity_env", "dev")
# 如果pity_env存在且为prod
Config = ProConfig() if PITY_ENV and PITY_ENV.lower() == "pro" else DevConfig()
# init redis
Config.REDIS_NODES = [
{
"host": Config.REDIS_HOST, "port": Config.REDIS_PORT, "db": Config.REDIS_DB, "password": Config.REDIS_PASSWORD
}
]
# init sqlalchemy (used by apscheduler)
Config.SQLALCHEMY_DATABASE_URI = 'mysql+mysqlconnector://{}:{}@{}:{}/{}'.format(
Config.MYSQL_USER, Config.MYSQL_PWD, Config.MYSQL_HOST, Config.MYSQL_PORT, Config.DBNAME)
# init async sqlalchemy
Config.ASYNC_SQLALCHEMY_URI = f'mysql+aiomysql://{Config.MYSQL_USER}:{Config.MYSQL_PWD}' \
f'@{Config.MYSQL_HOST}:{Config.MYSQL_PORT}/{Config.DBNAME}'
BANNER = """
________ ___ _________ ___ ___
|\ __ \ |\ \ |\___ ___\ |\ \ / /|
\ \ \|\ \ \ \ \ \|___ \ \_| \ \ \/ / /
\ \ ____\ \ \ \ \ \ \ \ \ / /
\ \ \___| \ \ \ \ \ \ \/ / /
\ \__\ \ \__\ \ \__\ __/ / /
\|__| \|__| \|__| |\___/ /
\|___|/
"""