Stop using global state to store configuration options
还没有人认领这个 Issue。
- #309 来自 @rudi193-cmd —— 已关闭,未合并
评估
调研方向
首先阅读 codejail.jail_code.COMMANDS 和 configure,然后检查用于填充配置的 codejail.django_integration middleware。确定并实现一种非全局配置设计,使重复配置不受单元测试顺序影响,并在不同 Python 进程之间保持行为一致。
由索引模型根据 Issue 内容生成。
描述
Codejail has a global variable at codejail.jail_code.COMMANDS. It's a dictionary that maps command names (like "python") to safe shell commands. An example value is:
{'python': {'cmdline_start': ['/edx/app/edxapp/venvs/edxapp-sandbox/bin/python', '-E', '-B'], 'user': 'sandbox'}}
The dictionary is populated by calling codejail.jail_code.configure, which is generally done via the codejail.django_integration middleware.
This all works fine, but the fact that COMMANDS is a global variable is not idiomatic Python. More concretely, it's a pain in the neck for unit tests: the order and timing with which unit tests are run will affect whether .configure has been called or not. This could also cause problems across Python processes in production, leading to situations where codejail is configured in one process but effectively disabled in another process without anyone knowing. Not good.
This stateful system also forces us to use a middleware in order to configure codejail in Django--that's another layer where something could go wrong.
I recommend replacing COMMANDS with either:
- a stateless function named
load_commands(), which is safe to call over and over again, which does something like this:try: from django.conf import settings except ImportError, AttributeError settings = {} if settings.get('CODE_JAIL'): return _load_command_from_django_settings(settings) else: # .... load alternative/fallback configuration options, if we're not using Django - putting the entire Codejail interface behind a class, so clients would need to pass the settings into it, like this:
from django.conf import settings codejail = CodeJail(some_setting=settings.CODEJAIL[...], etc..) codejail.safe_exec(...)
- 主要语言
- Python
- 星标
- 477
- 派生
- 83
- 平均合并
- 1 天 8 小时
- 30 天内合并 PR
- 6
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
openedx/codejail 的其他 Issue
-
难度 4/5 3-5 天 新手友好度 35/100
-
难度 2/5 1-3 小时 新手友好度 50/100
-
难度 3/5 1-2 天 新手友好度 30/100
-
难度 4/5 3-5 天 新手友好度 35/100
-
难度 3/5 1-2 天 新手友好度 35/100
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 64/100
-
难度 2/5 1-3 小时 新手友好度 76/100
btclib-org/btclib-wallet#1045 ·
维护者通常 1 天内回复
-
area-templates triage:bot-seen triage:needs-human
难度 2/5 1-3 小时 新手友好度 75/100
microsoft/aspire#22356 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
[Train] An elastic ScalingConfig(num_workers=(0, 0)) is accepted and the run waits forever可能已有人在做 @wguo7 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 75/100
ray-project/ray#68217 ·
维护者通常 2 天内回复