✨ qBittorrent: identifiants optionnels via bypass d'authentification (pas d'API key native)
This commit is contained in:
1 parent
95e5ead67a
commit
e8bbbc7d1e
5 files changed
+48
-9
No files matched your search
+8
-1
@@ -204,7 +204,7 @@ async def test_radarr() -> ConnectionResult:
|
|||||||
def qbittorrent_from_config() -> QbittorrentClient:
|
def qbittorrent_from_config() -> QbittorrentClient:
|
||||||
qb = read_config().qbittorrent
|
qb = read_config().qbittorrent
|
||||||
url = build_base_url(qb.url, qb.port)
|
url = build_base_url(qb.url, qb.port)
|
||||||
if not url or not qb.username or not qb.password:
|
if not url:
|
||||||
raise HTTPException(status_code=409, detail="La connexion qBittorrent n'est pas configurée")
|
raise HTTPException(status_code=409, detail="La connexion qBittorrent n'est pas configurée")
|
||||||
return QbittorrentClient(url, qb.username, qb.password)
|
return QbittorrentClient(url, qb.username, qb.password)
|
||||||
|
|
||||||
@@ -230,6 +230,13 @@ def put_qbittorrent_settings(payload: QbittorrentSettingsWrite) -> QbittorrentSe
|
|||||||
cfg.qbittorrent.username = payload.username
|
cfg.qbittorrent.username = payload.username
|
||||||
if payload.password:
|
if payload.password:
|
||||||
cfg.qbittorrent.password = payload.password
|
cfg.qbittorrent.password = payload.password
|
||||||
|
elif payload.password:
|
||||||
|
# Mot de passe seul: on conserve l'utilisateur existant.
|
||||||
|
cfg.qbittorrent.password = payload.password
|
||||||
|
else:
|
||||||
|
# Champs vides: mode bypass d'authentification qBittorrent, sans identifiants.
|
||||||
|
cfg.qbittorrent.username = None
|
||||||
|
cfg.qbittorrent.password = None
|
||||||
write_config(cfg)
|
write_config(cfg)
|
||||||
return QbittorrentSettingsRead(
|
return QbittorrentSettingsRead(
|
||||||
url=cfg.qbittorrent.url,
|
url=cfg.qbittorrent.url,
|
||||||
|
|||||||
+8
-1
@@ -6,13 +6,20 @@ import httpx
|
|||||||
|
|
||||||
|
|
||||||
class QbittorrentClient:
|
class QbittorrentClient:
|
||||||
def __init__(self, url: str, username: str, password: str) -> None:
|
"""Client WebUI (API v2). Identifiants optionnels: sans eux, aucun login
|
||||||
|
n'est effectue — qBittorrent doit alors autoriser la plage IP (bypass
|
||||||
|
d'authentification), car il n'existe pas d'API key cote qBittorrent."""
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self, url: str, username: str | None = None, password: str | None = None
|
||||||
|
) -> None:
|
||||||
self._url = url.rstrip("/")
|
self._url = url.rstrip("/")
|
||||||
self._username = username
|
self._username = username
|
||||||
self._password = password
|
self._password = password
|
||||||
|
|
||||||
async def _request(self, method: str, endpoint: str, **kwargs) -> httpx.Response:
|
async def _request(self, method: str, endpoint: str, **kwargs) -> httpx.Response:
|
||||||
async with httpx.AsyncClient(timeout=30) as client:
|
async with httpx.AsyncClient(timeout=30) as client:
|
||||||
|
if self._username and self._password:
|
||||||
login = await client.post(
|
login = await client.post(
|
||||||
f"{self._url}/api/v2/auth/login",
|
f"{self._url}/api/v2/auth/login",
|
||||||
data={"username": self._username, "password": self._password},
|
data={"username": self._username, "password": self._password},
|
||||||
|
|||||||
+2
-1
@@ -37,7 +37,8 @@ class QbittorrentSettingsRead(BaseModel):
|
|||||||
class QbittorrentSettingsWrite(BaseModel):
|
class QbittorrentSettingsWrite(BaseModel):
|
||||||
url: str | None = None
|
url: str | None = None
|
||||||
port: int | None = Field(default=None, ge=1, le=65535)
|
port: int | None = Field(default=None, ge=1, le=65535)
|
||||||
username: str | None = Field(default=None, min_length=1)
|
# Utilisateur vide = bypass d'authentification qBittorrent.
|
||||||
|
username: str | None = None
|
||||||
password: str | None = Field(default=None, min_length=1)
|
password: str | None = Field(default=None, min_length=1)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -102,6 +102,28 @@ def test_qbittorrent_connection_local_address_with_port() -> None:
|
|||||||
assert test.json()["version"] == "v5.0.2"
|
assert test.json()["version"] == "v5.0.2"
|
||||||
|
|
||||||
|
|
||||||
|
@respx.mock
|
||||||
|
def test_qbittorrent_connection_without_credentials() -> None:
|
||||||
|
"""Sans identifiants (bypass d'authentification qBittorrent): aucun login,
|
||||||
|
l'API est appelee directement."""
|
||||||
|
respx.post("http://192.168.1.50:8555/api/v2/auth/login").mock(
|
||||||
|
return_value=Response(404)
|
||||||
|
)
|
||||||
|
respx.get("http://192.168.1.50:8555/api/v2/app/version").mock(
|
||||||
|
return_value=Response(200, text="v5.0.2")
|
||||||
|
)
|
||||||
|
with TestClient(app) as client:
|
||||||
|
put = client.put(
|
||||||
|
"/api/settings/qbittorrent",
|
||||||
|
json={"url": "192.168.1.50", "port": 8555, "username": "", "password": None},
|
||||||
|
)
|
||||||
|
assert put.status_code == 200
|
||||||
|
assert put.json()["password_configured"] is False
|
||||||
|
test = client.post("/api/settings/qbittorrent/test")
|
||||||
|
assert test.status_code == 200
|
||||||
|
assert test.json()["version"] == "v5.0.2"
|
||||||
|
|
||||||
|
|
||||||
def test_settings_persist_to_conf_json() -> None:
|
def test_settings_persist_to_conf_json() -> None:
|
||||||
with TestClient(app) as client:
|
with TestClient(app) as client:
|
||||||
put = client.put(
|
put = client.put(
|
||||||
|
|||||||
+8
-6
@@ -987,21 +987,23 @@ export default function App() {
|
|||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
<label>
|
<label>
|
||||||
Utilisateur
|
Utilisateur (optionnel)
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
required
|
placeholder="admin — vide = bypass qBittorrent"
|
||||||
placeholder="admin"
|
|
||||||
value={qbitUsername}
|
value={qbitUsername}
|
||||||
onChange={(event) => setQbitUsername(event.target.value)}
|
onChange={(event) => setQbitUsername(event.target.value)}
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
<label>
|
<label>
|
||||||
Mot de passe
|
Mot de passe (optionnel)
|
||||||
<input
|
<input
|
||||||
type="password"
|
type="password"
|
||||||
required={!qbitConfigured}
|
placeholder={
|
||||||
placeholder={qbitConfigured ? "Configuré — laisser vide pour conserver" : "Mot de passe WebUI"}
|
qbitConfigured
|
||||||
|
? "Configuré — laisser vide pour conserver, tout vider = bypass"
|
||||||
|
: "Vide = bypass d'authentification qBittorrent"
|
||||||
|
}
|
||||||
value={qbitPassword}
|
value={qbitPassword}
|
||||||
onChange={(event) => setQbitPassword(event.target.value)}
|
onChange={(event) => setQbitPassword(event.target.value)}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in new issue
Block a user