Browse Source

🔒 Security fix: docs_src/app_testing/app_b_an_py310/main.py

修复了硬编码密码的问题,使用环境变量来存储敏感信息。代码现在从环境变量中读取 `FAKE_SECRET_TOKEN` 的值,并在未设置该变量时抛出异常。这样避免了将敏感信息直接写入源代码中。
pull/15602/head
Wulan Ramadhani 2 weeks ago
parent
commit
d9105e1a26
  1. 18
      docs_src/app_testing/app_b_an_py310/main.py

18
docs_src/app_testing/app_b_an_py310/main.py

@ -1,3 +1,21 @@
import os
from fastapi import FastAPI, Header, HTTPException
from pydantic import BaseModel
fake_secret_token = os.getenv("FAKE_SECRET_TOKEN")
if not fake_secret_token:
raise RuntimeError("Environment variable FAKE_SECRET_TOKEN is not set.")
fake_db = {
"foo": {"id": "foo", "title": "Foo", "description": "There goes my hero"},
"bar": {"id": "bar", "title": "Bar", "description": "The bartenders"},
}
app = FastAPI()
class Item(BaseModel):
pass
from typing import Annotated
from fastapi import FastAPI, Header, HTTPException

Loading…
Cancel
Save