Skip to content

Commit

Permalink
添加全局环境变量配置 (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-clan authored Aug 1, 2024
1 parent 03a973c commit 14dd6f1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions httpfpt/core/conf.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ send = false

# 请求发送
[request]
global_env = 'dev.env'
timeout = 10
verify = false
redirects = true
Expand Down
1 change: 1 addition & 0 deletions httpfpt/core/get_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def __init__(self) -> None:
self.WECHAT_SEND = glom(self.settings, 'wechat.send')

# 请求发送
self.REQUEST_GLOBAL_ENV = glom(self.settings, 'request.global_env')
self.REQUEST_TIMEOUT = glom(self.settings, 'request.timeout')
self.REQUEST_VERIFY = glom(self.settings, 'request.verify')
self.REQUEST_REDIRECTS = glom(self.settings, 'request.redirects')
Expand Down
10 changes: 9 additions & 1 deletion httpfpt/utils/request/request_data_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from httpfpt.common.env_handler import get_env_dict
from httpfpt.common.errors import RequestDataParseError
from httpfpt.common.log import log
from httpfpt.core.get_conf import httpfpt_config
from httpfpt.core.path_conf import httpfpt_path
from httpfpt.db.mysql_db import mysql_client
from httpfpt.enums.allure_severity_type import SeverityType
Expand Down Expand Up @@ -112,10 +113,17 @@ def allure_severity(self) -> str | None:

@property
def env(self) -> str:
env = httpfpt_config.REQUEST_GLOBAL_ENV
if env:
if not isinstance(env, str):
raise RequestDataParseError(_error_msg('配置文件参数 conf.toml:request:global_env 不是有效的 str 类型'))
if not env.endswith('.env'):
raise RequestDataParseError(_error_msg('配置文件参数 conf.toml:request:global_env 输入不合法'))
return env
try:
env = self.request_data['config']['request']['env']
except _RequestDataParamGetError:
raise RequestDataParseError(_error_msg('缺少 config:request:env 参数'))
raise RequestDataParseError(_error_msg('缺少 conf.toml:request:global_env 或 config:request:env 参数'))
else:
if env is None:
raise RequestDataParseError(_error_msg('参数 config:request:env 为空'))
Expand Down

0 comments on commit 14dd6f1

Please sign in to comment.