Skip to content

Commit 1264eb2

Browse files
committed
feat!: 令牌环境变量改名 QODER_ACCESS_TOKEN -> QODER_PAT
与 examples 已在用的 QODER_FORWARD_PAT / QODER_MANAGED_PAT 统一为 PAT 口径;构造参数仍是 access_token,不随环境变量改名。
1 parent 01ace80 commit 1264eb2

5 files changed

Lines changed: 7 additions & 7 deletions

File tree

.env.live.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ QODER_MANAGED_BASE_URL=https://api.qoder.com.cn/api/v1/cloud
88
QODER_MANAGED_MODEL=
99

1010
# Optional fallback for either mode.
11-
QODER_ACCESS_TOKEN=
11+
QODER_PAT=
1212

1313
# pytest live tests require explicit opt-in in the process environment:
1414
# QODER_RUN_LIVE=1 python -m pytest examples -m live -v

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Both clients read their token from the environment. `from qca.forward import Cli
4646

4747
| Setting | Forward | Managed |
4848
|---|---|---|
49-
| Token | `QODER_ACCESS_TOKEN` | `QODER_ACCESS_TOKEN` |
49+
| Token | `QODER_PAT` | `QODER_PAT` |
5050
| Base URL | `QODER_FORWARD_BASE_URL` | `QODER_MANAGED_BASE_URL` |
5151
| Default base URL | `https://api.qoder.com/api/v1/forward/` | `https://api.qoder.com/api/v1/cloud/` |
5252

examples/common/live.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ class Config:
6666
def load(cls, mode: str, *, env_file: str = ".env.live", region: str | None = None, timeout: float = 300) -> Config:
6767
values = {**read_env(env_file), **os.environ}
6868
prefix = f"QODER_{mode.upper()}_"
69-
token = values.get(prefix + "PAT") or values.get("QODER_ACCESS_TOKEN", "")
69+
token = values.get(prefix + "PAT") or values.get("QODER_PAT", "")
7070
if not token:
71-
raise ValueError(f"Configure {prefix}PAT or QODER_ACCESS_TOKEN")
71+
raise ValueError(f"Configure {prefix}PAT or QODER_PAT")
7272
suffix = "forward" if mode == "forward" else "cloud"
7373
base = values.get(prefix + "BASE_URL") or f"https://api.qoder.com.cn/api/v1/{suffix}"
7474
url = httpx.URL(base)

src/qca/common/_base_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def _configure(
5454
) -> None:
5555
if not isinstance(max_retries, int) or isinstance(max_retries, bool) or max_retries < 0:
5656
raise ValueError("max_retries must be a non-negative integer")
57-
self.access_token = access_token if access_token is not None else os.environ.get("QODER_ACCESS_TOKEN")
57+
self.access_token = access_token if access_token is not None else os.environ.get("QODER_PAT")
5858
self.credential = credential
5959
self.base_url = httpx.URL(base_url or os.environ.get(self._base_url_env) or self._default_base_url)
6060
if self.base_url.scheme not in ("http", "https") or not self.base_url.host or self.base_url.userinfo:

tests/test_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def make_client(handler, cls=Forward, **kwargs):
4444
"cls,env,suffix", [(Forward, "QODER_FORWARD_BASE_URL", "forward"), (Managed, "QODER_MANAGED_BASE_URL", "cloud")]
4545
)
4646
def test_environment_defaults_and_explicit_precedence(monkeypatch, cls, env, suffix):
47-
monkeypatch.setenv("QODER_ACCESS_TOKEN", "from-env")
47+
monkeypatch.setenv("QODER_PAT", "from-env")
4848
monkeypatch.setenv(env, f"https://configured.test/api/v1/{suffix}")
4949
with cls() as client:
5050
assert client.access_token == "from-env"
@@ -226,7 +226,7 @@ def handle(request):
226226

227227

228228
def test_dynamic_credentials_refresh_and_explicit_headers(monkeypatch):
229-
monkeypatch.delenv("QODER_ACCESS_TOKEN", raising=False)
229+
monkeypatch.delenv("QODER_PAT", raising=False)
230230
monkeypatch.setattr("qca.common._base_client.time.sleep", lambda _: None)
231231

232232
class Rotating:

0 commit comments

Comments
 (0)