feat: Integrate `licaeros` library for licensed AEROS API calls, centralizing request logic in `aeros_utils.py` and updating services to use it.
parent
e740b46612
commit
d6d6ab3631
@ -0,0 +1,32 @@
|
||||
import anyio
|
||||
from licaeros import LicensedSession, device_fingerprint_hex
|
||||
from src.config import AEROS_BASE_URL, AEROS_LICENSE_ID, AEROS_LICENSE_SECRET
|
||||
import logging
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
# Initialize a global session if possible, or create on demand
|
||||
_aeros_session = None
|
||||
|
||||
def get_aeros_session():
|
||||
global _aeros_session
|
||||
if _aeros_session is None:
|
||||
log.info(f"Initializing LicensedSession with base URL: {AEROS_BASE_URL}")
|
||||
log.info(f"Encrypted Device ID: {device_fingerprint_hex()}")
|
||||
_aeros_session = LicensedSession(
|
||||
api_base=AEROS_BASE_URL,
|
||||
license_id=AEROS_LICENSE_ID,
|
||||
license_secret=AEROS_LICENSE_SECRET,
|
||||
)
|
||||
return _aeros_session
|
||||
|
||||
async def aeros_post(path: str, json: dict = None, **kwargs):
|
||||
"""
|
||||
Asynchronous wrapper for LicensedSession.post
|
||||
"""
|
||||
session = get_aeros_session()
|
||||
# LicensedSession might not be async-compatible, so we run it in a thread
|
||||
response = await anyio.to_thread.run_sync(
|
||||
lambda: session.post(path, json)
|
||||
)
|
||||
return response
|
||||
Loading…
Reference in New Issue