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

feat: support parse config file with Variable Expansion for some secret keys #342

Merged
merged 1 commit into from
Jun 16, 2023

Conversation

zthxxx
Copy link
Collaborator

@zthxxx zthxxx commented Jun 15, 2023

根据早期讨论的提案 -> 在配置文件中对敏感 token 支持环境变量语法声明

实现与改动

本 PR 增加支持的配置项包括:

  • downloader.username
  • downloader.password
  • rss_parser.token
  • notification.token
  • notification.chat_id
  • proxy.username
  • proxy.password

本次实现对代码中所有使用处无感无改动,实现原理:

  • pydantic Model 上使用 @property getter 字段,通过原生 expandvars 方法做 shell 变量扩展(Variable expansion),

    用于支持原本形如 settings.rss_parser.token 直接访问的用法

  • 对于 pydantic Field 字段添加 alias 字段支持,并对 dict() 方法添加默认 by_alias 参数,

    用于 Model 的序列化和反序列化过程中字段名称正确,以支持如下几种使用方式:

    • settings.dict()
    • Config.parse_obj()
    • settings.__dict__.update()

这总体使得所有访问值的地方(形如 settings.rss_parser.token ) 都能获取到展开后具体环境变量的值,

而通过 settings.dict() 给到 WebUI 和保存配置的是原始字符串 ${XXXX_VAR}

.gitattributes Show resolved Hide resolved
.gitignore Show resolved Hide resolved
backend/dev.sh Show resolved Hide resolved
.vscode/setttings.json Outdated Show resolved Hide resolved
Copy link
Owner

@EstrellaXD EstrellaXD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Backend reviewed, Need do some test. Wait for webui test.

@EstrellaXD EstrellaXD merged commit 7eb00bf into EstrellaXD:3.1-dev Jun 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants