mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-05-31 01:45:10 +00:00
Modify the backend so that instead of using the server owner's QRZ & HamQTH credentials, it instead requires them to be provided by the client (if none are provided, the lookups do not occur.)
This commit is contained in:
27
data/lookup_credentials.py
Normal file
27
data/lookup_credentials.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from dataclasses import dataclass
|
||||
|
||||
|
||||
@dataclass
|
||||
class LookupCredentials:
|
||||
"""Per-request credentials for QRZ.com and HamQTH online callsign lookups."""
|
||||
qrz_username: str = ""
|
||||
qrz_password: str = ""
|
||||
qrz_session_key: str = "" # alternative to username/password
|
||||
hamqth_username: str = ""
|
||||
hamqth_password: str = ""
|
||||
hamqth_session_id: str = "" # alternative to username/password
|
||||
|
||||
|
||||
def extract_credentials(query_params):
|
||||
"""Build a LookupCredentials from HTTP query params; returns None if no usable credentials are present."""
|
||||
creds = LookupCredentials(
|
||||
qrz_username=query_params.get("qrz_username", ""),
|
||||
qrz_password=query_params.get("qrz_password", ""),
|
||||
qrz_session_key=query_params.get("qrz_session_key", ""),
|
||||
hamqth_username=query_params.get("hamqth_username", ""),
|
||||
hamqth_password=query_params.get("hamqth_password", ""),
|
||||
hamqth_session_id=query_params.get("hamqth_session_id", ""),
|
||||
)
|
||||
has_qrz = creds.qrz_session_key or (creds.qrz_username and creds.qrz_password)
|
||||
has_hamqth = creds.hamqth_session_id or (creds.hamqth_username and creds.hamqth_password)
|
||||
return creds if (has_qrz or has_hamqth) else None
|
||||
Reference in New Issue
Block a user